Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Dec 25, 2024
1 parent c2d3341 commit 4cd17c3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 22 deletions.
30 changes: 13 additions & 17 deletions crates/bsnext_input/src/route_cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::path_def::PathDef;
use crate::route::{DelayKind, DelayOpts, DirRoute, Route, RouteKind};
use crate::route::{DelayKind, DelayOpts, DirRoute, Opts, Route, RouteKind};
use clap::Parser;
use shell_words::split;

Expand Down Expand Up @@ -35,17 +35,15 @@ impl TryInto<Route> for RouteCli {
dir,
path,
delay: ms,
} => {
let mut route = Route {
path: PathDef::try_new(path)?,
kind: RouteKind::Dir(DirRoute { dir, base: None }),
} => Route {
path: PathDef::try_new(path)?,
kind: RouteKind::Dir(DirRoute { dir, base: None }),
opts: Opts {
delay: ms.map(|ms| DelayOpts::Delay(DelayKind::Ms(ms))),
..std::default::Default::default()
};
if let Some(ms) = ms {
route.opts.delay = Some(DelayOpts::Delay(DelayKind::Ms(ms)))
}
route
}
},
..std::default::Default::default()
},
})
}
}
Expand Down Expand Up @@ -77,19 +75,17 @@ mod test {
let input = "bslive serve-dir --path=/ --dir=examples/basic/public";
let as_args = split(input)?;
let parsed = RouteCli::try_parse_from(as_args)?;
let as_route: Result<Route, _> = parsed.try_into();
dbg!(&as_route);
// assert_debug_snapshot!(parsed);
let as_route: Route = parsed.try_into().unwrap();
insta::assert_debug_snapshot!(as_route);
Ok(())
}
#[test]
fn test_serve_dir_delay() -> anyhow::Result<()> {
let input = "bslive serve-dir --path=/ --dir=examples/basic/public --delay=1000";
let as_args = split(input)?;
let parsed = RouteCli::try_parse_from(as_args)?;
let as_route: Result<Route, _> = parsed.try_into();
dbg!(&as_route);
// assert_debug_snapshot!(parsed);
let as_route: Route = parsed.try_into().unwrap();
insta::assert_debug_snapshot!(as_route);
Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
---
source: crates/bsnext_input/src/route_cli.rs
expression: parsed
expression: as_route
---
RouteCli {
command: ServeDir {
path: "/",
dir: "examples/basic/public",
Route {
path: PathDef {
inner: "/",
},
kind: Dir(
DirRoute {
dir: "examples/basic/public",
base: None,
},
),
opts: Opts {
cors: None,
delay: None,
watch: Bool(
true,
),
inject: Bool(
true,
),
headers: None,
cache: Prevent,
compression: None,
},
fallback: None,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
source: crates/bsnext_input/src/route_cli.rs
expression: as_route
---
Route {
path: PathDef {
inner: "/",
},
kind: Dir(
DirRoute {
dir: "examples/basic/public",
base: None,
},
),
opts: Opts {
cors: None,
delay: Some(
Delay(
Ms(
1000,
),
),
),
watch: Bool(
true,
),
inject: Bool(
true,
),
headers: None,
cache: Prevent,
compression: None,
},
fallback: None,
}

0 comments on commit 4cd17c3

Please sign in to comment.