mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
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:
parent
b03b13b720
commit
c367063823
Notes:
github-actions[bot]
2024-08-19 10:57:49 +00:00
Author: https://github.com/ADKaster
Commit: c367063823
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1107
Reviewed-by: https://github.com/jamierocks
2 changed files with 54 additions and 0 deletions
47
Tests/LibWeb/TestLibWebSwiftBindings.swift
Normal file
47
Tests/LibWeb/TestLibWebSwiftBindings.swift
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue