Skip to content

Commit f94c73f

Browse files
committed
WIP: test for struct field sorting
1 parent a441242 commit f94c73f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

obj/objFixtures_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ type t5b struct {
9393
K5 tObjStr
9494
}
9595

96+
type tFieldSort1 struct {
97+
Aaaaa string
98+
Bbbb string
99+
Ddd string
100+
Ccc string
101+
Eee string
102+
Ff string
103+
G string
104+
}
105+
96106
var objFixtures = []struct {
97107
title string
98108

@@ -401,6 +411,24 @@ var objFixtures = []struct {
401411
}},
402412
},
403413
},
414+
{title: "map with struct fields in different than expected order (rfc7049 expected)",
415+
sequence: fixtures.SequenceMap["10 struct rfc7049 order"],
416+
atlas: atlas.MustBuild(atlas.BuildEntry(tFieldSort1{}).MapMorphism().SetKeySortMode(atlas.KeySortMode_RFC7049).Complete()),
417+
marshalResults: []marshalResults{
418+
{title: "from map",
419+
valueFn: func() interface{} {
420+
return tFieldSort1{
421+
G: "1",
422+
Ff: "2",
423+
Ccc: "3",
424+
Ddd: "4",
425+
Eee: "5",
426+
Bbbb: "6",
427+
Aaaaa: "7",
428+
}
429+
}},
430+
},
431+
},
404432
{title: "empty primitive arrays",
405433
sequence: fixtures.SequenceMap["empty array"],
406434
marshalResults: []marshalResults{

tok/fixtures/fixtures.go

+13
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ var Sequences = []Sequence{
117117
{Type: TMapClose},
118118
},
119119
},
120+
{"7 struct rfc7049 order",
121+
[]Token{
122+
{Type: TMapOpen, Length: 7},
123+
TokStr("G"), TokStr("1"),
124+
TokStr("Ff"), TokStr("2"),
125+
TokStr("Ccc"), TokStr("3"),
126+
TokStr("Ddd"), TokStr("4"),
127+
TokStr("Eee"), TokStr("5"),
128+
TokStr("Bbbb"), TokStr("6"),
129+
TokStr("Aaaaa"), TokStr("7"),
130+
{Type: TMapClose},
131+
},
132+
},
120133

121134
// Arrays.
122135
{"empty array",

0 commit comments

Comments
 (0)