Permalink
Browse files

hello unittest

  • Loading branch information...
1 parent 69da7de commit 2901de1d78d561dfe6b9a717f41c226a59420630 Alok Menghrajani committed May 3, 2012
Showing with 30 additions and 3 deletions.
  1. +8 −3 Makefile
  2. +22 −0 riskybird_unittest.opa
View
@@ -7,8 +7,7 @@ SRC= \
riskybird_lint.opa \
riskybird_parser.opa \
riskybird_string_printer.opa \
- riskybird_xhtml_printer.opa \
- riskybird.opa
+ riskybird_xhtml_printer.opa
BINDINGS= \
riskybird_binding.js
@@ -20,8 +19,14 @@ default: run
run: riskybird.exe
./riskybird.exe
+test: riskybird_unittest.exe
+ ./riskybird_unittest.exe
+
riskybird.exe: $(BINDINGS_OBJ) $(SRC)
- opa --parser js-like -o riskybird.exe *.op?
+ $(OPA) -o riskybird.exe $(SRC) riskybird.opa
+
+riskybird_unittest.exe: $(BINDINGS_OBJ) $(SRC) riskybird_unittest.opa
+ $(OPA) -o riskybird_unittest.exe $(SRC) riskybird_unittest.opa
clean:
rm -Rf *~ *.exe *.log _build/ *.opp
@@ -0,0 +1,22 @@
+/**
+ * RiskyBird
+ * Regular expression authors best friend
+ *
+ * Running: make test
+ */
+
+import stdlib.tests
+
+function expect_parse(rule_str, s) {
+ p = RegexpParser.parse(s)
+ r = RegexpStringPrinter.pretty_print(p)
+ OK.check_equal("test [{rule_str}]: {s}", s, r)
+}
+
+function expect_fail(rule_str, s) {
+ p = RegexpParser.parse(s)
+ OK.ok_ko("test [{rule_str}]: {s}", Option.is_none(p))
+}
+
+expect_parse("simple expression", "a|bc+")
+expect_fail("open parenthesis", "abc(")

0 comments on commit 2901de1

Please sign in to comment.