2024-04-02 21:43:06 -07:00
|
|
|
//
|
|
|
|
// EntityDecodingTests.swift
|
|
|
|
// RSParserTests
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 12/30/17.
|
|
|
|
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
2024-09-16 21:57:05 -07:00
|
|
|
import SAX
|
2024-04-02 21:43:06 -07:00
|
|
|
|
2024-09-23 21:39:00 -07:00
|
|
|
final class EntityDecodingTests: XCTestCase {
|
2024-09-16 21:57:05 -07:00
|
|
|
|
|
|
|
func test39Decoding() {
|
|
|
|
|
|
|
|
// Bug found by Manton Reece — the ' entity was not getting decoded by NetNewsWire in JSON Feeds from micro.blog.
|
|
|
|
|
|
|
|
let s = "These are the times that try men's souls."
|
|
|
|
let decoded = HTMLEntityDecoder.decodedString(s)
|
|
|
|
|
|
|
|
XCTAssertEqual(decoded, "These are the times that try men's souls.")
|
|
|
|
}
|
|
|
|
|
2024-09-16 22:07:31 -07:00
|
|
|
func testEntityAtBeginning() {
|
|
|
|
|
|
|
|
let s = "'leading single quote"
|
|
|
|
let decoded = HTMLEntityDecoder.decodedString(s)
|
|
|
|
|
|
|
|
XCTAssertEqual(decoded, "'leading single quote")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testEntityAtEnd() {
|
|
|
|
|
|
|
|
let s = "trailing single quote'"
|
|
|
|
let decoded = HTMLEntityDecoder.decodedString(s)
|
|
|
|
|
|
|
|
XCTAssertEqual(decoded, "trailing single quote'")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testEntityInMiddle() {
|
|
|
|
|
|
|
|
let s = "entity ç in middle"
|
|
|
|
let decoded = HTMLEntityDecoder.decodedString(s)
|
|
|
|
|
|
|
|
XCTAssertEqual(decoded, "entity ç in middle")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testMultipleEntitiesInARow() {
|
|
|
|
|
|
|
|
let s = "çèmult……iple 'æ"entities÷♥"
|
|
|
|
let decoded = HTMLEntityDecoder.decodedString(s)
|
|
|
|
|
|
|
|
XCTAssertEqual(decoded, "çèmult……iple 'æ\"entities÷♥")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testOnlyEntity() {
|
2024-09-16 21:57:05 -07:00
|
|
|
var s = "…"
|
|
|
|
var decoded = HTMLEntityDecoder.decodedString(s)
|
|
|
|
|
|
|
|
XCTAssertEqual(decoded, "…")
|
|
|
|
|
|
|
|
s = "…"
|
|
|
|
decoded = HTMLEntityDecoder.decodedString(s)
|
|
|
|
XCTAssertEqual(decoded, "…")
|
|
|
|
|
|
|
|
s = "'"
|
|
|
|
decoded = HTMLEntityDecoder.decodedString(s)
|
|
|
|
XCTAssertEqual(decoded, "'")
|
|
|
|
|
|
|
|
s = "§"
|
|
|
|
decoded = HTMLEntityDecoder.decodedString(s)
|
|
|
|
XCTAssertEqual(decoded, "§")
|
|
|
|
|
|
|
|
s = "£"
|
|
|
|
decoded = HTMLEntityDecoder.decodedString(s)
|
|
|
|
XCTAssertEqual(decoded, "£")
|
|
|
|
}
|
|
|
|
}
|