package com.hubspot.jinjava.lib.filter;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Before;
import org.junit.Test;

import com.hubspot.jinjava.Jinjava;
import com.hubspot.jinjava.interpret.InterpretException;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;

public class RegexReplaceFilterTest {

    JinjavaInterpreter interpreter;
    RegexReplaceFilter filter;

    @Before
    public void setup() {
        interpreter = new Jinjava().newInterpreter();
        filter = new RegexReplaceFilter();
    }

    @Test(expected = InterpretException.class)
    public void expects2Args() {
        filter.filter("foo", interpreter);
    }

    public void noopOnNullExpr() {
        assertThat(filter.filter(null, interpreter, "foo", "bar")).isNull();
    }

    @Test
    public void replaceString() {
        assertThat(filter.filter("It costs $300", interpreter, "[^a-zA-Z]", "")).isEqualTo("Itcosts");
    }

}

@@ -821,15 +821,33 @@
 oid 
-r
+itMatchesRegexAndR
 eplace
+s
 Stri
@@ -963,10 +963,177 @@
 %0A    %7D%0A%0A
+    @Test(expected = InterpretException.class)%0A    public void isThrowsExceptionOnInvalidRegex() %7B%0A        filter.filter(%22It costs $300%22, interpreter, %22%5B%22, %22%22);%0A    %7D%0A
 %7D%0A

Add test coverage for invalid regex