Akron | 8ef408b | 2021-08-02 22:11:04 +0200 | [diff] [blame] | 1 | package datokenizer |
| 2 | |
| 3 | import ( |
Akron | c9d84a6 | 2021-08-03 15:56:03 +0200 | [diff] [blame^] | 4 | "fmt" |
Akron | 8ef408b | 2021-08-02 22:11:04 +0200 | [diff] [blame] | 5 | "testing" |
| 6 | |
| 7 | "github.com/stretchr/testify/assert" |
| 8 | ) |
| 9 | |
| 10 | func TestSimpleString(t *testing.T) { |
| 11 | assert := assert.New(t) |
| 12 | |
| 13 | // bau | bauamt |
Akron | 740f3d7 | 2021-08-03 12:12:34 +0200 | [diff] [blame] | 14 | tok := ParseFile("testdata/bauamt.fst") |
| 15 | tok.ToDoubleArray() |
| 16 | assert.True(tok.Match("bau")) |
| 17 | assert.True(tok.Match("bauamt")) |
| 18 | assert.False(tok.Match("baum")) |
Akron | 8ef408b | 2021-08-02 22:11:04 +0200 | [diff] [blame] | 19 | } |
Akron | 75ebe7f | 2021-08-03 10:34:10 +0200 | [diff] [blame] | 20 | |
| 21 | func TestSimpleBranches(t *testing.T) { |
| 22 | assert := assert.New(t) |
| 23 | |
| 24 | // (bau | wahl) (amt | en) |
Akron | 740f3d7 | 2021-08-03 12:12:34 +0200 | [diff] [blame] | 25 | tok := ParseFile("testdata/wahlamt.fst") |
| 26 | tok.ToDoubleArray() |
| 27 | assert.False(tok.Match("bau")) |
| 28 | assert.True(tok.Match("bauamt")) |
| 29 | assert.True(tok.Match("wahlamt")) |
| 30 | assert.True(tok.Match("bauen")) |
| 31 | assert.True(tok.Match("wahlen")) |
| 32 | assert.False(tok.Match("baum")) |
Akron | 75ebe7f | 2021-08-03 10:34:10 +0200 | [diff] [blame] | 33 | } |
Akron | 730a79c | 2021-08-03 11:05:29 +0200 | [diff] [blame] | 34 | |
| 35 | func TestSimpleTokenizer(t *testing.T) { |
| 36 | assert := assert.New(t) |
Akron | 740f3d7 | 2021-08-03 12:12:34 +0200 | [diff] [blame] | 37 | tok := ParseFile("testdata/simpletok.fst") |
| 38 | tok.ToDoubleArray() |
| 39 | assert.True(tok.Match("bau")) |
| 40 | assert.True(tok.Match("bad")) |
| 41 | assert.True(tok.Match("wald gehen")) |
Akron | 730a79c | 2021-08-03 11:05:29 +0200 | [diff] [blame] | 42 | } |
Akron | 740f3d7 | 2021-08-03 12:12:34 +0200 | [diff] [blame] | 43 | |
Akron | 740f3d7 | 2021-08-03 12:12:34 +0200 | [diff] [blame] | 44 | func TestFullTokenizer(t *testing.T) { |
| 45 | assert := assert.New(t) |
| 46 | tok := ParseFile("testdata/tokenizer.fst") |
| 47 | tok.ToDoubleArray() |
Akron | c9d84a6 | 2021-08-03 15:56:03 +0200 | [diff] [blame^] | 48 | fmt.Println("Size:", tok.maxSize) |
Akron | 740f3d7 | 2021-08-03 12:12:34 +0200 | [diff] [blame] | 49 | assert.True(tok.Match("bau")) |
| 50 | assert.True(tok.Match("bad")) |
| 51 | assert.True(tok.Match("wald gehen")) |
| 52 | } |