Initial import
This commit is contained in:
52
po_test.go
Normal file
52
po_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package gotext
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPo(t *testing.T) {
|
||||
// Set PO content
|
||||
str := `# Some comment
|
||||
msgid "My text"
|
||||
msgstr "Translated text"
|
||||
|
||||
# More comments
|
||||
msgid "Another string"
|
||||
msgstr ""
|
||||
|
||||
msgid "One with var: %s"
|
||||
msgstr "This one sets the var: %s"
|
||||
|
||||
`
|
||||
// Write PO content to file
|
||||
filename := path.Clean(os.TempDir() + string(os.PathSeparator) + "default.po")
|
||||
|
||||
f, err := os.Create(filename)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't create test file: %s", err.Error())
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, err = f.WriteString(str)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't write to test file: %s", err.Error())
|
||||
}
|
||||
|
||||
// Parse po file
|
||||
po := new(Po)
|
||||
po.ParseFile(filename)
|
||||
|
||||
// Test translations
|
||||
tr := po.Get("My text")
|
||||
if tr != "Translated text" {
|
||||
t.Errorf("Expected 'Translated text' but got '%s'", tr)
|
||||
}
|
||||
|
||||
v := "Variable"
|
||||
tr = po.Get("One with var: %s", v)
|
||||
if tr != "This one sets the var: Variable" {
|
||||
t.Errorf("Expected 'This one sets the var: Variable' but got '%s'", tr)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user