2022-07-14 22:26:57 +00:00
|
|
|
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);
|
|
|
|
}
|
2022-09-24 17:17:56 +00:00
|
|
|
|
|
|
|
#[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);
|
|
|
|
}
|