oysh/crates/oyster_parser/tests/it/lexer.rs
Charlotte Meyer 4e1a835ddc feat: add command substitutions with ()
This requires PreparedCommand's to work with OsStrings rather than
Strings.

Acked-by: cpli
Acked-by: ElKowar
2022-10-28 08:12:25 +00:00

146 lines
2.4 KiB
Rust

use insta::assert_debug_snapshot as assert_snapshot;
use oyster_parser::Lexer;
#[test]
fn eof() {
let source = "";
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn whitespace() {
let source = " \t \t\t";
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn newlines() {
let source = "\n\n\n";
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn semicolon() {
let source = ";";
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn pipe() {
let source = "|";
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn plain_word() {
let source = "whoami";
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn word_with_hash() {
let source = "nixpkgs#hello";
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn escaped_hash() {
let source = r"\#";
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn comment() {
let source = "# hey";
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn double_quotes_in_command() {
let source = r#"""#;
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn double_quotes_in_string() {
let source = r#"""#;
let actual = Lexer::new(source).next_string_token();
assert_snapshot!(actual);
}
#[test]
fn escaped_quotes_in_string() {
let source = r#"\""#;
let actual = Lexer::new(source).next_string_token();
assert_snapshot!(actual);
}
#[test]
fn opening_parenthesis_command_mode() {
let source = r"(";
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn closing_parenthesis_command_mode() {
let source = r")";
let actual = Lexer::new(source).next_command_token();
assert_snapshot!(actual);
}
#[test]
fn opening_parenthesis_string_mode() {
let source = r"(";
let actual = Lexer::new(source).next_string_token();
assert_snapshot!(actual);
}
#[test]
fn closing_parenthesis_string_mode() {
let source = r")";
let actual = Lexer::new(source).next_string_token();
assert_snapshot!(actual);
}