@@ -6,49 +6,7 @@ import (
6
6
"github.com/72636c/hyperspaced"
7
7
)
8
8
9
- func Test_Spaced (t * testing.T ) {
10
- testCases := []struct {
11
- description string
12
- input string
13
- expected string
14
- }{
15
- {
16
- description : "Empty String" ,
17
- input : "" ,
18
- expected : "" ,
19
- },
20
- {
21
- description : "One Word" ,
22
- input : "AESTHETIC" ,
23
- expected : "A E S T H E T I C" ,
24
- },
25
- {
26
- description : "Two Words" ,
27
- input : "no u" ,
28
- expected : "n o u" ,
29
- },
30
- {
31
- description : "Emojified Buzzword" ,
32
- input : "\U0001f30f planet scale \u2696 " ,
33
- expected : "🌏 p l a n e t s c a l e ⚖" ,
34
- },
35
- }
36
-
37
- for _ , testCase := range testCases {
38
- t .Run (testCase .description , func (t * testing.T ) {
39
- actual := hyperspaced .Spaced (testCase .input )
40
- if actual != testCase .expected {
41
- t .Errorf (
42
- "expected %+[1]q (%[1]s), received %+[2]q (%[2]s)" ,
43
- testCase .expected ,
44
- actual ,
45
- )
46
- }
47
- })
48
- }
49
- }
50
-
51
- func Test_SpacedN (t * testing.T ) {
9
+ func Suite_N (t * testing.T , f func (string , int ) string ) {
52
10
testCases := []struct {
53
11
description string
54
12
inputString string
@@ -71,7 +29,7 @@ func Test_SpacedN(t *testing.T) {
71
29
72
30
for _ , testCase := range testCases {
73
31
t .Run (testCase .description , func (t * testing.T ) {
74
- actual := hyperspaced . SpacedN (testCase .inputString , testCase .inputN )
32
+ actual := f (testCase .inputString , testCase .inputN )
75
33
if actual != testCase .expected {
76
34
t .Errorf (
77
35
"expected %+[1]q (%[1]s), received %+[2]q (%[2]s)" ,
@@ -83,8 +41,8 @@ func Test_SpacedN(t *testing.T) {
83
41
}
84
42
}
85
43
86
- func Test_SpacedN_Panics_OnNegativeN (t * testing.T ) {
87
- expectedMessage := "hyperspaced.SpacedN: really?"
44
+ func Suite_N_Panics_OnNegativeN (t * testing.T , f func ( string , int ) string ) {
45
+ expectedMessage := "hyperspaced/internal/text .SpacedN: really?"
88
46
89
47
defer func () {
90
48
r := recover ()
@@ -105,7 +63,73 @@ func Test_SpacedN_Panics_OnNegativeN(t *testing.T) {
105
63
}
106
64
}()
107
65
108
- hyperspaced . SpacedN ("" , - 1 )
66
+ f ("" , - 1 )
109
67
110
68
t .Error ("expected panic" )
111
69
}
70
+
71
+ func Suite_One (t * testing.T , f func (string ) string ) {
72
+ testCases := []struct {
73
+ description string
74
+ input string
75
+ expected string
76
+ }{
77
+ {
78
+ description : "Empty String" ,
79
+ input : "" ,
80
+ expected : "" ,
81
+ },
82
+ {
83
+ description : "One Word" ,
84
+ input : "AESTHETIC" ,
85
+ expected : "A E S T H E T I C" ,
86
+ },
87
+ {
88
+ description : "Two Words" ,
89
+ input : "no u" ,
90
+ expected : "n o u" ,
91
+ },
92
+ {
93
+ description : "Emojified Buzzword" ,
94
+ input : "\U0001f30f planet scale \u2696 " ,
95
+ expected : "🌏 p l a n e t s c a l e ⚖" ,
96
+ },
97
+ }
98
+
99
+ for _ , testCase := range testCases {
100
+ t .Run (testCase .description , func (t * testing.T ) {
101
+ actual := f (testCase .input )
102
+ if actual != testCase .expected {
103
+ t .Errorf (
104
+ "expected %+[1]q (%[1]s), received %+[2]q (%[2]s)" ,
105
+ testCase .expected ,
106
+ actual ,
107
+ )
108
+ }
109
+ })
110
+ }
111
+ }
112
+
113
+ func Test_N (t * testing.T ) {
114
+ Suite_N (t , hyperspaced .N )
115
+ }
116
+
117
+ func Test_N_Panics_OnNegativeN (t * testing.T ) {
118
+ Suite_N_Panics_OnNegativeN (t , hyperspaced .N )
119
+ }
120
+
121
+ func Test_One (t * testing.T ) {
122
+ Suite_One (t , hyperspaced .One )
123
+ }
124
+
125
+ func Test_Spaced (t * testing.T ) {
126
+ Suite_One (t , hyperspaced .Spaced )
127
+ }
128
+
129
+ func Test_SpacedN (t * testing.T ) {
130
+ Suite_N (t , hyperspaced .SpacedN )
131
+ }
132
+
133
+ func Test_SpacedN_Panics_OnNegativeN (t * testing.T ) {
134
+ Suite_N_Panics_OnNegativeN (t , hyperspaced .SpacedN )
135
+ }
0 commit comments