Skip to content

Commit

Permalink
fix: Test organization
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Nov 26, 2024
1 parent 4670637 commit e846bf3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 75 deletions.
72 changes: 72 additions & 0 deletions lykiadb-lang/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,75 @@ impl Expr {
}
}
}

#[cfg(test)]
mod test {
use std::collections::HashSet;

use crate::{ast::expr::Expr, Literal, Span};

fn create_simple_add_expr(id: usize, left: f64, right: f64) -> Expr {
Expr::Binary {
left: Box::new(Expr::Literal {
value: Literal::Num(left),
span: Span::default(),
id: 0,
raw: left.to_string(),
}),
operation: crate::ast::expr::Operation::Add,
right: Box::new(Expr::Literal {
value: Literal::Num(right),
span: Span::default(),
id: 0,
raw: right.to_string(),
}),
span: Span::default(),
id,
}
}
#[test]
fn identical_exprs_should_be_equal_when_ids_are_different() {
let e0 = create_simple_add_expr(0, 1.0, 2.0);

let e1 = create_simple_add_expr(1, 1.0, 2.0);

assert_eq!(e0, e1);

let mut set: HashSet<Expr> = HashSet::new();

set.insert(e0);

assert!(set.contains(&e1));
}

#[test]
fn different_exprs_with_same_ids_should_not_be_equal() {
let e0 = create_simple_add_expr(1, 2.0, 3.0);

let e1 = create_simple_add_expr(1, 1.0, 2.0);

assert_ne!(e0, e1);

let mut set: HashSet<Expr> = HashSet::new();

set.insert(e0);

assert!(!set.contains(&e1));
}

#[test]
fn mirrored_exprs_should_not_be_equal() {
let e0 = create_simple_add_expr(0, 2.0, 1.0);

let e1 = create_simple_add_expr(1, 1.0, 2.0);

assert_ne!(e0, e1);

let mut set: HashSet<Expr> = HashSet::new();

set.insert(e0);

assert!(!set.contains(&e1));
}

}
2 changes: 1 addition & 1 deletion lykiadb-lang/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
fmt::{Display, Formatter, Result},
hash::Hash,
sync::Arc,
hash::Hash
};

use ast::expr::Expr;
Expand Down
73 changes: 0 additions & 73 deletions lykiadb-lang/tests/lang/generic/expr.rs

This file was deleted.

1 change: 0 additions & 1 deletion lykiadb-lang/tests/lang/generic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod array_literal;
pub mod binary;
pub mod expr;
pub mod function_call;
pub mod grouping;
pub mod loops;
Expand Down

0 comments on commit e846bf3

Please sign in to comment.