1use std::cell::RefCell;
11use std::future::Future;
12use std::pin::Pin;
13use std::rc::Rc;
14use std::task::{Context, Poll};
15
16use day_core::conformance::{
17 Case, Drive, DriveBackend, DriveOp, Fail, NativeExpect, OpFuture, TestKind,
18};
19use serde::{Deserialize, Serialize};
20
21use crate::{Reply, Step, b64encode, next_capture_revision};
22
23pub use day_script_protocol::ShotPolicy;
24
25#[derive(Clone, Debug, Serialize, Deserialize)]
27pub struct Outcome {
28 pub name: String,
29 pub kind: String,
30 pub verdict: String,
32 #[serde(default, skip_serializing_if = "Option::is_none")]
33 pub message: Option<String>,
34 #[serde(default, skip_serializing_if = "Option::is_none")]
35 pub reason: Option<String>,
36 pub ms: u64,
37 pub proves: Vec<String>,
38 #[serde(default)]
40 pub shots: Vec<String>,
41 #[serde(default, skip_serializing_if = "Vec::is_empty")]
44 pub native_unread: Vec<String>,
45}
46
47#[derive(Clone, Debug, Serialize, Deserialize)]
49pub struct Shot {
50 pub test: String,
51 pub name: String,
52 pub png_base64: String,
53}
54
55#[derive(Clone, Debug, Default, Serialize, Deserialize)]
57pub struct RunReport {
58 pub tests: Vec<Outcome>,
59 #[serde(default)]
60 pub shots: Vec<Shot>,
61 #[serde(default)]
64 pub caps: std::collections::BTreeMap<String, String>,
65}
66
67struct Run {
68 report: RunReport,
69 done: bool,
70}
71
72thread_local! {
73 static RUN: RefCell<Option<Rc<RefCell<Run>>>> = const { RefCell::new(None) };
74}
75
76pub fn listing() -> Result<serde_json::Value, String> {
78 day_core::conformance::validate_registry()?;
79 let cases = day_core::conformance::cases();
80 Ok(serde_json::Value::Array(
81 cases
82 .iter()
83 .map(|c| {
84 serde_json::json!({
85 "name": c.name(),
86 "kind": kind_name(c.kind()),
87 "proves": c.proves_keys(),
88 "requires": c.requirements().iter().map(|r| format!("{r:?}")).collect::<Vec<_>>(),
89 })
90 })
91 .collect(),
92 ))
93}
94
95pub fn run_tests(
99 filter: &[String],
100 shots: ShotPolicy,
101 case_timeout_secs: Option<f64>,
102) -> Result<Reply, Reply> {
103 day_core::conformance::validate_registry().map_err(|e| Reply::fail(e, false))?;
104 let run = RUN.with(|r| r.borrow().clone());
105 match run {
106 None => {
107 start(filter.to_vec(), shots, case_timeout_secs);
108 Err(Reply::fail("tests running", true))
109 }
110 Some(run) => {
111 if !run.borrow().done {
112 return Err(Reply::fail("tests running", true));
113 }
114 RUN.with(|r| *r.borrow_mut() = None);
115 let report = std::mem::take(&mut run.borrow_mut().report);
116 let data = serde_json::to_value(&report)
117 .map_err(|e| Reply::fail(format!("test report: {e}"), false))?;
118 Ok(Reply {
119 data: Some(data),
120 ..Reply::ok()
121 })
122 }
123 }
124}
125
126fn kind_name(kind: TestKind) -> &'static str {
127 match kind {
128 TestKind::Gui => "gui",
129 TestKind::Headless => "headless",
130 }
131}
132
133fn matches(filter: &[String], name: &str) -> bool {
134 filter.is_empty() || filter.iter().any(|f| glob(f, name))
135}
136
137fn glob(pattern: &str, name: &str) -> bool {
139 let mut parts = pattern.split('*');
140 let Some(first) = parts.next() else {
141 return pattern == name;
142 };
143 if !pattern.contains('*') {
144 return pattern == name;
145 }
146 if !name.starts_with(first) {
147 return false;
148 }
149 let mut rest = &name[first.len()..];
150 let parts: Vec<&str> = parts.collect();
151 for (i, part) in parts.iter().enumerate() {
152 if part.is_empty() {
153 continue;
154 }
155 let last = i + 1 == parts.len() && !pattern.ends_with('*');
156 if last {
157 return rest.ends_with(part);
158 }
159 match rest.find(part) {
160 Some(at) => rest = &rest[at + part.len()..],
161 None => return false,
162 }
163 }
164 true
165}
166
167const DEFAULT_CASE_TIMEOUT_SECS: f64 = 30.0;
169
170fn start(filter: Vec<String>, policy: ShotPolicy, case_timeout_secs: Option<f64>) {
171 let run = Rc::new(RefCell::new(Run {
172 report: RunReport::default(),
173 done: false,
174 }));
175 run.borrow_mut().report.caps = day_spec::Cap::ALL
176 .iter()
177 .map(|cap| {
178 let answer = match day_core::capability(*cap) {
179 day_spec::Support::Native => "N",
180 day_spec::Support::Emulated => "E",
181 day_spec::Support::Unsupported => "-",
182 };
183 (format!("{cap:?}"), answer.to_owned())
184 })
185 .collect();
186 RUN.with(|r| *r.borrow_mut() = Some(run.clone()));
187 day_core::conformance::set_intercepting_urls(true);
189 day_core::task(async move {
190 let cases: Vec<Case> = day_core::conformance::cases()
191 .into_iter()
192 .filter(|c| matches(&filter, c.name()))
193 .collect();
194 let mut gui = false;
195 for (i, case) in cases.iter().enumerate() {
196 let mut shots = Vec::new();
197 let twin = cases
200 .iter()
201 .enumerate()
202 .any(|(j, c)| j != i && c.name() == case.name());
203 let outcome = if twin {
204 let mut o = outcome_for(case);
205 o.verdict = "fail".into();
206 o.message = Some(format!(
207 "two #[day::test] functions are named {}; rename one",
208 case.name()
209 ));
210 o
211 } else {
212 gui |= case.kind() == TestKind::Gui;
213 run_case(case, policy, case_timeout_secs, &mut shots).await
214 };
215 let mut run = run.borrow_mut();
216 run.report.shots.extend(shots);
217 run.report.tests.push(outcome);
218 }
219 if gui {
221 day_core::conformance::clear_active();
222 }
223 day_core::conformance::set_intercepting_urls(false);
224 run.borrow_mut().done = true;
225 });
226}
227
228fn outcome_for(case: &Case) -> Outcome {
229 Outcome {
230 name: case.name().to_owned(),
231 kind: kind_name(case.kind()).to_owned(),
232 verdict: "pass".into(),
233 message: None,
234 reason: None,
235 ms: 0,
236 proves: case.proves_keys().to_vec(),
237 shots: Vec::new(),
238 native_unread: Vec::new(),
239 }
240}
241
242async fn run_case(
243 case: &Case,
244 policy: ShotPolicy,
245 run_timeout_secs: Option<f64>,
246 shots: &mut Vec<Shot>,
247) -> Outcome {
248 let started = Stopwatch::start();
249 let mut outcome = outcome_for(case);
250 if let Some(cap) = case
253 .requirements()
254 .iter()
255 .find(|c| day_core::capability(**c) == day_spec::Support::Unsupported)
256 {
257 outcome.verdict = "skip".into();
258 outcome.reason = Some(format!("Cap::{cap:?} is Unsupported on this toolkit"));
259 return outcome;
260 }
261 if let Some(what) = case.missing_support() {
262 outcome.verdict = "skip".into();
263 outcome.reason = Some(format!("{what} is Unsupported on this toolkit"));
264 return outcome;
265 }
266 let backend = Rc::new(Engine {
267 shots: Rc::new(RefCell::new(Vec::new())),
268 unread: Rc::new(RefCell::new(Vec::new())),
269 });
270 let drive = Drive::new(backend.clone());
271 let limit = match run_timeout_secs {
274 Some(t) if t <= 0.0 => None,
275 run => Some(
276 case.timeout_secs()
277 .or(run)
278 .unwrap_or(DEFAULT_CASE_TIMEOUT_SECS),
279 ),
280 };
281 let body = {
282 let (case, drive) = (case.clone(), drive.clone());
283 async move {
284 if case.kind() == TestKind::Gui {
285 if !day_core::conformance::set_active(case.clone()) {
288 return Err(Fail(
289 "the app shows no test host: root its test build in \
290 `day::test_host(..)` (docs/testing.md)"
291 .into(),
292 ));
293 }
294 day_reactive::flush_sync();
295 drive.wait_idle().await?;
296 if let Some(message) = day_core::conformance::take_page_panic() {
297 return Err(Fail(format!("the page panicked: {message}")));
298 }
299 for name in case.shots() {
300 drive.shot(name).await?;
301 }
302 }
303 case.run_body(drive).await
304 }
305 };
306 let result = Guarded::new(Box::pin(body), limit).await;
307 let placeholders = day_spec::placeholder::seen();
310 if let Some(kind) = case.proves_keys().iter().find_map(|k| {
311 k.strip_prefix("kind:")
312 .filter(|kind| placeholders.iter().any(|seen| seen == kind))
313 }) {
314 outcome.verdict = "skip".into();
315 outcome.reason = Some(format!("no {kind} renderer on this toolkit"));
316 outcome.ms = started.elapsed_ms();
317 return outcome;
318 }
319 if let Err(Fail(message)) = &result {
320 outcome.verdict = "fail".into();
321 outcome.message = Some(message.clone());
322 if policy != ShotPolicy::Never {
323 let _ = drive.shot("failed").await;
325 }
326 }
327 outcome.ms = started.elapsed_ms();
328 outcome.native_unread = std::mem::take(&mut *backend.unread.borrow_mut());
329 outcome.native_unread.dedup();
330 let keep = match policy {
331 ShotPolicy::Never => false,
332 ShotPolicy::OnFailure => result.is_err(),
333 ShotPolicy::Always => true,
334 };
335 if keep {
336 for (name, png) in backend.shots.borrow_mut().drain(..) {
337 outcome.shots.push(name.clone());
338 shots.push(Shot {
339 test: case.name().to_owned(),
340 name,
341 png_base64: b64encode(&png),
342 });
343 }
344 }
345 outcome
346}
347
348struct Guarded {
354 body: Pin<Box<dyn Future<Output = Result<(), Fail>>>>,
355 limit: Option<(f64, Pin<Box<day_core::Sleep>>)>,
356}
357
358impl Guarded {
359 fn new(body: Pin<Box<dyn Future<Output = Result<(), Fail>>>>, secs: Option<f64>) -> Self {
360 Guarded {
361 body,
362 limit: secs.map(|s| (s, Box::pin(day_core::sleep((s * 1000.0) as u32)))),
363 }
364 }
365}
366
367impl Future for Guarded {
368 type Output = Result<(), Fail>;
369
370 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
371 let this = &mut *self;
372 let polled =
373 std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| this.body.as_mut().poll(cx)));
374 match polled {
375 Ok(Poll::Ready(result)) => return Poll::Ready(result),
376 Err(payload) => {
377 let message = day_core::conformance::panic_message(payload.as_ref());
378 return Poll::Ready(Err(Fail(format!("panicked: {message}"))));
379 }
380 Ok(Poll::Pending) => {}
381 }
382 if let Some((secs, timer)) = &mut this.limit
383 && timer.as_mut().poll(cx).is_ready()
384 {
385 return Poll::Ready(Err(Fail(format!("timed out after {secs} s"))));
386 }
387 Poll::Pending
388 }
389}
390
391struct Engine {
399 shots: Rc<RefCell<Vec<Capture>>>,
400 unread: Rc<RefCell<Vec<String>>>,
402}
403
404type Capture = (String, Vec<u8>);
406
407impl DriveBackend for Engine {
408 fn run(&self, op: DriveOp) -> OpFuture {
409 let (shots, unread) = (self.shots.clone(), self.unread.clone());
410 Box::pin(async move {
411 if let DriveOp::Pause(secs) = op {
412 day_core::sleep((secs * 1000.0) as u32).await;
413 return Ok(());
414 }
415 run_step(&op, &shots, &unread).await?;
416 if let Some(native) = native_follow_up(&op) {
417 run_step(&native, &shots, &unread).await?;
418 }
419 Ok(())
420 })
421 }
422}
423
424fn native_follow_up(op: &DriveOp) -> Option<DriveOp> {
426 let (id, expect) = match op {
427 DriveOp::AssertText(id, text) => (
428 id,
429 NativeExpect {
430 text: Some(text.clone()),
431 ..Default::default()
432 },
433 ),
434 DriveOp::AssertValue(id, value) => (
435 id,
436 NativeExpect {
437 number: Some(*value),
438 ..Default::default()
439 },
440 ),
441 DriveOp::AssertOn(id, on) => (
442 id,
443 NativeExpect {
444 checked: Some(*on),
445 ..Default::default()
446 },
447 ),
448 _ => return None,
449 };
450 Some(DriveOp::AssertNative(id.clone(), expect))
451}
452
453async fn run_step(
455 op: &DriveOp,
456 shots: &Rc<RefCell<Vec<Capture>>>,
457 unread: &Rc<RefCell<Vec<String>>>,
458) -> Result<(), Fail> {
459 let step = step_for(op)?;
460 let clock = Stopwatch::start();
465 let mut waited_ms = 0u32;
466 let budget_ms = (crate::DEFAULT_TIMEOUT_SECS * 1000.0) as u32;
467 let revision = next_capture_revision();
470 loop {
471 let reply = crate::exec(step.clone(), revision);
472 if reply.ok {
473 if let (DriveOp::Shot(name), Some(png)) = (op, &reply.png_base64) {
474 shots
475 .borrow_mut()
476 .push((name.clone(), crate::b64decode(png)));
477 }
478 let checked = match op {
479 DriveOp::AssertNative(id, _)
480 | DriveOp::AssertFrame(id, _)
481 | DriveOp::SamplePixel(id, ..) => Some(id),
482 _ => None,
483 };
484 if let (Some(id), Some(data)) = (checked, &reply.data) {
485 let fields = data.get("unread").and_then(|u| u.as_array());
486 for f in fields.into_iter().flatten().filter_map(|f| f.as_str()) {
487 unread.borrow_mut().push(format!("{id} {f}"));
488 }
489 }
490 return Ok(());
491 }
492 let message = reply.error.unwrap_or_else(|| "failed".into());
493 let elapsed_ms = u32::try_from(clock.elapsed_ms()).unwrap_or(u32::MAX);
494 if !reply.retryable || waited_ms.max(elapsed_ms) >= budget_ms {
495 return Err(Fail(format!("{}: {message}", op_name(op))));
496 }
497 let wait = if reply.capture_pending {
498 16
499 } else {
500 crate::RETRY_MS
501 };
502 waited_ms += wait;
503 day_core::sleep(wait).await;
504 }
505}
506
507fn op_name(op: &DriveOp) -> String {
508 match op {
509 DriveOp::Tap(id) => format!("tap {id}"),
510 DriveOp::Input(id, _) => format!("input {id}"),
511 DriveOp::Toggle(id, _) => format!("toggle {id}"),
512 DriveOp::SetValue(id, _) => format!("set_value {id}"),
513 DriveOp::Select(id, _) => format!("select {id}"),
514 DriveOp::Focus(id) => format!("focus {id}"),
515 DriveOp::Submit(id) => format!("submit {id}"),
516 DriveOp::Navigate(route) => format!("navigate {route}"),
517 DriveOp::WaitIdle => "wait_idle".into(),
518 DriveOp::Pause(_) => "pause".into(),
519 DriveOp::Shot(name) => format!("shot {name}"),
520 DriveOp::AssertText(id, _) => format!("assert_text {id}"),
521 DriveOp::AssertVisible(id) => format!("assert_visible {id}"),
522 DriveOp::AssertMissing(id) => format!("assert_missing {id}"),
523 DriveOp::AssertHidden(id) => format!("assert_hidden {id}"),
524 DriveOp::Hover(id, _) | DriveOp::HoverLeave(id) => format!("hover {id}"),
525 DriveOp::Pan(id, ..) => format!("pan {id}"),
526 DriveOp::Pinch(id, _) => format!("pinch {id}"),
527 DriveOp::Rotate(id, _) => format!("rotate {id}"),
528 DriveOp::Drag(id, ..) => format!("drag {id}"),
529 DriveOp::TapAt(id, ..) => format!("tap {id}"),
530 DriveOp::Key(_, key) => format!("key {key}"),
531 DriveOp::AssertAnnounced(text) => format!("assert_announced {text}"),
532 DriveOp::AssertValue(id, _) | DriveOp::AssertOn(id, _) => format!("assert_value {id}"),
533 DriveOp::AssertFocused(id, _) => format!("assert_focused {id}"),
534 DriveOp::AssertRoute(route) => format!("assert_route {route}"),
535 DriveOp::A11yAudit(_) => "a11y_audit".into(),
536 DriveOp::AssertNative(id, _) => format!("assert_native {id}"),
537 DriveOp::AssertFrame(id, _) => format!("assert_frame {id}"),
538 DriveOp::SamplePixel(id, ..) => format!("sample_pixel {id}"),
539 DriveOp::AssertOpenedUrl(url) => format!("assert_opened_url {url}"),
540 DriveOp::Activate(id, _) => format!("activate {id}"),
541 DriveOp::Reorder(id, ..) => format!("reorder {id}"),
542 DriveOp::DeleteRow(id, _) => format!("delete_row {id}"),
543 DriveOp::SwipeRow(id, ..) => format!("swipe_row {id}"),
544 DriveOp::ScrollTo(id, _) => format!("scroll_to {id}"),
545 DriveOp::Expand(id, row, _) => format!("expand {id} {row}"),
546 DriveOp::NavBack => "nav_back".into(),
547 DriveOp::TreeMove(id, row, ..) => format!("tree_move {id} {row}"),
548 DriveOp::ContextMenu(id, item) => format!("context_menu {id} {item}"),
549 DriveOp::Menu(item) => format!("menu {item}"),
550 DriveOp::ToolbarPress(item) | DriveOp::ToolbarToggle(item, _) => format!("toolbar {item}"),
551 DriveOp::DialogScripted(_) => "dialog_mode".into(),
552 DriveOp::AssertPresented(_) => "assert_presented".into(),
553 DriveOp::Respond(_) => "respond".into(),
554 DriveOp::RespondText(_) => "respond".into(),
555 }
556}
557
558fn step_for(op: &DriveOp) -> Result<Step, Fail> {
561 use serde_json::json;
562 let v = match op {
563 DriveOp::Tap(id) => json!({"op": "tap", "id": id}),
564 DriveOp::Input(id, text) => json!({"op": "input", "id": id, "text": text}),
565 DriveOp::Toggle(id, on) => json!({"op": "toggle", "id": id, "value": on}),
566 DriveOp::SetValue(id, value) => json!({"op": "set_value", "id": id, "value": value}),
567 DriveOp::Select(id, index) => json!({"op": "select", "id": id, "index": index}),
568 DriveOp::Focus(id) => json!({"op": "focus", "id": id}),
569 DriveOp::Submit(id) => json!({"op": "submit", "id": id}),
570 DriveOp::Navigate(route) => json!({"op": "navigate", "route": route}),
571 DriveOp::WaitIdle => json!({"op": "wait_idle"}),
572 DriveOp::Pause(secs) => json!({"op": "pause", "secs": secs}),
573 DriveOp::Shot(name) => json!({"op": "screenshot", "name": name, "in_process": true}),
574 DriveOp::AssertText(id, text) => json!({"op": "assert_text", "id": id, "text": text}),
575 DriveOp::AssertVisible(id) => json!({"op": "assert_visible", "id": id}),
576 DriveOp::AssertMissing(id) => json!({"op": "assert_missing", "id": id}),
577 DriveOp::AssertHidden(id) => json!({"op": "assert_hidden", "id": id}),
578 DriveOp::Hover(id, at) => json!({"op": "hover", "id": id, "at": at.map(|(x, y)| [x, y])}),
579 DriveOp::HoverLeave(id) => json!({"op": "hover", "id": id, "leave": true}),
580 DriveOp::Pan(id, dx, dy) => json!({"op": "pan", "id": id, "by": [dx, dy]}),
581 DriveOp::Pinch(id, scale) => json!({"op": "pinch", "id": id, "scale": scale}),
582 DriveOp::Rotate(id, rotation) => {
583 json!({"op": "rotate", "id": id, "rotation": rotation})
584 }
585 DriveOp::Drag(id, (fx, fy), (tx, ty)) => {
586 json!({"op": "drag", "id": id, "from": [fx, fy], "to": [tx, ty]})
587 }
588 DriveOp::TapAt(id, x, y) => json!({"op": "tap", "id": id, "at": [x, y]}),
589 DriveOp::Key(id, key) => json!({"op": "key", "id": id, "key": key}),
590 DriveOp::AssertAnnounced(text) => json!({"op": "assert_announced", "text": text}),
591 DriveOp::AssertValue(id, value) => json!({"op": "assert_value", "id": id, "value": value}),
592 DriveOp::AssertOn(id, on) => json!({"op": "assert_value", "id": id, "value": on}),
593 DriveOp::AssertFocused(id, focused) => {
594 json!({"op": "assert_focused", "id": id, "focused": focused})
595 }
596 DriveOp::AssertRoute(route) => json!({"op": "assert_route", "route": route}),
597 DriveOp::A11yAudit(id) => json!({"op": "a11y_audit", "id": id}),
598 DriveOp::AssertNative(id, e) => json!({
599 "op": "assert_native", "id": id, "text": e.text, "number": e.number,
600 "checked": e.checked, "enabled": e.enabled, "visible": e.visible,
601 }),
602 DriveOp::AssertFrame(id, f) => json!({
603 "op": "assert_frame", "id": id, "width": f.width, "height": f.height,
604 "x": f.x, "y": f.y, "relative_to": f.relative_to, "tolerance": f.tolerance,
605 }),
606 DriveOp::SamplePixel(id, x, y, color) => {
607 json!({"op": "sample_pixel", "id": id, "x": x, "y": y, "color": color})
608 }
609 DriveOp::AssertOpenedUrl(url) => json!({"op": "assert_opened_url", "url": url}),
610 DriveOp::Activate(id, index) => json!({"op": "activate", "id": id, "index": index}),
611 DriveOp::Reorder(id, from, to) => {
612 json!({"op": "reorder", "id": id, "from": from, "to": to})
613 }
614 DriveOp::DeleteRow(id, row) => json!({"op": "delete_row", "id": id, "row": row}),
615 DriveOp::SwipeRow(id, row, leading, action) => json!({
616 "op": "swipe_row", "id": id, "row": row, "action": action,
617 "edge": if *leading { "leading" } else { "trailing" },
618 }),
619 DriveOp::ScrollTo(id, edge) => json!({"op": "scroll_to", "id": id, "edge": edge}),
620 DriveOp::Expand(id, row, expanded) => {
621 json!({"op": "expand", "id": id, "row": row, "expanded": expanded})
622 }
623 DriveOp::NavBack => json!({"op": "nav_back"}),
624 DriveOp::TreeMove(id, row, parent, index) => json!({
625 "op": "tree_move", "id": id, "row": row, "parent": parent, "index": index,
626 }),
627 DriveOp::ContextMenu(id, item) => json!({"op": "context_menu", "id": id, "item": item}),
628 DriveOp::Menu(item) => json!({"op": "menu", "id": item}),
629 DriveOp::ToolbarPress(item) => json!({"op": "toolbar", "item": item}),
630 DriveOp::ToolbarToggle(item, on) => json!({"op": "toolbar", "item": item, "on": on}),
631 DriveOp::DialogScripted(scripted) => json!({
632 "op": "dialog_mode", "mode": if *scripted { "scripted" } else { "native" },
633 }),
634 DriveOp::AssertPresented(title) => json!({"op": "assert_presented", "title": title}),
635 DriveOp::Respond(Some(button)) => json!({"op": "respond", "button": button}),
636 DriveOp::Respond(None) => json!({"op": "respond", "dismiss": true}),
637 DriveOp::RespondText(text) => json!({"op": "respond", "text": text}),
638 };
639 serde_json::from_value(v).map_err(|e| Fail(format!("{}: {e}", op_name(op))))
640}
641
642struct Stopwatch {
645 #[cfg(not(target_arch = "wasm32"))]
646 started: std::time::Instant,
647}
648
649impl Stopwatch {
650 fn start() -> Self {
651 Stopwatch {
652 #[cfg(not(target_arch = "wasm32"))]
653 started: std::time::Instant::now(),
654 }
655 }
656 fn elapsed_ms(&self) -> u64 {
657 #[cfg(not(target_arch = "wasm32"))]
658 {
659 self.started.elapsed().as_millis() as u64
660 }
661 #[cfg(target_arch = "wasm32")]
662 {
663 0
664 }
665 }
666}
667
668#[cfg(test)]
669mod tests {
670 use super::glob;
671
672 #[test]
673 fn globs_match_prefixes_suffixes_and_middles() {
674 assert!(glob("button-*", "button-status"));
675 assert!(glob("*-status", "button-status"));
676 assert!(glob("button*status", "button-status"));
677 assert!(glob("*", "anything"));
678 assert!(glob("button-status", "button-status"));
679 assert!(!glob("button-*", "slider-range"));
680 assert!(!glob("button", "button-status"));
681 }
682}