mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 07:07:23 +00:00
LibWeb: Add start of HTML Tokenizer in Swift
Currently it's just a Token class.
This commit is contained in:
committed by
Andrew Kaster
parent
d0bc266c55
commit
fb074f9d0c
58
Tests/LibWeb/TestHTMLTokenizerSwift.swift
Normal file
58
Tests/LibWeb/TestHTMLTokenizerSwift.swift
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
import AK
|
||||
import LibWeb
|
||||
import SwiftLibWeb
|
||||
import Foundation
|
||||
|
||||
class StandardError: TextOutputStream {
|
||||
func write(_ string: Swift.String) {
|
||||
try! FileHandle.standardError.write(contentsOf: Data(string.utf8))
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct TestHTMLTokenizerSwift {
|
||||
|
||||
static func testTokenTypes() {
|
||||
var standardError = StandardError()
|
||||
print("Testing HTMLToken types...", to: &standardError)
|
||||
|
||||
let default_token = HTMLToken()
|
||||
default_token.type = .Character(codePoint: "a")
|
||||
precondition(default_token.isCharacter())
|
||||
|
||||
print("HTMLToken types pass", to: &standardError)
|
||||
}
|
||||
|
||||
static func testParserWhitespace() {
|
||||
var standardError = StandardError()
|
||||
print("Testing HTMLToken parser whitespace...", to: &standardError)
|
||||
|
||||
for codePoint: Character in ["\t", "\n", "\r", "\u{000C}", " "] {
|
||||
let token = HTMLToken(type: .Character(codePoint: codePoint))
|
||||
precondition(token.isParserWhitespace())
|
||||
}
|
||||
|
||||
for codePoint: Character in ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] {
|
||||
let token = HTMLToken(type: .Character(codePoint: codePoint))
|
||||
precondition(!token.isParserWhitespace())
|
||||
}
|
||||
|
||||
print("HTMLToken parser whitespace pass", to: &standardError)
|
||||
}
|
||||
|
||||
static func main() {
|
||||
var standardError = StandardError()
|
||||
print("Starting test suite...", to: &standardError)
|
||||
|
||||
testTokenTypes()
|
||||
testParserWhitespace()
|
||||
|
||||
print("All tests pass", to: &standardError)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user