aboutsummaryrefslogtreecommitdiff
path: root/scanners_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'scanners_test.go')
-rw-r--r--scanners_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/scanners_test.go b/scanners_test.go
new file mode 100644
index 0000000..cab697e
--- /dev/null
+++ b/scanners_test.go
@@ -0,0 +1,53 @@
+package unilex
+
+import "testing"
+
+func TestScanNumber(t *testing.T) {
+ testCases := []struct {
+ Input string
+ Expected bool
+ Pos int
+ }{
+ {"asd", false, 0},
+ {"asd123", false, 0},
+ {"123", true, 3},
+ {"123asd", true, 3},
+ {"123.321", true, 7},
+ }
+ for _, tc := range testCases {
+ l := New(tc.Input)
+ actual := ScanNumber(l)
+ if actual != tc.Expected {
+ t.Errorf("Input: %s expected scan result: %v actual: %v", tc.Input, tc.Expected, actual)
+ }
+ if l.Pos != tc.Pos {
+ t.Errorf("Input: %s expected scan position: %d actual: %d", tc.Input, tc.Pos, l.Pos)
+ }
+ }
+}
+
+func TestScanAlphaNum(t *testing.T) {
+ testCases := []struct {
+ Input string
+ Expected bool
+ Pos int
+ }{
+ {"asd", true, 3},
+ {"asd123", true, 6},
+ {"123", false, 0},
+ {"123asd", false, 0},
+ {"123.321", false, 0},
+ {"asd!dsa", true, 3},
+ {"asd dsa", true, 3},
+ }
+ for _, tc := range testCases {
+ l := New(tc.Input)
+ actual := ScanAlphaNum(l)
+ if actual != tc.Expected {
+ t.Errorf("Input: %s expected scan result: %v actual: %v", tc.Input, tc.Expected, actual)
+ }
+ if l.Pos != tc.Pos {
+ t.Errorf("Input: %s expected scan position: %d actual: %d", tc.Input, tc.Pos, l.Pos)
+ }
+ }
+}