(t *testing.T)
| 421 | } |
| 422 | |
| 423 | func TestSubsetStdLib(t *testing.T) { |
| 424 | env, err := NewCustomEnv( |
| 425 | StdLib(StdLibSubset( |
| 426 | &env.LibrarySubset{ |
| 427 | IncludeMacros: []string{"has"}, |
| 428 | IncludeFunctions: []*env.Function{ |
| 429 | {Name: operators.Equals}, |
| 430 | {Name: operators.NotEquals}, |
| 431 | {Name: operators.LogicalAnd}, |
| 432 | {Name: operators.LogicalOr}, |
| 433 | {Name: operators.LogicalNot}, |
| 434 | {Name: overloads.Size, Overloads: []*env.Overload{{ID: "list_size"}}}, |
| 435 | }, |
| 436 | }, |
| 437 | ))) |
| 438 | if err != nil { |
| 439 | t.Fatalf("StdLib() subsetting failed: %v", err) |
| 440 | } |
| 441 | tests := []struct { |
| 442 | name string |
| 443 | expr string |
| 444 | compiles bool |
| 445 | want ref.Val |
| 446 | }{ |
| 447 | { |
| 448 | name: "has macro", |
| 449 | expr: "!has({}.a)", |
| 450 | compiles: true, |
| 451 | want: types.True, |
| 452 | }, |
| 453 | { |
| 454 | name: "not equals", |
| 455 | expr: "has({}.a) != true", |
| 456 | compiles: true, |
| 457 | want: types.True, |
| 458 | }, |
| 459 | { |
| 460 | name: "logical operators", |
| 461 | expr: "has({}.a) != true && has({'b': 1}.b) == true", |
| 462 | compiles: true, |
| 463 | want: types.True, |
| 464 | }, |
| 465 | { |
| 466 | name: "list size - allowed", |
| 467 | expr: "[1, 2, 3].size()", |
| 468 | compiles: true, |
| 469 | want: types.Int(3), |
| 470 | }, |
| 471 | { |
| 472 | name: "excluded macro", |
| 473 | expr: "[1, 2, 3].exists(i, i != 0)", |
| 474 | compiles: false, |
| 475 | }, |
| 476 | { |
| 477 | name: "string size - not allowed", |
| 478 | expr: "'hello'.size()", |
| 479 | compiles: false, |
| 480 | }, |
nothing calls this directly
no test coverage detected