From 1eb73eb5211fb43e2389857dda4f7afa15e55433 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 6 Mar 2021 02:31:28 +0100 Subject: add some basic tests to matrix module --- src/matrix.rs | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'src') diff --git a/src/matrix.rs b/src/matrix.rs index 5e9b2b7..bd83a1f 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -185,3 +185,103 @@ fn state_emoji(log: &Log) -> &'static str { None => "❓", } } + +#[cfg(test)] +mod test { + use super::*; + use std::io::Cursor; + use evtclib::Compression; + + static ARKK_LOG: &[u8] = include_bytes!("../test/logs/arkk.zevtc"); + + fn arkk_log() -> Log { + evtclib::process_stream(Cursor::new(ARKK_LOG), Compression::Zip).unwrap() + } + + #[test] + fn test_insert_log_new_category() { + let log = arkk_log(); + let old_text = "\ +Unknown +x https://dps.report.example"; + let new_text = insert_log(old_text, &log, "foobar"); + + assert_eq!("\ +Unknown +x https://dps.report.example + +99 CM (Shattered Observatory) +✅ foobar", new_text); + } + + #[test] + fn test_insert_log_appending() { + let log = arkk_log(); + let old_text = "\ +99 CM (Shattered Observatory) +x old log here"; + let new_text = insert_log(old_text, &log, "foobar"); + assert_eq!("\ +99 CM (Shattered Observatory) +x old log here +✅ foobar", new_text); + } + + #[test] + fn test_insert_log_multiple() { + let log = arkk_log(); + let old_text = "\ +100 CM (Sunqua Peak) +y some old log here + +99 CM (Shattered Observatory) +x old log here + +98 CM (Nightmare) +z raboof"; + let new_text = insert_log(old_text, &log, "foobar"); + assert_eq!("\ +100 CM (Sunqua Peak) +y some old log here + +99 CM (Shattered Observatory) +x old log here +✅ foobar + +98 CM (Nightmare) +z raboof", new_text); + } + + #[test] + fn test_htmlify_single() { + let plain = "\ +Header +Log 1 +Log 2"; + assert_eq!(htmlify(plain), "\ +Header
+Log 1
+Log 2"); + } + + #[test] + fn test_htmlify_multiple() { + let plain = "\ +Header 1 +Log 1 +Log 2 + +Header 2 +Log 3 +Log 4"; + assert_eq!(htmlify(plain), "\ +Header 1
+Log 1
+Log 2
+
+Header 2
+Log 3
+Log 4"); + } + +} -- cgit v1.2.3