mirror of
https://github.com/mat-1/azalea.git
synced 2024-09-20 07:02:31 +00:00
dbb2092ac0
* add a couple more packets and improve codegen
* enums in packet codegen
* fix enums and MORE PACKETS
* make unsigned numbers the default
* codegen can make hashmaps
* UnsizedByteArray in codegen
* Vec and Option
* enum codgen works in more situations
* ServerboundInteractPacket
* Fix error with new error system
* More packets
* more packets
* more packets
* guess what was added
* yeah it's more packets
* add more packets
* packets
* start adding ClientboundBossEventPacket
* finish boss event packet
* improve codegen for linux
* start on command suggestions packet
* rename declare_commands to commands
* más paquetes
* fix generating custom payload packet
* more packets
* mehr Pakete
* improve codegen for movement packets
* rename move packets to have "packet" at the end
* fix some unused variable warns
* addere plus facis
* pli da pakoj
* plus de paquets
* più pacchetti
* make ChatFormatting a macro in azalea-chat
* change a match to matches! macro
* update SetPlayerTeam to use ChatFormatting
* ClientboundSetScorePacket & fix clippy warnings
* finish game state 🎉
* add remaining packets for other states
* fix error in ping.rs
75 lines
1.9 KiB
Rust
Executable file
75 lines
1.9 KiB
Rust
Executable file
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");
|
|
}
|