Files
pikl/crates/pikl-core/tests/dsl_tests.rs

196 lines
4.3 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
}
}
}
// ---------------------------------------------------------------------------
// 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
}
}
}