Skip to content

Commit

Permalink
test only mod
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodesdev committed Jun 7, 2024
1 parent e01c1e4 commit d7e6fed
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions challenges/declaring-variables/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
use declaring_variables::*;
use syntest::{Syntest, Value};
#[cfg(test)]
mod tests {
use declaring_variables::*;
use syntest::{Syntest, Value};

#[test]
fn test_calculate_area() {
assert_eq!(calculate_area(), 50);
}
#[test]
fn test_calculate_area() {
assert_eq!(calculate_area(), 50);
}

#[test]
fn test_variables() {
let syntest = Syntest::from("./src/lib.rs");
#[test]
fn test_variables() {
let syntest = Syntest::from("./src/lib.rs");

// Expect the 2 variables to exist
let variables_to_exist = ["height", "width"];
variables_to_exist.iter().for_each(|&v| {
let var = syntest
.var_details("calculate_area", v)
.expect(&format!("Variable {} was not declared", v));
// Expect the 2 variables to exist
let variables_to_exist = ["height", "width"];
variables_to_exist.iter().for_each(|&v| {
let var = syntest
.var_details("calculate_area", v)
.expect(&format!("Variable {} was not declared", v));

assert!(var.is_used(), "Variable {v} was not used");
assert_eq!(var.name(), v);
assert!(var.is_used(), "Variable {v} was not used");
assert_eq!(var.name(), v);

if v == "width" {
assert_eq!(var.value(), Value::Int(10), "Width should be 10");
} else if v == "height" {
assert_eq!(var.value(), Value::Int(5), "Height should be 5");
}
});
if v == "width" {
assert_eq!(var.value(), Value::Int(10), "Width should be 10");
} else if v == "height" {
assert_eq!(var.value(), Value::Int(5), "Height should be 5");
}
});
}
}

0 comments on commit d7e6fed

Please sign in to comment.