diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2021-12-05 12:21:19 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2021-12-05 12:21:19 -0300 |
commit | ea604e09b8338b9fdb66c3921ea3dc955168e79b (patch) | |
tree | a839b77eb3832385fa6e404b0e0a6f6fbdeb8617 /tests | |
parent | 23712f84e2f72bc8ac516882888d011e13f8c49a (diff) |
Add StringArgumentType
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arguments.rs | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/tests/arguments.rs b/tests/arguments.rs index 55b4a4b..0029998 100644 --- a/tests/arguments.rs +++ b/tests/arguments.rs @@ -13,7 +13,10 @@ use ::iosonism::args::BoolArgumentType; use ::iosonism::args::bounded_float; use ::iosonism::args::bounded_integer; use ::iosonism::args::float; +use ::iosonism::args::greedy_string; use ::iosonism::args::integer; +use ::iosonism::args::string; +use ::iosonism::args::word; use ::iosonism::strcursor::StringReader; mod common; @@ -45,10 +48,7 @@ fn test_bool__parse() { fn test_i32__parse() { let mut reader = Cursor::new("15"); assert_eq!( - ArgumentType::<(), ErrorPanic>::parse( - &integer::<i32>(), - &mut reader, - ), + ArgumentType::<(), ErrorPanic>::parse(&integer::<i32>(), &mut reader), Ok(15), ); assert!(!reader.can_read()); @@ -74,10 +74,7 @@ fn test_i32__parse__range() { fn test_i64__parse() { let mut reader = Cursor::new("15"); assert_eq!( - ArgumentType::<(), ErrorPanic>::parse( - &integer::<i64>(), - &mut reader, - ), + ArgumentType::<(), ErrorPanic>::parse(&integer::<i64>(), &mut reader), Ok(15), ); assert!(!reader.can_read()); @@ -103,10 +100,7 @@ fn test_i64__parse__range() { fn test_f32__parse() { let mut reader = Cursor::new("15"); assert_eq!( - ArgumentType::<(), ErrorPanic>::parse( - &float::<f32>(), - &mut reader, - ), + ArgumentType::<(), ErrorPanic>::parse(&float::<f32>(), &mut reader), Ok(15.0), ); assert!(!reader.can_read()); @@ -157,3 +151,30 @@ fn test_f64__parse__range() { } } +#[test] +fn test_string__parse__word() { + let mut reader = Cursor::new("hello"); + assert_eq!( + ArgumentType::<(), ErrorPanic>::parse(&word(), &mut reader), + Ok("hello".into()), + ); +} + +#[test] +fn test_string__parse__string() { + let mut reader = Cursor::new("\"hello world\""); + assert_eq!( + ArgumentType::<(), ErrorPanic>::parse(&string(), &mut reader), + Ok("hello world".into()), + ); +} + +#[test] +fn test_string__parse__greedy_string() { + let mut reader = Cursor::new("Hello world! This is a test."); + assert_eq!( + ArgumentType::<(), ErrorPanic>::parse(&greedy_string(), &mut reader), + Ok("Hello world! This is a test.".into()), + ); + assert!(!reader.can_read()); +} |