Skip to content

Commit 6c025cd

Browse files
authored
Merge pull request #72 from epage/test
fix: Don't crash when highlighting JS
2 parents 79eeeb2 + 8f35154 commit 6c025cd

File tree

3 files changed

+189
-25
lines changed

3 files changed

+189
-25
lines changed

Cargo.lock

Lines changed: 116 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ concolor-clap = { version = "0.1.0", features = ["api"] }
3939
proc-exit = "2.0.1"
4040
human-panic = "1.1.3"
4141
anyhow = "1.0.68"
42-
syntect = { version = "5.0.0", default-features = false, features = ["parsing", "regex-fancy"] }
42+
syntect = { version = "5.0.0", default-features = false, features = ["parsing", "regex-onig"] }
4343
terminal_size = "0.2.3"
4444
textwrap = "0.16.0"
4545
anstyle = "0.3.1"
@@ -58,6 +58,7 @@ bugreport = "0.5.0"
5858
dunce = "1.0.3"
5959

6060
[dev-dependencies]
61+
git-fixture = "0.3.1"
6162
snapbox = { version = "0.4.10", features = ["path"] }
6263
term-transcript = "0.2.0"
6364

tests/cli.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#[test]
2+
fn basic() {
3+
let root = snapbox::path::PathFixture::mutable_temp().unwrap();
4+
let root_path = root.path().unwrap();
5+
let plan = git_fixture::TodoList {
6+
commands: vec![
7+
git_fixture::Command::Tree(git_fixture::Tree {
8+
files: [("basic.js", "test('arg1');")]
9+
.into_iter()
10+
.map(|(p, c)| (p.into(), c.into()))
11+
.collect::<std::collections::HashMap<_, _>>(),
12+
message: Some("A".to_owned()),
13+
author: None,
14+
}),
15+
git_fixture::Command::Branch("main".into()),
16+
],
17+
..Default::default()
18+
};
19+
plan.run(root_path).unwrap();
20+
21+
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("git-dive"))
22+
.arg("basic.js")
23+
.current_dir(root_path)
24+
.assert()
25+
.success()
26+
.stdout_eq(
27+
"\
28+
HEAD 1 │ test('arg1');
29+
",
30+
)
31+
.stderr_matches(
32+
"\
33+
",
34+
);
35+
36+
root.close().unwrap();
37+
}
38+
39+
#[test]
40+
fn js_highlight_panics() {
41+
let root = snapbox::path::PathFixture::mutable_temp().unwrap();
42+
let root_path = root.path().unwrap();
43+
let plan = git_fixture::TodoList {
44+
commands: vec![
45+
git_fixture::Command::Tree(git_fixture::Tree {
46+
files: [("basic.js", "test('arg1');")]
47+
.into_iter()
48+
.map(|(p, c)| (p.into(), c.into()))
49+
.collect::<std::collections::HashMap<_, _>>(),
50+
message: Some("A".to_owned()),
51+
author: None,
52+
}),
53+
git_fixture::Command::Branch("main".into()),
54+
],
55+
..Default::default()
56+
};
57+
plan.run(root_path).unwrap();
58+
59+
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("git-dive"))
60+
.arg("basic.js")
61+
.current_dir(root_path)
62+
.env("CLICOLOR_FORCE", "1")
63+
.assert()
64+
.success()
65+
.stderr_matches(
66+
"\
67+
",
68+
);
69+
70+
root.close().unwrap();
71+
}

0 commit comments

Comments
 (0)