aboutsummaryrefslogtreecommitdiff
path: root/azalea-brigadier/tests
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-05-30 20:07:28 -0330
committermat <git@matdoes.dev>2025-05-30 16:37:40 -0700
commita5e7ff771d657258cedcc7a8b3ce265c655f0860 (patch)
treeea5fdbbee32c1b9917a7ece03f6a1a70ee8e63fa /azalea-brigadier/tests
parentda73b4316de4b26322c53f14222c7751a0be55a1 (diff)
downloadazalea-drasl-a5e7ff771d657258cedcc7a8b3ce265c655f0860.tar.xz
implement missing brigadier features and cleanup some more
Diffstat (limited to 'azalea-brigadier/tests')
-rw-r--r--azalea-brigadier/tests/bevy_app_usage.rs4
-rw-r--r--azalea-brigadier/tests/command_dispatcher_test.rs50
-rw-r--r--azalea-brigadier/tests/string_reader_test.rs52
3 files changed, 41 insertions, 65 deletions
diff --git a/azalea-brigadier/tests/bevy_app_usage.rs b/azalea-brigadier/tests/bevy_app_usage.rs
index e962d7d1..d4660a5d 100644
--- a/azalea-brigadier/tests/bevy_app_usage.rs
+++ b/azalea-brigadier/tests/bevy_app_usage.rs
@@ -131,7 +131,7 @@ impl DispatchStorage {
///
/// Spawns an entity with the [`SpawnedEntity`] component.
fn command_spawn_entity(context: &CommandContext<WorldAccessor>) -> i32 {
- context.source.lock().spawn(SpawnedEntity);
+ context.source().lock().spawn(SpawnedEntity);
0
}
@@ -143,7 +143,7 @@ impl DispatchStorage {
let num = get_integer(context, "entities").unwrap();
for _ in 0..num {
- context.source.lock().spawn(SpawnedEntity);
+ context.source().lock().spawn(SpawnedEntity);
}
0
diff --git a/azalea-brigadier/tests/command_dispatcher_test.rs b/azalea-brigadier/tests/command_dispatcher_test.rs
index eecbf668..f04ddfdf 100644
--- a/azalea-brigadier/tests/command_dispatcher_test.rs
+++ b/azalea-brigadier/tests/command_dispatcher_test.rs
@@ -5,7 +5,7 @@ use azalea_brigadier::{
builder::{literal_argument_builder::literal, required_argument_builder::argument},
command_dispatcher::CommandDispatcher,
context::CommandContext,
- exceptions::{BuiltInExceptions, CommandSyntaxException},
+ errors::{BuiltInError, CommandSyntaxError},
string_reader::StringReader,
};
@@ -50,10 +50,7 @@ fn execute_unknown_command() {
let execute_result = subject.execute("foo", &CommandSource {});
let err = execute_result.err().unwrap();
- match err.type_ {
- BuiltInExceptions::DispatcherUnknownCommand => {}
- _ => panic!("Unexpected error"),
- }
+ assert_eq!(err.kind(), &BuiltInError::DispatcherUnknownCommand);
assert_eq!(err.cursor().unwrap(), 0);
}
@@ -65,10 +62,7 @@ fn execute_impermissible_command() {
let execute_result = subject.execute("foo", &CommandSource {});
let err = execute_result.err().unwrap();
- match err.type_ {
- BuiltInExceptions::DispatcherUnknownCommand => {}
- _ => panic!("Unexpected error"),
- }
+ assert_eq!(err.kind(), &BuiltInError::DispatcherUnknownCommand);
assert_eq!(err.cursor().unwrap(), 0);
}
@@ -80,10 +74,7 @@ fn execute_empty_command() {
let execute_result = subject.execute("", &CommandSource {});
let err = execute_result.err().unwrap();
- match err.type_ {
- BuiltInExceptions::DispatcherUnknownCommand => {}
- _ => panic!("Unexpected error"),
- }
+ assert_eq!(err.kind(), &BuiltInError::DispatcherUnknownCommand);
assert_eq!(err.cursor().unwrap(), 0);
}
@@ -95,10 +86,7 @@ fn execute_unknown_subcommand() {
let execute_result = subject.execute("foo bar", &CommandSource {});
let err = execute_result.err().unwrap();
- match err.type_ {
- BuiltInExceptions::DispatcherUnknownArgument => {}
- _ => panic!("Unexpected error"),
- }
+ assert_eq!(err.kind(), &BuiltInError::DispatcherUnknownArgument);
assert_eq!(err.cursor().unwrap(), 4);
}
@@ -110,10 +98,7 @@ fn execute_incorrect_literal() {
let execute_result = subject.execute("foo baz", &CommandSource {});
let err = execute_result.err().unwrap();
- match err.type_ {
- BuiltInExceptions::DispatcherUnknownArgument => {}
- _ => panic!("Unexpected error"),
- }
+ assert_eq!(err.kind(), &BuiltInError::DispatcherUnknownArgument);
assert_eq!(err.cursor().unwrap(), 4);
}
@@ -130,10 +115,7 @@ fn execute_ambiguous_incorrect_argument() {
let execute_result = subject.execute("foo unknown", &CommandSource {});
let err = execute_result.err().unwrap();
- match err.type_ {
- BuiltInExceptions::DispatcherUnknownArgument => {}
- _ => panic!("Unexpected error"),
- }
+ assert_eq!(err.kind(), &BuiltInError::DispatcherUnknownArgument);
assert_eq!(err.cursor().unwrap(), 4);
}
@@ -245,7 +227,7 @@ fn execute_redirected_multiple_times() {
);
assert_eq!(*child2.unwrap().nodes[0].node.read(), *concrete_node.read());
- assert_eq!(CommandDispatcher::execute_parsed(parse).unwrap(), 42);
+ assert_eq!(subject.execute_parsed(parse).unwrap(), 42);
}
#[test]
@@ -255,7 +237,7 @@ fn execute_redirected() {
let source1 = Arc::new(CommandSource {});
let source2 = Arc::new(CommandSource {});
- let modifier = move |_: &CommandContext<CommandSource>| -> Result<Vec<Arc<CommandSource>>, CommandSyntaxException> {
+ let modifier = move |_: &CommandContext<CommandSource>| -> Result<Vec<Arc<CommandSource>>, CommandSyntaxError> {
Ok(vec![source1.clone(), source2.clone()])
};
@@ -281,7 +263,7 @@ fn execute_redirected() {
assert_eq!(*parent.nodes[0].node.read(), *concrete_node.read());
assert_eq!(*parent.source, CommandSource {});
- assert_eq!(CommandDispatcher::execute_parsed(parse).unwrap(), 2);
+ assert_eq!(subject.execute_parsed(parse).unwrap(), 2);
}
#[test]
@@ -297,10 +279,7 @@ fn execute_orphaned_subcommand() {
let result = subject.execute("foo 5", &CommandSource {});
assert!(result.is_err());
let result = result.unwrap_err();
- assert_eq!(
- *result.get_type(),
- BuiltInExceptions::DispatcherUnknownCommand
- );
+ assert_eq!(*result.kind(), BuiltInError::DispatcherUnknownCommand);
assert_eq!(result.cursor(), Some(5));
}
@@ -327,10 +306,7 @@ fn parse_no_space_separator() {
let result = subject.execute("foo$", &CommandSource {});
assert!(result.is_err());
let result = result.unwrap_err();
- assert_eq!(
- *result.get_type(),
- BuiltInExceptions::DispatcherUnknownCommand
- );
+ assert_eq!(*result.kind(), BuiltInError::DispatcherUnknownCommand);
assert_eq!(result.cursor(), Some(0));
}
@@ -348,7 +324,7 @@ fn execute_invalid_subcommand() {
assert!(result.is_err());
let result = result.unwrap_err();
// this fails for some reason, i blame mojang
- // assert_eq!(*result.get_type(), BuiltInExceptions::ReaderExpectedInt);
+ // assert_eq!(*result.get_type(), BuiltInError::ReaderExpectedInt);
assert_eq!(result.cursor(), Some(4));
}
diff --git a/azalea-brigadier/tests/string_reader_test.rs b/azalea-brigadier/tests/string_reader_test.rs
index de605e99..3b70043b 100644
--- a/azalea-brigadier/tests/string_reader_test.rs
+++ b/azalea-brigadier/tests/string_reader_test.rs
@@ -1,4 +1,4 @@
-use azalea_brigadier::{exceptions::BuiltInExceptions, string_reader::StringReader};
+use azalea_brigadier::{errors::BuiltInError, string_reader::StringReader};
#[test]
fn can_read() {
@@ -222,7 +222,7 @@ fn read_quoted_string_no_open() {
let result = reader.read_quoted_string();
assert!(result.is_err());
if let Err(e) = result {
- assert_eq!(e.get_type(), &BuiltInExceptions::ReaderExpectedStartOfQuote);
+ assert_eq!(e.kind(), &BuiltInError::ReaderExpectedStartOfQuote);
assert_eq!(e.cursor(), Some(0));
}
}
@@ -233,7 +233,7 @@ fn read_quoted_string_no_close() {
let result = reader.read_quoted_string();
assert!(result.is_err());
if let Err(e) = result {
- assert_eq!(e.get_type(), &BuiltInExceptions::ReaderExpectedEndOfQuote);
+ assert_eq!(e.kind(), &BuiltInError::ReaderExpectedEndOfQuote);
assert_eq!(e.cursor(), Some(12));
}
}
@@ -245,8 +245,8 @@ fn read_quoted_string_invalid_escape() {
assert!(result.is_err());
if let Err(e) = result {
assert_eq!(
- e.get_type(),
- &BuiltInExceptions::ReaderInvalidEscape { character: 'n' }
+ e.kind(),
+ &BuiltInError::ReaderInvalidEscape { character: 'n' }
);
assert_eq!(e.cursor(), Some(7));
}
@@ -259,8 +259,8 @@ fn read_quoted_string_invalid_quote_escape() {
assert!(result.is_err());
if let Err(e) = result {
assert_eq!(
- e.get_type(),
- &BuiltInExceptions::ReaderInvalidEscape { character: '"' }
+ e.kind(),
+ &BuiltInError::ReaderInvalidEscape { character: '"' }
);
assert_eq!(e.cursor(), Some(7));
}
@@ -313,8 +313,8 @@ fn read_int_invalid() {
assert!(result.is_err());
if let Err(e) = result {
assert_eq!(
- e.get_type(),
- &BuiltInExceptions::ReaderInvalidInt {
+ e.kind(),
+ &BuiltInError::ReaderInvalidInt {
value: "12.34".to_string()
}
);
@@ -328,7 +328,7 @@ fn read_int_none() {
let result = reader.read_int();
assert!(result.is_err());
if let Err(e) = result {
- assert_eq!(e.get_type(), &BuiltInExceptions::ReaderExpectedInt);
+ assert_eq!(e.kind(), &BuiltInError::ReaderExpectedInt);
assert_eq!(e.cursor(), Some(0));
}
}
@@ -372,8 +372,8 @@ fn read_long_invalid() {
assert!(result.is_err());
if let Err(e) = result {
assert_eq!(
- e.get_type(),
- &BuiltInExceptions::ReaderInvalidLong {
+ e.kind(),
+ &BuiltInError::ReaderInvalidLong {
value: "12.34".to_string()
}
);
@@ -387,7 +387,7 @@ fn read_long_none() {
let result = reader.read_long();
assert!(result.is_err());
if let Err(e) = result {
- assert_eq!(e.get_type(), &BuiltInExceptions::ReaderExpectedLong);
+ assert_eq!(e.kind(), &BuiltInError::ReaderExpectedLong);
assert_eq!(e.cursor(), Some(0));
}
}
@@ -439,8 +439,8 @@ fn read_double_invalid() {
assert!(result.is_err());
if let Err(e) = result {
assert_eq!(
- e.get_type(),
- &BuiltInExceptions::ReaderInvalidDouble {
+ e.kind(),
+ &BuiltInError::ReaderInvalidDouble {
value: "12.34.56".to_string()
}
);
@@ -454,7 +454,7 @@ fn read_double_none() {
let result = reader.read_double();
assert!(result.is_err());
if let Err(e) = result {
- assert_eq!(e.get_type(), &BuiltInExceptions::ReaderExpectedDouble);
+ assert_eq!(e.kind(), &BuiltInError::ReaderExpectedDouble);
assert_eq!(e.cursor(), Some(0));
}
}
@@ -506,8 +506,8 @@ fn read_float_invalid() {
assert!(result.is_err());
if let Err(e) = result {
assert_eq!(
- e.get_type(),
- &BuiltInExceptions::ReaderInvalidFloat {
+ e.kind(),
+ &BuiltInError::ReaderInvalidFloat {
value: "12.34.56".to_string()
}
);
@@ -521,7 +521,7 @@ fn read_float_none() {
let result = reader.read_float();
assert!(result.is_err());
if let Err(e) = result {
- assert_eq!(e.get_type(), &BuiltInExceptions::ReaderExpectedFloat);
+ assert_eq!(e.kind(), &BuiltInError::ReaderExpectedFloat);
assert_eq!(e.cursor(), Some(0));
}
}
@@ -556,8 +556,8 @@ fn expect_incorrect() {
assert!(result.is_err());
if let Err(e) = result {
assert_eq!(
- e.get_type(),
- &BuiltInExceptions::ReaderExpectedSymbol { symbol: 'a' }
+ e.kind(),
+ &BuiltInError::ReaderExpectedSymbol { symbol: 'a' }
);
assert_eq!(e.cursor(), Some(0));
}
@@ -570,8 +570,8 @@ fn expect_none() {
assert!(result.is_err());
if let Err(e) = result {
assert_eq!(
- e.get_type(),
- &BuiltInExceptions::ReaderExpectedSymbol { symbol: 'a' }
+ e.kind(),
+ &BuiltInError::ReaderExpectedSymbol { symbol: 'a' }
);
assert_eq!(e.cursor(), Some(0));
}
@@ -591,8 +591,8 @@ fn read_boolean_incorrect() {
assert!(result.is_err());
if let Err(e) = result {
assert_eq!(
- e.get_type(),
- &BuiltInExceptions::ReaderInvalidBool {
+ e.kind(),
+ &BuiltInError::ReaderInvalidBool {
value: "tuesday".to_string()
}
);
@@ -606,7 +606,7 @@ fn read_boolean_none() {
let result = reader.read_boolean();
assert!(result.is_err());
if let Err(e) = result {
- assert_eq!(e.get_type(), &BuiltInExceptions::ReaderExpectedBool);
+ assert_eq!(e.kind(), &BuiltInError::ReaderExpectedBool);
assert_eq!(e.cursor(), Some(0));
}
}