-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdecritic_test.go
More file actions
80 lines (71 loc) · 1.96 KB
/
decritic_test.go
File metadata and controls
80 lines (71 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"bytes"
"io"
"os"
"strings"
"testing"
"github.com/urfave/cli/v2"
)
func TestDecritic(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{"Empty", "", ""},
{"ASCII", "hello world", "hello world"},
{"French", "déjà vu", "deja vu"},
{"Spanish", "pingüino", "pinguino"},
{"German", "über", "uber"},
{"Vietnamese", "phở", "pho"},
{"Mixed", "crème brûlée", "creme brulee"},
{"More French", "français", "francais"},
{"More Spanish", "mañana", "manana"},
{"More German", "schön", "schon"},
{"Accents on capitals", "ÉÀÇ", "EAC"},
{"Czech", "žluťoučký kůň", "zlutoucky kun"},
{"Polish", "zażółć gęślą jaźń", "zazołc gesla jazn"},
{"Romanian", "învățământ", "invatamant"},
{"Slovak", "ľúbozvučný", "lubozvucny"},
{"Hungarian", "árvíztűrő tükörfúrógép", "arvizturo tukorfurogep"},
{"Latvian", "glāžšķūņu rūķīši", "glazskunu rukisi"},
{"Lithuanian", "įgarsinkite", "igarsinkite"},
{"Turkish", "şeker", "seker"},
{"Icelandic", "hæð", "hæð"},
{"No accents", "12345", "12345"},
{"Symbols", "!@#$%^&*()", "!@#$%^&*()"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Simulate command-line arguments
app := &cli.App{
Action: action,
}
// Redirect stdout to a buffer to capture the output
oldStdout := os.Stdout
r, w, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
os.Stdout = w
// Run the action with the test input
args := os.Args[0:1]
args = append(args, strings.Split(tt.input, " ")...)
if err := app.Run(args); err != nil {
t.Fatal(err)
}
// Restore stdout
w.Close()
os.Stdout = oldStdout
var buf bytes.Buffer
if _, err := io.Copy(&buf, r); err != nil {
t.Fatal(err)
}
got := strings.TrimSpace(buf.String())
if got != tt.expected {
t.Errorf("decritic(%q) = %q; want %q", tt.input, got, tt.expected)
}
})
}
}