this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue: teach the fuzzer to check against cue/ast and cue/literal

While here, check that we can get all positions without crashing.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Iaf5a3204362f79407854c1e2782f54f555964a32
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1234635
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>

+31 -1
+31 -1
cue/fuzz_test.go
··· 20 20 "cuelang.org/go/cue/ast" 21 21 "cuelang.org/go/cue/ast/astutil" 22 22 "cuelang.org/go/cue/format" 23 + "cuelang.org/go/cue/literal" 23 24 "cuelang.org/go/cue/parser" 25 + "cuelang.org/go/cue/token" 24 26 ) 25 27 26 28 func FuzzStandaloneCUE(f *testing.F) { ··· 79 81 func(ast.Node) {}, 80 82 ) 81 83 astutil.Apply(f, 82 - func(astutil.Cursor) bool { return true }, 84 + func(c astutil.Cursor) bool { 85 + node := c.Node() 86 + _ = node.Pos().Position() 87 + _ = node.End().Position() 88 + switch node := node.(type) { 89 + case *ast.Ident: 90 + if !ast.IsValidIdent(node.Name) { 91 + t.Fatalf("cue/parser and cue/ast should agree on what is a valid identifier: %s", node.Name) 92 + } 93 + case *ast.BasicLit: 94 + switch node.Kind { 95 + case token.INT, token.FLOAT: 96 + var info literal.NumInfo 97 + if err := literal.ParseNum(node.Value, &info); err != nil { 98 + t.Fatalf("cue/parser and cue/literal should agree on what is a valid number: %s", node.Value) 99 + } 100 + case token.STRING: 101 + if _, ok := c.Parent().Node().(*ast.Interpolation); ok { 102 + // An interpolation consists of incomplete basic literals like: "\( 103 + break 104 + } 105 + if _, err := literal.Unquote(node.Value); err != nil { 106 + t.Fatalf("cue/parser and cue/literal should agree on what is a valid string: %s", node.Value) 107 + } 108 + } 109 + } 110 + 111 + return true 112 + }, 83 113 func(astutil.Cursor) bool { return true }, 84 114 ) 85 115