Improve test coverage to ~100%
This commit is contained in:
parent
2c5ca9c0e6
commit
21c6bc86cb
3 changed files with 52 additions and 33 deletions
|
@ -7,26 +7,26 @@ import (
|
|||
)
|
||||
|
||||
func TestGettersSetters(t *testing.T) {
|
||||
SetDomain("test")
|
||||
dom := GetDomain()
|
||||
|
||||
if dom != "test" {
|
||||
t.Errorf("Expected GetDomain to return 'test', but got '%s'", dom)
|
||||
}
|
||||
|
||||
SetLibrary("/tmp/test")
|
||||
lib := GetLibrary()
|
||||
|
||||
if lib != "/tmp/test" {
|
||||
t.Errorf("Expected GetLibrary to return '/tmp/test', but got '%s'", lib)
|
||||
}
|
||||
|
||||
SetLanguage("es")
|
||||
lang := GetLanguage()
|
||||
|
||||
if lang != "es" {
|
||||
t.Errorf("Expected GetLanguage to return 'es', but got '%s'", lang)
|
||||
}
|
||||
SetDomain("test")
|
||||
dom := GetDomain()
|
||||
|
||||
if dom != "test" {
|
||||
t.Errorf("Expected GetDomain to return 'test', but got '%s'", dom)
|
||||
}
|
||||
|
||||
SetLibrary("/tmp/test")
|
||||
lib := GetLibrary()
|
||||
|
||||
if lib != "/tmp/test" {
|
||||
t.Errorf("Expected GetLibrary to return '/tmp/test', but got '%s'", lib)
|
||||
}
|
||||
|
||||
SetLanguage("es")
|
||||
lang := GetLanguage()
|
||||
|
||||
if lang != "es" {
|
||||
t.Errorf("Expected GetLanguage to return 'es', but got '%s'", lang)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPackageFunctions(t *testing.T) {
|
||||
|
@ -46,10 +46,10 @@ msgstr[1] "This one is the plural: %s"
|
|||
msgstr[2] "And this is the second plural form: %s"
|
||||
|
||||
`
|
||||
|
||||
// Set default configuration
|
||||
Configure("/tmp", "en_US", "default")
|
||||
|
||||
|
||||
// Set default configuration
|
||||
Configure("/tmp", "en_US", "default")
|
||||
|
||||
// Create Locales directory on default location
|
||||
dirname := path.Clean(library + string(os.PathSeparator) + "en_US")
|
||||
err := os.MkdirAll(dirname, os.ModePerm)
|
||||
|
|
|
@ -47,7 +47,7 @@ msgstr[2] "And this is the second plural form: %s"
|
|||
|
||||
// Create Locale with full language code
|
||||
l := NewLocale("/tmp", "en_US")
|
||||
|
||||
|
||||
// Force nil domain storage
|
||||
l.domains = nil
|
||||
|
||||
|
@ -71,13 +71,13 @@ msgstr[2] "And this is the second plural form: %s"
|
|||
if tr != "And this is the second plural form: Variable" {
|
||||
t.Errorf("Expected 'And this is the second plural form: Variable' but got '%s'", tr)
|
||||
}
|
||||
|
||||
|
||||
// Test non-existent "deafult" domain responses
|
||||
tr = l.Get("My text")
|
||||
if tr != "My text" {
|
||||
t.Errorf("Expected 'My text' but got '%s'", tr)
|
||||
}
|
||||
|
||||
|
||||
tr = l.GetN("One with var: %s", "Several with vars: %s", 2, v)
|
||||
if tr != "Several with vars: Variable" {
|
||||
t.Errorf("Expected 'Several with vars: Variable' but got '%s'", tr)
|
||||
|
|
31
po_test.go
31
po_test.go
|
@ -45,10 +45,10 @@ msgstr[0] "Badly formatted string'
|
|||
|
||||
// Create po object
|
||||
po := new(Po)
|
||||
|
||||
|
||||
// Try to parse a directory
|
||||
po.ParseFile(path.Clean(os.TempDir()))
|
||||
|
||||
|
||||
// Parse file
|
||||
po.ParseFile(filename)
|
||||
|
||||
|
@ -69,30 +69,49 @@ msgstr[0] "Badly formatted string'
|
|||
if tr != "And this is the second plural form: Variable" {
|
||||
t.Errorf("Expected 'And this is the second plural form: Variable' but got '%s'", tr)
|
||||
}
|
||||
|
||||
|
||||
// Test inexistent translations
|
||||
tr = po.Get("This is a test")
|
||||
if tr != "This is a test" {
|
||||
t.Errorf("Expected 'This is a test' but got '%s'", tr)
|
||||
}
|
||||
|
||||
|
||||
tr = po.GetN("This is a test", "This are tests", 1)
|
||||
if tr != "This are tests" {
|
||||
t.Errorf("Expected 'This are tests' but got '%s'", tr)
|
||||
}
|
||||
|
||||
|
||||
// Test syntax error parsed translations
|
||||
tr = po.Get("This one has invalid syntax translations")
|
||||
if tr != "" {
|
||||
t.Errorf("Expected '' but got '%s'", tr)
|
||||
}
|
||||
|
||||
|
||||
tr = po.GetN("This one has invalid syntax translations", "This are tests", 1)
|
||||
if tr != "Plural index" {
|
||||
t.Errorf("Expected 'Plural index' but got '%s'", tr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTranslationObject(t *testing.T) {
|
||||
tr := newTranslation()
|
||||
str := tr.get()
|
||||
|
||||
if str != "" {
|
||||
t.Errorf("Expected '' but got '%s'", str)
|
||||
}
|
||||
|
||||
// Set id
|
||||
tr.id = "Text"
|
||||
|
||||
// Get again
|
||||
str = tr.get()
|
||||
|
||||
if str != "Text" {
|
||||
t.Errorf("Expected 'Text' but got '%s'", str)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPoRace(t *testing.T) {
|
||||
// Set PO content
|
||||
str := `# Some comment
|
||||
|
|
Loading…
Reference in a new issue