blob: 335c7ee79b713fd2baa2471edc6a7c1ee9ce9e7b [file] [log] [blame]
Akron8ef408b2021-08-02 22:11:04 +02001package datokenizer
2
3import (
Akron8ef408b2021-08-02 22:11:04 +02004 "testing"
5
6 "github.com/stretchr/testify/assert"
7)
8
9func TestSimpleString(t *testing.T) {
10 assert := assert.New(t)
11
12 // bau | bauamt
Akron740f3d72021-08-03 12:12:34 +020013 tok := ParseFile("testdata/bauamt.fst")
Akronf2120ca2021-08-03 16:26:41 +020014 dat := tok.ToDoubleArray()
15 assert.True(dat.Match("bau"))
16 assert.True(dat.Match("bauamt"))
17 assert.False(dat.Match("baum"))
Akron8ef408b2021-08-02 22:11:04 +020018}
Akron75ebe7f2021-08-03 10:34:10 +020019
20func TestSimpleBranches(t *testing.T) {
21 assert := assert.New(t)
22
23 // (bau | wahl) (amt | en)
Akron740f3d72021-08-03 12:12:34 +020024 tok := ParseFile("testdata/wahlamt.fst")
Akronf2120ca2021-08-03 16:26:41 +020025 dat := tok.ToDoubleArray()
26 assert.False(dat.Match("bau"))
27 assert.True(dat.Match("bauamt"))
28 assert.True(dat.Match("wahlamt"))
29 assert.True(dat.Match("bauen"))
30 assert.True(dat.Match("wahlen"))
31 assert.False(dat.Match("baum"))
Akron75ebe7f2021-08-03 10:34:10 +020032}
Akron730a79c2021-08-03 11:05:29 +020033
34func TestSimpleTokenizer(t *testing.T) {
35 assert := assert.New(t)
Akron740f3d72021-08-03 12:12:34 +020036 tok := ParseFile("testdata/simpletok.fst")
Akronf2120ca2021-08-03 16:26:41 +020037 dat := tok.ToDoubleArray()
38 assert.True(dat.Match("bau"))
39 assert.True(dat.Match("bad"))
40 assert.True(dat.Match("wald gehen"))
Akron730a79c2021-08-03 11:05:29 +020041}
Akron740f3d72021-08-03 12:12:34 +020042
Akron740f3d72021-08-03 12:12:34 +020043func TestFullTokenizer(t *testing.T) {
44 assert := assert.New(t)
45 tok := ParseFile("testdata/tokenizer.fst")
Akronf2120ca2021-08-03 16:26:41 +020046 dat := tok.ToDoubleArray()
Akrond66a9262021-08-03 17:09:09 +020047 assert.True(dat.loadLevel() >= 70)
Akronf2120ca2021-08-03 16:26:41 +020048 assert.True(dat.Match("bau"))
49 assert.True(dat.Match("bad"))
50 assert.True(dat.Match("wald gehen"))
Akron740f3d72021-08-03 12:12:34 +020051}