<commit_before>/*******************************************************************************
 * This file is part of Pebble.
 * 
 * Copyright (c) 2014 by <NAME>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 ******************************************************************************/
package com.mitchellbosecke.pebble.node.expression;

import java.util.Map;

import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.extension.LocaleAware;
import com.mitchellbosecke.pebble.extension.Test;
import com.mitchellbosecke.pebble.node.ArgumentsNode;
import com.mitchellbosecke.pebble.node.TestInvocationExpression;
import com.mitchellbosecke.pebble.template.EvaluationContext;
import com.mitchellbosecke.pebble.template.PebbleTemplateImpl;

public class NegativeTestExpression extends BinaryExpression<Object> {

    @Override
    public Object evaluate(PebbleTemplateImpl self, EvaluationContext context) throws PebbleException {

        TestInvocationExpression testInvocation = (TestInvocationExpression) getRightExpression();
        ArgumentsNode args = testInvocation.getArgs();
        String testName = testInvocation.getTestName();

        Map<String, Test> tests = context.getTests();
        Test test = tests.get(testInvocation.getTestName());

        if (test == null) {
            throw new PebbleException(null, String.format("Test [%s] does not exist.", testName));
        }

        if (test instanceof LocaleAware) {
            ((LocaleAware) test).setLocale(context.getLocale());
        }

        Map<String, Object> namedArguments = args.getArgumentMap(self, context, test);

        return !test.apply(getLeftExpression().evaluate(self, context), namedArguments);
    }
}<commit_msg>Improve handling negative test expression (reuse the positive expression).<commit_after>/*******************************************************************************
 * This file is part of Pebble.
 *
 * Copyright (c) 2014 by <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 ******************************************************************************/
package com.mitchellbosecke.pebble.node.expression;

import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.template.EvaluationContext;
import com.mitchellbosecke.pebble.template.PebbleTemplateImpl;

public class NegativeTestExpression extends PositiveTestExpression {

    @Override
    public Object evaluate(PebbleTemplateImpl self, EvaluationContext context) throws PebbleException {
        return !((Boolean) super.evaluate(self, context));
    }
}
{'fraction_non_alphanumeric': 0.19248826291079812, 'fraction_numerical': 0.00288912964969303, 'mean_word_length': 5.155555555555556, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5632419', 'n_tokens_mistral': 737, 'n_tokens_neox': 691, 'n_words': 173}