Permalink
Browse files

Added Glob Custom comparator.

Used for testing custom comparators.
  • Loading branch information...
1 parent 7da3db2 commit cfe619c1e0dd233d06d3ce50b94a772b8a1b7c05 @amolenaar amolenaar committed Feb 5, 2014
@@ -0,0 +1,16 @@
+package fitnesse.testsystems.slim;
+
+import java.util.regex.Pattern;
+
+public class GlobComparator implements CustomComparator {
+
+ @Override
+ public boolean matches(String actual, String expected) {
+ return globToRegExp(expected).matcher(actual).matches();
+ }
+
+ private Pattern globToRegExp(String glob) {
+ return Pattern.compile("^\\Q" + glob.replace("*", "\\E.*\\Q").replace("?", "\\E.\\Q") + "\\E$", Pattern.DOTALL);
+ }
+
+}
@@ -0,0 +1,17 @@
+package fitnesse.testsystems.slim;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class GlobComparatorTest {
+
+ @Test
+ public void matchesGlobPatterns() {
+ GlobComparator comparator = new GlobComparator();
+ assertTrue(comparator.matches("foo", "fo*"));
+ assertTrue(comparator.matches("bar", "b*"));
+ assertTrue(comparator.matches("bar", "*"));
+
+ }
+}

0 comments on commit cfe619c

Please sign in to comment.