Skip to content

Commit

Permalink
new line edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
malta895 committed Sep 8, 2024
1 parent 9a74f8e commit 986d06b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ pub fn lex<R: BufRead>(mut reader: R) -> Result<Vec<Token>, JSONError> {
('\n', State::Normal) => {
tokens.push(Token::NewLine);
}
('\n', State::ValueNumber) => {
state = State::Normal;
tokens.push(Token::Number);
tokens.push(Token::NewLine);
}

(':', State::Normal) => {
tokens.push(Token::Column);
Expand Down Expand Up @@ -342,6 +347,23 @@ mod lexer_tests {
)
}

#[test]
fn should_lex_a_number_before_new_line() {
run_test_case_with(
"{ \"key\": 123456789\n}",
Vec::from([
Token::OpenBrace,
Token::DoubleQuotes,
Token::StringLiteral("key".to_string()),
Token::DoubleQuotes,
Token::Column,
Token::Number,
Token::NewLine,
Token::ClosedBrace,
]),
)
}

#[test]
fn should_lex_a_number_before_comma() {
run_test_case_with(
Expand Down Expand Up @@ -382,6 +404,23 @@ mod lexer_tests {
)
}

#[test]
fn should_lex_true_before_new_line() {
run_test_case_with(
"{ \"key\": true\n}",
Vec::from([
Token::OpenBrace,
Token::DoubleQuotes,
Token::StringLiteral("key".to_string()),
Token::DoubleQuotes,
Token::Column,
Token::BoolTrue,
Token::NewLine,
Token::ClosedBrace,
]),
)
}

#[test]
fn should_lex_true_before_comma() {
run_test_case_with(
Expand Down

0 comments on commit 986d06b

Please sign in to comment.