MCPcopy
hub / github.com/nektos/act / TestOperators

Function TestOperators

pkg/exprparser/interpreter_test.go:40–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestOperators(t *testing.T) {
41 table := []struct {
42 input string
43 expected interface{}
44 name string
45 error string
46 }{
47 {"(false || (false || true))", true, "logical-grouping", ""},
48 {"github.action", "push", "property-dereference", ""},
49 {"github['action']", "push", "property-index", ""},
50 {"github.action[0]", nil, "string-index", ""},
51 {"github.action['0']", nil, "string-index", ""},
52 {"fromJSON('[0,1]')[1]", 1.0, "array-index", ""},
53 {"fromJSON('[0,1]')[1.1]", nil, "array-index", ""},
54 // Disabled weird things are happening
55 // {"fromJSON('[0,1]')['1.1']", nil, "array-index", ""},
56 {"(github.event.commits.*.author.username)[0]", "someone", "array-index-0", ""},
57 {"fromJSON('[0,1]')[2]", nil, "array-index-out-of-bounds-0", ""},
58 {"fromJSON('[0,1]')[34553]", nil, "array-index-out-of-bounds-1", ""},
59 {"fromJSON('[0,1]')[-1]", nil, "array-index-out-of-bounds-2", ""},
60 {"fromJSON('[0,1]')[-34553]", nil, "array-index-out-of-bounds-3", ""},
61 {"!true", false, "not", ""},
62 {"1 < 2", true, "less-than", ""},
63 {`'b' <= 'a'`, false, "less-than-or-equal", ""},
64 {"1 > 2", false, "greater-than", ""},
65 {`'b' >= 'a'`, true, "greater-than-or-equal", ""},
66 {`'a' == 'a'`, true, "equal", ""},
67 {`'a' != 'a'`, false, "not-equal", ""},
68 {`true && false`, false, "and", ""},
69 {`true || false`, true, "or", ""},
70 {`fromJSON('{}') && true`, true, "and-boolean-object", ""},
71 {`fromJSON('{}') || false`, make(map[string]interface{}), "or-boolean-object", ""},
72 {"github.event.commits[0].author.username != github.event.commits[1].author.username", true, "property-comparison1", ""},
73 {"github.event.commits[0].author.username1 != github.event.commits[1].author.username", true, "property-comparison2", ""},
74 {"github.event.commits[0].author.username != github.event.commits[1].author.username1", true, "property-comparison3", ""},
75 {"github.event.commits[0].author.username1 != github.event.commits[1].author.username2", true, "property-comparison4", ""},
76 {"secrets != env", nil, "property-comparison5", "Compare not implemented for types: left: map, right: map"},
77 }
78
79 env := &EvaluationEnvironment{
80 Github: &model.GithubContext{
81 Action: "push",
82 Event: map[string]interface{}{
83 "commits": []interface{}{
84 map[string]interface{}{
85 "author": map[string]interface{}{
86 "username": "someone",
87 },
88 },
89 map[string]interface{}{
90 "author": map[string]interface{}{
91 "username": "someone-else",
92 },
93 },
94 },
95 },
96 },
97 }

Callers

nothing calls this directly

Calls 4

makeFunction · 0.85
NewInterpeterFunction · 0.85
EvaluateMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…