| 1641 | } |
| 1642 | |
| 1643 | func TestEnvExtensionIsolation(t *testing.T) { |
| 1644 | baseEnv := testEnv(t, |
| 1645 | Container("google.expr"), |
| 1646 | Variable("age", IntType), |
| 1647 | Variable("gender", StringType), |
| 1648 | Variable("country", StringType), |
| 1649 | ) |
| 1650 | env1, err := baseEnv.Extend( |
| 1651 | Types(&proto2pb.TestAllTypes{}), |
| 1652 | Variable("name", StringType), |
| 1653 | ) |
| 1654 | if err != nil { |
| 1655 | t.Fatal(err) |
| 1656 | } |
| 1657 | env2, err := baseEnv.Extend( |
| 1658 | Types(&proto3pb.TestAllTypes{}), |
| 1659 | Variable("group", StringType), |
| 1660 | ) |
| 1661 | if err != nil { |
| 1662 | t.Fatal(err) |
| 1663 | } |
| 1664 | _, issues := env2.Compile(`size(group) > 10 |
| 1665 | && !has(proto3.test.TestAllTypes{}.single_int32)`) |
| 1666 | if issues.Err() != nil { |
| 1667 | t.Fatal(issues.Err()) |
| 1668 | } |
| 1669 | _, issues = env2.Compile(`size(name) > 10`) |
| 1670 | if issues.Err() == nil { |
| 1671 | t.Fatal("env2 contains 'name', but should not") |
| 1672 | } |
| 1673 | _, issues = env2.Compile(`!has(proto2.test.TestAllTypes{}.single_int32)`) |
| 1674 | if issues.Err() == nil { |
| 1675 | t.Fatal("env2 contains 'proto2.test.TestAllTypes', but should not") |
| 1676 | } |
| 1677 | |
| 1678 | _, issues = env1.Compile(`size(name) > 10 |
| 1679 | && !has(proto2.test.TestAllTypes{}.single_int32)`) |
| 1680 | if issues.Err() != nil { |
| 1681 | t.Fatal(issues.Err()) |
| 1682 | } |
| 1683 | _, issues = env1.Compile("size(group) > 10") |
| 1684 | if issues.Err() == nil { |
| 1685 | t.Fatal("env1 contains 'group', but should not") |
| 1686 | } |
| 1687 | _, issues = env1.Compile(`!has(proto3.test.TestAllTypes{}.single_int32)`) |
| 1688 | if issues.Err() == nil { |
| 1689 | t.Fatal("env1 contains 'proto3.test.TestAllTypes', but should not") |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | func TestVariadicLogicalOperators(t *testing.T) { |
| 1694 | env := testEnv(t, variadicLogicalOperatorASTs()) |