diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-05 15:38:37 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-05 15:38:37 -0500 |
commit | 9f9c519cbaa5384e666ffa2b5e1cf4f99780ba28 (patch) | |
tree | 6f4e0b348edcfd31d795d863722be358f4b2e99a | |
parent | 2471941ad0ee28a0c27df3f007faa16ff7028fa8 (diff) | |
download | vt100-rust-9f9c519cbaa5384e666ffa2b5e1cf4f99780ba28.tar.gz vt100-rust-9f9c519cbaa5384e666ffa2b5e1cf4f99780ba28.zip |
fix erasing cells in diff
also add more comprehensive tests
32 files changed, 83 insertions, 2 deletions
@@ -158,7 +158,7 @@ impl Row { contents.extend(if cell.has_contents() { cell.contents().as_bytes() } else { - b"\x1b[X" + b"\x1b[X\x1b[C" }); } } diff --git a/tests/data/crawl/crawl1 b/tests/data/crawl/crawl1 new file mode 100644 index 0000000..48328c5 --- /dev/null +++ b/tests/data/crawl/crawl1 @@ -0,0 +1,8 @@ +[2J[1;1H
+Player: doy
+Game: Crawl (0.18)
+Server: Public Crawl server: crawl.akrasiac.org
+Filename: 2016-08-15.01:36:02.ttyrec
+Time: (1471224962) Sun Aug 14 21:36:02 2016 +
+[2J
\ No newline at end of file diff --git a/tests/data/crawl/crawl10 b/tests/data/crawl/crawl10 new file mode 100644 index 0000000..bb80abe --- /dev/null +++ b/tests/data/crawl/crawl10 @@ -0,0 +1 @@ +[39;49m[37m[40m[H[2J[33m[40mWelcome, doy.[1m Please select your species.[3;4H[m[37m[44ma - Human[3;29H[37m[40mj - Troll[3;54Hs - Vine Stalker[4;4Hb - High Elf[4;29Hk - Naga[4;54Ht - Demigod[5;4Hc - Deep Elf[5;29Hl - Centaur[5;54Hu - Demonspawn[6;4Hd - Deep Dwarf[6;29Hm - Merfolk[6;54Hv - Mummy[7;4He - Hill Orc[7;29Hn - Minotaur[7;54Hw - Ghoul[8;4Hf - Halfling[8;29Ho - Tengu[8;54Hx - Vampire[9;4Hg - Kobold[9;29Hp - Draconian[9;54Hy - Felid[10;4Hh - Spriggan[10;29Hq - Gargoyle[10;54Hz - Octopode[11;4Hi - Ogre[11;29Hr - Formicid[16;4H[1mHumans advance quickly in levels and have equal abilities in most skills.[m[30m[40m [17;4H [18;4H [20;4H[33m[40m+ - Viable species[29G* - Random species[21;4H# - Viable character[m[39;49m[37m[40m [33m[40m! - Random character[22;4H% - List aptitudes[m[39;49m[37m[40m [33m[40mSpace - Pick background first[23;4H? - Help[23;27HTab - Human Necromancer[3;13H[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl11 b/tests/data/crawl/crawl11 new file mode 100644 index 0000000..c4b1bfc --- /dev/null +++ b/tests/data/crawl/crawl11 @@ -0,0 +1 @@ +[39;49m
[24d[K[24;1H[?25h[2J[?47l8
>
\ No newline at end of file diff --git a/tests/data/crawl/crawl12 b/tests/data/crawl/crawl12 new file mode 100644 index 0000000..115441f --- /dev/null +++ b/tests/data/crawl/crawl12 @@ -0,0 +1 @@ +[?1051l[?1052l[?1060l[?1061l
\ No newline at end of file diff --git a/tests/data/crawl/crawl13 b/tests/data/crawl/crawl13 new file mode 100644 index 0000000..19ac3d6 --- /dev/null +++ b/tests/data/crawl/crawl13 @@ -0,0 +1 @@ +[?1051l[?1052l[?1060l[?1061h
\ No newline at end of file diff --git a/tests/data/crawl/crawl14 b/tests/data/crawl/crawl14 new file mode 100644 index 0000000..efa8c19 --- /dev/null +++ b/tests/data/crawl/crawl14 @@ -0,0 +1 @@ +=
\ No newline at end of file diff --git a/tests/data/crawl/crawl15 b/tests/data/crawl/crawl15 new file mode 100644 index 0000000..efa8c19 --- /dev/null +++ b/tests/data/crawl/crawl15 @@ -0,0 +1 @@ +=
\ No newline at end of file diff --git a/tests/data/crawl/crawl16 b/tests/data/crawl/crawl16 new file mode 100644 index 0000000..ab58084 --- /dev/null +++ b/tests/data/crawl/crawl16 @@ -0,0 +1 @@ +7[?47h[1;24r[?25l
\ No newline at end of file diff --git a/tests/data/crawl/crawl17 b/tests/data/crawl/crawl17 new file mode 100644 index 0000000..9ba9231 --- /dev/null +++ b/tests/data/crawl/crawl17 @@ -0,0 +1 @@ +[39;49m[m[4l[39;49m[37m[40m[H[2J[33m[40mWelcome, doy.[1m Please select your species.[3;4H[m[37m[44ma - Human[3;29H[37m[40mj - Troll[3;54Hs - Vine Stalker[4;4Hb - High Elf[4;29Hk - Naga[4;54Ht - Demigod[5;4Hc - Deep Elf[5;29Hl - Centaur[5;54Hu - Demonspawn[6;4Hd - Deep Dwarf[6;29Hm - Merfolk[6;54Hv - Mummy[7;4He - Hill Orc[7;29Hn - Minotaur[7;54Hw - Ghoul[8;4Hf - Halfling[8;29Ho - Tengu[8;54Hx - Vampire[9;4Hg - Kobold[9;29Hp - Draconian[9;54Hy - Felid[10;4Hh - Spriggan[10;29Hq - Gargoyle[10;54Hz - Octopode[11;4Hi - Ogre[11;29Hr - Formicid[16;4H[1mHumans advance quickly in levels and have equal abilities in most skills.[m[30m[40m [17;4H [18;4H [20;4H[33m[40m+ - Viable species[29G* - Random species[21;4H# - Viable character[m[39;49m[37m[40m [33m[40m! - Random character[22;4H% - List aptitudes[m[39;49m[37m[40m [33m[40mSpace - Pick background first[23;4H? - Help[23;27HTab - Human Necromancer[3;13H[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl18 b/tests/data/crawl/crawl18 new file mode 100644 index 0000000..c97699c --- /dev/null +++ b/tests/data/crawl/crawl18 @@ -0,0 +1 @@ +[2J
\ No newline at end of file diff --git a/tests/data/crawl/crawl19 b/tests/data/crawl/crawl19 new file mode 100644 index 0000000..26fad4e --- /dev/null +++ b/tests/data/crawl/crawl19 @@ -0,0 +1 @@ +[39;49m[37m[40m[H[2J[1;38H[33m[40m[1mdoy the Grave Robber [2;38HHuman[3;38H[m[33m[40mHealth: [37m[40m13/13 [32m[40m[1m========================[4;38H[m[33m[40mMagic: [37m[40m3/3[56G[34m[40m[1m========================[5;38H[m[33m[40mAC:[m[39;49m[37m[40m [37m[40m 2[5;56H[33m[40mStr:[m[39;49m[37m[40m [37m[40m8[6;38H[33m[40mEV:[m[39;49m[37m[40m [37m[40m12[6;56H[33m[40mInt:[m[39;49m[37m[40m [37m[40m15[7;38H[33m[40mSH:[m[39;49m[37m[40m [37m[40m 0[7;56H[33m[40mDex:[m[39;49m[37m[40m [37m[40m13[8;38H[33m[40mXL: [37m[40m 1 [33m[40mNext: [37m[40m 0% [m[39;49m[37m[40m [33m[40mPlace: [37m[40mDungeon:1[9;38H[33m[40mGold:[m[39;49m[37m[40m [37m[40m0[9;56H[33m[40mTime:[m[39;49m[37m[40m [37m[40m0.0 (0.0)[10;38H[33m[40m-) [37m[40mNothing wielded[11;38H[33m[40m-) [37m[40mNothing quivered[79G[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl2 b/tests/data/crawl/crawl2 new file mode 100644 index 0000000..9d99541 --- /dev/null +++ b/tests/data/crawl/crawl2 @@ -0,0 +1 @@ +[2J[H
\ No newline at end of file diff --git a/tests/data/crawl/crawl20 b/tests/data/crawl/crawl20 new file mode 100644 index 0000000..39c81b8 --- /dev/null +++ b/tests/data/crawl/crawl20 @@ -0,0 +1 @@ +[1;33H[30m[40m[1m[1K[2;9H[1K[3d[1K[4d[1K[5d[1K[6d[1K[7d[1K[8d[1K [16G[m[33m[40m####[9;9H[30m[40m[1m[1K [16G[m[33m[40m#[37m[40m[7mp[m[37m[40m.[33m[40m#[10;9H[30m[40m[1m[1K [16G[m[33m[40m##[37m[40m.......[11;9H[30m[40m[1m[1K [11;18H[m[37m[40m.......[12;9H[30m[40m[1m[1K [12;18H[m[33m[40m#[37m[40m...[36m[40m([37m[40m..[13;9H[30m[40m[1m[1K [13;19H[m[37m[40m..[33m[40m#[37m[40m.[33m[40m#[37m[40m.[14;9H[30m[40m[1m[1K [14;19H[m[37m[40m.[33m[40m#[37m[40m. [33m[40m#[15;9H[30m[40m[1m[1K [15;20H[m[33m[40m###[16;9H[30m[40m[1m[1K[17d[1K[17;34H[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl21 b/tests/data/crawl/crawl21 new file mode 100644 index 0000000..16cb040 --- /dev/null +++ b/tests/data/crawl/crawl21 @@ -0,0 +1 @@ +
[20d[37m[40m[J[18d [33m[40m[1mWelcome, doy the Human Necromancer.[19;2HWill you prevail where others failed? Will you find the Orb of Zot?[9;50H[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl22 b/tests/data/crawl/crawl22 new file mode 100644 index 0000000..d84b899 --- /dev/null +++ b/tests/data/crawl/crawl22 @@ -0,0 +1 @@ +[17;34H
\ No newline at end of file diff --git a/tests/data/crawl/crawl23 b/tests/data/crawl/crawl23 new file mode 100644 index 0000000..d53987d --- /dev/null +++ b/tests/data/crawl/crawl23 @@ -0,0 +1 @@ +[20;2H[37m[40mPress [1m?[m[37m[40m for a list of commands and other information.
[21d Found 10 sling bullets.[9;50H[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl24 b/tests/data/crawl/crawl24 new file mode 100644 index 0000000..d84b899 --- /dev/null +++ b/tests/data/crawl/crawl24 @@ -0,0 +1 @@ +[17;34H
\ No newline at end of file diff --git a/tests/data/crawl/crawl25 b/tests/data/crawl/crawl25 new file mode 100644 index 0000000..bb5d42e --- /dev/null +++ b/tests/data/crawl/crawl25 @@ -0,0 +1 @@ +
[22d[30m[40m[1m_[m[37m[40mFound a staircase leading out of the dungeon.[9;17H[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl26 b/tests/data/crawl/crawl26 new file mode 100644 index 0000000..765cd31 --- /dev/null +++ b/tests/data/crawl/crawl26 @@ -0,0 +1 @@ +[9;50H
[22d[37m[40m_[9;50H[m[39;49m[37m[40m[8;16H[30m[40m[1m###[m[33m[40m###[9;16H[30m[40m[1m#[34m[40m<[30m[40m.[m[33m[40m#[37m[40m[7mp[m[33m[40m#[30m[40m[1m###.#[9;62H[m[37m[40m3.0 (3[10;16H[30m[40m[1m#[10;25H[m[37m[40m..[33m[40m#[11;17H#[25G[37m[40m...[12;17H[33m[40m#[25G[37m[40m...[13;18H.[25G..[33m[40m#[14;17H>#[37m[40m.[33m[40m#[37m[40m.[33m[40m##[37m[40m..[33m[40m#[37m[40m.[15;17H[33m[40m###[30m[40m[1m#[m[33m[40m#[30m[40m[1m#[m[37m[40m [33m[40m##[17;34H[m[39;49m[37m[40m
[23d[30m[40m[1m_[m[37m[40mFound an escape hatch in the floor.[9;20H[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl27 b/tests/data/crawl/crawl27 new file mode 100644 index 0000000..d0906bf --- /dev/null +++ b/tests/data/crawl/crawl27 @@ -0,0 +1 @@ +[9;50H
[23d[37m[40m_[9;50H[m[39;49m[37m[40m
[24d[37m[40m_There is an escape hatch in the floor here.[9;50H[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl28 b/tests/data/crawl/crawl28 new file mode 100644 index 0000000..20add35 --- /dev/null +++ b/tests/data/crawl/crawl28 @@ -0,0 +1 @@ +
[18d[M[24d[37m[40m_You see here 10 sling bullets.[9;50H[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl29 b/tests/data/crawl/crawl29 new file mode 100644 index 0000000..499d593 --- /dev/null +++ b/tests/data/crawl/crawl29 @@ -0,0 +1 @@ +[1;5H[37m[40m [30m[40m[1m##...#.#...#.#[m[37m[40m [2;5H [30m[40m[1m#[m[33m[40m>[30m[40m[1m#.#.##..#[m[37m[40m..[33m[40m#[3;5H[37m[40m [30m[40m[1m###########[m[33m[40m#[37m[40m.[33m[40m#[4;5H[37m[40m [4;22H[33m[40m#[37m[40m.[33m[40m#[30m[40m[1m#######[5;5H[m[37m[40m [5;22H[33m[40m#[37m[40m..[30m[40m[1m.......[6;5H[m[37m[40m [6;22H[33m[40m#[37m[40m.[33m[40m#[30m[40m[1m#######[7;5H[m[37m[40m [16G[33m[40m#######[37m[40m.[33m[40m#######[30m[40m[1m#[8;5H[m[37m[40m [16G...............[30m[40m[1m.[9;5H[m[37m[40m [17G[30m[40m[1m#####[m[33m[40m#[37m[40m[7mp[m[33m[40m#[30m[40m[1m#######[9;62H[m[37m[40m25.0 (22.0)[10;5H [16G..[24G[33m[40m#[37m[40m [11;5H [16G[1m>[m[37m[40m.[25G [12;5H [16G........[33m[40m##[37m[40m [13;5H [16G[33m[40m#####[37m[40m.[33m[40m#[37m[40m.[33m[40m#[37m[40m [14;5H [17G [33m[40m#[37m[40m...[33m[40m#[37m[40m [15;5H [17G [33m[40m###[37m[40m.[33m[40m#[37m[40m [16;5H [16;22H[33m[40m#[37m[40m.[33m[40m#[17;5H[37m[40m [17;34H[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl3 b/tests/data/crawl/crawl3 new file mode 100644 index 0000000..19ac3d6 --- /dev/null +++ b/tests/data/crawl/crawl3 @@ -0,0 +1 @@ +[?1051l[?1052l[?1060l[?1061h
\ No newline at end of file diff --git a/tests/data/crawl/crawl30 b/tests/data/crawl/crawl30 new file mode 100644 index 0000000..b8bd936 --- /dev/null +++ b/tests/data/crawl/crawl30 @@ -0,0 +1 @@ +
[18d[M[24d[30m[40m[1m_[m[37m[40mFound a stone staircase leading down.[9;23H[m[39;49m[37m[40m
\ No newline at end of file diff --git a/tests/data/crawl/crawl4 b/tests/data/crawl/crawl4 new file mode 100644 index 0000000..e4a08bc --- /dev/null +++ b/tests/data/crawl/crawl4 @@ -0,0 +1 @@ +(B)07[?47h[1;24r[m[4l=
\ No newline at end of file diff --git a/tests/data/crawl/crawl5 b/tests/data/crawl/crawl5 new file mode 100644 index 0000000..a4e3d21 --- /dev/null +++ b/tests/data/crawl/crawl5 @@ -0,0 +1 @@ +[39;49m[39;49m[37m[40m[H[2J
\ No newline at end of file diff --git a/tests/data/crawl/crawl6 b/tests/data/crawl/crawl6 new file mode 100644 index 0000000..4f9e18b --- /dev/null +++ b/tests/data/crawl/crawl6 @@ -0,0 +1 @@ +[?25l
\ No newline at end of file diff --git a/tests/data/crawl/crawl7 b/tests/data/crawl/crawl7 new file mode 100644 index 0000000..c97699c --- /dev/null +++ b/tests/data/crawl/crawl7 @@ -0,0 +1 @@ +[2J
\ No newline at end of file diff --git a/tests/data/crawl/crawl8 b/tests/data/crawl/crawl8 new file mode 100644 index 0000000..c97699c --- /dev/null +++ b/tests/data/crawl/crawl8 @@ -0,0 +1 @@ +[2J
\ No newline at end of file diff --git a/tests/data/crawl/crawl9 b/tests/data/crawl/crawl9 new file mode 100644 index 0000000..c97699c --- /dev/null +++ b/tests/data/crawl/crawl9 @@ -0,0 +1 @@ +[2J
\ No newline at end of file diff --git a/tests/window_contents.rs b/tests/window_contents.rs index 723e0d8..32921b8 100644 --- a/tests/window_contents.rs +++ b/tests/window_contents.rs @@ -1,3 +1,5 @@ +use std::io::Read as _; + #[test] fn formatted() { let mut parser = vt100::Parser::new(24, 80); @@ -339,7 +341,7 @@ fn diff() { parser.process(b"\x1b[1;8H\x1b[X"); let screen5 = parser.screen().clone(); - assert_eq!(screen5.contents_diff(&screen4), b"\x1b[1;8H\x1b[X"); + assert_eq!(screen5.contents_diff(&screen4), b"\x1b[1;8H\x1b[X\x1b[C"); compare_diff( &screen4, &screen5, @@ -347,6 +349,34 @@ fn diff() { ); } +#[test] +fn diff_crawl() { + let mut parser = vt100::Parser::new(24, 80); + let screens: Vec<_> = (1..=30) + .map(|i| { + let mut file = + std::fs::File::open(format!("tests/data/crawl/crawl{}", i)) + .unwrap(); + let mut frame = vec![]; + file.read_to_end(&mut frame).unwrap(); + parser.process(&frame); + (frame.clone(), parser.screen().clone()) + }) + .collect(); + + let mut all_frames: Vec<u8> = vec![]; + for two_screens in screens.windows(2) { + eprintln!("loop"); + match two_screens { + [(prev_frame, prev_screen), (_, screen)] => { + all_frames.extend(prev_frame); + compare_diff(prev_screen, screen, &all_frames); + } + _ => unreachable!(), + } + } +} + fn compare_formatted(screen: &vt100::Screen) { let (rows, cols) = screen.size(); let mut parser = vt100::Parser::new(rows, cols); @@ -370,6 +400,20 @@ fn compare_diff( compare_cells(parser.screen(), &prev_screen); parser.process(&screen.contents_diff(prev_screen)); + if parser.screen().contents_formatted() != screen.contents_formatted() { + use std::io::Write as _; + let mut prev_screen_file = + std::fs::File::create("prev_screen").unwrap(); + prev_screen_file + .write_all(&prev_screen.contents_formatted()) + .unwrap(); + let mut screen_file = std::fs::File::create("screen").unwrap(); + screen_file.write_all(&screen.contents_formatted()).unwrap(); + let mut diff_file = std::fs::File::create("diff").unwrap(); + diff_file + .write_all(&screen.contents_diff(prev_screen)) + .unwrap(); + } assert_eq!( parser.screen().contents_formatted(), screen.contents_formatted() |