package scopes_test import ( "fmt" tbase "testing" "git.sr.ht/~cco/go-scopes/lib" "git.sr.ht/~cco/go-scopes/lib/message" "git.sr.ht/~cco/go-scopes/testing" ) func TestUnit(tb *tbase.T) { t := testing.SetUp(tb) t.Run("address", AddressTest) t.Run("message", MessageTest) } func AddressTest(t *testing.T) { var ad1 lib.Address = message.SimpleAddress("worker") t.AssertEqual(fmt.Sprint(ad1), "#worker//") astr := "@scopes.cy7.eu#server/1abc/2cde" var ad2 lib.Address = message.ParseAddress(astr) t.AssertEqual(fmt.Sprint(ad2), astr) t.AssertEqual(fmt.Sprint(message.ParseAddress("worker")), "#worker//") t.AssertEqual(ad1.Url(), "") t.AssertEqual(ad2.Url(), "@scopes.cy7.eu") sid, iid := ad1.Interaction() t.AssertEqual(sid, "") t.AssertEqual(iid, "") sid, iid = ad2.Interaction() t.AssertEqual(sid, "1abc") t.AssertEqual(iid, "2cde") ad1.SetUrl("@scopes.cy7.eu") ad1.SetInteraction("1abc", "2cde") t.AssertEqual(fmt.Sprint(ad1), "@scopes.cy7.eu#worker/1abc/2cde") } func MessageTest(t *testing.T) { t.AssertEqual(message.Quit.Action(), "quit") var msg lib.Message = message.SimpleMessage("doit") t.AssertEqual(msg.Action(), "doit") t.AssertEqual(msg.Head().Action(), "doit") t.AssertEqual(fmt.Sprint(msg), "standard/doit//") }