saltyim is the Go library and reference client and broker implementation for Salty IM it contains a command-line client (cli), a terminal user interface (tui), builtin server/broker and a Mobile / Desktop App PWA (progressive web app) https://salty.im/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
saltyim/format_test.go

48 lines
1.1 KiB

package saltyim_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mills.io/saltyim"
"go.yarn.social/lextwt"
)
func TestFormatMessage(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
me, err := saltyim.ParseAddr(userAlice)
require.NoError(err)
message := "Hello World!"
packed := saltyim.PackMessage(me, message)
unpacked := saltyim.FormatMessage(string(packed))
assert.Contains(unpacked, userAlice)
assert.Contains(unpacked, message)
}
func TestPackMessage(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
addr, err := saltyim.ParseAddr("alice@example.com")
require.NoError(err)
assert.Equal("alice", addr.User())
assert.Equal("example.com", addr.Domain())
msg := "Hello World!"
packed := saltyim.PackMessage(addr, msg)
require.NotNil(packed)
s, err := lextwt.ParseSalty(string(packed))
require.NoError(err)
st, ok := s.(*lextwt.SaltyText)
require.Equal(true, ok)
assert.Equal("alice@example.com", st.User.String())
assert.Equal("Hello World!", st.LiteralText())
}