Skip to content

Commit

Permalink
feat(parser): made tokenizer Err on empty long name literal
Browse files Browse the repository at this point in the history
E.g. `a && {}`. Tests included.
  • Loading branch information
AurumTheEnd committed Mar 8, 2024
1 parent 0fae7a2 commit 978cbaf
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/parser/tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ fn tokenize_level(
if !did_hit_closing_brace {
return Err(TokenizeError::MissingClosingCurlyBrace);
}
if literal_buffer.is_empty() {
return Err(TokenizeError::EmptyLiteralName);
}

// TODO return TokenizeError if builder is empty at the end
(FinalToken::Literal(literal_buffer), 0)
Expand Down Expand Up @@ -190,7 +193,8 @@ mod tests {
use super::FinalToken::*;
use super::*;
use crate::parser::error::TokenizeError::{
MissingClosingCurlyBrace, UnexpectedClosingCurlyBrace, UnexpectedClosingParenthesis,
EmptyLiteralName, MissingClosingCurlyBrace, UnexpectedClosingCurlyBrace,
UnexpectedClosingParenthesis,
};

#[test]
Expand Down Expand Up @@ -705,6 +709,26 @@ mod tests {
Ok(())
}

#[test]
fn test_brace_ok() -> Result<(), TokenizeError> {
let actual = tokenize("{abc&&}")?;
let expected = vec![Literal("abc&&".to_string())];

assert_eq!(actual, expected);

Ok(())
}

#[test]
fn test_brace_empty_nok() -> Result<(), TokenizeError> {
let actual = tokenize("{}");

assert!(actual.is_err());
assert_eq!(actual.unwrap_err(), EmptyLiteralName);

Ok(())
}

#[test]
fn test_operator_boundary_andword_space_charvar_ok() -> Result<(), TokenizeError> {
let actual = tokenize("a and b")?;
Expand Down

0 comments on commit 978cbaf

Please sign in to comment.