mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
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:
parent
188b3bb9b8
commit
782926601d
Notes:
github-actions[bot]
2024-08-29 03:28:30 +00:00
Author: https://github.com/ADKaster
Commit: 782926601d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1202
5 changed files with 44 additions and 70 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue