(t *testing.T)
| 217 | } |
| 218 | |
| 219 | func TestFunctionFormat(t *testing.T) { |
| 220 | table := []struct { |
| 221 | input string |
| 222 | expected interface{} |
| 223 | error interface{} |
| 224 | name string |
| 225 | }{ |
| 226 | {"format('text')", "text", nil, "format-plain-string"}, |
| 227 | {"format('Hello {0} {1} {2}!', 'Mona', 'the', 'Octocat')", "Hello Mona the Octocat!", nil, "format-with-placeholders"}, |
| 228 | {"format('{{Hello {0} {1} {2}!}}', 'Mona', 'the', 'Octocat')", "{Hello Mona the Octocat!}", nil, "format-with-escaped-braces"}, |
| 229 | {"format('{{0}}', 'test')", "{0}", nil, "format-with-escaped-braces"}, |
| 230 | {"format('{{{0}}}', 'test')", "{test}", nil, "format-with-escaped-braces-and-value"}, |
| 231 | {"format('}}')", "}", nil, "format-output-closing-brace"}, |
| 232 | {`format('Hello "{0}" {1} {2} {3} {4}', null, true, -3.14, NaN, Infinity)`, `Hello "" true -3.14 NaN Infinity`, nil, "format-with-primitives"}, |
| 233 | {`format('Hello "{0}" {1} {2}', fromJSON('[0, true, "abc"]'), fromJSON('[{"a":1}]'), fromJSON('{"a":{"b":1}}'))`, `Hello "Array" Array Object`, nil, "format-with-complex-types"}, |
| 234 | {"format(true)", "true", nil, "format-with-primitive-args"}, |
| 235 | {"format('echo Hello {0} ${{Test}}', github.undefined_property)", "echo Hello ${Test}", nil, "format-with-undefined-value"}, |
| 236 | {"format('{0}}', '{1}', 'World')", nil, "Closing bracket without opening one. The following format string is invalid: '{0}}'", "format-invalid-format-string"}, |
| 237 | {"format('{0', '{1}', 'World')", nil, "Unclosed brackets. The following format string is invalid: '{0'", "format-invalid-format-string"}, |
| 238 | {"format('{2}', '{1}', 'World')", "", "The following format string references more arguments than were supplied: '{2}'", "format-invalid-replacement-reference"}, |
| 239 | {"format('{2147483648}')", "", "The following format string is invalid: '{2147483648}'", "format-invalid-replacement-reference"}, |
| 240 | {"format('{0} {1} {2} {3}', 1.0, 1.1, 1234567890.0, 12345678901234567890.0)", "1 1.1 1234567890 1.23456789012346E+19", nil, "format-floats"}, |
| 241 | } |
| 242 | |
| 243 | env := &EvaluationEnvironment{ |
| 244 | Github: &model.GithubContext{}, |
| 245 | } |
| 246 | |
| 247 | for _, tt := range table { |
| 248 | t.Run(tt.name, func(t *testing.T) { |
| 249 | output, err := NewInterpeter(env, Config{}).Evaluate(tt.input, DefaultStatusCheckNone) |
| 250 | if tt.error != nil { |
| 251 | assert.Equal(t, tt.error, err.Error()) |
| 252 | } else { |
| 253 | assert.Nil(t, err) |
| 254 | assert.Equal(t, tt.expected, output) |
| 255 | } |
| 256 | }) |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | func TestMapContains(t *testing.T) { |
| 261 | env := &EvaluationEnvironment{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…