MCPcopy Create free account
hub / github.com/expr-lang/expr / TestPrint

Function TestPrint

ast/print_test.go:13–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestPrint(t *testing.T) {
14 tests := []struct {
15 input string
16 want string
17 }{
18 {`nil`, `nil`},
19 {`true`, `true`},
20 {`false`, `false`},
21 {`1`, `1`},
22 {`1.1`, `1.1`},
23 {`"a"`, `"a"`},
24 {`'a'`, `"a"`},
25 {`a`, `a`},
26 {`a.b`, `a.b`},
27 {`a[0]`, `a[0]`},
28 {`a["the b"]`, `a["the b"]`},
29 {`a.b[0]`, `a.b[0]`},
30 {`a?.b`, `a?.b`},
31 {`x[0][1]`, `x[0][1]`},
32 {`x?.[0]?.[1]`, `x?.[0]?.[1]`},
33 {`-a`, `-a`},
34 {`!a`, `!a`},
35 {`not a`, `not a`},
36 {`a + b`, `a + b`},
37 {`a + b * c`, `a + b * c`},
38 {`(a + b) * c`, `(a + b) * c`},
39 {`a * (b + c)`, `a * (b + c)`},
40 {`-(a + b) * c`, `-(a + b) * c`},
41 {`a == b`, `a == b`},
42 {`a matches b`, `a matches b`},
43 {`a in b`, `a in b`},
44 {`a not in b`, `not (a in b)`},
45 {`a and b`, `a and b`},
46 {`a or b`, `a or b`},
47 {`a or b and c`, `a or (b and c)`},
48 {`a or (b and c)`, `a or (b and c)`},
49 {`(a or b) and c`, `(a or b) and c`},
50 {`a ? b : c`, `a ? b : c`},
51 {`a ? b : c ? d : e`, `a ? b : (c ? d : e)`},
52 {`(a ? b : c) ? d : e`, `(a ? b : c) ? d : e`},
53 {`a ? (b ? c : d) : e`, `a ? (b ? c : d) : e`},
54 {`func()`, `func()`},
55 {`func(a)`, `func(a)`},
56 {`func(a, b)`, `func(a, b)`},
57 {`{}`, `{}`},
58 {`{a: b}`, `{a: b}`},
59 {`{a: b, c: d}`, `{a: b, c: d}`},
60 {`{"a": b, 'c': d}`, `{a: b, c: d}`},
61 {`{"a": b, c: d}`, `{a: b, c: d}`},
62 {`{"a": b, 8: 8}`, `{a: b, "8": 8}`},
63 {`{"9": 9, '8': 8, "foo": d}`, `{"9": 9, "8": 8, foo: d}`},
64 {`[]`, `[]`},
65 {`[a]`, `[a]`},
66 {`[a, b]`, `[a, b]`},
67 {`len(a)`, `len(a)`},
68 {`map(a, # > 0)`, `map(a, # > 0)`},
69 {`map(a, {# > 0})`, `map(a, # > 0)`},
70 {`map(a, .b)`, `map(a, .b)`},

Callers

nothing calls this directly

Calls 5

ParseFunction · 0.92
NoErrorFunction · 0.92
EqualFunction · 0.92
RunMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…