Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the code points of ≪⃒ and add a test case (#67) #68

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
)
]
)
2 changes: 1 addition & 1 deletion Sources/HTMLEntities/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ let namedCharactersDecodeMap2: [String: Character] = [
"nlarr;":"\u{219A}","nldr;":"\u{2025}","nlE;":"\u{2266}\u{338}","nle;":"\u{2270}",
"nLeftarrow;":"\u{21CD}","nleftarrow;":"\u{219A}","nLeftrightarrow;":"\u{21CE}","nleftrightarrow;":"\u{21AE}",
"nleq;":"\u{2270}","nleqq;":"\u{2266}\u{338}","nleqslant;":"\u{2A7D}\u{338}","nles;":"\u{2A7D}\u{338}",
"nless;":"\u{226E}","nLl;":"\u{22D8}\u{338}","nlsim;":"\u{2274}","nLt;":"\u{226A}\u{338}",
"nless;":"\u{226E}","nLl;":"\u{22D8}\u{338}","nlsim;":"\u{2274}","nLt;":"\u{226A}\u{20D2}",
"nlt;":"\u{226E}","nltri;":"\u{22EA}","nltrie;":"\u{22EC}","nLtv;":"\u{226A}\u{338}",
"nmid;":"\u{2224}","NoBreak;":"\u{2060}","NonBreakingSpace;":"\u{A0}","Nopf;":"\u{2115}",
"nopf;":"\u{1D55F}","Not;":"\u{2AEC}","not;":"\u{AC}","NotCongruent;":"\u{2262}",
Expand Down
33 changes: 32 additions & 1 deletion Tests/HTMLEntitiesTests/HTMLEntitiesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,36 @@ class HTMLEntitiesTests: XCTestCase {
XCTAssertEqual(try text.htmlUnescape(strict: false), "한")
}

func testDecodeMaps() throws {
struct CodePointsAndCharacters: Codable {
var codepoints: [UInt32]
var characters: String
}

#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 {
XCTAssertEqual(dict["&\(k)"]!.codepoints, v.unicodeScalars.map(\.value), k)
}

for (k, v) in legacyNamedCharactersDecodeMap {
XCTAssertEqual(dict["&\(k)"]!.codepoints, v.unicodeScalars.map(\.value), k)
}

for (k, v) in namedCharactersDecodeMap {
XCTAssertEqual(dict["&\(k)"]!.codepoints, v.unicodeScalars.map(\.value), k)
}
}

static var allTests : [(String, (HTMLEntitiesTests) -> () throws -> Void)] {
return [
("testNamedCharacterReferences", testNamedCharacterReferences),
Expand All @@ -406,7 +436,8 @@ class HTMLEntitiesTests: XCTestCase {
("testDecode", testDecode),
("testInvertibility", testInvertibility),
("testEdgeCases", testEdgeCases),
("testREADMEExamples", testREADMEExamples)
("testREADMEExamples", testREADMEExamples),
("testDecodeMaps", testDecodeMaps)
]
}
}
Loading