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