2024-01-06 10:29:38 +00:00
|
|
|
use dust_lang::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn format_simple_program() {
|
|
|
|
let mut interpreter = Interpreter::new(Map::new());
|
|
|
|
|
|
|
|
interpreter.run("x=1").unwrap();
|
|
|
|
|
|
|
|
assert_eq!(interpreter.format(), "x = 1");
|
|
|
|
}
|
|
|
|
|
|
|
|
const FORMATTED_BLOCK: &str = "{
|
|
|
|
1
|
|
|
|
2
|
|
|
|
3
|
2024-01-06 13:53:31 +00:00
|
|
|
}";
|
2024-01-06 10:29:38 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn format_block() {
|
|
|
|
let mut interpreter = Interpreter::new(Map::new());
|
|
|
|
|
|
|
|
interpreter.run("{1 2 3}").unwrap();
|
|
|
|
|
|
|
|
assert_eq!(FORMATTED_BLOCK, interpreter.format());
|
|
|
|
}
|
|
|
|
|
2024-01-06 13:53:31 +00:00
|
|
|
const FORMATTED_NESTED_BLOCK: &str = "{
|
|
|
|
{
|
|
|
|
x = 1
|
|
|
|
}
|
|
|
|
}";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn format_nested_block() {
|
|
|
|
let mut interpreter = Interpreter::new(Map::new());
|
|
|
|
|
|
|
|
interpreter.run("{{x=1}}").unwrap();
|
|
|
|
|
|
|
|
assert_eq!(FORMATTED_NESTED_BLOCK, interpreter.format());
|
|
|
|
}
|
|
|
|
|
2024-01-06 10:29:38 +00:00
|
|
|
const FORMATTED_FUNCTION: &str = "(x <int>) <num> {
|
|
|
|
x / 2
|
2024-01-06 13:53:31 +00:00
|
|
|
}";
|
2024-01-06 10:29:38 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn format_function() {
|
|
|
|
let mut interpreter = Interpreter::new(Map::new());
|
|
|
|
|
|
|
|
interpreter.run("( x< int > )<num>{x/2}").unwrap();
|
|
|
|
|
|
|
|
assert_eq!(FORMATTED_FUNCTION, interpreter.format());
|
|
|
|
}
|