Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaoboy committed Oct 19, 2024
1 parent 7a4c030 commit c7cd6bf
Show file tree
Hide file tree
Showing 21 changed files with 1,084 additions and 19 deletions.
43 changes: 43 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ base64 = "0.22.1"
wasm-bindgen-test = "0.3.45"
ansi2 = { path = "./ansi2", features = ["wasm"] }
osvg = { version = "0.1.1", features = ["bindgen"] }
insta = { version = "1.40.0" }

[profile.release]
debug = false
Expand Down
3 changes: 3 additions & 0 deletions ansi2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ html-escape = { workspace = true }
base64 = { workspace = true }
osvg = { workspace = true, optional = true }

[dev-dependencies]
insta = { workspace = true }

[profile.release]
opt-level = 3

Expand Down
41 changes: 22 additions & 19 deletions ansi2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,120 +310,123 @@ impl Canvas {
#[cfg(test)]
mod test {
use crate::lex::parse_ansi;
use insta::assert_debug_snapshot;

#[test]
fn test() {
let s = "\x1b[0;5;35;45m";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}
#[test]
fn test_reset() {
let s = "\x1b[m\x1b";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_starship() {
fn test_starship_title() {
let s = "\x1b[?2004h\x1b]0;/c/wt\x1b[30m\x1b(B\x1b[m\x1b[J\x1b[K";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);

assert_debug_snapshot!(r);
}
#[test]
fn test_starship_prompt() {
let s = "\x1b[38;2;218;98;125m\x1b[48;2;218;98;125;30mwin\x1b[38;2;218;98;125m\x1b[30mC:/wt \x1b[48;2;252;161;125;38;2;218;98;125m\x1b[48;2;134;187;216;38;2;252;161;125m\x1b[48;2;6;150;154;38;2;134;187;216m\x1b[48;2;51;101;138;38;2;6;150;154m\x1b[0m\x1b[K";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_vitest_bench() {
let s = "\x1b[36m\x1b[7m\x1b[1m BENCH \x1b[22m\x1b[27m\x1b[39m \x1b[36mSummary\x1b[39m";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_fastfetch() {
let s = "\x1b[1G\x1b[19A\x1b[47C";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_color256() {
let s = "\x1b[38;5;99ma\x1b[48;5;99mb";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_color24() {
let s = "\x1b[38;2;0;0;114m";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}
#[test]
fn test_base() {
let s =
"\x1b[30mblack\x1b[0m \x1b[90mbright black\x1b[0m \x1b[40mblack\x1b[0m \x1b[100mbright black\x1b[0m";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_link() {
let s =
"\x1b]8;;file:///Users/xxx/src/new-nu-parser/Cargo.toml\x1b\\Cargo.toml\x1b]8;;\x1b";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}
#[test]
fn test_link_hide() {
let s = "\x1b[8mhttp://example.com/how_about_me\x1b[m";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_link_id() {
let s = "\x1b]8;id=1;http://example.com/id\x1b\\twice\x1b]8;;\x1b\\";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_empty_link() {
let s = "\x1b]8;;\x1b\\";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_link_soft_reset() {
let s = "\x1b]8;;http://example.com/softreset\\\x1b[3;31mfoo[!pbar";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_link_no_close() {
let s = "\x1b]8;;http://example.com/foo\x1b\\foo\x1b]8;;http://example.com/foo\x1b\\foo\x1b]8;;\x1b\\ \x1b]8;;http://example.com/foo\x1b\\foo\x1b]8;;http://example.com/bar\x1b\\bar\x1b]8;;\x1b\\";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_sgr6() {
let s = "\x1b[48;5;186;38;5;16m";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}

#[test]
fn test_style() {
let s =
"aaa\x1b[1mbold\x1b[0m \x1b[2mdim\x1b[0m \x1b[3mitalic\x1b[3m \x1b[4munderline\x1b[4m";
let r = parse_ansi(s).unwrap();
println!("{:?}", r);
assert_debug_snapshot!(r);
}
}
Loading

0 comments on commit c7cd6bf

Please sign in to comment.