Charlotte Meyer
fbba44312f
Before it would escape the newline resulting in passing it as an argument. Signed-off-by: Charlotte Meyer <dev@buffet.sh>
155 lines
2.6 KiB
Rust
155 lines
2.6 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);
|
|
}
|
|
|
|
#[test]
|
|
fn escape_newline() {
|
|
let source = "\\\n";
|
|
|
|
let actual = Lexer::new(source).next_command_token();
|
|
|
|
assert_snapshot!(actual);
|
|
}
|