Skip to content

Commit

Permalink
Change testDecodeMaps to be completed locally
Browse files Browse the repository at this point in the history
  • Loading branch information
kkebo committed Aug 24, 2022
1 parent fac7e32 commit b86aa37
Show file tree
Hide file tree
Showing 4 changed files with 2,287 additions and 31 deletions.
5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.2
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

/**
Expand Down Expand Up @@ -36,7 +36,8 @@ let package = Package(
),
.testTarget(
name: "HTMLEntitiesTests",
dependencies: ["HTMLEntities"]
dependencies: ["HTMLEntities"],
resources: [.process("Resources")]
)
]
)
42 changes: 42 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

/**
* Copyright IBM Corporation and the Kitura project authors 2016-2020
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

import PackageDescription

let package = Package(
name: "HTMLEntities",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "HTMLEntities",
targets: ["HTMLEntities"]
)
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "HTMLEntities"
),
.testTarget(
name: "HTMLEntitiesTests",
dependencies: ["HTMLEntities"]
)
]
)
38 changes: 9 additions & 29 deletions Tests/HTMLEntitiesTests/HTMLEntitiesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
import XCTest
@testable import HTMLEntities

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

let replacementCharacterAsString = "\u{FFFD}"

/// HTML snippet
Expand Down Expand Up @@ -408,31 +404,15 @@ class HTMLEntitiesTests: XCTestCase {
var characters: String
}

var entitiesData: Data?
var dataTaskError: Error?
let expectation = self.expectation(description: "Downloading entities.json")

let url = URL(string: "https://html.spec.whatwg.org/entities.json")!
URLSession.shared.dataTask(with: url) { data, _, error in
if let error = error {
dataTaskError = error
} else if let data = data {
entitiesData = data
}
expectation.fulfill()
}.resume()

self.wait(for: [expectation], timeout: 60)

if let dataTaskError = dataTaskError {
throw dataTaskError
}

guard let data = entitiesData else {
XCTFail("Failed to download entities.json")
return
}

#if swift(>=5.3)
let url = Bundle.module.url(forResource: "entities", withExtension: "json")!
#else
let url = URL(fileURLWithPath: #file)
.deletingLastPathComponent()
.appendingPathComponent("Resources")
.appendingPathComponent("entities.json")
#endif
let data = try Data(contentsOf: url)
let dict = try JSONDecoder().decode([String: CodePointsAndCharacters].self, from: data)

for (k, v) in specialNamedCharactersDecodeMap {
Expand Down
Loading

0 comments on commit b86aa37

Please sign in to comment.