1
1
@testable import SwiftlyCore
2
2
import Testing
3
- import XCTest
4
3
5
4
@Suite struct StringExtensionsTests {
6
5
@Test ( " Basic text wrapping at column width " )
7
6
func testBasicWrapping( ) {
8
7
let input = " This is a simple test string that should be wrapped at the specified width. "
9
8
let expected = """
10
9
This is a
11
- simple test
12
- string that
10
+ simple
11
+ test
12
+ string
13
+ that
13
14
should be
14
15
wrapped at
15
16
the
16
17
specified
17
18
width.
18
19
"""
19
20
20
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
21
+ #expect ( input. wrapText ( to: 10 ) == expected)
21
22
}
22
23
23
24
@Test ( " Preserve existing line breaks " )
24
25
func testPreserveLineBreaks( ) {
25
26
let input = " First line \n Second line \n Third line "
26
27
let expected = " First line \n Second line \n Third line "
27
28
28
- XCTAssertEqual ( input. wrapText ( to: 20 ) , expected)
29
+ #expect ( input. wrapText ( to: 20 ) == expected)
29
30
}
30
31
31
32
@Test ( " Combine wrapping with existing line breaks " )
32
33
func testCombineWrappingAndLineBreaks( ) {
33
- let input = " Short line \n This is a very long line that needs to be wrapped \n Another short line "
34
+ let input = """
35
+ Short line
36
+ This is a very long line that needs to be wrapped
37
+ Another short line
38
+ """
39
+
34
40
let expected = """
35
41
Short line
36
42
This is a very
37
43
long line that
38
44
needs to be
39
45
wrapped
40
- Another short line
46
+ Another short
47
+ line
41
48
"""
42
49
43
- XCTAssertEqual ( input. wrapText ( to: 15 ) , expected)
50
+ #expect ( input. wrapText ( to: 15 ) == expected)
44
51
}
45
52
46
53
@Test ( " Words longer than column width " )
@@ -52,72 +59,55 @@ import XCTest
52
59
word
53
60
"""
54
61
55
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
62
+ #expect ( input. wrapText ( to: 10 ) == expected)
56
63
}
57
64
58
65
@Test ( " Text with no spaces " )
59
66
func testNoSpaces( ) {
60
67
let input = " ThisIsALongStringWithNoSpaces "
61
68
let expected = " ThisIsALongStringWithNoSpaces "
62
69
63
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
70
+ #expect ( input. wrapText ( to: 10 ) == expected)
64
71
}
65
72
66
73
@Test ( " Empty string " )
67
74
func testEmptyString( ) {
68
75
let input = " "
69
76
let expected = " "
70
77
71
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
78
+ #expect ( input. wrapText ( to: 10 ) == expected)
72
79
}
73
80
74
81
@Test ( " Single character " )
75
82
func testSingleCharacter( ) {
76
83
let input = " X "
77
84
let expected = " X "
78
85
79
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
86
+ #expect ( input. wrapText ( to: 10 ) == expected)
80
87
}
81
88
82
89
@Test ( " Single line not exceeding width " )
83
90
func testSingleLineNoWrapping( ) {
84
91
let input = " Short text "
85
92
let expected = " Short text "
86
93
87
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
88
- }
89
-
90
- @Test ( " Wrapping with indentation " )
91
- func testWrappingWithIndent( ) {
92
- let input = " This is text that should be wrapped with indentation on new lines. "
93
- let expected = """
94
- This is
95
- text that
96
- should be
97
- wrapped
98
- with
99
- indentation
100
- on new
101
- lines.
102
- """
103
-
104
- XCTAssertEqual ( input. wrapText ( to: 10 , wrappingIndent: 2 ) , expected)
94
+ #expect( input. wrapText ( to: 10 ) == expected)
105
95
}
106
96
107
97
@Test ( " Zero or negative column width " )
108
98
func testZeroOrNegativeWidth( ) {
109
99
let input = " This should not be wrapped "
110
100
111
- XCTAssertEqual ( input. wrapText ( to: 0 ) , input)
112
- XCTAssertEqual ( input. wrapText ( to: - 5 ) , input)
101
+ #expect ( input. wrapText ( to: 0 ) == input)
102
+ #expect ( input. wrapText ( to: - 5 ) == input)
113
103
}
114
104
115
105
@Test ( " Very narrow column width " )
116
106
func testVeryNarrowWidth( ) {
117
107
let input = " A B C "
118
108
let expected = " A \n B \n C "
119
109
120
- XCTAssertEqual ( input. wrapText ( to: 1 ) , expected)
110
+ #expect ( input. wrapText ( to: 1 ) == expected)
121
111
}
122
112
123
113
@Test ( " Special characters " )
@@ -129,7 +119,7 @@ import XCTest
129
119
chars
130
120
"""
131
121
132
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
122
+ #expect ( input. wrapText ( to: 10 ) == expected)
133
123
}
134
124
135
125
@Test ( " Unicode characters " )
@@ -140,69 +130,69 @@ import XCTest
140
130
😀🚀🌍
141
131
"""
142
132
143
- XCTAssertEqual ( input. wrapText ( to: 15 ) , expected)
133
+ #expect ( input. wrapText ( to: 15 ) == expected)
144
134
}
145
135
146
136
@Test ( " Irregular spacing " )
147
137
func testIrregularSpacing( ) {
148
138
let input = " Words with irregular spacing "
149
- let expected = """
150
- Words with
151
- irregular
152
- spacing
153
- """
139
+ let expected = " Words \n with \n irregular \n spacing "
154
140
155
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
141
+ #expect ( input. wrapText ( to: 10 ) == expected)
156
142
}
157
143
158
144
@Test ( " Tab characters " )
159
145
func testTabCharacters( ) {
160
146
let input = " Text \t with \t tabs "
161
147
let expected = """
162
148
Text \t with
163
- \t tabs
149
+ tabs
164
150
"""
165
151
166
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
152
+ #expect ( input. wrapText ( to: 10 ) == expected)
167
153
}
168
154
169
155
@Test ( " Trailing spaces " )
170
156
func testTrailingSpaces( ) {
171
157
let input = " Text with trailing spaces "
172
- let expected = """
173
- Text with
174
- trailing
175
- spaces
176
- """
158
+ let expected = " Text with \n trailing \n spaces "
177
159
178
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
160
+ #expect ( input. wrapText ( to: 10 ) == expected)
179
161
}
180
162
181
163
@Test ( " Leading spaces " )
182
164
func testLeadingSpaces( ) {
183
165
let input = " Leading spaces with text "
184
166
let expected = """
185
167
Leading
186
- spaces with
187
- text
168
+ spaces
169
+ with text
188
170
"""
189
171
190
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
172
+ #expect ( input. wrapText ( to: 10 ) == expected)
191
173
}
192
174
193
175
@Test ( " Multiple consecutive newlines " )
194
176
func testMultipleNewlines( ) {
195
177
let input = " First \n \n Second \n \n \n Third "
196
178
let expected = " First \n \n Second \n \n \n Third "
197
179
198
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
180
+ #expect ( input. wrapText ( to: 10 ) == expected)
199
181
}
200
182
201
183
@Test ( " Edge case - exactly at column width " )
202
184
func testExactColumnWidth( ) {
203
185
let input = " 1234567890 abcdefghij "
204
186
let expected = " 1234567890 \n abcdefghij "
205
187
206
- XCTAssertEqual ( input. wrapText ( to: 10 ) , expected)
188
+ #expect( input. wrapText ( to: 10 ) == expected)
189
+ }
190
+
191
+ @Test ( " Lines ending exactly at column boundary " )
192
+ func testLinesEndingAtBoundary( ) {
193
+ let input = " exactlyten \n moretextat \n the end "
194
+ let expected = " exactlyten \n moretextat \n the end "
195
+
196
+ #expect( input. wrapText ( to: 10 ) == expected)
207
197
}
208
198
}
0 commit comments