diff options
m--------- | libvt100 | 0 | ||||
-rw-r--r-- | tests/data/weechat.typescript | 35 | ||||
-rw-r--r-- | tests/split-escapes.rs | 45 |
3 files changed, 80 insertions, 0 deletions
diff --git a/libvt100 b/libvt100 -Subproject 8adbc77bbde64b1312a5ede8b8c8febde563b57 +Subproject f340bd2bb7b9872948aab33124814a67093f036 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"
+[1m[7m%[27m[1m[0m
]0;doy@lance:~
[0m[27m[24m[J [31m([38;5;8m~[38;5;8m[31m) [38;5;8m--------------------------------------------------------------------------------------------------------------------------------------------------------- [31m{[38;5;8m--<=======[31m} [38;5;12mdoy[38;5;8m@[31mlance [31m[[38;5;8m01:31:36[31m]
+[38;5;8m000 [38;5;12m$[m(B [K[?2004h[4m[34mc[24m[39m[39m[4mc[4mh[24m[4mc[4mh[4ma[24m[24m[32mc[24m[32mh[24m[32ma[32mt[39m[?2004l
+[?1049h[m(B>[H[2J[?25h[?1000l[?1002l[?1006l[?1005l]2;chat:0:WeeChat 1.5 - "WeeChat 1.5" [?25l[1;1H [38;5;2m[1m1[m(B[38;5;6m[1m#tw[m(B[38;5;4m│[m(B[48;5;4mBitlBee groupchat: "twitter/timeline". Please keep in mind that root-commands won't work here. Have fun! [2;1H[m(B [38;5;2m[1m2[m(B[38;5;0m[1m##c[m(B[38;5;4m│[m(B <buzzfeed.com/katiejmbaker/h…> [38;5;4m│[m(B[38;5;1m-- Chatters -----[3;1H[m(B [38;5;2m[1m3[m(B[38;5;7m[1m##c[m(B[38;5;4m│[m(B01:12:56 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B70[1m][m(B RT @wkamaubell: “I ain’t got no quarrel with them Viet Cong. No Viet Cong ever called me nigger.” [38;5;4m│[m(B[38;5;3m[1mgenehack[m(B[38;5;3m [4;1H[m(B [38;5;2m[1m4[m(B[38;5;7m[1m##c[m(B[38;5;4m│[m(B01:12:56 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B - Muhammad Ali https://t.co/LEOnx2objr <pic.twitter.com/LEOnx2objr> [38;5;4m│[m(B[38;5;1m-----------------[5;1H[m(B [38;5;2m[1m5[m(B[38;5;0m[1mbit[m(B[38;5;4m│[m(B01:14:08 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B71[1m][m(B RT @AndyCole84: @mma_gifs_ Slowed down its' even more insane. https://t.co/uFxovzJVAO <pic.twitter.com/uFxovzJVAO> [38;5;4m│[m(B[38;5;2m[1m@[m(Bdoy[K
+ [38;5;2m[1m6[m(B[38;5;0m[1m&bi[m(B[38;5;4m│[m(B01:15:06 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B72[1m][m(B RT @postsecret: Muhammad Ali [38;5;4m│[m(B[38;5;2m[1m@[m(Broot[K
+ [38;5;2m[1m7[m(B[38;5;0m[1m?Se[m(B[38;5;4m│[m(B01:15:06 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B RIP GOAT https://t.co/eQUpWkyGND <pic.twitter.com/eQUpWkyGND> [38;5;4m│[1m [m(B__upasana__[K
+ [38;5;2m[1m8[m(B[38;5;0m[1m?Ch[m(B[38;5;4m│[m(B01:15:39 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B73[1m][m(B RT @PenofUmar: White America hated Ali. Then loved him. A commitment to truth and justice attracts even the haters. #MuhammedAli #RIPAli [38;5;4m│[1m [m(B_jak[K
+ [38;5;2m[1m9[m(B[38;5;0m[1m?ge[m(B[38;5;4m│[m(B01:16:11 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B74[1m][m(B RT @owillis: lets also remember muhammad ali wasn't some apolitical santa claus figure either. https://t.co/tZyppQ3F0E [38;5;4m│[1m [m(B_vhf[K
+[38;5;2m[1m10[m(B[38;5;0m[1m?sa[m(B[38;5;4m│[m(B <pic.twitter.com/tZyppQ3F0E> [38;5;4m│[1m [m(BAdrianFeniXx[K
+[38;5;2m[1m11[m(B[38;5;0m[1m?th[m(B[38;5;4m│[m(B01:16:27 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B75[1m][m(B RT @BarefootBoomer: Hopefully you know at least one now. [38;5;4m│[1m [m(Bamygdalama[K
+[38;5;2m[1m12[m(B[38;5;0m[1m##c[m(B[38;5;4m│[m(B01:16:27 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B He was the greatest. [38;5;4m│[1m [m(Bantifuchs[K
+[38;5;2m[1m13[m(B[38;5;0m[1m##i[m(B[38;5;4m│[m(B01:16:27 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B #MuhammadAli https://t.co/xnuOgAnotJ <twitter.com/realdonaldtrum…> [38;5;4m│[1m [m(Banyharder[K
+[38;5;2m[1m14[m(B[38;5;0m[1m?Pl[m(B[38;5;4m│[m(B01:16:31 [38;5;0m<[m(B[38;5;1mhypatiadotca[m(B[38;5;0m>[m(B [1m[[m(B76[1m][m(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 [38;5;4m│[1m [m(Baphyr[K
+ [38;5;4m│[m(B haters" [38;5;4m│[1m [m(Bashedryden[K
+ [38;5;4m│[m(B01:17:08 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B77[1m][m(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 [38;5;4m│[1m [m(Bavibryant[K
+ [38;5;4m│[m(B it ever has. [38;5;4m│[1m [m(Bawwaiid[K
+ [38;5;4m│[m(B01:18:33 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B78[1m][m(B Jesus Fucking Christ. <https://t.co/xFbaAmiZYz> [@BuzzFeedAndrew: https://t.co/U0UJGT0BnF <pic.twitter.com/U0UJGT0BnF>] [38;5;4m│[1m [m(Bb0rk[K
+ [38;5;4m│[m(B01:19:27 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B79[1m][m(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. [38;5;4m│[1m [m(Bballingt[K
+ [38;5;4m│[m(B01:19:53 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B7a[1m][m(B RT @BaltoSpectator: Legends live forever... #MyHeroes #MuhammadAli #MalcolmX https://t.co/ARfs2cqNgf <pic.twitter.com/ARfs2cqNgf> [38;5;4m│[1m [m(Bbrainwane[K
+ [38;5;4m│[m(B01:20:22 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B7b[1m][m(B RT @BeeJanay: Muhammad Ali, the black Muslim athlete to tell America "no." 💪🏾 https://t.co/hIbAsVrFHy <pic.twitter.com/hIbAsVrFHy> [38;5;4m│[1m [m(Bchimeracoder[K
+ [38;5;4m│[m(B01:21:50 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B7c[1m][m(B RT @JamesPMorrison: https://t.co/DN8Ca1A5nI <pic.twitter.com/DN8Ca1A5nI> [38;5;4m│[1m [m(Bcodexjourneys[K
+ [38;5;4m│[m(B01:22:14 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B7d[1m][m(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 [38;5;4m│[1m [m(Bcollision[K
+ [38;5;4m│[m(B because they say so. [38;5;4m│[1m [m(Bcomonad[K
+ [38;5;4m│[m(B01:22:44 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B7e[1m][m(B RT @PaddydubPatrick: Let this sink in https://t.co/S8DhtV5onI <pic.twitter.com/S8DhtV5onI> [38;5;4m│[1m [m(Bconnor_osborn[K
+ [38;5;4m│[m(B01:26:58 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B7f[1m][m(B Drinking a Sticky Hands by @block15brewing @ GenehackHomestead — https://t.co/fyF9cDKv1O <untp.beer/s/c319408384> #photo [38;5;4m│[1m [m(Bcrawl_offtopic[K
+ [38;5;4m│[m(B01:28:31 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [1m[[m(B80[1m][m(B RT @saladinahmed: pro-Black. [38;5;4m│[1m [m(Bcrawlcode[K
+ [38;5;4m│[m(B01:28:31 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B anti-war. [38;5;4m│[1m [m(BDanielleSucher[K
+ [38;5;4m│[m(B01:28:31 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B defiantly Muslim. [38;5;4m│[1m [m(Bdewche_man[K
+ [38;5;4m│[m(B01:28:31 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B [38;5;4m│[1m [m(Bdylan_hardison[K
+ [38;5;4m│[m(B01:28:31 [38;5;0m<[m(B[38;5;1mgenehack[m(B[38;5;0m>[m(B don't let them sell you any other story. [38;5;4m│[1m [m(Beronarn [38;5;5m[1m++[32;1H[m(B [38;5;4m│[38;5;6m[48;5;4m[[m(B[48;5;4m01:31[38;5;6m][m(B[48;5;4m [38;5;6m[[m(B[48;5;4mirc[38;5;6m/[m(B[48;5;4mbitlbee[38;5;6m][m(B[48;5;4m [38;5;3m[1m1[m(B[38;5;6m[48;5;4m:[38;5;2m[1m#twitter_doyster[m(B[38;5;6m[48;5;4m{[m(B[48;5;4m105[38;5;6m}[m(B[48;5;4m [33;1H[m(B [38;5;4m│[m(B[38;5;6m[[m(B[38;5;2m[1m@[m(B[38;5;7m[1mdoy[m(B[38;5;6m([m(BRs[38;5;6m)][m(B[K
+ [38;5;4m│-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------[35;1H[m(B [38;5;4m│[m(B01:31:12 [38;5;3m4[m(B <[38;5;1mJorgrell[m(B> mahalanobis (L16 TrMo) reached level 4 of the Swamp. (Swamp:4) [36;1H [38;5;4m│[m(B01:31:29 [38;5;3m4[m(B <[38;5;3mRotatell[m(B> Nanomashoes (L27 MiFi) killed Dispater. (Dis:7) [37;1H [38;5;4m│[m(B01:31:35 [38;5;3m4[m(B <[38;5;3mRotatell[m(B> Nanomashoes (L27 MiFi) found an iron rune of Zot. (Dis:7) [K[1;37r[H[33;18H 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<u8> { + 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<Vec<u8>>) -> 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"); +} |