MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestUnparse

Function TestUnparse

parser/unparser_test.go:31–507  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestUnparse(t *testing.T) {
32 tests := []struct {
33 name string
34 in string
35 out interface{}
36 requiresMacroCalls bool
37 unparserOptions []UnparserOption
38 }{
39 {name: "call_add", in: `a + b - c`},
40 {name: "call_and", in: `a && b && c && d && e`},
41 {name: "call_and_or", in: `a || b && (c || d) && e`},
42 {name: "call_cond", in: `a ? b : c`},
43 {name: "call_cond_nested_inner", in: `a ? (c ? d : e) : b`},
44 {name: "call_cond_nested_outer", in: `a ? b : c ? d : e`, out: `a ? b : (c ? d : e)`},
45 {name: "call_index", in: `a[1]["b"]`},
46 {name: "call_index_eq", in: `x["a"].single_int32 == 23`},
47 {name: "call_mul", in: `a * (b / c) % 0`},
48 {name: "call_mul_add", in: `a + b * c`},
49 {name: "call_mul_add_nested", in: `(a + b) * c / (d - e)`},
50 {name: "call_mul_nested", in: `a * b / c % 0`},
51 {name: "call_not", in: `!true`},
52 {name: "call_neg", in: `-num`},
53 {name: "call_or", in: `a || b || c || d || e`},
54 {name: "call_neg_mult", in: `-(1 * 2)`},
55 {name: "call_neg_add", in: `-(1 + 2)`},
56 {name: "call_operator_precedence", in: `1 - (2 == -1)`},
57 {name: "calc_distr_paren", in: `(1 + 2) * 3`},
58 {name: "calc_distr_noparen", in: `1 + 2 * 3`},
59 {name: "cond_tern_simple", in: `(x > 5) ? (x - 5) : 0`},
60 {name: "cond_tern_neg_expr", in: `-((x > 5) ? (x - 5) : 0)`},
61 {name: "cond_tern_neg_term", in: `-x ? (x - 5) : 0`},
62 {name: "func_global", in: `size(a ? (b ? c : d) : e)`},
63 {name: "func_member", in: `a.hello("world")`},
64 {name: "func_no_arg", in: `zero()`},
65 {name: "func_one_arg", in: `one("a")`},
66 {name: "func_two_args", in: `and(d, 32u)`},
67 {name: "func_var_args", in: `max(a, b, 100)`},
68 {name: "func_neq", in: `x != "a"`},
69 {name: "func_in", in: `a in b`},
70 {name: "list_empty", in: `[]`},
71 {name: "list_one", in: `[1]`},
72 {name: "list_ints", in: `[1, 2, 3]`},
73 {name: "list_doubles", in: `[1.0, 2.0, 3.0]`},
74 {name: "list_doubles", in: `[1.1, 2.1, 3.1]`},
75 {name: "list_uints", in: `[1u, 2u, 3u]`},
76 {name: "list_numeric", in: `[1, 2.0, 3u]`},
77 {name: "list_many", in: `["hello, world", "goodbye, world", "sure, why not?"]`},
78 {name: "lit_bytes", in: `b"\303\203\302\277"`},
79 {name: "lit_double", in: `-42.101`},
80 {name: "lit_false", in: `false`},
81 {name: "lit_int", in: `-405069`},
82 {name: "lit_null", in: `null`},
83 {name: "lit_string", in: `"hello:\t'world'"`},
84 {name: "lit_string_quote", in: `"hello:\"world\""`},
85 {name: "lit_true", in: `true`},
86 {name: "lit_uint", in: `42u`},
87 {name: "ident", in: `my_ident`},
88 {name: "macro_has", in: `has(hello.world)`},

Callers

nothing calls this directly

Calls 15

ParseMethod · 0.95
NewTextSourceFunction · 0.92
ExprToProtoFunction · 0.92
WrapOnColumnFunction · 0.85
WrapOnOperatorsFunction · 0.85
WrapAfterColumnLimitFunction · 0.85
PopulateMacroCallsFunction · 0.85
EnableOptionalSyntaxFunction · 0.85
EnableIdentEscapeSyntaxFunction · 0.85
UnparseFunction · 0.85
GetErrorsMethod · 0.80
NewParserFunction · 0.70

Tested by

no test coverage detected