forked from nbd-wtf/go-nostr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tag_test.go
48 lines (43 loc) · 1.24 KB
/
tag_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package nostr
import (
"testing"
)
func TestTagHelpers(t *testing.T) {
tags := Tags{
Tag{"x"},
Tag{"p", "abcdef", "wss://x.com"},
Tag{"p", "123456", "wss://y.com"},
Tag{"e", "eeeeee"},
Tag{"e", "ffffff"},
}
if tags.GetFirst([]string{"x"}) == nil {
t.Error("failed to get existing prefix")
}
if tags.GetFirst([]string{"x", ""}) != nil {
t.Error("got with wrong prefix")
}
if tags.GetFirst([]string{"p", "abcdef", "wss://"}) == nil {
t.Error("failed to get with existing prefix")
}
if tags.GetFirst([]string{"p", "abcdef", ""}) == nil {
t.Error("failed to get with existing prefix (blank last string)")
}
if (*(tags.GetLast([]string{"e"})))[1] != "ffffff" {
t.Error("failed to get last")
}
if len(tags.GetAll([]string{"e", ""})) != 2 {
t.Error("failed to get all")
}
if len(tags.AppendUnique(Tag{"e", "ffffff"})) != 5 {
t.Error("append unique changed the array size when existed")
}
if len(tags.AppendUnique(Tag{"e", "bbbbbb"})) != 6 {
t.Error("append unique failed to append when didn't exist")
}
if tags.AppendUnique(Tag{"e", "eeeeee"})[4][1] != "ffffff" {
t.Error("append unique changed the order")
}
if tags.AppendUnique(Tag{"e", "eeeeee"})[3][1] != "eeeeee" {
t.Error("append unique changed the order")
}
}