Skip to content

Commit

Permalink
Merge pull request #72 from epage/test
Browse files Browse the repository at this point in the history
fix: Don't crash when highlighting JS
  • Loading branch information
epage authored Mar 23, 2023
2 parents 79eeeb2 + 8f35154 commit 6c025cd
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 25 deletions.
140 changes: 116 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ concolor-clap = { version = "0.1.0", features = ["api"] }
proc-exit = "2.0.1"
human-panic = "1.1.3"
anyhow = "1.0.68"
syntect = { version = "5.0.0", default-features = false, features = ["parsing", "regex-fancy"] }
syntect = { version = "5.0.0", default-features = false, features = ["parsing", "regex-onig"] }
terminal_size = "0.2.3"
textwrap = "0.16.0"
anstyle = "0.3.1"
Expand All @@ -58,6 +58,7 @@ bugreport = "0.5.0"
dunce = "1.0.3"

[dev-dependencies]
git-fixture = "0.3.1"
snapbox = { version = "0.4.10", features = ["path"] }
term-transcript = "0.2.0"

Expand Down
71 changes: 71 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#[test]
fn basic() {
let root = snapbox::path::PathFixture::mutable_temp().unwrap();
let root_path = root.path().unwrap();
let plan = git_fixture::TodoList {
commands: vec![
git_fixture::Command::Tree(git_fixture::Tree {
files: [("basic.js", "test('arg1');")]
.into_iter()
.map(|(p, c)| (p.into(), c.into()))
.collect::<std::collections::HashMap<_, _>>(),
message: Some("A".to_owned()),
author: None,
}),
git_fixture::Command::Branch("main".into()),
],
..Default::default()
};
plan.run(root_path).unwrap();

snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("git-dive"))
.arg("basic.js")
.current_dir(root_path)
.assert()
.success()
.stdout_eq(
"\
HEAD 1 │ test('arg1');
",
)
.stderr_matches(
"\
",
);

root.close().unwrap();
}

#[test]
fn js_highlight_panics() {
let root = snapbox::path::PathFixture::mutable_temp().unwrap();
let root_path = root.path().unwrap();
let plan = git_fixture::TodoList {
commands: vec![
git_fixture::Command::Tree(git_fixture::Tree {
files: [("basic.js", "test('arg1');")]
.into_iter()
.map(|(p, c)| (p.into(), c.into()))
.collect::<std::collections::HashMap<_, _>>(),
message: Some("A".to_owned()),
author: None,
}),
git_fixture::Command::Branch("main".into()),
],
..Default::default()
};
plan.run(root_path).unwrap();

snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("git-dive"))
.arg("basic.js")
.current_dir(root_path)
.env("CLICOLOR_FORCE", "1")
.assert()
.success()
.stderr_matches(
"\
",
);

root.close().unwrap();
}

0 comments on commit 6c025cd

Please sign in to comment.