From 685e4a1f0b9038e102e18bf9ed18c9d0f5a67b98 Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Fri, 9 Jan 2015 19:41:12 -0500 Subject: [PATCH] Add unit tests --- test/init.nim | 26 ++++++++++++++++++++++++++ test/testall.nim | 1 + 2 files changed, 27 insertions(+) create mode 100644 test/init.nim create mode 100644 test/testall.nim diff --git a/test/init.nim b/test/init.nim new file mode 100644 index 0000000000..a3c9f24fef --- /dev/null +++ b/test/init.nim @@ -0,0 +1,26 @@ +import unittest +include nre + +suite "Test NRE initialization": + test "correct intialization": + check(initRegex("[0-9]+") != nil) + check(initRegex("[0-9]+", "iS") != nil) + + test "correct options": + expect(SyntaxError): # ValueError would be bad + discard initRegex("[0-9]+", + "89?AEfiJmNOsUWXxY") + + test "incorrect options": + expect(KeyError): discard initRegex("[0-9]+", "a") + expect(KeyError): discard initRegex("[0-9]+", "") + + test "invalid regex": + expect(SyntaxError): discard initRegex("[0-9") + try: + discard initRegex("[0-9") + except SyntaxError: + let ex = SyntaxError(getCurrentException()) + check(ex.pos == 4) + check(ex.pattern == "[0-9") + diff --git a/test/testall.nim b/test/testall.nim new file mode 100644 index 0000000000..214787264c --- /dev/null +++ b/test/testall.nim @@ -0,0 +1 @@ +include init