diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/matrix.rs | 100 |
1 files changed, 100 insertions, 0 deletions
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), "\ +<b>Header</b><br> +Log 1<br> +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), "\ +<b>Header 1</b><br> +Log 1<br> +Log 2<br> +<br> +<b>Header 2</b><br> +Log 3<br> +Log 4"); + } + +} |