Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Increased test coverage by adding test on public API.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettRToomey committed Dec 30, 2016
1 parent e9d1471 commit f038991
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 0 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ coverage:
range: "80...100"
ignore:
- "Sources/Scanner.swift"
- "Sources/DataURI+String.swift"
- "Tests/"
1 change: 1 addition & 0 deletions Sources/DataURI+String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extension Sequence where Iterator.Element == Byte {
internal var base64Decoded: Bytes {
let bytes = [Byte](self)
let dataBase64 = Data(bytes: bytes)

guard let data = Data(base64Encoded: dataBase64) else {
return []
}
Expand Down
24 changes: 24 additions & 0 deletions Tests/DataURITests/DataURITests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import XCTest

import Core

@testable import DataURI

class DataURITests: XCTestCase {
Expand All @@ -8,6 +11,7 @@ class DataURITests: XCTestCase {
("testHTMLText", testHTMLText),
("testHTMLJavascriptText", testHTMLJavascriptText),
("testFailedInvalidScheme", testFailedInvalidScheme),
("testPublicInterface", testPublicInterface),
("testSpeed", testSpeed)
]

Expand Down Expand Up @@ -64,6 +68,14 @@ class DataURITests: XCTestCase {
}
}

func testPublicInterface() {
expectNoThrow() {
let (data, type) = try "data:,Hello%2C%20World!".dataURIDecoded()
XCTAssertEqual(data.string, "Hello, World!")
XCTAssertEqual(type, "text/plain;charset=US-ASCII")
}
}

func testSpeed() {
measure {
for _ in 0..<10_000 {
Expand All @@ -73,4 +85,16 @@ class DataURITests: XCTestCase {
}
}
}

//FIXME(Brett): remove when Core 1.1 includes `base64Decoded`
// required for 100% coverage
func testBase64DecodeFailure() {
var bytes = "SGVsbG8sIFdvcmxkIQ%3D%3D".bytes //Hello World!
bytes.append(0x1E) //invalid control character
let decodedBytes = bytes.base64Decoded
XCTAssertEqual(
decodedBytes, [],
"Invalid character should have caused the base64Decoder to escape."
)
}
}

0 comments on commit f038991

Please sign in to comment.