diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-03-06 02:31:28 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-03-06 02:31:28 +0100 |
commit | 1eb73eb5211fb43e2389857dda4f7afa15e55433 (patch) | |
tree | 9d12b56bb55a96e2d42275f17b27b420d66d9e40 | |
parent | 7398f8b7e9e5df6fe791383406c834b44fddbe2b (diff) | |
download | ezau-1eb73eb5211fb43e2389857dda4f7afa15e55433.tar.gz ezau-1eb73eb5211fb43e2389857dda4f7afa15e55433.tar.bz2 ezau-1eb73eb5211fb43e2389857dda4f7afa15e55433.zip |
add some basic tests to matrix module
-rw-r--r-- | src/matrix.rs | 100 | ||||
-rw-r--r-- | test/logs/arkk.zevtc | bin | 0 -> 465767 bytes |
2 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"); + } + +} diff --git a/test/logs/arkk.zevtc b/test/logs/arkk.zevtc Binary files differnew file mode 100644 index 0000000..510df20 --- /dev/null +++ b/test/logs/arkk.zevtc |