Skip to content

Commit

Permalink
chore: flatten_json_test: use bytes.Equal
Browse files Browse the repository at this point in the history
  • Loading branch information
yosiat committed Sep 28, 2022
1 parent 9560837 commit c9a0cbc
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions flatten_json_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
package quamina

import (
"bytes"
"os"
"testing"
)

func equal(a []byte, b []byte) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}

func TestFJBasic(t *testing.T) {
j := `{ "a": 1, "b": "two", "c": true, "d": null, "e": { "e1": 2, "e2": 3.02e-5}, "f": [33e2, "x", true, false, null], "g": false, "h": [], "i": {}}`
allYes := fakeMatcher("a", "b", "c", "d", "e", "e1", "e2", "f", "g", "h", "i")
Expand All @@ -32,10 +21,10 @@ func TestFJBasic(t *testing.T) {
t.Errorf("list len %d wanted %d", len(list), len(wantedVals))
}
for i, field := range list {
if !equal([]byte(wantedPaths[i]), field.Path) {
if !bytes.Equal([]byte(wantedPaths[i]), field.Path) {
t.Errorf("pos %d wanted %s got %s", i, wantedPaths[i], field.Path)
}
if !equal([]byte(wantedVals[i]), field.Val) {
if !bytes.Equal([]byte(wantedVals[i]), field.Val) {
t.Errorf("pos %d wanted %s got %s", i, wantedVals[i], field.Val)
}
}
Expand All @@ -46,10 +35,10 @@ func TestFJBasic(t *testing.T) {
wantedPaths = []string{"a", "f", "f", "f", "f", "f"}
wantedVals = []string{"1", "33e2", "\"x\"", "true", "false", "null"}
for i, field := range list {
if !equal([]byte(wantedPaths[i]), field.Path) {
if !bytes.Equal([]byte(wantedPaths[i]), field.Path) {
t.Errorf("pos %d wanted %s got %s", i, wantedPaths[i], field.Path)
}
if !equal([]byte(wantedVals[i]), field.Val) {
if !bytes.Equal([]byte(wantedVals[i]), field.Val) {
t.Errorf("pos %d wanted %s got %s", i, wantedVals[i], field.Val)
}
}
Expand Down Expand Up @@ -112,7 +101,7 @@ func TestMinimal(t *testing.T) {
if err != nil {
t.Error("Huh? " + err.Error())
}
if len(fields) != 1 || !equal(fields[0].Path, []byte("a")) || len(fields[0].Val) != 1 || fields[0].Val[0] != '1' {
if len(fields) != 1 || !bytes.Equal(fields[0].Path, []byte("a")) || len(fields[0].Val) != 1 || fields[0].Val[0] != '1' {
t.Error("Name/Val wrong")
}
}
Expand All @@ -130,7 +119,7 @@ func testTrackerSelection(t *testing.T, fj Flattener, tracker NameTracker, label
t.Error(label + ": " + err.Error())
}
for i, field := range list {
if !equal([]byte(wantedPaths[i]), field.Path) {
if !bytes.Equal([]byte(wantedPaths[i]), field.Path) {
t.Errorf("pos %d wanted Path %s got %s", i, wantedPaths[i], field.Path)
}
if wantedVals[i] != string(field.Val) {
Expand Down

0 comments on commit c9a0cbc

Please sign in to comment.