1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import org.pablotron.luigi.LuigiError;
import org.pablotron.luigi.Template;
import org.pablotron.luigi.Filter;
import org.pablotron.luigi.FilterError;
import org.pablotron.luigi.ResultHandler;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
public final class DefaultFiltersTest {
private static final class TestCase {
private final String name;
private final String arg;
public final String expect;
public TestCase(final String name, final String arg, final String expect) {
this.name = name;
this.arg = arg;
this.expect = expect;
}
public String run() throws LuigiError {
final Map<String, String> args = new HashMap<String, String>();
args.put("val", arg);
return Template.run(String.format("%%{val|%s}", name), args);
}
};
private static final List<TestCase> TEST_CASES = new ArrayList<TestCase>() {{
add(new TestCase("uc", "bar", "BAR"));
add(new TestCase("lc", "BAR", "bar"));
add(new TestCase("h", "asdf<>&\"'\u000f", "asdf<>&"'"));
add(new TestCase("u", "asdf<>&\"' \u000f", "asdf%3C%3E%26%22%27+%0F"));
add(new TestCase("trim", " \r\n\tfoo", "foo"));
add(new TestCase("trim", " \r\n\tfoo \r\n\t", "foo"));
add(new TestCase("trim", "foo \r\n\t", "foo"));
}};
@Test
public void testDefaultFilters() throws LuigiError {
for (final TestCase t: TEST_CASES) {
assertEquals(t.expect, t.run());
}
}
};
|