Skip to content

Commit

Permalink
feat(tests): added tests for parser and tokenizer of empty inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
AurumTheEnd committed Mar 8, 2024
1 parent bb19b5a commit ea6f94e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/parser/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,23 @@ fn priority_2_terminal(data: &[FinalToken]) -> Result<Expression<String>, ParseT
#[cfg(test)]
mod tests {
use crate::expressions::Expression::{Constant, Literal};
use crate::parser::error::ParseTokensError::EmptySideOfOperator;
use crate::parser::{tokenize, ParseError};
use crate::traits::SemanticEq;

use super::*;

#[test]
fn test_empty_nok() -> Result<(), ParseError> {
let input = tokenize("")?;
let actual = parse_tokens(&input);

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

Ok(())
}

#[test]
fn test_binaryand_ok() -> Result<(), ParseError> {
let input = tokenize("a & b")?;
Expand Down
10 changes: 10 additions & 0 deletions src/parser/tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ mod tests {

use super::*;

#[test]
fn test_empty_technicallyok() -> Result<(), TokenizeError> {
let input = "";

let actual = tokenize(input)?;
assert_eq!(actual, vec![]);

Ok(())
}

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

0 comments on commit ea6f94e

Please sign in to comment.