Return temporary buffer as a .characterSequence
This commit is contained in:
parent
f585a6b502
commit
38b1d2949b
|
@ -30,11 +30,13 @@ struct Tokenizer<Chars: IteratorProtocol<Unicode.Scalar>>: IteratorProtocol {
|
||||||
mutating func next() -> Token? {
|
mutating func next() -> Token? {
|
||||||
switch state {
|
switch state {
|
||||||
case .flushingTemporaryBuffer(let returnState):
|
case .flushingTemporaryBuffer(let returnState):
|
||||||
|
state = returnState
|
||||||
if temporaryBuffer == nil || temporaryBuffer!.isEmpty {
|
if temporaryBuffer == nil || temporaryBuffer!.isEmpty {
|
||||||
state = returnState
|
|
||||||
return next()
|
return next()
|
||||||
} else {
|
} else {
|
||||||
return .character(temporaryBuffer!.unicodeScalars.removeFirst())
|
var buffer: String? = nil
|
||||||
|
swap(&buffer, &temporaryBuffer)
|
||||||
|
return .characterSequence(buffer!)
|
||||||
}
|
}
|
||||||
case .endOfFile:
|
case .endOfFile:
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -17,22 +17,22 @@ final class TokenizerTests: XCTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNamedCharacterReferences() {
|
func testNamedCharacterReferences() {
|
||||||
XCTAssertEqual(tokenize("&"), [.character("&")])
|
XCTAssertEqual(tokenize("&"), [.characterSequence("&")])
|
||||||
// missing-semicolon-after-character-reference:
|
// missing-semicolon-after-character-reference:
|
||||||
XCTAssertEqual(tokenize("¬in"), [.character("¬"), .characterSequence("in")])
|
XCTAssertEqual(tokenize("¬in"), [.characterSequence("¬"), .characterSequence("in")])
|
||||||
XCTAssertEqual(tokenize("¬in"), [.character("¬"), .characterSequence("in")])
|
XCTAssertEqual(tokenize("¬in"), [.characterSequence("¬"), .characterSequence("in")])
|
||||||
// unknown-named-character-reference:
|
// unknown-named-character-reference:
|
||||||
XCTAssertEqual(tokenize("¬it;"), [.character("¬"), .characterSequence("it;")])
|
XCTAssertEqual(tokenize("¬it;"), [.characterSequence("¬"), .characterSequence("it;")])
|
||||||
XCTAssertEqual(tokenize("&asdf"), "&asdf".unicodeScalars.map { .character($0) })
|
XCTAssertEqual(tokenize("&asdf"), [.characterSequence("&asdf")])
|
||||||
XCTAssertEqual(tokenize("&a"), "&a".unicodeScalars.map { .character($0) })
|
XCTAssertEqual(tokenize("&a"), [.characterSequence("&a")])
|
||||||
|
|
||||||
// attribute special case
|
// attribute special case
|
||||||
XCTAssertEqual(tokenize("<a a='¬a' />"), [.startTag("a", selfClosing: true, attributes: [Attribute(name: "a", value: "¬a")])])
|
XCTAssertEqual(tokenize("<a a='¬a' />"), [.startTag("a", selfClosing: true, attributes: [Attribute(name: "a", value: "¬a")])])
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNumericCharacterReference() {
|
func testNumericCharacterReference() {
|
||||||
XCTAssertEqual(tokenize("!"), [.character("!")])
|
XCTAssertEqual(tokenize("!"), [.characterSequence("!")])
|
||||||
XCTAssertEqual(tokenize("!"), [.character("!")])
|
XCTAssertEqual(tokenize("!"), [.characterSequence("!")])
|
||||||
}
|
}
|
||||||
|
|
||||||
func testStartTag() {
|
func testStartTag() {
|
||||||
|
|
Loading…
Reference in New Issue