From 635226ae425905d5b255df0c1509646ba566c287 Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Mon, 10 Apr 2017 11:41:19 -0700 Subject: [PATCH] minor format updates --- gjson.go | 19 +++++++++---------- gjson_test.go | 31 ++++++++++++------------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/gjson.go b/gjson.go index d5a6097..e01fb01 100644 --- a/gjson.go +++ b/gjson.go @@ -905,7 +905,7 @@ func parseObject(c *parseContext, i int, path string) (int, bool) { break } } - i, key, kesc, ok = i, c.json[s:], false, false + key, kesc, ok = c.json[s:], false, false parse_key_string_done: break } @@ -1223,16 +1223,15 @@ func parseArray(c *parseContext, i int, path string) (int, bool) { c.value.Type = JSON c.value.Raw = string(jsons) return i + 1, true - } else { - if rp.alogok { - break - } - c.value.Raw = val - c.value.Type = Number - c.value.Num = float64(h - 1) - c.calcd = true - return i + 1, true } + if rp.alogok { + break + } + c.value.Raw = val + c.value.Type = Number + c.value.Num = float64(h - 1) + c.calcd = true + return i + 1, true } if len(multires) > 0 && !c.value.Exists() { c.value = Result{ diff --git a/gjson_test.go b/gjson_test.go index 330d54e..758277e 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -244,19 +244,19 @@ func TestBasic(t *testing.T) { } var token Result if token = Parse("-102"); token.Num != -102 { - t.Fatal("expected %v, got %v", -102, token.Num) + t.Fatalf("expected %v, got %v", -102, token.Num) } if token = Parse("102"); token.Num != 102 { - t.Fatal("expected %v, got %v", 102, token.Num) + t.Fatalf("expected %v, got %v", 102, token.Num) } if token = Parse("102.2"); token.Num != 102.2 { - t.Fatal("expected %v, got %v", 102.2, token.Num) + t.Fatalf("expected %v, got %v", 102.2, token.Num) } if token = Parse(`"hello"`); token.Str != "hello" { - t.Fatal("expected %v, got %v", "hello", token.Str) + t.Fatalf("expected %v, got %v", "hello", token.Str) } if token = Parse(`"\"he\nllo\""`); token.Str != "\"he\nllo\"" { - t.Fatal("expected %v, got %v", "\"he\nllo\"", token.Str) + t.Fatalf("expected %v, got %v", "\"he\nllo\"", token.Str) } mtok = get(basicJSON, "loggy.programmers.#.firstName") if len(mtok.Array()) != 4 { @@ -269,7 +269,7 @@ func TestBasic(t *testing.T) { } mtok = get(basicJSON, "loggy.programmers.#.asd") if mtok.Type != JSON { - t.Fatal("expected %v, got %v", JSON, mtok.Type) + t.Fatalf("expected %v, got %v", JSON, mtok.Type) } if len(mtok.Array()) != 0 { t.Fatalf("expected 0, got %v", len(mtok.Array())) @@ -518,17 +518,17 @@ func TestSingleArrayValue(t *testing.T) { t.Fatal("array is empty") } if array[0].String() != "value" { - t.Fatal("got %s, should be %s", array[0].String(), "value") + t.Fatalf("got %s, should be %s", array[0].String(), "value") } array = Get(json, "key2.#").Array() if len(array) != 1 { - t.Fatal("got '%v', expected '%v'", len(array), 1) + t.Fatalf("got '%v', expected '%v'", len(array), 1) } array = Get(json, "key3").Array() if len(array) != 0 { - t.Fatal("got '%v', expected '%v'", len(array), 0) + t.Fatalf("got '%v', expected '%v'", len(array), 0) } } @@ -570,10 +570,9 @@ func TestManyBasic(t *testing.T) { if fmt.Sprintf("%v", results) != expect { t.Fatalf("expected %v, got %v", expect, results) } - return - if testLastWasFallback != shouldFallback { - t.Fatalf("expected %v, got %v", shouldFallback, testLastWasFallback) - } + //if testLastWasFallback != shouldFallback { + // t.Fatalf("expected %v, got %v", shouldFallback, testLastWasFallback) + //} } testMany(false, "[Point]", "position.type") testMany(false, `[emptya ["world peace"] 31]`, ".a", "loves", "age") @@ -724,12 +723,6 @@ func BenchmarkGJSONGetMany64Paths(t *testing.B) { func BenchmarkGJSONGetMany128Paths(t *testing.B) { benchmarkGJSONGetManyN(t, 128) } -func BenchmarkGJSONGetMany256Paths(t *testing.B) { - benchmarkGJSONGetManyN(t, 256) -} -func BenchmarkGJSONGetMany512Paths(t *testing.B) { - benchmarkGJSONGetManyN(t, 512) -} func benchmarkGJSONGetManyN(t *testing.B, n int) { var paths []string for len(paths) < n {