diff --git a/codec/dagjson/roundtripBytes_test.go b/codec/dagjson/roundtripBytes_test.go index a8c05fcf..9c58e723 100644 --- a/codec/dagjson/roundtripBytes_test.go +++ b/codec/dagjson/roundtripBytes_test.go @@ -15,6 +15,10 @@ var byteNode = fluent.MustBuildMap(basicnode.Prototype__Map{}, 4, func(na fluent na.AssembleEntry("plain").AssignString("olde string") na.AssembleEntry("bytes").AssignBytes([]byte("deadbeef")) }) +var byteNodeSorted = fluent.MustBuildMap(basicnode.Prototype__Map{}, 4, func(na fluent.MapAssembler) { + na.AssembleEntry("bytes").AssignBytes([]byte("deadbeef")) + na.AssembleEntry("plain").AssignString("olde string") +}) var byteSerial = `{"bytes":{"/":{"bytes":"ZGVhZGJlZWY="}},"plain":"olde string"}` func TestRoundtripBytes(t *testing.T) { @@ -29,7 +33,7 @@ func TestRoundtripBytes(t *testing.T) { nb := basicnode.Prototype__Map{}.NewBuilder() err := Decode(nb, buf) Require(t, err, ShouldEqual, nil) - Wish(t, nb.Build(), ShouldEqual, byteNode) + Wish(t, nb.Build(), ShouldEqual, byteNodeSorted) }) } diff --git a/codec/dagjson/roundtripCidlink_test.go b/codec/dagjson/roundtripCidlink_test.go index 43c63bb0..56cb3707 100644 --- a/codec/dagjson/roundtripCidlink_test.go +++ b/codec/dagjson/roundtripCidlink_test.go @@ -36,7 +36,7 @@ func TestRoundtripCidlink(t *testing.T) { n2, err := lsys.Load(ipld.LinkContext{}, lnk, basicnode.Prototype.Any) Require(t, err, ShouldEqual, nil) - Wish(t, n2, ShouldEqual, n) + Wish(t, n2, ShouldEqual, nSorted) } // Make sure that a map that *almost* looks like a link is handled safely. diff --git a/codec/dagjson/roundtrip_test.go b/codec/dagjson/roundtrip_test.go index ff64ec2f..4bfd4f6d 100644 --- a/codec/dagjson/roundtrip_test.go +++ b/codec/dagjson/roundtrip_test.go @@ -27,6 +27,22 @@ var n = fluent.MustBuildMap(basicnode.Prototype__Map{}, 4, func(na fluent.MapAss }) }) }) +var nSorted = fluent.MustBuildMap(basicnode.Prototype__Map{}, 4, func(na fluent.MapAssembler) { + na.AssembleEntry("list").CreateList(2, func(na fluent.ListAssembler) { + na.AssembleValue().AssignString("three") + na.AssembleValue().AssignString("four") + }) + na.AssembleEntry("map").CreateMap(2, func(na fluent.MapAssembler) { + na.AssembleEntry("one").AssignInt(1) + na.AssembleEntry("two").AssignInt(2) + }) + na.AssembleEntry("nested").CreateMap(1, func(na fluent.MapAssembler) { + na.AssembleEntry("deeper").CreateList(1, func(na fluent.ListAssembler) { + na.AssembleValue().AssignString("things") + }) + }) + na.AssembleEntry("plain").AssignString("olde string") +}) var serial = `{"list":["three","four"],"map":{"one":1,"two":2},"nested":{"deeper":["things"]},"plain":"olde string"}` func TestRoundtrip(t *testing.T) { @@ -41,7 +57,7 @@ func TestRoundtrip(t *testing.T) { nb := basicnode.Prototype__Map{}.NewBuilder() err := Decode(nb, buf) Require(t, err, ShouldEqual, nil) - Wish(t, nb.Build(), ShouldEqual, n) + Wish(t, nb.Build(), ShouldEqual, nSorted) }) } diff --git a/fluent/qp/example_test.go b/fluent/qp/example_test.go index c0cac27a..f6cc2a7a 100644 --- a/fluent/qp/example_test.go +++ b/fluent/qp/example_test.go @@ -30,5 +30,5 @@ func Example() { dagjson.Encode(n, os.Stdout) // Output: - // {"some key":"some value","another key":"another value","nested map":{"deeper entries":"deeper values","more deeper entries":"more deeper values"},"nested list":[1,2]} + // {"another key":"another value","nested list":[1,2],"nested map":{"deeper entries":"deeper values","more deeper entries":"more deeper values"},"some key":"some value"} } diff --git a/node/bindnode/example_test.go b/node/bindnode/example_test.go index 199d6cf9..d3e72bbc 100644 --- a/node/bindnode/example_test.go +++ b/node/bindnode/example_test.go @@ -43,7 +43,7 @@ func ExampleWrap_withSchema() { dagjson.Marshal(nodeRepr, refmtjson.NewEncoder(os.Stdout, refmtjson.EncodeOptions{}), true) // Output: - // {"Name":"Michael","Friends":["Sarah","Alex"]} + // {"Friends":["Sarah","Alex"],"Name":"Michael"} } func ExamplePrototype_onlySchema() { @@ -79,5 +79,5 @@ func ExamplePrototype_onlySchema() { dagjson.Marshal(nodeRepr, refmtjson.NewEncoder(os.Stdout, refmtjson.EncodeOptions{}), true) // Output: - // {"Name":"Michael","Friends":["Sarah","Alex"]} + // {"Friends":["Sarah","Alex"],"Name":"Michael"} } diff --git a/node/tests/schemaStructsContainingMaybe.go b/node/tests/schemaStructsContainingMaybe.go index 16c2f5e2..e4010555 100644 --- a/node/tests/schemaStructsContainingMaybe.go +++ b/node/tests/schemaStructsContainingMaybe.go @@ -47,7 +47,7 @@ func SchemaTestStructsContainingMaybe(t *testing.T, engine Engine) { { name: "vvvvv-AllFieldsSet", typeJson: `{"f1":"a","f2":"b","f3":"c","f4":"d","f5":"e"}`, - reprJson: `{"r1":"a","r2":"b","r3":"c","r4":"d","f5":"e"}`, + reprJson: `{"f5":"e","r1":"a","r2":"b","r3":"c","r4":"d"}`, typePoints: []testcasePoint{ {"", ipld.Kind_Map}, {"f1", "a"}, @@ -68,7 +68,7 @@ func SchemaTestStructsContainingMaybe(t *testing.T, engine Engine) { { name: "vvnnv-Nulls", typeJson: `{"f1":"a","f2":"b","f3":null,"f4":null,"f5":"e"}`, - reprJson: `{"r1":"a","r2":"b","r3":null,"r4":null,"f5":"e"}`, + reprJson: `{"f5":"e","r1":"a","r2":"b","r3":null,"r4":null}`, typePoints: []testcasePoint{ {"", ipld.Kind_Map}, {"f1", "a"}, @@ -89,7 +89,7 @@ func SchemaTestStructsContainingMaybe(t *testing.T, engine Engine) { { name: "vzvzv-AbsentOptionals", typeJson: `{"f1":"a","f3":"c","f5":"e"}`, - reprJson: `{"r1":"a","r3":"c","f5":"e"}`, + reprJson: `{"f5":"e","r1":"a","r3":"c"}`, typePoints: []testcasePoint{ {"", ipld.Kind_Map}, {"f1", "a"}, diff --git a/traversal/focus_test.go b/traversal/focus_test.go index 0b3f0591..301efb50 100644 --- a/traversal/focus_test.go +++ b/traversal/focus_test.go @@ -318,7 +318,7 @@ func TestFocusedTransformWithLinks(t *testing.T) { Wish(t, progress.Path.String(), ShouldEqual, "linkedMap/nested/nonlink") Wish(t, must.String(prev), ShouldEqual, "zoo") Wish(t, progress.LastBlock.Path.String(), ShouldEqual, "linkedMap") - Wish(t, progress.LastBlock.Link.String(), ShouldEqual, "baguqeeye2opztzy") + Wish(t, progress.LastBlock.Link.String(), ShouldEqual, "baguqeeyezhlahvq") nb := prev.Prototype().NewBuilder() nb.AssignString("new string!") return nb.Build(), nil