(t *testing.T)
| 506 | } |
| 507 | |
| 508 | func TestSubsetStdLib(t *testing.T) { |
| 509 | env, err := NewCustomEnv( |
| 510 | StdLib(StdLibSubset( |
| 511 | &env.LibrarySubset{ |
| 512 | IncludeMacros: []string{"has"}, |
| 513 | IncludeFunctions: []*env.Function{ |
| 514 | {Name: operators.Equals}, |
| 515 | {Name: operators.NotEquals}, |
| 516 | {Name: operators.LogicalAnd}, |
| 517 | {Name: operators.LogicalOr}, |
| 518 | {Name: operators.LogicalNot}, |
| 519 | {Name: overloads.Size, Overloads: []*env.Overload{{ID: "list_size"}}}, |
| 520 | }, |
| 521 | }, |
| 522 | ))) |
| 523 | if err != nil { |
| 524 | t.Fatalf("StdLib() subsetting failed: %v", err) |
| 525 | } |
| 526 | tests := []struct { |
| 527 | name string |
| 528 | expr string |
| 529 | compiles bool |
| 530 | want ref.Val |
| 531 | }{ |
| 532 | { |
| 533 | name: "has macro", |
| 534 | expr: "!has({}.a)", |
| 535 | compiles: true, |
| 536 | want: types.True, |
| 537 | }, |
| 538 | { |
| 539 | name: "not equals", |
| 540 | expr: "has({}.a) != true", |
| 541 | compiles: true, |
| 542 | want: types.True, |
| 543 | }, |
| 544 | { |
| 545 | name: "logical operators", |
| 546 | expr: "has({}.a) != true && has({'b': 1}.b) == true", |
| 547 | compiles: true, |
| 548 | want: types.True, |
| 549 | }, |
| 550 | { |
| 551 | name: "list size - allowed", |
| 552 | expr: "[1, 2, 3].size()", |
| 553 | compiles: true, |
| 554 | want: types.Int(3), |
| 555 | }, |
| 556 | { |
| 557 | name: "excluded macro", |
| 558 | expr: "[1, 2, 3].exists(i, i != 0)", |
| 559 | compiles: false, |
| 560 | }, |
| 561 | { |
| 562 | name: "string size - not allowed", |
| 563 | expr: "'hello'.size()", |
| 564 | compiles: false, |
| 565 | }, |
nothing calls this directly
no test coverage detected