(t *testing.T)
| 401 | } |
| 402 | |
| 403 | func TestSubsetStdLib(t *testing.T) { |
| 404 | env, err := NewCustomEnv( |
| 405 | StdLib(StdLibSubset( |
| 406 | &env.LibrarySubset{ |
| 407 | IncludeMacros: []string{"has"}, |
| 408 | IncludeFunctions: []*env.Function{ |
| 409 | {Name: operators.Equals}, |
| 410 | {Name: operators.NotEquals}, |
| 411 | {Name: operators.LogicalAnd}, |
| 412 | {Name: operators.LogicalOr}, |
| 413 | {Name: operators.LogicalNot}, |
| 414 | {Name: overloads.Size, Overloads: []*env.Overload{{ID: "list_size"}}}, |
| 415 | }, |
| 416 | }, |
| 417 | ))) |
| 418 | if err != nil { |
| 419 | t.Fatalf("StdLib() subsetting failed: %v", err) |
| 420 | } |
| 421 | tests := []struct { |
| 422 | name string |
| 423 | expr string |
| 424 | compiles bool |
| 425 | want ref.Val |
| 426 | }{ |
| 427 | { |
| 428 | name: "has macro", |
| 429 | expr: "!has({}.a)", |
| 430 | compiles: true, |
| 431 | want: types.True, |
| 432 | }, |
| 433 | { |
| 434 | name: "not equals", |
| 435 | expr: "has({}.a) != true", |
| 436 | compiles: true, |
| 437 | want: types.True, |
| 438 | }, |
| 439 | { |
| 440 | name: "logical operators", |
| 441 | expr: "has({}.a) != true && has({'b': 1}.b) == true", |
| 442 | compiles: true, |
| 443 | want: types.True, |
| 444 | }, |
| 445 | { |
| 446 | name: "list size - allowed", |
| 447 | expr: "[1, 2, 3].size()", |
| 448 | compiles: true, |
| 449 | want: types.Int(3), |
| 450 | }, |
| 451 | { |
| 452 | name: "excluded macro", |
| 453 | expr: "[1, 2, 3].exists(i, i != 0)", |
| 454 | compiles: false, |
| 455 | }, |
| 456 | { |
| 457 | name: "string size - not allowed", |
| 458 | expr: "'hello'.size()", |
| 459 | compiles: false, |
| 460 | }, |
nothing calls this directly
no test coverage detected