Tests: Convert Swift tests to use Testing module where possible

The AK tests can't seem to use it because it crashes the frontend :)
This commit is contained in:
Andrew Kaster 2024-08-27 01:57:13 -06:00 committed by Andrew Kaster
commit 782926601d
Notes: github-actions[bot] 2024-08-29 03:28:30 +00:00
5 changed files with 44 additions and 70 deletions

View file

@ -6,54 +6,28 @@
import AK
import Web
import Foundation
import Testing
class StandardError: TextOutputStream {
func write(_ string: Swift.String) {
try! FileHandle.standardError.write(contentsOf: Data(string.utf8))
}
}
@main
@Suite
struct TestHTMLTokenizerSwift {
static func testTokenTypes() {
var standardError = StandardError()
print("Testing HTMLToken types...", to: &standardError)
@Test func tokenTypes() {
let default_token = HTMLToken()
default_token.type = .Character(codePoint: "a")
precondition(default_token.isCharacter())
#expect(default_token.isCharacter())
print("\(default_token)", to: &standardError)
print("HTMLToken types pass", to: &standardError)
#expect("\(default_token)" == "HTMLToken(type: Character(codePoint: a))")
}
static func testParserWhitespace() {
var standardError = StandardError()
print("Testing HTMLToken parser whitespace...", to: &standardError)
@Test func parserWhitespace() {
for codePoint: Character in ["\t", "\n", "\r", "\u{000C}", " "] {
let token = HTMLToken(type: .Character(codePoint: codePoint))
precondition(token.isParserWhitespace())
#expect(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())
#expect(!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)
}
}