-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl_test.go
More file actions
68 lines (64 loc) · 1.52 KB
/
repl_test.go
File metadata and controls
68 lines (64 loc) · 1.52 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
package main
import (
"testing"
)
func TestCleanInput(t *testing.T) {
cases := []struct {
input string
expected []string
}{
{
input: " hello world ",
expected: []string{"hello", "world"},
},
{
input: "foo bar baz",
expected: []string{"foo", "bar", "baz"},
},
{
input: "THIS SHOULD BE LOWERCASE",
expected: []string{"this", "should", "be", "lowercase"},
},
{
input: " mixed CASE Input ",
expected: []string{"mixed", "case", "input"},
},
{
input: "",
expected: []string{},
},
{
input: "fire\twater\n grass",
expected: []string{"fire", "water", "grass"},
},
{
input: " \n\t ",
expected: []string{},
},
{
input: " Eevee ",
expected: []string{"eevee"},
},
}
for _, c := range cases {
actual := cleanInput(c.input)
// Check the length of the actual slice against the expected slice
actualSize := len(actual)
expectedSize := len(c.expected)
if actualSize != expectedSize {
t.Errorf("resulting slice does not match number of items expected. expected [%v], got [%v]", expectedSize, actualSize)
}
// if they don't match, use t.Errorf to print an error message
// and fail the test
for i := range actual {
word := actual[i]
expectedWord := c.expected[i]
// Check each word in the slice
// if they don't match, use t.Errorf to print an error message
// and fail the test
if word != expectedWord {
t.Errorf("provided word [%s] does not match expected word %s", word, expectedWord)
}
}
}
}