truecalc-core 7.1.1

Formula engine with exact Google Sheets semantics — stateless, embeddable evaluator
Documentation
use super::super::*;
use crate::types::Value;

#[test]
fn bool_to_number_true() {
    assert_eq!(to_number(Value::Bool(true)), Ok(1.0));
}

#[test]
fn bool_to_number_false() {
    assert_eq!(to_number(Value::Bool(false)), Ok(0.0));
}

#[test]
fn numeric_text_to_number() {
    assert_eq!(to_number(Value::Text("5".into())), Ok(5.0));
}

// Issue #842: arithmetic-context coercion (`to_number`) must accept the same
// strings VALUE() accepts — currency prefix, percent suffix, and
// surrounding whitespace.
#[test]
fn currency_text_to_number() {
    assert_eq!(to_number(Value::Text("$5".into())), Ok(5.0));
}

#[test]
fn percent_text_to_number() {
    assert_eq!(to_number(Value::Text("5%".into())), Ok(0.05));
}

#[test]
fn whitespace_padded_text_to_number() {
    assert_eq!(to_number(Value::Text("  5  ".into())), Ok(5.0));
}

#[test]
fn empty_to_number() {
    assert_eq!(to_number(Value::Empty), Ok(0.0));
}

#[test]
fn number_to_string() {
    assert_eq!(to_string_val(Value::Number(1.5)), Ok("1.5".to_string()));
    assert_eq!(to_string_val(Value::Number(0.1 + 0.2)), Ok("0.3".to_string()));
}

#[test]
fn bool_to_string_true() {
    assert_eq!(to_string_val(Value::Bool(true)), Ok("TRUE".to_string()));
}

#[test]
fn bool_to_string_false() {
    assert_eq!(to_string_val(Value::Bool(false)), Ok("FALSE".to_string()));
}

#[test]
fn empty_to_string() {
    assert_eq!(to_string_val(Value::Empty), Ok(String::new()));
}

#[test]
fn number_to_bool_nonzero() {
    assert_eq!(to_bool(Value::Number(1.0)), Ok(true));
}

#[test]
fn bool_passthrough() {
    assert_eq!(to_bool(Value::Bool(true)), Ok(true));
    assert_eq!(to_bool(Value::Bool(false)), Ok(false));
}