This repository was archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathsoundex_test.go
50 lines (44 loc) · 1.75 KB
/
soundex_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package function
import (
"testing"
"github.com/src-d/go-mysql-server/sql"
"github.com/src-d/go-mysql-server/sql/expression"
"github.com/stretchr/testify/require"
)
func TestSoundex(t *testing.T) {
testCases := []struct {
name string
rowType sql.Type
row sql.Row
expected interface{}
}{
{"text nil", sql.Text, sql.NewRow(nil), nil},
{"text empty", sql.Text, sql.NewRow(""), "0000"},
{"text ignored character", sql.Text, sql.NewRow("-"), "0000"},
{"text runes", sql.Text, sql.NewRow("日本語"), "日000"},
{"text Hello ok", sql.Text, sql.NewRow("Hello"), "H400"},
{"text Quadratically ok", sql.Text, sql.NewRow("Quadratically"), "Q36324"},
{"text Lee ok", sql.Text, sql.NewRow("Lee"), "L000"},
{"text McKnockitter ok", sql.Text, sql.NewRow("McKnockitter"), "M25236"},
{"text Honeyman ok", sql.Text, sql.NewRow("Honeyman"), "H500"},
{"text Munn ok", sql.Text, sql.NewRow("Munn"), "M000"},
{"text Poppett ok", sql.Text, sql.NewRow("Poppett"), "P300"},
{"text Peachman ok", sql.Text, sql.NewRow("Peachman"), "P250"},
{"text Cochrane ok", sql.Text, sql.NewRow("Cochrane"), "C650"},
{"text Chesley ok", sql.Text, sql.NewRow("Chesley"), "C400"},
{"text Tachenion ok", sql.Text, sql.NewRow("Tachenion"), "T250"},
{"text Wilcox ok", sql.Text, sql.NewRow("Wilcox"), "W420"},
{"binary ok", sql.Text, sql.NewRow([]byte("Harvey")), "H610"},
{"string one", sql.Text, sql.NewRow("1"), "0000"},
{"other type", sql.Text, sql.NewRow(int32(1)), "0000"},
}
for _, tt := range testCases {
f := NewSoundex(expression.NewGetField(0, tt.rowType, "", true))
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.expected, eval(t, f, tt.row))
})
req := require.New(t)
req.True(f.IsNullable())
req.Equal(tt.rowType, f.Type())
}
}