-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaser_test.go
52 lines (45 loc) · 1.48 KB
/
caser_test.go
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
// neng -- Non-Extravagant Name Generator
// Copyright (C) 2024 Wojciech Głąb (github.com/Zedran)
//
// This file is part of neng.
//
// neng is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3 only.
//
// neng is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with neng. If not, see <https://www.gnu.org/licenses/>.
package neng
import "testing"
// Tests case transformations handled by caser.
func TestCaser(t *testing.T) {
type testCase struct {
input string
expected string
function func(string) string
}
caser := newCaser()
cases := []testCase{
{"LOWER", "lower", caser.toLower},
{"LoWeR", "lower", caser.toLower},
{"a man", "A man", caser.toSentence},
{"A MAN", "A man", caser.toSentence},
{"title", "Title", caser.toSentence},
{"title", "Title", caser.toTitle},
{"tItLe", "Title", caser.toTitle},
{"a man", "A Man", caser.toTitle},
{"upper", "UPPER", caser.toUpper},
{"uPpEr", "UPPER", caser.toUpper},
}
for _, c := range cases {
output := c.function(c.input)
if output != c.expected {
t.Errorf("Failed for '%s': expected '%s', got '%s'", c.input, c.expected, output)
}
}
}