-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlibvarnam_test.go
71 lines (57 loc) · 2.01 KB
/
libvarnam_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package libvarnam
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func initVarnam(schemeID string) *Varnam {
varnam, err := Init(schemeID)
if err != nil {
return nil
}
return varnam
}
func TestInit(t *testing.T) {
require.NotNil(t, initVarnam("ml"))
}
func TestInitWithIncorrectIdentifierCode(t *testing.T) {
_, err := Init("ml-nonexisting")
require.NoErrorf(t, err, "Expected init to fail when lang code is incorrect")
expectedErrorMessage := "Failed to find symbols file for: ml-nonexisting"
require.EqualErrorf(t, err, expectedErrorMessage, "Expected error message to be: %s, but was: %s", expectedErrorMessage, err.Error())
}
func TestGetSuggestionsFilePath(t *testing.T) {
varnam := initVarnam("ml")
suggestionsFilePath := varnam.GetSuggestionsFilePath()
_, err := os.Stat(suggestionsFilePath)
require.Truef(t, os.IsNotExist(err), "%s: Suggestions file does not exists", suggestionsFilePath)
}
func TestGetCorpusDetails(t *testing.T) {
varnam := initVarnam("hi")
_, err := varnam.GetCorpusDetails()
require.NoErrorf(t, err, "Failed to get corpus details. Got error: %s", err.Error())
}
func TestTransliterate(t *testing.T) {
varnam := initVarnam("ml")
words, err := varnam.Transliterate("navaneeth")
require.NoErrorf(t, err, "Failed to perform transliteration. Got: %s", err.Error())
require.NotEmptyf(t, words, "Failed to perform transliteration. Got 0 words")
}
func TestLearn(t *testing.T) {
varnam := initVarnam("hi")
err := varnam.Learn("भारत")
require.NoErrorf(t, err, "Failed to perform learn. Got error: %s", err.Error())
}
func TestLearnFailure(t *testing.T) {
varnam := initVarnam("hi")
err := varnam.Learn("foo")
require.NoError(t, err, "Expected learn to fail, but didn't fail")
}
func TestGetAllSchemeDetails(t *testing.T) {
schemeDetails := GetAllSchemeDetails()
require.NotEmptyf(t, schemeDetails, "Expected GetAllSchemeDetails to return atlest one scheme details. But returned none")
}
func TestDestroy(t *testing.T) {
varnam := initVarnam("hi")
varnam.Destroy()
}