Select Darwin host code for the native ZX player and keep its Linux socket service on Linux. Feed RGB to the JPEG encoder and retain Android notification callbacks when generating native host libraries. Resolve the Pages gallery verifier against the same source revisions as the build. Reuse prepared template dependencies and check the JavaScript policy against files present in the checkout. Combine related text-input checks and perform shared source policy checks once per CI run.
136 lines
5.1 KiB
Ziran
136 lines
5.1 KiB
Ziran
#import "session"
|
|
#import "geometry"
|
|
#import "tree"
|
|
#import "widget_kind"
|
|
#import "key_input"
|
|
TextField :: #import "textfield";
|
|
#import "tree_input"
|
|
using WidgetKind;
|
|
|
|
TextFocusCase :: struct {
|
|
kind: s32
|
|
selected: bool
|
|
disabled: bool
|
|
active: bool
|
|
}
|
|
|
|
Build :: (session: Session, test: TextFocusCase) -> bool {
|
|
bounds: Rectangle = .{0.0, 0.0, 100.0, 20.0}
|
|
TreeStart(session, cast(u64)1, bounds)
|
|
if !TreeIsBuilding(session) { return false }
|
|
for i: 1..40 {
|
|
unused TreeSubmit(session, cast(u64)i, 0, WidgetKindImage, bounds)
|
|
}
|
|
node := TreeSubmit(session, cast(u64)50, 0, test.kind, bounds)
|
|
TreeSetSelected(session, node, test.selected)
|
|
TreeSetInteractive(session, node, test.disabled, false, 50)
|
|
if !TreeFinish(session) { return false }
|
|
return TreeTextInputActive(session) == test.active
|
|
}
|
|
|
|
CheckKeysAndUTF8 :: () -> s32 {
|
|
session: Session = SessionOpen()
|
|
if !SessionValid(session) { return 1 }
|
|
defer { unused SessionClose(session) }
|
|
if KeyF3 != 292 { return 12 }
|
|
unused KeyboardSend(session, KeyF3)
|
|
if KeyboardTake(session) != KeyF3 || KeyboardTake(session) != 0 { return 13 }
|
|
// Typed codepoints arrive as one UTF-8 text, then the queue is empty.
|
|
storage: [16]u8
|
|
TypedCodepointSend(session, 104)
|
|
TypedCodepointSend(session, 233)
|
|
TypedCodepointSend(session, 0x20AC)
|
|
TypedCodepointSend(session, 0x1F600)
|
|
{
|
|
typed: string = TypedTextTake(session, storage[:])
|
|
if typed != "hé€😀" { return 2 }
|
|
}
|
|
if TypedTextTake(session, storage[:]).count != 0 { return 3 }
|
|
// Text that does not fit stops at the last whole codepoint.
|
|
small: [3]u8
|
|
TypedCodepointSend(session, 97)
|
|
TypedCodepointSend(session, 0x20AC)
|
|
if TypedTextTake(session, small[:]) != "a" { return 4 }
|
|
if TypedTextTake(session, small[:]) != "€" { return 14 }
|
|
// A burst longer than one retained queue drains without loss.
|
|
if TypedCodepointCapacity(session) != 32 { return 20 }
|
|
burst: [128]u8
|
|
for group: 0..1 {
|
|
base: s32 = 48 + cast(s32)group * 32
|
|
for index: 0..31 {
|
|
if !TypedCodepointSend(session, base + cast(s32)index) {
|
|
return 15
|
|
}
|
|
}
|
|
{
|
|
typed := TypedTextTake(session, burst[:])
|
|
if typed.count != 32 ||
|
|
typed[0] != cast(u8)base ||
|
|
typed[typed.count - 1] != cast(u8)(base + 31) { return 16 }
|
|
}
|
|
}
|
|
for index: 0..7 {
|
|
if !TypedCodepointSend(session, 112 + cast(s32)index) { return 15 }
|
|
}
|
|
{
|
|
typed := TypedTextTake(session, burst[:])
|
|
if typed.count != 8 || typed[0] != cast(u8)112 ||
|
|
typed[7] != cast(u8)119 { return 16 }
|
|
}
|
|
if TypedTextTake(session, burst[:]).count != 0 { return 17 }
|
|
// A caller-sized UTF-8 buffer keeps every scalar boundary.
|
|
unicode: [8]u8
|
|
for index: 0..4 {
|
|
if !TypedCodepointSend(session, 0x1F600) { return 18 }
|
|
}
|
|
if TypedTextTake(session, unicode[:]).count != 8 ||
|
|
TypedTextTake(session, unicode[:]).count != 8 ||
|
|
TypedTextTake(session, unicode[:]).count != 4 ||
|
|
TypedTextTake(session, unicode[:]).count != 0 { return 19 }
|
|
// Keys map to the matching edits; typed text is inserted.
|
|
input: TextField.Input = TextFieldInputFor(KeyBackspace, 0, "")
|
|
if !input.backspace || input.left || input.text.count != 0 { return 5 }
|
|
input = TextFieldInputFor(KeyLeft, KeyModifierShift, "")
|
|
if !input.left || !input.shift { return 6 }
|
|
input = TextFieldInputFor(KeyEnter, 0, "")
|
|
if !input.commit || input.escape { return 7 }
|
|
input = TextFieldInputFor(0, 0, "ab")
|
|
if input.text != "ab" || input.backspace { return 8 }
|
|
// Control turns letters into shortcuts and inserts no text.
|
|
input = TextFieldInputFor(86, KeyModifierControl, "v")
|
|
if !input.paste || input.text.count != 0 { return 9 }
|
|
input = TextFieldInputFor(65, KeyModifierControl, "")
|
|
if !input.select_all || input.copy { return 10 }
|
|
input = TextFieldInputFor(KeyDelete, 0, "")
|
|
if !input.delete_forward || !TextFieldInputFor(KeyHome, 0, "").home ||
|
|
!TextFieldInputFor(KeyEnd, 0, "").end ||
|
|
!TextFieldInputFor(KeyEscape, 0, "").escape { return 11 }
|
|
return 0
|
|
}
|
|
|
|
#program_export
|
|
main :: () -> s32 {
|
|
keys := CheckKeysAndUTF8()
|
|
if keys != 0 { return 20 + keys }
|
|
session := SessionOpen()
|
|
if TreeTextInputActive(session) { return 1 }
|
|
cases: [5]TextFocusCase = .[
|
|
.{WidgetKindTextField, true, false, true},
|
|
.{WidgetKindTextArea, true, false, true},
|
|
.{WidgetKindTextField, true, true, false},
|
|
.{WidgetKindTextField, false, false, false},
|
|
.{WidgetKindButton, true, false, false}]
|
|
for index: 0..4 {
|
|
if !Build(session, cases[index]) { return 2 + cast(s32)index }
|
|
}
|
|
// A cancelled submission keeps the previous committed editing state.
|
|
if !Build(session, cases[1]) { return 7 }
|
|
TreeStart(session, cast(u64)1, .{0.0, 0.0, 100.0, 20.0})
|
|
if !TreeIsBuilding(session) { return 8 }
|
|
TreeCancel(session)
|
|
if !TreeTextInputActive(session) { return 9 }
|
|
unused SessionClose(session)
|
|
if TreeTextInputActive(session) { return 10 }
|
|
return 0
|
|
}
|