diff options
| author | mat <git@matdoes.dev> | 2023-05-07 02:50:52 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-05-07 02:50:52 -0500 |
| commit | 53d51a5ca92aa8ddea9d82b6b44ac7aaa06c2095 (patch) | |
| tree | 52ea13066f52bf46529debc0312ae420a295702a /azalea-brigadier/tests | |
| parent | 2823e508b389194ee1d8b3f4180fc3a15a7e077e (diff) | |
| download | azalea-drasl-53d51a5ca92aa8ddea9d82b6b44ac7aaa06c2095.tar.xz | |
more brigadier docs
Diffstat (limited to 'azalea-brigadier/tests')
| -rwxr-xr-x | azalea-brigadier/tests/command_dispatcher_test.rs | 82 |
1 files changed, 21 insertions, 61 deletions
diff --git a/azalea-brigadier/tests/command_dispatcher_test.rs b/azalea-brigadier/tests/command_dispatcher_test.rs index 4479cfa2..eecbf668 100755 --- a/azalea-brigadier/tests/command_dispatcher_test.rs +++ b/azalea-brigadier/tests/command_dispatcher_test.rs @@ -19,26 +19,13 @@ fn input_with_offset(input: &str, offset: usize) -> StringReader { } #[test] -fn create_and_execute_command() { - let mut subject = CommandDispatcher::new(); - subject.register(literal("foo").executes(|_| 42)); - - assert_eq!( - subject - .execute("foo".into(), Arc::new(CommandSource {})) - .unwrap(), - 42 - ); -} - -#[test] fn create_and_execute_offset_command() { let mut subject = CommandDispatcher::new(); subject.register(literal("foo").executes(|_| 42)); assert_eq!( subject - .execute(input_with_offset("/foo", 1), Arc::new(CommandSource {})) + .execute(input_with_offset("/foo", 1), &CommandSource {}) .unwrap(), 42 ); @@ -50,18 +37,8 @@ fn create_and_merge_commands() { subject.register(literal("base").then(literal("foo").executes(|_| 42))); subject.register(literal("base").then(literal("bar").executes(|_| 42))); - assert_eq!( - subject - .execute("base foo".into(), Arc::new(CommandSource {})) - .unwrap(), - 42 - ); - assert_eq!( - subject - .execute("base bar".into(), Arc::new(CommandSource {})) - .unwrap(), - 42 - ); + assert_eq!(subject.execute("base foo", &CommandSource {}).unwrap(), 42); + assert_eq!(subject.execute("base bar", &CommandSource {}).unwrap(), 42); } #[test] @@ -70,7 +47,7 @@ fn execute_unknown_command() { subject.register(literal("bar")); subject.register(literal("baz")); - let execute_result = subject.execute("foo".into(), Arc::new(CommandSource {})); + let execute_result = subject.execute("foo", &CommandSource {}); let err = execute_result.err().unwrap(); match err.type_ { @@ -85,7 +62,7 @@ fn execute_impermissible_command() { let mut subject = CommandDispatcher::new(); subject.register(literal("foo").requires(|_| false)); - let execute_result = subject.execute("foo".into(), Arc::new(CommandSource {})); + let execute_result = subject.execute("foo", &CommandSource {}); let err = execute_result.err().unwrap(); match err.type_ { @@ -100,7 +77,7 @@ fn execute_empty_command() { let mut subject = CommandDispatcher::new(); subject.register(literal("")); - let execute_result = subject.execute("".into(), Arc::new(CommandSource {})); + let execute_result = subject.execute("", &CommandSource {}); let err = execute_result.err().unwrap(); match err.type_ { @@ -115,7 +92,7 @@ fn execute_unknown_subcommand() { let mut subject = CommandDispatcher::new(); subject.register(literal("foo").executes(|_| 42)); - let execute_result = subject.execute("foo bar".into(), Arc::new(CommandSource {})); + let execute_result = subject.execute("foo bar", &CommandSource {}); let err = execute_result.err().unwrap(); match err.type_ { @@ -130,7 +107,7 @@ fn execute_incorrect_literal() { let mut subject = CommandDispatcher::new(); subject.register(literal("foo").executes(|_| 42).then(literal("bar"))); - let execute_result = subject.execute("foo baz".into(), Arc::new(CommandSource {})); + let execute_result = subject.execute("foo baz", &CommandSource {}); let err = execute_result.err().unwrap(); match err.type_ { @@ -150,7 +127,7 @@ fn execute_ambiguous_incorrect_argument() { .then(literal("baz")), ); - let execute_result = subject.execute("foo unknown".into(), Arc::new(CommandSource {})); + let execute_result = subject.execute("foo unknown", &CommandSource {}); let err = execute_result.err().unwrap(); match err.type_ { @@ -172,12 +149,7 @@ fn execute_subcommand() { .executes(|_| 42), ); - assert_eq!( - subject - .execute("foo =".into(), Arc::new(CommandSource {})) - .unwrap(), - 100 - ); + assert_eq!(subject.execute("foo =", &CommandSource {}).unwrap(), 100); } #[test] @@ -185,7 +157,7 @@ fn parse_incomplete_literal() { let mut subject = CommandDispatcher::new(); subject.register(literal("foo").then(literal("bar").executes(|_| 42))); - let parse = subject.parse("foo ".into(), Arc::new(CommandSource {})); + let parse = subject.parse("foo ".into(), &CommandSource {}); assert_eq!(parse.reader.remaining(), " "); assert_eq!(parse.context.nodes.len(), 1); } @@ -195,7 +167,7 @@ fn parse_incomplete_argument() { let mut subject = CommandDispatcher::new(); subject.register(literal("foo").then(argument("bar", integer()).executes(|_| 42))); - let parse = subject.parse("foo ".into(), Arc::new(CommandSource {})); + let parse = subject.parse("foo ".into(), &CommandSource {}); assert_eq!(parse.reader.remaining(), " "); assert_eq!(parse.context.nodes.len(), 1); } @@ -210,12 +182,7 @@ fn execute_ambiguious_parent_subcommand() { .then(argument("right", integer()).then(argument("sub", integer()).executes(|_| 100))), ); - assert_eq!( - subject - .execute("test 1 2".into(), Arc::new(CommandSource {})) - .unwrap(), - 100 - ); + assert_eq!(subject.execute("test 1 2", &CommandSource {}).unwrap(), 100); } #[test] @@ -231,9 +198,7 @@ fn execute_ambiguious_parent_subcommand_via_redirect() { subject.register(literal("redirect").redirect(real)); assert_eq!( - subject - .execute("redirect 1 2".into(), Arc::new(CommandSource {})) - .unwrap(), + subject.execute("redirect 1 2", &CommandSource {}).unwrap(), 100 ); } @@ -248,7 +213,7 @@ fn execute_redirected_multiple_times() { let input = "redirected redirected actual"; - let parse = subject.parse(input.into(), Arc::new(CommandSource {})); + let parse = subject.parse(input.into(), &CommandSource {}); assert_eq!(parse.context.range.get(input), "redirected"); assert_eq!(parse.context.nodes.len(), 1); assert_eq!(*parse.context.root.read(), *root.read()); @@ -299,7 +264,7 @@ fn execute_redirected() { subject.register(literal("redirected").fork(subject.root.clone(), Arc::new(modifier))); let input = "redirected actual"; - let parse = subject.parse(input.into(), Arc::new(CommandSource {})); + let parse = subject.parse(input.into(), CommandSource {}); assert_eq!(parse.context.range.get(input), "redirected"); assert_eq!(parse.context.nodes.len(), 1); assert_eq!(*parse.context.root.read(), *subject.root.read()); @@ -314,7 +279,7 @@ fn execute_redirected() { assert_eq!(*parse.context.root.read(), *subject.root.read()); assert_eq!(parent.nodes[0].range, parent.range); assert_eq!(*parent.nodes[0].node.read(), *concrete_node.read()); - assert_eq!(parent.source, Arc::new(CommandSource {})); + assert_eq!(*parent.source, CommandSource {}); assert_eq!(CommandDispatcher::execute_parsed(parse).unwrap(), 2); } @@ -329,7 +294,7 @@ fn execute_orphaned_subcommand() { .executes(|_| 42), ); - let result = subject.execute("foo 5".into(), Arc::new(CommandSource {})); + let result = subject.execute("foo 5", &CommandSource {}); assert!(result.is_err()); let result = result.unwrap_err(); assert_eq!( @@ -346,12 +311,7 @@ fn execute_invalid_other() { subject.register(literal("w").executes(|_| panic!("This should not run"))); subject.register(literal("world").executes(|_| 42)); - assert_eq!( - subject - .execute("world".into(), Arc::new(CommandSource {})) - .unwrap(), - 42 - ); + assert_eq!(subject.execute("world", &CommandSource {}).unwrap(), 42); } #[test] @@ -364,7 +324,7 @@ fn parse_no_space_separator() { .executes(|_| 42), ); - let result = subject.execute("foo$".into(), Arc::new(CommandSource {})); + let result = subject.execute("foo$", &CommandSource {}); assert!(result.is_err()); let result = result.unwrap_err(); assert_eq!( @@ -384,7 +344,7 @@ fn execute_invalid_subcommand() { .executes(|_| 42), ); - let result = subject.execute("foo bar".into(), Arc::new(CommandSource {})); + let result = subject.execute("foo bar", &CommandSource {}); assert!(result.is_err()); let result = result.unwrap_err(); // this fails for some reason, i blame mojang |
