From e59ec59b027f921a6bfbe5014b15c2a802445ada Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 29 Nov 2023 16:01:41 +0100 Subject: pkg/ast: support expressions with ast.Type So far they have the following grammar: OP = "==", "!=", "&" value-expr = value-expr OP value-expr | factor factor = "(" and-expr ")" | integer | identifier | string Operators are left associative, e.g. A & B & C is the same as (A & B) & C. Further restrictions will be imposed in pkg/compiler. This will help implement conditionally included fields. --- pkg/ast/parser_test.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'pkg/ast/parser_test.go') diff --git a/pkg/ast/parser_test.go b/pkg/ast/parser_test.go index cecdcc9b2..5e25157f5 100644 --- a/pkg/ast/parser_test.go +++ b/pkg/ast/parser_test.go @@ -4,14 +4,13 @@ package ast import ( - "bytes" "os" "path/filepath" - "reflect" "strings" "testing" "github.com/google/syzkaller/sys/targets" + "github.com/stretchr/testify/assert" ) func TestParseAll(t *testing.T) { @@ -47,14 +46,9 @@ func TestParseAll(t *testing.T) { if n1 == nil { t.Fatalf("got nil node") } - if !reflect.DeepEqual(n1, n2) { - t.Fatalf("formatting changed code:\n%#v\nvs:\n%#v", n1, n2) - } - } - data3 := Format(desc.Clone()) - if !bytes.Equal(data, data3) { - t.Fatalf("Clone lost data") + assert.Equal(t, n1, n2, "formating changed code") } + assert.Equal(t, string(data), string(Format(desc.Clone()))) nodes0 := 0 desc.Walk(func(n Node) { nodes0++ @@ -63,12 +57,13 @@ func TestParseAll(t *testing.T) { } }) nodes1 := 0 - desc.Walk(Recursive(func(n Node) { + desc.Walk(Recursive(func(n Node) bool { nodes1++ pos, typ, _ := n.Info() if typ == "" { t.Fatalf("%v: node has empty typ=%q: %#v", pos, typ, n) } + return true })) nodes2 := 0 desc.Walk(PostRecursive(func(n Node) { -- cgit mrf-deployment