oysh/crates/oyster_parser/tests/it/lexer.rs

156 lines
2.6 KiB
Rust
Raw Normal View History

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);
}
#[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);
}