summaryrefslogtreecommitdiffstats
path: root/src/recite.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/recite.rs')
-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());