Exemplo n.º 1
0
def test_string_concat():
    # Because we don't have implicit type conversions like JavaScript,
    # we diverge from the original JEXL test suite and add a filter.
    config = JEXLConfig({'str': str}, default_binary_operators, default_unary_operators)
    evaluator = Evaluator(config)
    result = evaluator.evaluate(tree('"Hello" + (4+4)|str + "Wo\\"rld"'))
    assert result == 'Hello8Wo"rld'
def test_string_concat():
    # Because we don't have implicit type conversions like JavaScript,
    # we diverge from the original JEXL test suite and add a filter.
    config = JEXLConfig({'str': str}, default_binary_operators,
                        default_unary_operators)
    evaluator = Evaluator(config)
    result = evaluator.evaluate(tree('"Hello" + (4+4)|str + "Wo\\"rld"'))
    assert result == 'Hello8Wo"rld'
Exemplo n.º 3
0
def test_transforms():
    config = JEXLConfig(
        {'half': lambda x: x / 2},
        default_binary_operators,
        default_unary_operators
    )
    evaluator = Evaluator(config)
    result = evaluator.evaluate(tree('foo|half + 3'), {'foo': 10})
    assert result == 8
def test_transforms_multiple_arguments():
    config = JEXLConfig(binary_operators=default_binary_operators,
                        unary_operators=default_unary_operators,
                        transforms={
                            'concat':
                            lambda val, a1, a2, a3: val + ': ' + a1 + a2 + a3,
                        })
    evaluator = Evaluator(config)
    result = evaluator.evaluate(tree('"foo"|concat("baz", "bar", "tek")'))
    assert result == 'foo: bazbartek'
Exemplo n.º 5
0
def test_transforms_multiple_arguments():
    config = JEXLConfig(
        binary_operators=default_binary_operators,
        unary_operators=default_unary_operators,
        transforms={
            'concat': lambda val, a1, a2, a3: val + ': ' + a1 + a2 + a3,
        }
    )
    evaluator = Evaluator(config)
    result = evaluator.evaluate(tree('"foo"|concat("baz", "bar", "tek")'))
    assert result == 'foo: bazbartek'
def test_transforms():
    config = JEXLConfig({'half': lambda x: x / 2}, default_binary_operators,
                        default_unary_operators)
    evaluator = Evaluator(config)
    result = evaluator.evaluate(tree('foo|half + 3'), {'foo': 10})
    assert result == 8
Exemplo n.º 7
0
 def evaluate(self, expression, context=None):
     parsed_expression = self.parse(expression)
     context = Context(context) if context is not None else self.context
     return Evaluator(self.config).evaluate(parsed_expression, context)