Simplify color parser tests
This commit is contained in:
parent
d660c40793
commit
4406619c84
1 changed files with 16 additions and 22 deletions
|
@ -3,68 +3,62 @@ import XCTest
|
||||||
|
|
||||||
final class ColorParserTest: XCTestCase {
|
final class ColorParserTest: XCTestCase {
|
||||||
func testScanningThreeDigitColor() throws {
|
func testScanningThreeDigitColor() throws {
|
||||||
let scanner = Scanner(string: "#abc")
|
let color = scanColor("#abc")
|
||||||
let color = scanner.color()
|
|
||||||
XCTAssertEqual(Color(red: 0xAA, green: 0xBB, blue: 0xCC), color)
|
XCTAssertEqual(Color(red: 0xAA, green: 0xBB, blue: 0xCC), color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testScanningThreeDigitColorUppercase() throws {
|
func testScanningThreeDigitColorUppercase() throws {
|
||||||
let scanner = Scanner(string: "#ABc")
|
let color = scanColor("#ABc")
|
||||||
let color = scanner.color()
|
|
||||||
XCTAssertEqual(Color(red: 0xAA, green: 0xBB, blue: 0xCC), color)
|
XCTAssertEqual(Color(red: 0xAA, green: 0xBB, blue: 0xCC), color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testScanningFourDigitColor() throws {
|
func testScanningFourDigitColor() throws {
|
||||||
let scanner = Scanner(string: "#abcd")
|
let color = scanColor("#abcd")
|
||||||
let color = scanner.color()
|
|
||||||
XCTAssertEqual(Color(red: 0xAA, green: 0xBB, blue: 0xCC, alpha: 0xDD), color)
|
XCTAssertEqual(Color(red: 0xAA, green: 0xBB, blue: 0xCC, alpha: 0xDD), color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testScanningSixDigitColor() throws {
|
func testScanningSixDigitColor() throws {
|
||||||
let scanner = Scanner(string: "#abcdef")
|
let color = scanColor("#abcdef")
|
||||||
let color = scanner.color()
|
|
||||||
XCTAssertEqual(Color(red: 0xAB, green: 0xCD, blue: 0xEF), color)
|
XCTAssertEqual(Color(red: 0xAB, green: 0xCD, blue: 0xEF), color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testScanningEightDigitColor() throws {
|
func testScanningEightDigitColor() throws {
|
||||||
let scanner = Scanner(string: "#abcdef17")
|
let color = scanColor("#abcdef17")
|
||||||
let color = scanner.color()
|
|
||||||
XCTAssertEqual(Color(red: 0xAB, green: 0xCD, blue: 0xEF, alpha: 0x17), color)
|
XCTAssertEqual(Color(red: 0xAB, green: 0xCD, blue: 0xEF, alpha: 0x17), color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testScanningRGBColor() throws {
|
func testScanningRGBColor() throws {
|
||||||
let scanner = Scanner(string: "rgb(1,2,3)")
|
let color = scanColor("rgb(1,2,3)")
|
||||||
let color = scanner.color()
|
|
||||||
XCTAssertEqual(Color(red: 1, green: 2, blue: 3), color)
|
XCTAssertEqual(Color(red: 1, green: 2, blue: 3), color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testScanningRGBAColor() throws {
|
func testScanningRGBAColor() throws {
|
||||||
let scanner = Scanner(string: "rgba(1,2,3,4)")
|
let color = scanColor("rgba(1,2,3,4)")
|
||||||
let color = scanner.color()
|
|
||||||
XCTAssertEqual(Color(red: 1, green: 2, blue: 3, alpha: 4), color)
|
XCTAssertEqual(Color(red: 1, green: 2, blue: 3, alpha: 4), color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testScanningWhite() throws {
|
func testScanningWhite() throws {
|
||||||
let scanner = Scanner(string: "white(255)")
|
let color = scanColor("white(255)")
|
||||||
let color = scanner.color()
|
|
||||||
XCTAssertEqual(Color(red: 255, green: 255, blue: 255, alpha: 255), color)
|
XCTAssertEqual(Color(red: 255, green: 255, blue: 255, alpha: 255), color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testScanningWhiteWithAlpha() throws {
|
func testScanningWhiteWithAlpha() throws {
|
||||||
let scanner = Scanner(string: "white(255, 128)")
|
let color = scanColor("white(255, 128)")
|
||||||
let color = scanner.color()
|
|
||||||
XCTAssertEqual(Color(red: 255, green: 255, blue: 255, alpha: 128), color)
|
XCTAssertEqual(Color(red: 255, green: 255, blue: 255, alpha: 128), color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testWhiteFailsWithoutArguments() throws {
|
func testWhiteFailsWithoutArguments() throws {
|
||||||
let scanner = Scanner(string: "white()")
|
let color = scanColor("white()")
|
||||||
let color = scanner.color()
|
|
||||||
XCTAssertNil(color)
|
XCTAssertNil(color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testWhiteFailsWith3Arguments() throws {
|
func testWhiteFailsWith3Arguments() throws {
|
||||||
let scanner = Scanner(string: "white(1,2,3)")
|
let color = scanColor("white(1,2,3)")
|
||||||
let color = scanner.color()
|
|
||||||
XCTAssertNil(color)
|
XCTAssertNil(color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func scanColor(_ input: String) -> Color? {
|
||||||
|
let scanner = Scanner(string: input)
|
||||||
|
return scanner.color()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue