aboutsummaryrefslogtreecommitdiff
path: root/scanners_test.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2021-03-06 22:30:32 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2021-03-06 22:30:32 +0300
commit93740d2d153b3da3a1be5707db1400106e3f6491 (patch)
treeddf705b638434710fa6304201f560f018f4864fe /scanners_test.go
Initial
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)
+ }
+ }
+}