diff options
Diffstat (limited to 'src/poem.rs')
-rw-r--r-- | src/poem.rs | 74 |
1 files changed, 42 insertions, 32 deletions
diff --git a/src/poem.rs b/src/poem.rs index 0eda6b7..a063a14 100644 --- a/src/poem.rs +++ b/src/poem.rs @@ -15,10 +15,11 @@ mod tests { use super::elements::rune::Rune; use super::read::Readable; use super::*; + use crate::compose::Environment; #[test] fn it_parses_a_verse_with_no_meter() { - let poem = Poem::read("cargo build --release".to_string()); + let poem = Poem::read("cargo build --release".to_string(), &Environment::new()); assert!(poem.is_ok()); let poem = poem.unwrap(); assert_eq!(poem.first().unwrap().verb(), "cargo"); @@ -26,7 +27,7 @@ mod tests { #[test] fn it_parses_a_verse_with_the_couplet_meter() { - let poem = Poem::read("ls -la | lolcat".to_string()); + let poem = Poem::read("ls -la | lolcat".to_string(), &Environment::new()); assert!(poem.is_ok()); let poem = poem.unwrap(); assert_eq!(poem.first().unwrap().verb(), "ls"); @@ -35,7 +36,7 @@ mod tests { #[test] fn it_parses_a_verse_with_the_quiet_meter() { - let poem = Poem::read("sleep 20 &".to_string()); + let poem = Poem::read("sleep 20 &".to_string(), &Environment::new()); assert!(poem.is_ok()); let poem = poem.unwrap(); assert_eq!(poem.first().unwrap().verb(), "sleep"); @@ -44,7 +45,7 @@ mod tests { #[test] fn it_parses_a_verse_with_the_and_meter() { - let poem = Poem::read("sleep 2 && ls -la".to_string()); + let poem = Poem::read("sleep 2 && ls -la".to_string(), &Environment::new()); assert!(poem.is_ok()); let poem = poem.unwrap(); assert_eq!(poem.first().unwrap().verb(), "sleep"); @@ -53,7 +54,7 @@ mod tests { #[test] fn it_parses_a_verse_with_the_continue_meter() { - let poem = Poem::read("sleep 2; ls -la".to_string()); + let poem = Poem::read("sleep 2; ls -la".to_string(), &Environment::new()); assert!(poem.is_ok()); let poem = poem.unwrap(); assert_eq!(poem.first().unwrap().verb(), "sleep"); @@ -62,7 +63,7 @@ mod tests { #[test] fn it_parses_a_verse_with_the_read_rune() { - let poem = Poem::read("lolcat < src/main.rs".to_string()); + let poem = Poem::read("lolcat < src/main.rs".to_string(), &Environment::new()); assert!(poem.is_ok()); let mut verses = poem.unwrap().into_iter(); let verse = verses.next().unwrap(); @@ -78,7 +79,10 @@ mod tests { #[test] fn it_parses_a_verse_with_the_write_rune() { - let poem = Poem::read("cat src/main.rs > /dev/null".to_string()); + let poem = Poem::read( + "cat src/main.rs > /dev/null".to_string(), + &Environment::new(), + ); assert!(poem.is_ok()); let mut verses = poem.unwrap().into_iter(); let verse = verses.next().unwrap(); @@ -94,7 +98,10 @@ mod tests { #[test] fn it_parses_a_verse_with_the_addendum_rune() { - let poem = Poem::read("cat src/main.rs >> /dev/null".to_string()); + let poem = Poem::read( + "cat src/main.rs >> /dev/null".to_string(), + &Environment::new(), + ); assert!(poem.is_ok()); let mut verses = poem.unwrap().into_iter(); let verse = verses.next().unwrap(); @@ -110,37 +117,40 @@ mod tests { #[test] fn it_throws_a_parse_error_if_no_files_are_specified_for_the_read_rune() { - let poem = Poem::read("lolcat <".to_string()); + let poem = Poem::read("lolcat <".to_string(), &Environment::new()); assert!(poem.is_err()); - let poem = Poem::read("lolcat <;".to_string()); + let poem = Poem::read("lolcat <;".to_string(), &Environment::new()); assert!(poem.is_err()); - let poem = Poem::read("lolcat < && ls -la".to_string()); + let poem = Poem::read("lolcat < && ls -la".to_string(), &Environment::new()); assert!(poem.is_err()); } #[test] 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()); + let poem = Poem::read("cat src/main.rs >".to_string(), &Environment::new()); assert!(poem.is_err()); - let poem = Poem::read("cat src/main.rs >;".to_string()); + let poem = Poem::read("cat src/main.rs >;".to_string(), &Environment::new()); assert!(poem.is_err()); - let poem = Poem::read("cat > && ls -la".to_string()); + let poem = Poem::read("cat > && ls -la".to_string(), &Environment::new()); assert!(poem.is_err()); } #[test] 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()); + let poem = Poem::read("cat src/main.rs >>".to_string(), &Environment::new()); assert!(poem.is_err()); - let poem = Poem::read("cat src/main.rs >>;".to_string()); + let poem = Poem::read("cat src/main.rs >>;".to_string(), &Environment::new()); assert!(poem.is_err()); - let poem = Poem::read("cat >> && ls -la".to_string()); + let poem = Poem::read("cat >> && ls -la".to_string(), &Environment::new()); assert!(poem.is_err()); } #[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()); + let poem = Poem::read( + "ls -la | lolcat && echo hello | lolcat && sleep 2 &".to_string(), + &Environment::new(), + ); assert!(poem.is_ok()); let mut verses = poem.unwrap().into_iter(); @@ -170,25 +180,25 @@ mod tests { #[test] fn it_parses_the_continue_meter_without_a_stanza() { - let poem = Poem::read(";;;;;;;".to_string()); + let poem = Poem::read(";;;;;;;".to_string(), &Environment::new()); assert!(poem.is_ok()); } #[test] fn it_errors_if_the_couplet_meter_is_used_without_a_stanza() { - let poem = Poem::read("|".to_string()); + let poem = Poem::read("|".to_string(), &Environment::new()); assert!(poem.is_err()); } #[test] fn it_errors_if_the_quiet_meter_is_used_without_a_stanza() { - let poem = Poem::read("&".to_string()); + let poem = Poem::read("&".to_string(), &Environment::new()); assert!(poem.is_err()); } #[test] fn it_errors_if_the_and_meter_is_used_without_a_stanza() { - let poem = Poem::read("&&".to_string()); + let poem = Poem::read("&&".to_string(), &Environment::new()); assert!(poem.is_err()); } @@ -199,7 +209,7 @@ mod tests { sleep 2 "; - let poem = Poem::read(file.to_string()); + let poem = Poem::read(file.to_string(), &Environment::new()); assert!(poem.is_ok()); let poem = poem.unwrap(); @@ -239,7 +249,7 @@ mod tests { wc -l src/**/*.rs | lolcat; ls -la | grep git "; - let poem = Poem::read(file.to_string()); + let poem = Poem::read(file.to_string(), &Environment::new()); assert!(poem.is_ok()); let poem = poem.unwrap(); @@ -249,36 +259,36 @@ mod tests { #[test] fn it_catches_parser_errors_related_to_invalid_use_of_special_runes() { let poetry = "cat file.txt &&&".to_string(); - assert_eq!(Poem::read(poetry).is_err(), true); + assert_eq!(Poem::read(poetry, &Environment::new()).is_err(), true); let poetry = "cat file.txt&&|".to_string(); - assert_eq!(Poem::read(poetry).is_err(), true); + assert_eq!(Poem::read(poetry, &Environment::new()).is_err(), true); let poetry = "cat <".to_string(); - assert_eq!(Poem::read(poetry).is_err(), true); + assert_eq!(Poem::read(poetry, &Environment::new()).is_err(), true); } #[test] fn it_catches_parser_errors_related_to_strings() { let poetry = "echo 'hello".to_string(); - assert_eq!(Poem::read(poetry).is_err(), true); + assert_eq!(Poem::read(poetry, &Environment::new()).is_err(), true); let poetry = "echo \"hello".to_string(); - assert_eq!(Poem::read(poetry).is_err(), true); + assert_eq!(Poem::read(poetry, &Environment::new()).is_err(), true); let poetry = "`true".to_string(); - assert_eq!(Poem::read(poetry).is_err(), true); + assert_eq!(Poem::read(poetry, &Environment::new()).is_err(), true); } #[test] fn it_interprets_tilda_as_home() { let poetry = "cd ~".to_string(); - let poem = Poem::read(poetry).unwrap(); + let poem = Poem::read(poetry, &Environment::new()).unwrap(); assert_eq!(poem[0].verb(), "cd"); assert_eq!(poem[0].clause(), Some(vec![env!("HOME").to_string()])); let poetry = "cd ~/Code/dwarvish".to_string(); - let poem = Poem::read(poetry).unwrap(); + let poem = Poem::read(poetry, &Environment::new()).unwrap(); assert_eq!(poem[0].verb(), "cd"); assert_eq!( poem[0].clause(), |