diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-11-29 16:01:41 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-02-19 11:54:01 +0000 |
| commit | e59ec59b027f921a6bfbe5014b15c2a802445ada (patch) | |
| tree | 1c69d1db1b34e0b53d620f9fe272cf9f374b1400 /pkg/ast/parser_test.go | |
| parent | 164800ebad7f26d05eefb0095d190462ed97bee0 (diff) | |
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.
Diffstat (limited to 'pkg/ast/parser_test.go')
| -rw-r--r-- | pkg/ast/parser_test.go | 15 |
1 files changed, 5 insertions, 10 deletions
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) { |
