1
0
dust/tests/format.rs

58 lines
997 B
Rust
Raw Permalink Normal View History

use dust_lang::*;
#[test]
fn format_simple_program() {
let mut interpreter = Interpreter::new(Map::new());
2024-01-30 23:13:30 +00:00
assert_eq!(interpreter.format("x=1"), Ok("x = 1\n".to_string()));
}
const FORMATTED_BLOCK: &str = "{
1
2
3
2024-01-06 15:40:25 +00:00
}
";
#[test]
fn format_block() {
let mut interpreter = Interpreter::new(Map::new());
2024-01-30 23:13:30 +00:00
assert_eq!(
interpreter.format("{1 2 3}"),
Ok(FORMATTED_BLOCK.to_string())
);
}
2024-01-06 15:40:25 +00:00
const FORMATTED_MAP: &str = "{
2024-01-06 13:53:31 +00:00
{
x = 1
2024-01-06 15:40:25 +00:00
y <int> = 2
2024-01-06 13:53:31 +00:00
}
2024-01-06 15:40:25 +00:00
}
";
2024-01-06 13:53:31 +00:00
#[test]
2024-01-06 15:40:25 +00:00
fn format_map() {
2024-01-06 13:53:31 +00:00
let mut interpreter = Interpreter::new(Map::new());
2024-01-30 23:13:30 +00:00
assert_eq!(
interpreter.format("{{x=1 y <int> = 2}}"),
Ok(FORMATTED_MAP.to_string())
);
2024-01-06 13:53:31 +00:00
}
const FORMATTED_FUNCTION: &str = "(x <int>) <num> {
x / 2
2024-01-06 15:40:25 +00:00
}
";
#[test]
fn format_function() {
let mut interpreter = Interpreter::new(Map::new());
2024-01-30 23:13:30 +00:00
assert_eq!(
interpreter.format("( x< int > )<num>{x/2}"),
Ok(FORMATTED_FUNCTION.to_string())
);
}