const ROUTE_SELECTOR: &str =
include_str!("../../../swift-bridge/Sources/SmixRunnerCore/RouteSelector.swift");
const TAP: &str = include_str!("../../../swift-bridge/Sources/SmixRunnerCore/TapRoute.swift");
const DOUBLE_TAP: &str =
include_str!("../../../swift-bridge/Sources/SmixRunnerCore/DoubleTapRoute.swift");
const LONG_PRESS: &str =
include_str!("../../../swift-bridge/Sources/SmixRunnerCore/LongPressRoute.swift");
#[test]
fn tap_route_decodes_three_selector_keys() {
let start = ROUTE_SELECTOR
.find("for key in [")
.expect("RouteSelector no longer iterates a key list; re-read the decoder");
let rest = &ROUTE_SELECTOR[start..];
let end = rest.find(']').expect("unterminated key list");
let list = &rest[..end];
for key in ["\"text\"", "\"id\"", "\"label\""] {
assert!(
list.contains(key),
"RouteSelector's decoder no longer accepts {key}; the wire doc promises it. \
Key list is: {list}"
);
}
}
#[test]
fn all_three_tap_routes_share_one_selector_decoder() {
for (name, src) in [
("TapRoute", TAP),
("DoubleTapRoute", DOUBLE_TAP),
("LongPressRoute", LONG_PRESS),
] {
assert!(
src.contains("RouteSelector.decode"),
"{name} decodes its selector itself instead of sharing RouteSelector"
);
}
}
#[test]
fn selector_wire_keys_match_rust_selector_enum() {
use smix_selector::{Modifiers, Pattern, Selector};
let cases = [
(
Selector::Text {
text: Pattern::Text("x".into()),
modifiers: Modifiers::default(),
},
"text",
),
(
Selector::Id {
id: "x".into(),
modifiers: Modifiers::default(),
},
"id",
),
(
Selector::Label {
label: "x".into(),
modifiers: Modifiers::default(),
},
"label",
),
];
for (selector, key) in cases {
let json = serde_json::to_value(&selector).expect("selector serializes");
assert!(
json.get(key).is_some(),
"Rust {selector:?} does not serialize under {key:?}, but the runner decodes that key"
);
}
}