mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-07 14:27:54 +00:00
format rust code
This commit is contained in:
parent
beec38ef8b
commit
d804303615
3 changed files with 59 additions and 49 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use command_parser::{parse_command, Tree, command::Command, parameter::*, tokens};
|
||||
use command_parser::{Tree, command::Command, parameter::*, parse_command, tokens};
|
||||
|
||||
/// this checks if we properly keep track of filtered tokens (eg. branches we failed on)
|
||||
/// when we backtrack. a previous parser bug would cause infinite loops since it did not
|
||||
|
|
@ -7,14 +7,14 @@ use command_parser::{parse_command, Tree, command::Command, parameter::*, tokens
|
|||
fn test_infinite_loop_repro() {
|
||||
let p1 = Optional(("param1", ParameterKind::OpaqueString));
|
||||
let p2 = Optional(("param2", ParameterKind::OpaqueString));
|
||||
|
||||
|
||||
let cmd1 = Command::new(tokens!("s", p1, "A"), "cmd1");
|
||||
let cmd2 = Command::new(tokens!("s", p2, "B"), "cmd2");
|
||||
|
||||
|
||||
let mut tree = Tree::default();
|
||||
tree.register_command(cmd1);
|
||||
tree.register_command(cmd2);
|
||||
|
||||
|
||||
let input = "s foo C";
|
||||
// this should fail and not loop
|
||||
let result = parse_command(tree, "pk;".to_string(), input.to_string());
|
||||
|
|
@ -28,18 +28,24 @@ fn test_infinite_loop_repro() {
|
|||
fn test_dirty_params() {
|
||||
let p1 = Optional(("param1", ParameterKind::OpaqueString));
|
||||
let p2 = Optional(("param2", ParameterKind::OpaqueString));
|
||||
|
||||
|
||||
let cmd1 = Command::new(tokens!("s", p1, "A"), "cmd1");
|
||||
let cmd2 = Command::new(tokens!("s", p2, "B"), "cmd2");
|
||||
|
||||
|
||||
let mut tree = Tree::default();
|
||||
tree.register_command(cmd1);
|
||||
tree.register_command(cmd2);
|
||||
|
||||
|
||||
let input = "s foo B";
|
||||
let result = parse_command(tree, "pk;".to_string(), input.to_string()).unwrap();
|
||||
|
||||
|
||||
println!("params: {:?}", result.parameters);
|
||||
assert!(!result.parameters.contains_key("param1"), "params should not contain 'param1' from failed branch");
|
||||
assert!(result.parameters.contains_key("param2"), "params should contain 'param2'");
|
||||
assert!(
|
||||
!result.parameters.contains_key("param1"),
|
||||
"params should not contain 'param1' from failed branch"
|
||||
);
|
||||
assert!(
|
||||
result.parameters.contains_key("param2"),
|
||||
"params should contain 'param2'"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue