TestHTMLTokenizerSwift.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. import AK
  7. import LibWeb
  8. import SwiftLibWeb
  9. import Foundation
  10. class StandardError: TextOutputStream {
  11. func write(_ string: Swift.String) {
  12. try! FileHandle.standardError.write(contentsOf: Data(string.utf8))
  13. }
  14. }
  15. @main
  16. struct TestHTMLTokenizerSwift {
  17. static func testTokenTypes() {
  18. var standardError = StandardError()
  19. print("Testing HTMLToken types...", to: &standardError)
  20. let default_token = HTMLToken()
  21. default_token.type = .Character(codePoint: "a")
  22. precondition(default_token.isCharacter())
  23. print("HTMLToken types pass", to: &standardError)
  24. }
  25. static func testParserWhitespace() {
  26. var standardError = StandardError()
  27. print("Testing HTMLToken parser whitespace...", to: &standardError)
  28. for codePoint: Character in ["\t", "\n", "\r", "\u{000C}", " "] {
  29. let token = HTMLToken(type: .Character(codePoint: codePoint))
  30. precondition(token.isParserWhitespace())
  31. }
  32. for codePoint: Character in ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] {
  33. let token = HTMLToken(type: .Character(codePoint: codePoint))
  34. precondition(!token.isParserWhitespace())
  35. }
  36. print("HTMLToken parser whitespace pass", to: &standardError)
  37. }
  38. static func main() {
  39. var standardError = StandardError()
  40. print("Starting test suite...", to: &standardError)
  41. testTokenTypes()
  42. testParserWhitespace()
  43. print("All tests pass", to: &standardError)
  44. }
  45. }