TestHTMLTokenizerSwift.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. import AK
  7. import Web
  8. import Foundation
  9. class StandardError: TextOutputStream {
  10. func write(_ string: Swift.String) {
  11. try! FileHandle.standardError.write(contentsOf: Data(string.utf8))
  12. }
  13. }
  14. @main
  15. struct TestHTMLTokenizerSwift {
  16. static func testTokenTypes() {
  17. var standardError = StandardError()
  18. print("Testing HTMLToken types...", to: &standardError)
  19. let default_token = HTMLToken()
  20. default_token.type = .Character(codePoint: "a")
  21. precondition(default_token.isCharacter())
  22. print("\(default_token)", to: &standardError)
  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. }