/*******************************************************************************
 * This file is part of Pebble.
 * 
 * Copyright (c) 2014 by Mitchell Bösecke
 * 
 * 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);
    }
}

@@ -108,18 +108,17 @@
 bble.%0A *
- 
 %0A
+
  * Copyr
@@ -153,17 +153,16 @@
 secke%0A *
- 
 %0A * For 
@@ -419,31 +419,8 @@
 n;%0A%0A
-import java.util.Map;%0A%0A
 impo
@@ -476,234 +476,8 @@
 on;%0A
-import com.mitchellbosecke.pebble.extension.LocaleAware;%0Aimport com.mitchellbosecke.pebble.extension.Test;%0Aimport com.mitchellbosecke.pebble.node.ArgumentsNode;%0Aimport com.mitchellbosecke.pebble.node.TestInvocationExpression;%0A
 impo
@@ -646,14 +646,20 @@
 nds 
-Binary
+PositiveTest
 Expr
@@ -668,16 +668,8 @@
 sion
-%3CObject%3E
  %7B%0A%0A
@@ -786,25 +786,24 @@
 ption %7B%0A
-%0A
         
 TestInvo
@@ -798,718 +798,32 @@
     
-TestInvocationExpression testInvocation = (TestInvocationExpression) getRightExpression();%0A        ArgumentsNode args = testInvocation.getArgs();%0A        String testName = testInvocation.getTestName();%0A%0A        Map%3CString, Test%3E tests = context.getTests();%0A        Test test = tests.get(testInvocation.getTestName());%0A%0A        if (test == null) %7B%0A            throw new PebbleException(null, String.format(%22Test %5B%25s%5D does not exist.%22, testName));%0A        %7D%0A%0A        if (test instanceof LocaleAware) %7B%0A            ((LocaleAware) test).setLocale(context.getLocale());%0A        %7D%0A%0A        Map%3CString, Object%3E namedArguments = args.getArgumentMap(self, context, test);%0A%0A        return !test.apply(getLeftExpression()
+return !((Boolean) super
 .eva
@@ -846,24 +846,8 @@
 ext)
-, namedArguments
 );%0A 

Improve handling negative test expression (reuse the positive expression).