aboutsummaryrefslogtreecommitdiff
path: root/tests/functional
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional')
-rw-r--r--tests/functional/api-usage/gotext.go81
1 files changed, 60 insertions, 21 deletions
diff --git a/tests/functional/api-usage/gotext.go b/tests/functional/api-usage/gotext.go
index 7ea7119..88dcbd0 100644
--- a/tests/functional/api-usage/gotext.go
+++ b/tests/functional/api-usage/gotext.go
@@ -1,66 +1,105 @@
package gotext
import (
+ "fmt"
"os"
-
- g "gobang"
+ "reflect"
)
+func showColour() bool {
+ return os.Getenv("NO_COLOUR") == ""
+}
+
+func testStart(name string) {
+ fmt.Fprintf(os.Stderr, "%s:\n", name)
+}
+
+func testing(message string, body func()) {
+ if showColour() {
+ fmt.Fprintf(
+ os.Stderr,
+ "\033[0;33mtesting\033[0m: %s... ",
+ message,
+ )
+ body()
+ fmt.Fprintf(os.Stderr, "\033[0;32mOK\033[0m.\n")
+ } else {
+ fmt.Fprintf(os.Stderr, "testing: %s... ", message)
+ body()
+ fmt.Fprintf(os.Stderr, "OK.\n")
+ }
+}
+
+func assertEq(given any, expected any) {
+ if !reflect.DeepEqual(given, expected) {
+ if showColour() {
+ fmt.Fprintf(os.Stderr, "\033[0;31mERR\033[0m.\n")
+ } else {
+ fmt.Fprintf(os.Stderr, "ERR.\n")
+ }
+ fmt.Fprintf(os.Stderr, "given != expected\n")
+ fmt.Fprintf(os.Stderr, "given: %#v\n", given)
+ fmt.Fprintf(os.Stderr, "expected: %#v\n", expected)
+ os.Exit(1)
+ }
+}
+
+
+
func MainTest() {
- g.Init()
Init("tests", "locale/")
- g.Testing("Español", func() {
+ testing("Español", func() {
os.Setenv("LANGUAGE", "es_MX.UTF-8")
SetLocale(LC_ALL, "")
- g.TAssertEqual(Gettext("Hello, world!"), "¡Hola, mundo!")
- g.TAssertEqual(Gettext("Good morning"), "Buenos días")
- g.TAssertEqual(Gettext("Good bye!"), "¡Hasta luego!")
- g.TAssertEqual(Sprintf(
+ assertEq(Gettext("Hello, world!"), "¡Hola, mundo!")
+ assertEq(Gettext("Good morning"), "Buenos días")
+ assertEq(Gettext("Good bye!"), "¡Hasta luego!")
+ assertEq(Sprintf(
NGettext("An apple", "%d apples", 1),
1,
"garbage",
), "Una manzana")
- g.TAssertEqual(Sprintf(
+ assertEq(Sprintf(
NGettext("An apple", "%d apples", 3),
3,
), "3 manzanas")
})
- g.Testing("Deutsch", func() {
+ testing("Deutsch", func() {
os.Setenv("LANGUAGE", "de_DE.UTF-8")
SetLocale(LC_ALL, "")
- g.TAssertEqual(Gettext("Hello, world!"), "Hallo, Welt!")
- g.TAssertEqual(Gettext("Good morning"), "Guten Morgen")
- g.TAssertEqual(Gettext("Good bye!"), "Auf Wiedersehen!")
- g.TAssertEqual(Sprintf(
+ assertEq(Gettext("Hello, world!"), "Hallo, Welt!")
+ assertEq(Gettext("Good morning"), "Guten Morgen")
+ assertEq(Gettext("Good bye!"), "Auf Wiedersehen!")
+ assertEq(Sprintf(
NGettext("An apple", "%d apples", 1),
1,
"garbage",
), "Ein Apfel")
- g.TAssertEqual(Sprintf(
+ assertEq(Sprintf(
NGettext("An apple", "%d apples", 3),
3,
), "3 Äpfel")
})
- g.Testing("Français", func() {
+ testing("Français", func() {
os.Setenv("LANGUAGE", "fr_FR.UTF-8")
SetLocale(LC_ALL, "")
- g.TAssertEqual(Gettext("Hello, world!"), "Hello, world!")
- g.TAssertEqual(Gettext("Good morning"), "Good morning")
- g.TAssertEqual(Gettext("Good bye!"), "Good bye!")
- g.TAssertEqual(Sprintf(
+ assertEq(Gettext("Hello, world!"), "Hello, world!")
+ assertEq(Gettext("Good morning"), "Good morning")
+ assertEq(Gettext("Good bye!"), "Good bye!")
+ assertEq(Sprintf(
NGettext("An apple", "%d apples", 1),
1,
"garbage",
), "An apple")
- g.TAssertEqual(Sprintf(
+ assertEq(Sprintf(
NGettext("An apple", "%d apples", 3),
3,
), "3 apples")