forked from segment-boneyard/inflector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinflector_test.go
88 lines (77 loc) · 2 KB
/
inflector_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
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
81
82
83
84
85
86
87
88
/*
* Inflector Pkg (Go)
*
* Copyright (c) 2013 Ivan Torres
* Released under the MIT license
* https://github.com/mexpolk/inflector/blob/master/LICENSE
*
*/
package inflector
import (
"testing"
)
type inflectionSample struct {
str, out string
}
func TestToCamel(t *testing.T) {
samples := []inflectionSample{
{"sample text", "sampleText"},
{"sample-text", "sampleText"},
{"sample_text", "sampleText"},
{"sampleText", "sampleText"},
{"sample 2 Text", "sample2Text"},
}
for _, sample := range samples {
if out := ToCamel(sample.str); out != sample.out {
t.Errorf("got %q, expected %q", out, sample.out)
}
}
}
func TestToDash(t *testing.T) {
samples := []inflectionSample{
{"sample text", "sample-text"},
{"sample-text", "sample-text"},
{"sample_text", "sample-text"},
{"sampleText", "sample-text"},
{"sample 2 Text", "sample-2-text"},
}
for _, sample := range samples {
if out := ToDash(sample.str); out != sample.out {
t.Errorf("got %q, expected %q", out, sample.out)
}
}
}
func TestToPascal(t *testing.T) {
samples := []inflectionSample{
{"sample text", "SampleText"},
{"sample-text", "SampleText"},
{"sample_text", "SampleText"},
{"sampleText", "SampleText"},
{"sample 2 Text", "Sample2Text"},
}
for _, sample := range samples {
if out := ToPascal(sample.str); out != sample.out {
t.Errorf("got %q, expected %q", out, sample.out)
}
}
}
func TestToUnderscore(t *testing.T) {
samples := []inflectionSample{
{"sample text", "sample_text"},
{"sample-text", "sample_text"},
{"sample_text", "sample_text"},
{"sampleText", "sample_text"},
{"sample 2 Text", "sample_2_text"},
{" sample 2 Text ", "sample_2_text"},
{"SAMPLE 2 TEXT", "sample_2_text"},
{"Base64Encode", "base64_encode"},
{"FOO:BAR$BAZ", "foo_bar_baz"},
{"FOO#BAR#BAZ", "foo_bar_baz"},
{"something.com", "something_com"},
}
for _, sample := range samples {
if out := ToUnderscore(sample.str); out != sample.out {
t.Errorf("got %q, expected %q", out, sample.out)
}
}
}