Files
pikl/crates/pikl-core/tests/dsl_tests.rs
J. Champagne d9ed49e7d9
Some checks failed
CI / Check (macos-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Clippy (strict) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (ubuntu-latest) (push) Has been cancelled
feat(core): Add input modes and half-page cursor movement.
2026-03-13 22:56:30 -04:00

299 lines
6.9 KiB
Rust

use pikl_test_macros::pikl_tests;
// ---------------------------------------------------------------------------
// Filter tests
// ---------------------------------------------------------------------------
pikl_tests! {
filter mod fuzzy_basics {
items: ["apple", "banana", "cherry"];
test empty_query_returns_all {
query: ""
matches: ["apple", "banana", "cherry"]
}
test no_results {
query: "xyz"
matches: []
}
test substring_match {
query: "ban"
matches: ["banana"]
}
}
filter mod empty_items {
items: [];
test query_on_empty {
query: "test"
matches: []
}
test empty_query_on_empty {
query: ""
matches: []
}
}
}
// ---------------------------------------------------------------------------
// Navigation tests
// ---------------------------------------------------------------------------
pikl_tests! {
nav mod basic_movement {
viewport: { height: 5, count: 10 };
test initial_state {
actions: []
cursor: 0
offset: 0
}
test move_down_once {
actions: [move-down]
cursor: 1
offset: 0
}
test move_down_past_viewport {
actions: [move-down, move-down, move-down, move-down, move-down]
cursor: 5
offset: 1
}
test move_up_at_top_stays {
actions: [move-up]
cursor: 0
offset: 0
}
test move_down_then_up {
actions: [move-down, move-down, move-up]
cursor: 1
offset: 0
}
}
nav mod jumps {
viewport: { height: 5, count: 20 };
test move_to_top {
actions: [move-down, move-down, move-down, move-to-top]
cursor: 0
offset: 0
}
test move_to_bottom {
actions: [move-to-bottom]
cursor: 19
offset: 15
}
test page_down_from_top {
actions: [page-down]
cursor: 5
offset: 1
}
}
nav mod small_list {
viewport: { height: 10, count: 3 };
test move_to_bottom_small {
actions: [move-to-bottom]
cursor: 2
offset: 0
}
test at_bottom_stays {
actions: [move-down, move-down, move-down]
cursor: 2
offset: 0
}
}
nav mod empty_list {
viewport: { height: 5, count: 0 };
test movement_on_empty {
actions: [move-down, move-up, page-down, page-up]
cursor: 0
offset: 0
}
}
nav mod half_page {
viewport: { height: 10, count: 30 };
test half_page_down_from_top {
actions: [half-page-down]
cursor: 5
offset: 0
}
test half_page_up_from_middle {
actions: [half-page-down, half-page-down, half-page-up]
cursor: 5
offset: 1
}
test half_page_down_clamps_at_bottom {
actions: [half-page-down, half-page-down, half-page-down,
half-page-down, half-page-down, half-page-down]
cursor: 29
}
test half_page_up_clamps_at_top {
actions: [half-page-down, half-page-up, half-page-up]
cursor: 0
offset: 0
}
}
}
// ---------------------------------------------------------------------------
// Menu tests
// ---------------------------------------------------------------------------
pikl_tests! {
menu mod selection {
items: ["alpha", "bravo", "charlie", "delta"];
test confirm_first_item {
actions: [confirm]
selected: "alpha"
}
test move_down_and_confirm {
actions: [move-down, confirm]
selected: "bravo"
}
test move_to_third {
actions: [move-down, move-down, confirm]
selected: "charlie"
}
test move_to_last {
actions: [move-down, move-down, move-down, confirm]
selected: "delta"
}
test cancel_result {
actions: [cancel]
cancelled
}
}
menu mod filter_then_select {
items: ["alpha", "beta", "banana"];
test filter_and_confirm {
actions: [filter "ban", confirm]
selected: "banana"
}
test filter_no_match_then_cancel {
actions: [filter "zzz", cancel]
cancelled
}
}
menu mod dynamic_items {
items: ["alpha", "beta"];
test add_then_filter_then_confirm {
actions: [add-items ["zephyr"], filter "zep", confirm]
selected: "zephyr"
}
}
menu mod sender_drop {
items: ["alpha"];
test drop_sender_cancels {
actions: []
cancelled
}
}
menu mod pipeline_queries {
items: ["error_log", "warning_temp", "info_log", "debug_temp"];
test exact_filter {
actions: [filter "'log", confirm]
selected: "error_log"
}
test exact_then_inverse {
actions: [filter "'log | !error", confirm]
selected: "info_log"
}
test cancel_pipeline {
actions: [filter "'xyz", cancel]
cancelled
}
}
menu mod mode_switching {
items: ["alpha", "bravo"];
test set_mode_and_confirm {
actions: [set-mode-normal, set-mode-insert, filter "bra", confirm]
selected: "bravo"
}
}
menu mod regex_pipeline {
items: ["item-001", "item-abc", "item-123"];
test regex_filter_confirm {
actions: [filter "/[0-9]+/", confirm]
selected: "item-001"
}
}
menu mod inverse_fuzzy {
items: ["alpha", "bravo"];
test exclude_alpha {
actions: [filter "!alpha", confirm]
selected: "bravo"
}
}
menu mod three_stage {
items: ["error_log_123", "warning_temp_456", "info_log_789", "debug_temp_012"];
test full_pipeline {
actions: [filter "'log | !error | /[0-9]+/", confirm]
selected: "info_log_789"
}
}
menu mod half_page_menu {
items: ["a","b","c","d","e","f","g","h","i","j"];
test half_page_then_confirm {
actions: [half-page-down, confirm]
// viewport height=50, half=25, clamps to last item (index 9)
selected: "j"
}
}
nav mod half_page_small_height {
viewport: { height: 2, count: 10 };
test half_page_moves_one {
actions: [half-page-down]
cursor: 1
offset: 0
}
}
}