From 7ea1b177b290dd4896b0e1deb7506ebe7b50abcf Mon Sep 17 00:00:00 2001 From: "duanyi.aster" Date: Thu, 27 Jun 2024 13:45:35 +0800 Subject: [PATCH] Revert "for test" This reverts commit 812ca44adcaf1efd5c7016709b4142dd9302e361. --- ast/node_test.go | 142 +++++++++++++++++++++++------------------------ 1 file changed, 70 insertions(+), 72 deletions(-) diff --git a/ast/node_test.go b/ast/node_test.go index 4ae3d1b7c..ae40c18c4 100644 --- a/ast/node_test.go +++ b/ast/node_test.go @@ -176,10 +176,9 @@ func TestLoadAll(t *testing.T) { t.Fatal(a.Key) } else if !a.Value.IsRaw() { t.Fatal(a.Value.itype()) - } else - // if n, err := a.Value.Len(); n != 0 || err != nil { - // t.Fatal(n, err) - // } + } else if n, err := a.Value.Len(); n != 0 || err != nil { + t.Fatal(n, err) + } if err := a.Value.Load(); err != nil { t.Fatal(err) } @@ -200,10 +199,9 @@ func TestLoadAll(t *testing.T) { t.Fatal(b.Key) } else if !b.Value.IsRaw() { t.Fatal(b.Value.itype()) - } else - // if n, err := b.Value.Len(); n != 0 || err != nil { - // t.Fatal(n, err) - // } + } else if n, err := b.Value.Len(); n != 0 || err != nil { + t.Fatal(n, err) + } if err := b.Value.Load(); err != nil { t.Fatal(err) } @@ -498,11 +496,11 @@ func TestTypeCast(t *testing.T) { {"Len", NewAny(0), 0, ErrUnsupportType}, {"Len", NewNull(), 0, nil}, {"Len", NewRaw(`"1"`), 1, nil}, - // {"Len", NewRaw(`[1]`), 0, nil}, + {"Len", NewRaw(`[1]`), 0, nil}, {"Len", NewArray([]Node{NewNull()}), 1, nil}, - // {"Len", lazyArray, 0, nil}, - // {"Len", NewRaw(`{"a":1}`), 0, nil}, - // {"Len", lazyObject, 0, nil}, + {"Len", lazyArray, 0, nil}, + {"Len", NewRaw(`{"a":1}`), 0, nil}, + {"Len", lazyObject, 0, nil}, {"Cap", Node{}, 0, nil}, {"Cap", NewAny(0), 0, ErrUnsupportType}, {"Cap", NewNull(), 0, nil}, @@ -701,70 +699,70 @@ func TestCheckError_Empty(t *testing.T) { t.Fatal() } - // n := newRawNode("[hello]", types.V_ARRAY) - // n.parseRaw(false) - // if n.Check() != nil { - // t.Fatal(n.Check()) - // } - // n = newRawNode("[hello]", types.V_ARRAY) - // n.parseRaw(true) - // p := NewParser("[hello]") - // p.noLazy = true - // p.skipValue = false - // _, x := p.Parse() - // if n.Error() != newSyntaxError(p.syntaxError(x)).Error() { - // t.Fatal(n.Check()) - // } + n := newRawNode("[hello]", types.V_ARRAY) + n.parseRaw(false) + if n.Check() != nil { + t.Fatal(n.Check()) + } + n = newRawNode("[hello]", types.V_ARRAY) + n.parseRaw(true) + p := NewParser("[hello]") + p.noLazy = true + p.skipValue = false + _, x := p.Parse() + if n.Error() != newSyntaxError(p.syntaxError(x)).Error() { + t.Fatal(n.Check()) + } - // s, err := NewParser(`{"a":{}, "b":talse, "c":{}}`).Parse() - // if err != 0 { - // t.Fatal(err) - // } + s, err := NewParser(`{"a":{}, "b":talse, "c":{}}`).Parse() + if err != 0 { + t.Fatal(err) + } - // root := s.GetByPath() - // // fmt.Println(root.Check()) - // a := root.Get("a") - // if a.Check() != nil { - // t.Fatal(a.Check()) - // } - // c := root.Get("c") - // if c.Check() == nil { - // t.Fatal() - // } - // fmt.Println(c.Check()) + root := s.GetByPath() + // fmt.Println(root.Check()) + a := root.Get("a") + if a.Check() != nil { + t.Fatal(a.Check()) + } + c := root.Get("c") + if c.Check() == nil { + t.Fatal() + } + fmt.Println(c.Check()) - // _, e := a.Properties() - // if e != nil { - // t.Fatal(e) - // } - // exist, e := a.Set("d", newRawNode("x", types.V_OBJECT)) - // if exist || e != nil { - // t.Fatal(err) - // } - // if a.len() != 1 { - // t.Fail() - // } - // d := a.Get("d").Get("") - // if d.Check() == nil { - // t.Fatal(d) - // } - // exist, e = a.Set("e", newRawNode("[}", types.V_ARRAY)) - // if e != nil { - // t.Fatal(e) - // } - // if a.len() != 2 { - // t.Fail() - // } - // d = a.Index(1).Index(0) - // if d.Check() == nil { - // t.Fatal(d) - // } + _, e := a.Properties() + if e != nil { + t.Fatal(e) + } + exist, e := a.Set("d", newRawNode("x", types.V_OBJECT)) + if exist || e != nil { + t.Fatal(err) + } + if a.len() != 1 { + t.Fail() + } + d := a.Get("d").Get("") + if d.Check() == nil { + t.Fatal(d) + } + exist, e = a.Set("e", newRawNode("[}", types.V_ARRAY)) + if e != nil { + t.Fatal(e) + } + if a.len() != 2 { + t.Fail() + } + d = a.Index(1).Index(0) + if d.Check() == nil { + t.Fatal(d) + } - // it, e := root.Interface() - // if e == nil { - // t.Fatal(it) - // } - // fmt.Println(e) + it, e := root.Interface() + if e == nil { + t.Fatal(it) + } + fmt.Println(e) } func TestIndex(t *testing.T) {