diff options
| author | mat <github@matdoes.dev> | 2021-12-15 23:10:55 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-15 23:10:55 -0600 |
| commit | 9642558f8f8d983a7087f15d68be8cf07a85f0c2 (patch) | |
| tree | 5f0a967f005cd5db510a13ab290c8ad6669b25aa /azalea-chat/tests | |
| parent | 72aefe871ca4983431b1a0b707b472e73ffea836 (diff) | |
| download | azalea-drasl-9642558f8f8d983a7087f15d68be8cf07a85f0c2.tar.xz | |
azalea
Diffstat (limited to 'azalea-chat/tests')
| -rw-r--r-- | azalea-chat/tests/integration_test.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/azalea-chat/tests/integration_test.rs b/azalea-chat/tests/integration_test.rs new file mode 100644 index 00000000..1278adfa --- /dev/null +++ b/azalea-chat/tests/integration_test.rs @@ -0,0 +1,75 @@ +use azalea_chat::{ + component::Component, + style::{Ansi, ChatFormatting, TextColor}, +}; +use serde::Deserialize; +use serde_json::Value; + +#[test] +fn basic_ansi_test() { + let j: Value = serde_json::from_str( + r#"{ + "text": "hello", + "color": "red", + "bold": true +}"#, + ) + .unwrap(); + let component = Component::deserialize(&j).unwrap(); + assert_eq!( + component.to_ansi(None), + "\u{1b}[1m\u{1b}[38;2;255;85;85mhello\u{1b}[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::deserialize(&j).unwrap(); + assert_eq!( + component.to_ansi(None), + format!( + "{bold}{italic}{underlined}{red}hello{reset}{bold}{italic}{red} {reset}{italic}{strikethrough}{abcdef}world{reset}{abcdef} 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), + ) + ); +} + +#[test] +fn component_from_string() { + let j: Value = serde_json::from_str("\"foo\"").unwrap(); + let component = Component::deserialize(&j).unwrap(); + assert_eq!(component.to_ansi(None), "foo"); +} |
