From f26501e6786f8ec1ee99c70c2b2d5e0d7687730b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 4 Jun 2016 02:26:07 -0400 Subject: bump libvt100 for a bug fix, and add tests for it --- libvt100 | 2 +- tests/data/weechat.typescript | 35 +++++++++++++++++++++++++++++++++ tests/split-escapes.rs | 45 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/data/weechat.typescript create mode 100644 tests/split-escapes.rs diff --git a/libvt100 b/libvt100 index 8adbc77..f340bd2 160000 --- a/libvt100 +++ b/libvt100 @@ -1 +1 @@ -Subproject commit 8adbc77bbde64b1312a5ede8b8c8febde563b574 +Subproject commit f340bd2bb7b9872948aab33124814a67093f0368 diff --git a/tests/data/weechat.typescript b/tests/data/weechat.typescript new file mode 100644 index 0000000..1082b1c --- /dev/null +++ b/tests/data/weechat.typescript @@ -0,0 +1,35 @@ +Script started on Sat 04 Jun 2016 01:31:36 AM EDT +Xander: Y'know, this might go a lot faster if you femmes actually picked up a shovel, too. +Giles: Hear, hear. +Buffy: Sorry, but I'm an old fashioned gal. I was raised to believe that men dig up the corpses and the women have the babies. + --Episode #2.2, "Some Assembly Required" +% ]0;doy@lance:~  (~) --------------------------------------------------------------------------------------------------------------------------------------------------------- {--<=======} doy@lance [01:31:36] +000 $(B [?2004hcchchachat[?2004l +[?1049h(B>[?25h[?1000l[?1002l[?1006l[?1005l]2;chat:0:WeeChat 1.5 - "WeeChat 1.5" [?25l 1(B#tw(B│(BBitlBee groupchat: "twitter/timeline". Please keep in mind that root-commands won't work here. Have fun! (B 2(B##c(B│(B │(B-- Chatters -----(B 3(B##c(B│(B01:12:56 <(Bgenehack(B>(B [(B70](B RT @wkamaubell: “I ain’t got no quarrel with them Viet Cong. No Viet Cong ever called me nigger.” │(Bgenehack(B (B 4(B##c(B│(B01:12:56 <(Bgenehack(B>(B - Muhammad Ali https://t.co/LEOnx2objr │(B-----------------(B 5(Bbit(B│(B01:14:08 <(Bgenehack(B>(B [(B71](B RT @AndyCole84: @mma_gifs_ Slowed down its' even more insane. https://t.co/uFxovzJVAO │(B@(Bdoy + 6(B&bi(B│(B01:15:06 <(Bgenehack(B>(B [(B72](B RT @postsecret: Muhammad Ali │(B@(Broot + 7(B?Se(B│(B01:15:06 <(Bgenehack(B>(B RIP GOAT https://t.co/eQUpWkyGND │ (B__upasana__ + 8(B?Ch(B│(B01:15:39 <(Bgenehack(B>(B [(B73](B RT @PenofUmar: White America hated Ali. Then loved him. A commitment to truth and justice attracts even the haters. #MuhammedAli #RIPAli │ (B_jak + 9(B?ge(B│(B01:16:11 <(Bgenehack(B>(B [(B74](B RT @owillis: lets also remember muhammad ali wasn't some apolitical santa claus figure either. https://t.co/tZyppQ3F0E │ (B_vhf +10(B?sa(B│(B │ (BAdrianFeniXx +11(B?th(B│(B01:16:27 <(Bgenehack(B>(B [(B75](B RT @BarefootBoomer: Hopefully you know at least one now. │ (Bamygdalama +12(B##c(B│(B01:16:27 <(Bgenehack(B>(B He was the greatest. │ (Bantifuchs +13(B##i(B│(B01:16:27 <(Bgenehack(B>(B #MuhammadAli https://t.co/xnuOgAnotJ │ (Banyharder +14(B?Pl(B│(B01:16:31 <(Bhypatiadotca(B>(B [(B76](B "Cassius Clay" was what my dad's childhood ski racing rivals called him, which I always thought was a gr8 lesson in saying "fuck the │ (Baphyr + │(B haters" │ (Bashedryden + │(B01:17:08 <(Bgenehack(B>(B [(B77](B RT @ChrisKorman: It's hard not to feel like maybe we lost Ali at precisely the moment when this country needs what he stood for more than │ (Bavibryant + │(B it ever has. │ (Bawwaiid + │(B01:18:33 <(Bgenehack(B>(B [(B78](B Jesus Fucking Christ. [@BuzzFeedAndrew: https://t.co/U0UJGT0BnF ] │ (Bb0rk + │(B01:19:27 <(Bgenehack(B>(B [(B79](B RT @brianwisti: Never been one for sports. Really not boxing. But since age 7 I knew who Ali was, and that he was a man to be respected. │ (Bballingt + │(B01:19:53 <(Bgenehack(B>(B [(B7a](B RT @BaltoSpectator: Legends live forever... #MyHeroes #MuhammadAli #MalcolmX https://t.co/ARfs2cqNgf │ (Bbrainwane + │(B01:20:22 <(Bgenehack(B>(B [(B7b](B RT @BeeJanay: Muhammad Ali, the black Muslim athlete to tell America "no." 💪🏾 https://t.co/hIbAsVrFHy │ (Bchimeracoder + │(B01:21:50 <(Bgenehack(B>(B [(B7c](B RT @JamesPMorrison: https://t.co/DN8Ca1A5nI │ (Bcodexjourneys + │(B01:22:14 <(Bgenehack(B>(B [(B7d](B RT @tcarmody: Ali shows what's still true. Want to infuriate the most people? Refuse to pretend that their unfair world is fair, just │ (Bcollision + │(B because they say so. │ (Bcomonad + │(B01:22:44 <(Bgenehack(B>(B [(B7e](B RT @PaddydubPatrick: Let this sink in https://t.co/S8DhtV5onI │ (Bconnor_osborn + │(B01:26:58 <(Bgenehack(B>(B [(B7f](B Drinking a Sticky Hands by @block15brewing @ GenehackHomestead — https://t.co/fyF9cDKv1O #photo │ (Bcrawl_offtopic + │(B01:28:31 <(Bgenehack(B>(B [(B80](B RT @saladinahmed: pro-Black. │ (Bcrawlcode + │(B01:28:31 <(Bgenehack(B>(B anti-war. │ (BDanielleSucher + │(B01:28:31 <(Bgenehack(B>(B defiantly Muslim. │ (Bdewche_man + │(B01:28:31 <(Bgenehack(B>(B │ (Bdylan_hardison + │(B01:28:31 <(Bgenehack(B>(B don't let them sell you any other story. │ (Beronarn ++(B │[(B01:31](B [(Birc/(Bbitlbee](B 1(B:#twitter_doyster(B{(B105}(B (B │(B[(B@(Bdoy(B((BRs)](B + │-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------(B │(B01:31:12 4(B <Jorgrell(B> mahalanobis (L16 TrMo) reached level 4 of the Swamp. (Swamp:4)  │(B01:31:29 4(B <Rotatell(B> Nanomashoes (L27 MiFi) killed Dispater. (Dis:7)  │(B01:31:35 4(B <Rotatell(B> Nanomashoes (L27 MiFi) found an iron rune of Zot. (Dis:7)  diff --git a/tests/split-escapes.rs b/tests/split-escapes.rs new file mode 100644 index 0000000..bd7d20a --- /dev/null +++ b/tests/split-escapes.rs @@ -0,0 +1,45 @@ +extern crate vt100; + +use std::io::prelude::*; + +fn get_file_contents(name: &str) -> Vec { + let mut file = std::fs::File::open(name).unwrap(); + let mut buf = vec![]; + file.read_to_end(&mut buf).unwrap(); + buf +} + +fn write_to_screen(chunks: &mut Vec>) -> String { + let mut screen = vt100::Screen::new(37, 193); + let mut full_chunk = vec![]; + for chunk in chunks.iter_mut() { + full_chunk.append(chunk); + let bytes = screen.process(&mut full_chunk); + full_chunk = full_chunk.split_off(bytes as usize); + } + assert_eq!(full_chunk.len(), 0); + screen.window_contents(0, 0, 36, 192) +} + +fn test_splits(filename: &str) { + let bytes = get_file_contents(filename); + let len = bytes.len(); + let expected = write_to_screen(&mut vec![bytes.clone()]); + for i in 0..(len - 1) { + let bytes_copy = bytes.clone(); + let (start, end) = bytes_copy.split_at(i); + let mut chunks = vec![start.to_vec(), end.to_vec()]; + let got = write_to_screen(&mut chunks); + assert!( + got == expected, + "failed to render {} when split at byte {}", + filename, + i + ); + } +} + +#[test] +fn split_escapes_weechat() { + test_splits("tests/data/weechat.typescript"); +} -- cgit v1.2.3