- internal/jcs: RFC 8785 canonical JSON (integers only) - internal/identity: ed25519 keypair, 0600 key file, no overwrite - internal/listing: signed listing record with PoW, validation, tombstones and supersede rules - docs/PROTOCOL.md: architecture and decisions so far Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package jcs
|
|
|
|
import "testing"
|
|
|
|
func TestMarshal(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
in any
|
|
want string
|
|
}{
|
|
{"sorted keys", map[string]any{"b": 1, "a": 2, "c": []int{3, 1}}, `{"a":2,"b":1,"c":[3,1]}`},
|
|
{"nested", map[string]any{"z": map[string]any{"y": true, "x": nil}}, `{"z":{"x":null,"y":true}}`},
|
|
{"no html escaping", "<a href=\"x\">&</a>", `"<a href=\"x\">&</a>"`},
|
|
{"control chars", "a\tb\nc\u0001", `"a\tb\nc\u0001"`},
|
|
{"unicode literal", "ä€😀
", "\"ä€😀
\""},
|
|
{"utf16 key order", map[string]any{"\U0001F600": 1, "": 2}, "{\"\U0001F600\":1,\"\":2}"},
|
|
{"negative int", -42, `-42`},
|
|
}
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got, err := Marshal(tc.in)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(got) != tc.want {
|
|
t.Fatalf("got %s want %s", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRejectsFloatsAndHugeInts(t *testing.T) {
|
|
if _, err := Marshal(1.5); err == nil {
|
|
t.Fatal("expected error for float")
|
|
}
|
|
if _, err := Marshal(int64(1) << 60); err == nil {
|
|
t.Fatal("expected error for out-of-range integer")
|
|
}
|
|
}
|