summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRory Dudley2024-03-03 01:41:21 -0700
committerRory Dudley2024-03-03 01:41:21 -0700
commitc2ce134cd393f397cb8b1e584949020c2c030f8d (patch)
tree505345ae6b18abab71e6e6bb8fcf098c54586f8c
parent8c2fe97a81a42e654258fd82d95e0650647208fb (diff)
downloaddwarvish-c2ce134cd393f397cb8b1e584949020c2c030f8d.tar.gz
Add unit tests for the new IO meters
Added six new units tests related to the IO meters (Read, Write, and Addendum). The first three tests check the meters under normal operation , and the last three tests ensures that the parser throws an error, unless one or more files where specified for the operation.
-rw-r--r--src/recite.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/recite.rs b/src/recite.rs
index 12c98ae..05e49f3 100644
--- a/src/recite.rs
+++ b/src/recite.rs
@@ -1040,6 +1040,80 @@ mod tests {
}
#[test]
+ fn it_parses_verse_with_the_read_meter() {
+ let poem = Poem::read("lolcat < src/main.rs".to_string());
+ assert!(poem.is_some());
+ let mut verses = poem.unwrap().verses.into_iter();
+
+ let verse = verses.next().unwrap();
+ assert_eq!(verse.verb(), "lolcat");
+ assert_eq!(verse.meter, Meter::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_some());
+ let mut verses = poem.unwrap().verses.into_iter();
+
+ let verse = verses.next().unwrap();
+ assert_eq!(verse.verb(), "cat");
+ assert_eq!(verse.clause(), vec!["src/main.rs".to_string()]);
+ assert_eq!(verse.meter, Meter::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_some());
+ let mut verses = poem.unwrap().verses.into_iter();
+
+ let verse = verses.next().unwrap();
+ assert_eq!(verse.verb(), "cat");
+ assert_eq!(verse.clause(), vec!["src/main.rs".to_string()]);
+ assert_eq!(verse.meter, Meter::Addendum);
+
+ let verse = verses.next().unwrap();
+ assert_eq!(verse.stanza(), vec!["/dev/null".to_string()]);
+ }
+
+ #[test]
+ fn it_throws_a_parse_error_if_no_files_are_specified_for_the_read_meter() {
+ let poem = Poem::read("lolcat <".to_string());
+ assert!(poem.is_none());
+ let poem = Poem::read("lolcat <;".to_string());
+ assert!(poem.is_none());
+ let poem = Poem::read("lolcat < && ls -la".to_string());
+ assert!(poem.is_none());
+ }
+
+ #[test]
+ fn it_throws_a_parse_error_if_no_files_are_specified_for_the_write_meter() {
+ let poem = Poem::read("cat src/main.rs >".to_string());
+ assert!(poem.is_none());
+ let poem = Poem::read("cat src/main.rs >;".to_string());
+ assert!(poem.is_none());
+ let poem = Poem::read("cat > && ls -la".to_string());
+ assert!(poem.is_none());
+ }
+
+ #[test]
+ fn it_throws_a_parse_error_if_no_files_are_specified_for_the_addendum_meter() {
+ let poem = Poem::read("cat src/main.rs >>".to_string());
+ assert!(poem.is_none());
+ let poem = Poem::read("cat src/main.rs >>;".to_string());
+ assert!(poem.is_none());
+ let poem = Poem::read("cat >> && ls -la".to_string());
+ assert!(poem.is_none());
+ }
+
+ #[test]
fn it_parses_a_complex_verse_with_lots_of_different_meters() {
let poem = Poem::read("ls -la | lolcat && echo hello | lolcat && sleep 2 &".to_string());
assert!(poem.is_some());