diff options
author | Rory Dudley | 2024-03-24 22:41:14 -0600 |
---|---|---|
committer | Rory Dudley | 2024-03-24 22:41:14 -0600 |
commit | 4250ed9e3e9733f97acfc6a43c26653d9ab45f2f (patch) | |
tree | 3b91212708cf1615d7c19cdf78ba2a92858c0514 | |
parent | 3dffade25dcb05c04fc0d229e0781a040b3fc885 (diff) | |
download | dwarvish-4250ed9e3e9733f97acfc6a43c26653d9ab45f2f.tar.gz |
Poem testing
Add back tests for Rune::Read, Rune::Write, and Rune::Addendum,
following the new parser output. Also, renames some tests, since Read,
Write, and Addendum are no longer meters.
-rw-r--r-- | src/poem.rs | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/src/poem.rs b/src/poem.rs index db51d16..069fb79 100644 --- a/src/poem.rs +++ b/src/poem.rs @@ -59,52 +59,56 @@ mod tests { assert_eq!(poem.first().unwrap().meter, Rune::Continue); } - // #[test] - // fn it_parses_verse_with_the_read_meter() { - // let poem = Poem::read("lolcat < src/main.rs".to_string()); - // assert!(poem.is_ok()); - // let mut verses = poem.unwrap().into_iter(); - - // let verse = verses.next().unwrap(); - // assert_eq!(verse.verb(), "lolcat"); - // assert_eq!(verse.meter, Rune::Read); - - // let verse = verses.next().unwrap(); - // assert_eq!(verse.stanza, vec!["src/main.rs".to_string()]); - // } - - // #[test] - // fn it_parses_verse_with_the_write_meter() { - // let poem = Poem::read("cat src/main.rs > /dev/null".to_string()); - // assert!(poem.is_ok()); - // let mut verses = poem.unwrap().into_iter(); - - // let verse = verses.next().unwrap(); - // assert_eq!(verse.verb(), "cat"); - // assert_eq!(verse.clause().unwrap(), vec!["src/main.rs".to_string()]); - // assert_eq!(verse.meter, Rune::Write); - - // let verse = verses.next().unwrap(); - // assert_eq!(verse.stanza, vec!["/dev/null".to_string()]); - // } - - // #[test] - // fn it_parses_verse_with_the_addenum_meter() { - // let poem = Poem::read("cat src/main.rs >> /dev/null".to_string()); - // assert!(poem.is_ok()); - // let mut verses = poem.unwrap().into_iter(); - - // let verse = verses.next().unwrap(); - // assert_eq!(verse.verb(), "cat"); - // assert_eq!(verse.clause().unwrap(), vec!["src/main.rs".to_string()]); - // assert_eq!(verse.meter, Rune::Addendum); - - // let verse = verses.next().unwrap(); - // assert_eq!(verse.stanza, vec!["/dev/null".to_string()]); - // } + #[test] + fn it_parses_a_verse_with_the_read_rune() { + let poem = Poem::read("lolcat < src/main.rs".to_string()); + assert!(poem.is_ok()); + let mut verses = poem.unwrap().into_iter(); + let verse = verses.next().unwrap(); + assert_eq!(verse.io, Rune::Read); + assert_eq!( + verse.stanza, + vec!["lolcat", "<", "src/main.rs"] + .iter() + .map(|s| s.to_string()) + .collect::<Vec<String>>() + ); + } + + #[test] + fn it_parses_a_verse_with_the_write_rune() { + let poem = Poem::read("cat src/main.rs > /dev/null".to_string()); + assert!(poem.is_ok()); + let mut verses = poem.unwrap().into_iter(); + let verse = verses.next().unwrap(); + assert_eq!(verse.io, Rune::Write); + assert_eq!( + verse.stanza, + vec!["cat", "src/main.rs", "<", "/dev/null"] + .iter() + .map(|s| s.to_string()) + .collect::<Vec<String>>() + ); + } + + #[test] + fn it_parses_a_verse_with_the_addendum_rune() { + let poem = Poem::read("cat src/main.rs >> /dev/null".to_string()); + assert!(poem.is_ok()); + let mut verses = poem.unwrap().into_iter(); + let verse = verses.next().unwrap(); + assert_eq!(verse.io, Rune::Addendum); + assert_eq!( + verse.stanza, + vec!["cat", "src/main.rs", "<", "/dev/null"] + .iter() + .map(|s| s.to_string()) + .collect::<Vec<String>>() + ); + } #[test] - fn it_throws_a_parse_error_if_no_files_are_specified_for_the_read_meter() { + fn it_throws_a_parse_error_if_no_files_are_specified_for_the_read_rune() { let poem = Poem::read("lolcat <".to_string()); assert!(poem.is_err()); let poem = Poem::read("lolcat <;".to_string()); @@ -114,7 +118,7 @@ mod tests { } #[test] - fn it_throws_a_parse_error_if_no_files_are_specified_for_the_write_meter() { + fn it_throws_a_parse_error_if_no_files_are_specified_for_the_write_rune() { let poem = Poem::read("cat src/main.rs >".to_string()); assert!(poem.is_err()); let poem = Poem::read("cat src/main.rs >;".to_string()); @@ -124,7 +128,7 @@ mod tests { } #[test] - fn it_throws_a_parse_error_if_no_files_are_specified_for_the_addendum_meter() { + fn it_throws_a_parse_error_if_no_files_are_specified_for_the_addendum_rune() { let poem = Poem::read("cat src/main.rs >>".to_string()); assert!(poem.is_err()); let poem = Poem::read("cat src/main.rs >>;".to_string()); |