datex-core 0.0.13

The DATEX Core Rust implementation
Documentation
/// Runtime execution tests that validate that values are consistent through
/// the compile and execution process.
/// Any value passed as input should be returned exactly as it was passed in after compilation and execution.
use datex_core::values::{
    core_values::{
        decimal::{Decimal, typed_decimal::TypedDecimal},
        integer::{Integer, typed_integer::TypedInteger},
        list::List,
        map::Map,
    },
    value_container::ValueContainer,
};

use crate::execution::compile_and_execute;

#[test]
fn compile_and_execute_integer() {
    let input = ValueContainer::from(Integer::from(42));
    let result = compile_and_execute(input.clone());
    assert_eq!(result, input);
}

#[test]
fn compile_and_execute_typed_integer() {
    let input = ValueContainer::from(TypedInteger::U8(42));
    let result = compile_and_execute(input.clone());
    assert_eq!(result, input);
}

#[test]
fn compile_and_execute_typed_decimals() {
    let input = ValueContainer::from(TypedDecimal::F32(42f32.into()));
    let result = compile_and_execute(input.clone());
    assert_eq!(result, input);

    let input = ValueContainer::from(TypedDecimal::F32(f32::INFINITY.into()));
    let result = compile_and_execute(input.clone());
    assert_eq!(result, input);

    let input = ValueContainer::from(TypedDecimal::F32(f32::NAN.into()));
    let result = compile_and_execute(input.clone());
    assert_eq!(result, input);

    let input = ValueContainer::from(TypedDecimal::Decimal(Decimal::Infinity));
    let result = compile_and_execute(input.clone());
    assert_eq!(result, input);

    let input = ValueContainer::from(TypedDecimal::Decimal(Decimal::Nan));
    let result = compile_and_execute(input.clone());
    assert_eq!(result, input);
}

#[test]
fn compile_and_execute_string() {
    let input = ValueContainer::from("Hello, World!".to_string());
    let result = compile_and_execute(input.clone());
    assert_eq!(result, input);
}

#[test]
fn compile_and_execute_bool() {
    let input = ValueContainer::from(true);
    let result = compile_and_execute(input.clone());
    assert_eq!(result, input);
}

#[test]
fn compile_and_execute_list() {
    let input = ValueContainer::from(List::new(vec![
        ValueContainer::from(Integer::from(1)),
        ValueContainer::from(Integer::from(2)),
        ValueContainer::from(Integer::from(3)),
    ]));
    let result = compile_and_execute(input.clone());
    assert_eq!(result, input);
}

#[test]
fn compile_and_execute_map() {
    let input = ValueContainer::from(Map::new_structural(vec![
        ("key1".into(), ValueContainer::from(Integer::from(1))),
        ("key2".into(), ValueContainer::from("value".to_string())),
        ("key3".into(), ValueContainer::from(true)),
    ]));
    let result = compile_and_execute(input.clone());
    assert_eq!(result, input);
}