ladybird/Tests/LibWeb/TestLibWebSwiftBindings.swift
Andrew Kaster c367063823 Tests: Add first test for LibWeb Swift bindings
Just to sanity check that we can import the library, and that it at
least interprets the generated enumeration values properly, let's
do some simple testing of the swift integration.
2024-08-19 12:56:55 +02:00

47 lines
No EOL
1.5 KiB
Swift

/*
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
import AK
import LibWeb
import Foundation
class StandardError: TextOutputStream {
func write(_ string: Swift.String) {
try! FileHandle.standardError.write(contentsOf: Data(string.utf8))
}
}
@main
struct TestLibWebSwiftBindings {
static func testEnumsAreBound() {
var standardError = StandardError()
print("Testing LibWeb enum types...", to: &standardError)
print("Web.DOM.NodeType.ELEMENT_NODE == \(Web.DOM.NodeType.ELEMENT_NODE)", to: &standardError)
precondition(Web.DOM.NodeType.ELEMENT_NODE.rawValue == 1)
print("Web.Bindings.NavigationType.Push == \(Web.Bindings.NavigationType.Push)", to: &standardError)
precondition(Web.Bindings.NavigationType.Push.rawValue == 0)
let end = Web.Bindings.idl_enum_to_string(Web.Bindings.ScrollLogicalPosition.End)
let end_view = end.__bytes_as_string_viewUnsafe().bytes();
let end_string = Swift.String(bytes: end_view, encoding: .utf8)!
print("Web.Bindings.idl_enum_to_string(Web.Bindings.ScrollLogicalPosition.End) == \(end_string)", to: &standardError)
precondition(end_string == "end")
print("LibWeb enum types pass", to: &standardError)
}
static func main() {
var standardError = StandardError()
print("Starting test suite...", to: &standardError)
testEnumsAreBound()
print("All tests pass", to: &standardError)
}
}