Improve test coverage to ~100%

This commit is contained in:
Leonel Quinteros
2016-06-26 12:15:08 -03:00
parent 2c5ca9c0e6
commit 21c6bc86cb
3 changed files with 52 additions and 33 deletions

View File

@@ -7,26 +7,26 @@ import (
) )
func TestGettersSetters(t *testing.T) { func TestGettersSetters(t *testing.T) {
SetDomain("test") SetDomain("test")
dom := GetDomain() dom := GetDomain()
if dom != "test" { if dom != "test" {
t.Errorf("Expected GetDomain to return 'test', but got '%s'", dom) t.Errorf("Expected GetDomain to return 'test', but got '%s'", dom)
} }
SetLibrary("/tmp/test") SetLibrary("/tmp/test")
lib := GetLibrary() lib := GetLibrary()
if lib != "/tmp/test" { if lib != "/tmp/test" {
t.Errorf("Expected GetLibrary to return '/tmp/test', but got '%s'", lib) t.Errorf("Expected GetLibrary to return '/tmp/test', but got '%s'", lib)
} }
SetLanguage("es") SetLanguage("es")
lang := GetLanguage() lang := GetLanguage()
if lang != "es" { if lang != "es" {
t.Errorf("Expected GetLanguage to return 'es', but got '%s'", lang) t.Errorf("Expected GetLanguage to return 'es', but got '%s'", lang)
} }
} }
func TestPackageFunctions(t *testing.T) { 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" msgstr[2] "And this is the second plural form: %s"
` `
// Set default configuration // Set default configuration
Configure("/tmp", "en_US", "default") Configure("/tmp", "en_US", "default")
// Create Locales directory on default location // Create Locales directory on default location
dirname := path.Clean(library + string(os.PathSeparator) + "en_US") dirname := path.Clean(library + string(os.PathSeparator) + "en_US")
err := os.MkdirAll(dirname, os.ModePerm) err := os.MkdirAll(dirname, os.ModePerm)

View File

@@ -47,7 +47,7 @@ msgstr[2] "And this is the second plural form: %s"
// Create Locale with full language code // Create Locale with full language code
l := NewLocale("/tmp", "en_US") l := NewLocale("/tmp", "en_US")
// Force nil domain storage // Force nil domain storage
l.domains = nil 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" { 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) t.Errorf("Expected 'And this is the second plural form: Variable' but got '%s'", tr)
} }
// Test non-existent "deafult" domain responses // Test non-existent "deafult" domain responses
tr = l.Get("My text") tr = l.Get("My text")
if tr != "My text" { if tr != "My text" {
t.Errorf("Expected 'My text' but got '%s'", tr) t.Errorf("Expected 'My text' but got '%s'", tr)
} }
tr = l.GetN("One with var: %s", "Several with vars: %s", 2, v) tr = l.GetN("One with var: %s", "Several with vars: %s", 2, v)
if tr != "Several with vars: Variable" { if tr != "Several with vars: Variable" {
t.Errorf("Expected 'Several with vars: Variable' but got '%s'", tr) t.Errorf("Expected 'Several with vars: Variable' but got '%s'", tr)

View File

@@ -45,10 +45,10 @@ msgstr[0] "Badly formatted string'
// Create po object // Create po object
po := new(Po) po := new(Po)
// Try to parse a directory // Try to parse a directory
po.ParseFile(path.Clean(os.TempDir())) po.ParseFile(path.Clean(os.TempDir()))
// Parse file // Parse file
po.ParseFile(filename) po.ParseFile(filename)
@@ -69,30 +69,49 @@ msgstr[0] "Badly formatted string'
if tr != "And this is the second plural form: Variable" { 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) t.Errorf("Expected 'And this is the second plural form: Variable' but got '%s'", tr)
} }
// Test inexistent translations // Test inexistent translations
tr = po.Get("This is a test") tr = po.Get("This is a test")
if tr != "This is a test" { if tr != "This is a test" {
t.Errorf("Expected 'This is a test' but got '%s'", tr) t.Errorf("Expected 'This is a test' but got '%s'", tr)
} }
tr = po.GetN("This is a test", "This are tests", 1) tr = po.GetN("This is a test", "This are tests", 1)
if tr != "This are tests" { if tr != "This are tests" {
t.Errorf("Expected 'This are tests' but got '%s'", tr) t.Errorf("Expected 'This are tests' but got '%s'", tr)
} }
// Test syntax error parsed translations // Test syntax error parsed translations
tr = po.Get("This one has invalid syntax translations") tr = po.Get("This one has invalid syntax translations")
if tr != "" { if tr != "" {
t.Errorf("Expected '' but got '%s'", tr) t.Errorf("Expected '' but got '%s'", tr)
} }
tr = po.GetN("This one has invalid syntax translations", "This are tests", 1) tr = po.GetN("This one has invalid syntax translations", "This are tests", 1)
if tr != "Plural index" { if tr != "Plural index" {
t.Errorf("Expected 'Plural index' but got '%s'", tr) 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) { func TestPoRace(t *testing.T) {
// Set PO content // Set PO content
str := `# Some comment str := `# Some comment