mirror of
https://github.com/versia-pub/versia-go.git
synced 2025-12-06 14:28:20 +01:00
30 lines
599 B
Go
30 lines
599 B
Go
package versia
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestExtensionKey_UnmarshalJSON(t *testing.T) {
|
|
cases := []struct {
|
|
Raw string
|
|
Expected ExtensionKey
|
|
Error bool
|
|
}{
|
|
{"\"pub.versia:Emoji\"", ExtensionKey{"pub.versia", "Emoji"}, false},
|
|
{"\"pub.versia\"", ExtensionKey{}, true},
|
|
}
|
|
|
|
for _, case_ := range cases {
|
|
key := ExtensionKey{}
|
|
err := json.Unmarshal([]byte(case_.Raw), &key)
|
|
|
|
assert.Equal(t, case_.Error, err != nil, "error assertion should match")
|
|
|
|
if !case_.Error {
|
|
assert.Equal(t, case_.Expected, key)
|
|
}
|
|
}
|
|
}
|