Skip to content

Commit

Permalink
adding string comparison pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhibas committed Feb 13, 2024
1 parent 60428aa commit 2c9812d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bool_expr_parser_nom"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
authors = ["Nikolajus Krauklis <[email protected]>"]

Expand Down
27 changes: 26 additions & 1 deletion src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod tests {
use super::*;

#[test]
fn test_basic_eval() {
fn test_comparison_expr_eval() {
let context = HashMap::from([
("a", Atom::Number(3)),
("b", Atom::String("demo".to_string())),
Expand Down Expand Up @@ -70,4 +70,29 @@ mod tests {
assert_eq!(eval(&parse("a==4").unwrap().1, &context).unwrap(), false);
assert_eq!(eval(&parse("a==3").unwrap().1, &context).unwrap(), true);
}
#[test]
fn test_compare_string_expr_eval() {
assert_eq!(
eval(
&parse("car!='Tesla'").unwrap().1,
&HashMap::from([("car", Atom::String("BMW".into()))])
)
.unwrap(),
true
);
assert_eq!(
eval(
&parse("car=='Tesla'").unwrap().1,
&HashMap::from([("car", Atom::String("Tesla".into()))])
)
.unwrap(),
true
);
}

#[test]
fn test_logic_expr_eval() {

// assert_eq!(eval(&parse("a>4 and b<3").unwrap().1, &HashMap::from([])).unwrap(), true);
}
}

0 comments on commit 2c9812d

Please sign in to comment.