-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix the order of the map * Unify the sorting algorithm * Put the sorting algorithm into an internal package * Rename to represent the content of the file * Remove the new sort library and tweak the old implementation
- Loading branch information
1 parent
0be52bb
commit c20dc2c
Showing
5 changed files
with
66 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package field | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
) | ||
|
||
var ( | ||
testOrderedMap = OrderedMap{ | ||
"z": &String{value: "555"}, | ||
"0": &String{value: "0100"}, | ||
"1": &String{value: "D00080000000000000000000002000000000000000000000"}, | ||
"107": &String{value: "102"}, | ||
"a": &String{value: "555"}, | ||
"17": &String{value: "101"}, | ||
"2": &String{value: "4242424242424242"}, | ||
"4": &String{value: "100"}, | ||
} | ||
) | ||
|
||
func TestOrderedMap_MarshalJSON(t *testing.T) { | ||
expected := `{"0":"0100","1":"D00080000000000000000000002000000000000000000000","2":"4242424242424242","4":"100","17":"101","107":"102","a":"555","z":"555"}` | ||
data, err := json.Marshal(testOrderedMap) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if string(data) != expected { | ||
t.Errorf("Marshalled value should be \n\t%s\ninstead of \n\t%s", expected, string(data)) | ||
} | ||
} | ||
|
||
func BenchmarkOrderedMap_MarshalJSON(b *testing.B) { | ||
b.ReportAllocs() | ||
for i := 0; i < b.N; i++ { | ||
_, err := json.Marshal(testOrderedMap) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters