Skip to content

Commit

Permalink
Add tests for Scanner.atEnd. (swiftlang#992)
Browse files Browse the repository at this point in the history
* Add tests for Scanner.atEnd.

Finish up SR-4398 by adding tests for Scanner's atEnd property.

* Add test for Scanner.atEnd when charactersToBeSkipped is set.
  • Loading branch information
mattrajca authored and parkera committed May 19, 2017
1 parent 425ea5e commit 2e50a38
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions TestFoundation/TestNSScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class TestNSScanner : XCTestCase {
return [
("test_scanInteger", test_scanInteger),
("test_scanFloat", test_scanFloat),
("test_scanString", test_scanString),
("test_charactersToBeSkipped", test_charactersToBeSkipped),
]
}

Expand All @@ -33,6 +35,7 @@ class TestNSScanner : XCTestCase {
var value: Int = 0
XCTAssert(scanner.scanInteger(&value), "An Integer should be found in the string `123`.")
XCTAssertEqual(value, 123, "Scanned Integer value of the string `123` should be `123`.")
XCTAssertTrue(scanner.atEnd)
}

func test_scanFloat() {
Expand All @@ -41,4 +44,27 @@ class TestNSScanner : XCTestCase {
XCTAssert(scanner.scanFloat(&value), "A Float should be found in the string `-350000000000000000000000000000000000000000`.")
XCTAssert(value.isInfinite, "Scanned Float value of the string `-350000000000000000000000000000000000000000` should be infinite`.")
}

func test_scanString() {
let scanner = Scanner(string: "apple sauce")

guard let firstPart = scanner.scanString(string: "apple ") else {
XCTFail()
return
}

XCTAssertEqual(firstPart, "apple ")
XCTAssertFalse(scanner.atEnd)

let _ = scanner.scanString(string: "sauce")
XCTAssertTrue(scanner.atEnd)
}

func test_charactersToBeSkipped() {
let scanner = Scanner(string: "xyz ")
scanner.charactersToBeSkipped = .whitespaces

let _ = scanner.scanString(string: "xyz")
XCTAssertTrue(scanner.atEnd)
}
}

0 comments on commit 2e50a38

Please sign in to comment.