|
1 | 1 | /*
|
2 | 2 | This source file is part of the Swift.org open source project
|
3 | 3 |
|
4 |
| - Copyright (c) 2021 Apple Inc. and the Swift project authors |
| 4 | + Copyright (c) 2021-2024 Apple Inc. and the Swift project authors |
5 | 5 | Licensed under Apache License v2.0 with Runtime Library Exception
|
6 | 6 |
|
7 | 7 | See https://swift.org/LICENSE.txt for license information
|
@@ -37,5 +37,25 @@ class String_WhitespaceTests: XCTestCase {
|
37 | 37 | XCTAssertEqual("Words: with, various. punctuation! as - separators".replacingWhitespaceAndPunctuation(with: "-"),
|
38 | 38 | "Words-with-various-punctuation-as-separators")
|
39 | 39 | }
|
| 40 | + |
| 41 | + func testTrimmingWhitespace() { |
| 42 | + XCTAssertEqual("".removingLeadingWhitespace(), "") |
| 43 | + XCTAssertEqual("".removingTrailingWhitespace(), "") |
| 44 | + |
| 45 | + XCTAssertEqual("ABC".removingLeadingWhitespace(), "ABC") |
| 46 | + XCTAssertEqual("ABC".removingTrailingWhitespace(), "ABC") |
| 47 | + |
| 48 | + XCTAssertEqual("\t ABC\t ".removingLeadingWhitespace(), "ABC\t ", "Removing leading whitespace doesn't remove trailing whitespace") |
| 49 | + XCTAssertEqual("\t ABC\t ".removingTrailingWhitespace(), "\t ABC", "Removing trailing whitespace doesn't remove leading whitespace") |
| 50 | + |
| 51 | + XCTAssertEqual("\t ".removingLeadingWhitespace(), "", "All characters are whitespace") |
| 52 | + XCTAssertEqual("\t ".removingTrailingWhitespace(), "", "All characters are whitespace") |
| 53 | + |
| 54 | + XCTAssertEqual("\n ABC \n".removingLeadingWhitespace(), "ABC \n", "Newline is considered a whitespace character") |
| 55 | + XCTAssertEqual("\n ABC \n".removingTrailingWhitespace(), "\n ABC", "Newline is considered a whitespace character") |
| 56 | + |
| 57 | + XCTAssertEqual("start ABC end".removingLeadingWhitespace(), "start ABC end", "Only removes whitespace at the start and end of the string") |
| 58 | + XCTAssertEqual("start ABC end".removingTrailingWhitespace(), "start ABC end", "Only removes whitespace at the start and end of the string") |
| 59 | + } |
40 | 60 | }
|
41 | 61 |
|
0 commit comments