2022-11-11 10:08:36 -03:00
|
|
|
package nostr
|
|
|
|
|
|
|
|
import (
|
2025-03-10 02:58:31 -03:00
|
|
|
"slices"
|
2022-11-11 10:08:36 -03:00
|
|
|
"testing"
|
2024-09-09 13:50:56 +03:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-11-11 10:08:36 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
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"},
|
|
|
|
}
|
|
|
|
|
2025-03-10 02:54:34 -03:00
|
|
|
assert.Nil(t, tags.Find("x"), "Find shouldn't have returned a tag with a single item")
|
|
|
|
assert.NotNil(t, tags.FindWithValue("p", "abcdef"), "failed to get with existing prefix")
|
2025-03-10 02:33:29 -03:00
|
|
|
assert.Equal(t, "ffffff", tags.FindLast("e")[1], "failed to get last")
|
2025-03-10 02:58:31 -03:00
|
|
|
assert.Equal(t, 2, len(slices.Collect(tags.FindAll("e"))), "failed to get all")
|
2024-10-13 10:32:34 -03:00
|
|
|
c := make(Tags, 0, 2)
|
|
|
|
for _, tag := range tags.All([]string{"e", ""}) {
|
|
|
|
c = append(c, tag)
|
|
|
|
}
|
2022-11-11 10:08:36 -03:00
|
|
|
}
|