25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

57 satır
1.2KB

  1. package gotext
  2. import (
  3. "os"
  4. "path"
  5. "testing"
  6. )
  7. func TestPackageFunctions(t *testing.T) {
  8. // Set PO content
  9. str := `# Some comment
  10. msgid "My text"
  11. msgstr "Translated text"
  12. # More comments
  13. msgid "Another string"
  14. msgstr ""
  15. msgid "One with var: %s"
  16. msgstr "This one sets the var: %s"
  17. `
  18. // Create Locales directory on default location
  19. dirname := path.Clean(library + string(os.PathSeparator) + "en_US")
  20. err := os.MkdirAll(dirname, os.ModePerm)
  21. if err != nil {
  22. t.Fatalf("Can't create test directory: %s", err.Error())
  23. }
  24. // Write PO content to default domain file
  25. filename := path.Clean(dirname + string(os.PathSeparator) + domain + ".po")
  26. f, err := os.Create(filename)
  27. if err != nil {
  28. t.Fatalf("Can't create test file: %s", err.Error())
  29. }
  30. defer f.Close()
  31. _, err = f.WriteString(str)
  32. if err != nil {
  33. t.Fatalf("Can't write to test file: %s", err.Error())
  34. }
  35. // Test translations
  36. tr := Get("My text")
  37. if tr != "Translated text" {
  38. t.Errorf("Expected 'Translated text' but got '%s'", tr)
  39. }
  40. v := "Variable"
  41. tr = Get("One with var: %s", v)
  42. if tr != "This one sets the var: Variable" {
  43. t.Errorf("Expected 'This one sets the var: Variable' but got '%s'", tr)
  44. }
  45. }