diff options
| author | Lakelezz <[email protected]> | 2017-12-18 22:23:07 +0100 |
|---|---|---|
| committer | alex <[email protected]> | 2017-12-18 22:23:07 +0100 |
| commit | 143fddd83f1fc93c070e36bf31906d2631c68f97 (patch) | |
| tree | 7d2f0ff78cab7c72e86d044d0022b9565dc44bf4 /tests | |
| parent | Fix ifs (diff) | |
| download | serenity-143fddd83f1fc93c070e36bf31906d2631c68f97.tar.xz serenity-143fddd83f1fc93c070e36bf31906d2631c68f97.zip | |
Actually fix `Args`'s `parse` and add a few tests (#236)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_args.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_args.rs b/tests/test_args.rs new file mode 100644 index 0000000..424bc76 --- /dev/null +++ b/tests/test_args.rs @@ -0,0 +1,50 @@ +extern crate serenity; + +use serenity::framework::standard::Args; + +#[test] +fn single_i32_with_2_bytes_long_delimiter() { + let mut args = Args::new("1, 2", &[", ".to_string()]); + + assert_eq!(args.single::<i32>().unwrap(), 1); + assert_eq!(args.single::<i32>().unwrap(), 2); +} + +#[test] +fn single_i32_with_1_byte_long_delimiter_i32() { + let mut args = Args::new("1,2", &[",".to_string()]); + + assert_eq!(args.single::<i32>().unwrap(), 1); + assert_eq!(args.single::<i32>().unwrap(), 2); +} + +#[test] +fn single_i32_with_wrong_char_after_first_arg() { + let mut args = Args::new("1, 2", &[",".to_string()]); + + assert_eq!(args.single::<i32>().unwrap(), 1); + assert!(args.single::<i32>().is_err()); +} + +#[test] +fn single_i32_with_one_character_being_3_bytes_long() { + let mut args = Args::new("1★2", &["★".to_string()]); + + assert_eq!(args.single::<i32>().unwrap(), 1); + assert_eq!(args.single::<i32>().unwrap(), 2); +} + +#[test] +fn single_i32_with_untrimmed_whitespaces() { + let mut args = Args::new(" 1, 2 ", &[",".to_string()]); + + assert!(args.single::<i32>().is_err()); +} + +#[test] +fn single_i32_n() { + let args = Args::new("1,2", &[",".to_string()]); + + assert_eq!(args.single_n::<i32>().unwrap(), 1); + assert_eq!(args.single_n::<i32>().unwrap(), 1); +} |