diff options
| author | mat <github@matdoes.dev> | 2021-12-09 18:14:18 +0000 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-09 18:14:18 +0000 |
| commit | a51524d457fff3e22183be72fb4837123875cfba (patch) | |
| tree | fa19cb43e57e3614cf5b2db116dddda71ef5afcd /minecraft-chat/tests | |
| parent | 1637e23c6c96feb30d09e472692387621ceb2cce (diff) | |
| download | azalea-drasl-a51524d457fff3e22183be72fb4837123875cfba.tar.xz | |
add more comprehensive test (fails rn)
Diffstat (limited to 'minecraft-chat/tests')
| -rw-r--r-- | minecraft-chat/tests/integration_test.rs | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/minecraft-chat/tests/integration_test.rs b/minecraft-chat/tests/integration_test.rs index 54426ed2..9119d58f 100644 --- a/minecraft-chat/tests/integration_test.rs +++ b/minecraft-chat/tests/integration_test.rs @@ -1,16 +1,67 @@ -use minecraft_chat::component::Component; +use minecraft_chat::{ + component::Component, + style::{Ansi, ChatFormatting, TextColor}, +}; use serde_json::{Result, Value}; #[test] -fn test() { +fn basic_ansi_test() { let j: Value = serde_json::from_str( r#"{ + "text": "hello", + "color": "red", + "bold": true +}"#, + ) + .unwrap(); + let component = Component::new(&j).unwrap(); + assert_eq!( + component.to_ansi(None), + "\x1b[1m\x1b[38;2;255;85;85mhello\x1b[m" + ); +} + +#[test] +fn complex_ansi_test() { + let j: Value = serde_json::from_str( + r##"[ + { "text": "hello", "color": "red", + "bold": true, + "italic": true, + "underlined": true, + "adsfsf": "this should be ignored", + "extra": [ + {"text": " ", "underlined": false}, + {"text": "world", "bold": false, "strikethrough": true, "color": "#abcdef"} + ] + }, + { + "text": " asdf", + "italic": false, + "obfuscated": "true", + "strikethrough": false + }, + { + "text": "!", "bold": true - }"#, + } +]"##, ) .unwrap(); let component = Component::new(&j).unwrap(); - assert_eq!(component.to_ansi(None), "\x1b[1m\x1b[38;2;255;85;85mhello\x1b[m"); + assert_eq!( + component.to_ansi(None), + format!( + "{bold}{italic}{underlined}{red}hello{reset}{bold}{italic} {reset}{italic}{strikethrough}{abcdef}world{reset} asdf{bold}!{reset}", + bold = Ansi::BOLD, + italic = Ansi::ITALIC, + underlined = Ansi::UNDERLINED, + red = Ansi::rgb(ChatFormatting::RED.color.unwrap()), + reset = Ansi::RESET, + strikethrough = Ansi::STRIKETHROUGH, + abcdef = Ansi::rgb(TextColor::parse("#abcdef".to_string()).unwrap().value), + ) + ); } |
