From b03283033ede70b7ccaeb4824425202f8e3d3172 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 9 Nov 2013 14:16:22 -0600 Subject: [PATCH] Add a unit test for the regular expression engine We still do not parse the regular expression patterns, but we can at least test that the hardcoded 'a(bb)+a' works as expected. This class will be extended as we support more and more features. Signed-off-by: Johannes Schindelin --- test/Regex.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/Regex.java diff --git a/test/Regex.java b/test/Regex.java new file mode 100644 index 0000000000..dba6aa6e80 --- /dev/null +++ b/test/Regex.java @@ -0,0 +1,26 @@ +import regex.Matcher; +import regex.Pattern; + +public class Regex { + private static void expect(boolean v) { + if (! v) throw new RuntimeException(); + } + + private static Matcher getMatcher(String regex, String string) { + return Pattern.compile(regex).matcher(string); + } + + private static void expectMatch(String regex, String string) { + expect(getMatcher(regex, string).matches()); + } + + private static void expectNoMatch(String regex, String string) { + expect(!getMatcher(regex, string).matches()); + } + + public static void main(String[] args) { + expectMatch("a(bb)?a", "abba"); + expectNoMatch("a(bb)?a", "abbba"); + expectNoMatch("a(bb)?a", "abbaa"); + } +}