diff --git a/src/asciicast.rs b/src/asciicast.rs index 97516e5..e516360 100644 --- a/src/asciicast.rs +++ b/src/asciicast.rs @@ -203,7 +203,8 @@ mod tests { #[test] fn open_v2_minimal() { let Asciicast { header, events } = - super::open_from_path("tests/casts/minimal.cast").unwrap(); + super::open_from_path("tests/casts/minimal-v2.cast").unwrap(); + let events = events.collect::>>().unwrap(); assert_eq!((header.term_cols, header.term_rows), (100, 50)); @@ -215,7 +216,8 @@ mod tests { #[test] fn open_v2_full() { - let Asciicast { header, events } = super::open_from_path("tests/casts/full.cast").unwrap(); + let Asciicast { header, events } = + super::open_from_path("tests/casts/full-v2.cast").unwrap(); let events = events.take(5).collect::>>().unwrap(); let theme = header.term_theme.unwrap(); @@ -235,6 +237,7 @@ mod tests { assert!(matches!(events[2].data, EventData::Input(ref s) if s == "\n")); assert_eq!(events[3].time, 5_600_001); + assert!( matches!(events[3].data, EventData::Resize(ref cols, ref rows) if *cols == 80 && *rows == 40) ); @@ -243,6 +246,52 @@ mod tests { assert!(matches!(events[4].data, EventData::Output(ref s) if s == "\r\n")); } + #[test] + fn open_v3_minimal() { + let Asciicast { header, events } = + super::open_from_path("tests/casts/minimal-v3.cast").unwrap(); + + let events = events.collect::>>().unwrap(); + + assert_eq!((header.term_cols, header.term_rows), (100, 50)); + assert!(header.term_theme.is_none()); + + assert_eq!(events[0].time, 1230000); + assert!(matches!(events[0].data, EventData::Output(ref s) if s == "hello")); + } + + #[test] + fn open_v3_full() { + let Asciicast { header, events } = + super::open_from_path("tests/casts/full-v3.cast").unwrap(); + let events = events.take(5).collect::>>().unwrap(); + let theme = header.term_theme.unwrap(); + + assert_eq!((header.term_cols, header.term_rows), (100, 50)); + assert_eq!(header.timestamp, Some(1509091818)); + assert_eq!(theme.fg, RGB8::new(0, 0, 0)); + assert_eq!(theme.bg, RGB8::new(0xff, 0xff, 0xff)); + assert_eq!(theme.palette[0], RGB8::new(0x24, 0x1f, 0x31)); + + assert_eq!(events[0].time, 1); + assert!(matches!(events[0].data, EventData::Output(ref s) if s == "ż")); + + assert_eq!(events[1].time, 1_000_001); + assert!(matches!(events[1].data, EventData::Output(ref s) if s == "ółć")); + + assert_eq!(events[2].time, 1_300_001); + assert!(matches!(events[2].data, EventData::Input(ref s) if s == "\n")); + + assert_eq!(events[3].time, 2_900_002); + + assert!( + matches!(events[3].data, EventData::Resize(ref cols, ref rows) if *cols == 80 && *rows == 40) + ); + + assert_eq!(events[4].time, 13_400_002); + assert!(matches!(events[4].data, EventData::Output(ref s) if s == "\r\n")); + } + #[test] fn encoder() { let mut data = Vec::new(); diff --git a/tests/casts/full.cast b/tests/casts/full-v2.cast similarity index 100% rename from tests/casts/full.cast rename to tests/casts/full-v2.cast diff --git a/tests/casts/full-v3.cast b/tests/casts/full-v3.cast new file mode 100644 index 0000000..30df3b0 --- /dev/null +++ b/tests/casts/full-v3.cast @@ -0,0 +1,6 @@ +{"version":3,"term":{"cols":100,"rows":50,"theme":{"fg":"#000000","bg":"#ffffff","palette":"#241f31:#c01c28:#2ec27e:#f5c211:#1e78e4:#9841bb:#0ab9dc:#c0bfbc:#5e5c64:#ed333b:#57e389:#f8e45c:#51a1ff:#c061cb:#4fd2fd:#f6f5f4"}},"timestamp": 1509091818,"command":"/bin/bash","env":{"TERM":"xterm-256color","SHELL":"/bin/bash"}} +[0.000001, "o", "ż"] +[1.0, "o", "ółć"] +[0.3, "i", "\n"] +[1.600001, "r", "80x40"] +[10.5, "o", "\r\n"] diff --git a/tests/casts/minimal.cast b/tests/casts/minimal-v2.cast similarity index 100% rename from tests/casts/minimal.cast rename to tests/casts/minimal-v2.cast diff --git a/tests/casts/minimal-v3.cast b/tests/casts/minimal-v3.cast new file mode 100644 index 0000000..7523424 --- /dev/null +++ b/tests/casts/minimal-v3.cast @@ -0,0 +1,2 @@ +{"version":3,"term":{"cols":100,"rows":50}} +[1.23, "o", "hello"]