1
+ import _InternalTestSupport
2
+
3
+ import XCTest
4
+
5
+ class TestGetNumberOfMatches : XCTestCase {
6
+
7
+ func testEmptyStringMatchesOnEmptyStringZeroTimes( ) {
8
+ let matchOn = " "
9
+ let value = " "
10
+ let expectedNumMatches = 0
11
+
12
+ let actual = getNumberOfMatches ( of: matchOn, in: value)
13
+
14
+ XCTAssertEqual ( actual, expectedNumMatches, " Actual is not as expected " )
15
+ }
16
+
17
+ func testEmptyStringMatchesOnNonEmptySingleLineStringZeroTimes( ) {
18
+ let matchOn = " "
19
+ let value = " This is a non-empty string "
20
+ let expectedNumMatches = 0
21
+
22
+ let actual = getNumberOfMatches ( of: matchOn, in: value)
23
+
24
+ XCTAssertEqual ( actual, expectedNumMatches, " Actual is not as expected " )
25
+ }
26
+
27
+ func testEmptyStringMatchesOnNonEmptyMultilineStringWithNeLineCharacterZeroTimes( ) {
28
+ let matchOn = " "
29
+ let value = " This is a non-empty string \n This is the second line "
30
+ let expectedNumMatches = 0
31
+
32
+ let actual = getNumberOfMatches ( of: matchOn, in: value)
33
+
34
+ XCTAssertEqual ( actual, expectedNumMatches, " Actual is not as expected " )
35
+ }
36
+
37
+ func testEmptyStringMatchesOnNonEmptyMultilineStringUsingTripleDoubleQuotesZeroTimes( ) {
38
+ let matchOn = " "
39
+ let value = """
40
+ This is a non-empty string
41
+ This is the second line
42
+ This is the third line
43
+ """
44
+ let expectedNumMatches = 0
45
+
46
+ let actual = getNumberOfMatches ( of: matchOn, in: value)
47
+
48
+ XCTAssertEqual ( actual, expectedNumMatches, " Actual is not as expected " )
49
+ }
50
+
51
+ func testfatalErrorMatchesOnMultiLineWithTwoOccurencesReturnsTwo( ) {
52
+ let matchOn = " error: fatalError "
53
+ let value = """
54
+ > swift test 25/10/24 10:44:14
55
+ Building for debugging...
56
+ /Users/maxd/Documents/personal/repro-swiftpm-6605/Tests/repro-swiftpm-6605Tests/repro_swiftpm_6605Tests.swift:7:19: error: division by zero
57
+ let y = 1 / x
58
+ ^
59
+ error: fatalError
60
+
61
+ error: fatalError
62
+ """
63
+ let expectedNumMatches = 2
64
+
65
+ let actual = getNumberOfMatches ( of: matchOn, in: value)
66
+
67
+ XCTAssertEqual ( actual, expectedNumMatches, " Actual is not as expected " )
68
+ }
69
+
70
+ func testfatalErrorWithLeadingNewLineMatchesOnMultiLineWithTwoOccurencesReturnsTwo( ) {
71
+ let matchOn = " \n error: fatalError "
72
+ let value = """
73
+ > swift test 25/10/24 10:44:14
74
+ Building for debugging...
75
+ /Users/maxd/Documents/personal/repro-swiftpm-6605/Tests/repro-swiftpm-6605Tests/repro_swiftpm_6605Tests.swift:7:19: error: division by zero
76
+ let y = 1 / x
77
+ ^
78
+ error: fatalError
79
+
80
+ error: fatalError
81
+ """
82
+ let expectedNumMatches = 2
83
+
84
+ let actual = getNumberOfMatches ( of: matchOn, in: value)
85
+
86
+ XCTAssertEqual ( actual, expectedNumMatches, " Actual is not as expected " )
87
+ }
88
+
89
+ func testfatalErrorWithLeadingAndTrailingNewLineMatchesOnMultiLineWithOneOccurencesReturnsOne( ) {
90
+ let matchOn = " \n error: fatalError \n "
91
+ let value = """
92
+ > swift test 25/10/24 10:44:14
93
+ Building for debugging...
94
+ /Users/maxd/Documents/personal/repro-swiftpm-6605/Tests/repro-swiftpm-6605Tests/repro_swiftpm_6605Tests.swift:7:19: error: division by zero
95
+ let y = 1 / x
96
+ ^
97
+ error: fatalError
98
+
99
+ error: fatalError
100
+ """
101
+ let expectedNumMatches = 1
102
+
103
+ let actual = getNumberOfMatches ( of: matchOn, in: value)
104
+
105
+ XCTAssertEqual ( actual, expectedNumMatches, " Actual is not as expected " )
106
+ }
107
+
108
+
109
+
110
+ }
0 commit comments