mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-27 10:11:51 +01:00
29 lines
893 B
Go
29 lines
893 B
Go
package nostr
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
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"},
|
|
}
|
|
|
|
assert.NotNil(t, tags.GetFirst([]string{"x"}), "failed to get existing prefix")
|
|
assert.Nil(t, tags.GetFirst([]string{"x", ""}), "got with wrong prefix")
|
|
assert.NotNil(t, tags.GetFirst([]string{"p", "abcdef", "wss://"}), "failed to get with existing prefix")
|
|
assert.NotNil(t, tags.GetFirst([]string{"p", "abcdef", ""}), "failed to get with existing prefix (blank last string)")
|
|
assert.Equal(t, "ffffff", tags.FindLast("e")[1], "failed to get last")
|
|
assert.Equal(t, 2, len(tags.GetAll([]string{"e", ""})), "failed to get all")
|
|
c := make(Tags, 0, 2)
|
|
for _, tag := range tags.All([]string{"e", ""}) {
|
|
c = append(c, tag)
|
|
}
|
|
}
|