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.
This commit is contained in:
Andrew Kaster 2024-08-17 20:58:59 -06:00 committed by Andreas Kling
commit c367063823
Notes: github-actions[bot] 2024-08-19 10:57:49 +00:00
2 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,47 @@
/*
* 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)
}
}