Skip to content

Commit

Permalink
add tests for tilde operator
Browse files Browse the repository at this point in the history
  • Loading branch information
letmutx committed Oct 24, 2019
1 parent dafa9cf commit 6f77842
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/lib/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,4 +760,42 @@ mod tests {
"#;
assert_eq!(exec(non_num_key_wont_affect_length), String::from("3"));
}

#[test]
fn test_tilde_operator() {
let float = r#"
let f = -1.2;
~f
"#;
assert_eq!(exec(float), String::from("0"));

let numeric = r#"
let f = 1789;
~f
"#;
assert_eq!(exec(numeric), String::from("-1790"));

// TODO: enable test after we have NaN
// let nan = r#"
// var m = NaN;
// ~m
// "#;
// assert_eq!(exec(nan), String::from("-1"));

let object = r#"
let m = {};
~m
"#;
assert_eq!(exec(object), String::from("-1"));

let boolean_true = r#"
~true
"#;
assert_eq!(exec(boolean_true), String::from("-2"));

let boolean_false = r#"
~false
"#;
assert_eq!(exec(boolean_false), String::from("-1"));
}
}

0 comments on commit 6f77842

Please sign in to comment.