2024-01-19 00:07:59 +00:00
|
|
|
use frostwalker::lexer;
|
2024-01-17 21:03:41 +00:00
|
|
|
use frostwalker::validator;
|
2024-01-19 00:26:05 +00:00
|
|
|
use frostwalker::formatter;
|
2024-01-17 21:03:41 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lv_single_key() {
|
|
|
|
let tree = lexer::tokenize("key = \"value\"");
|
|
|
|
let result = validator::validate(&tree);
|
|
|
|
assert_eq!(result.is_none(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lv_triple_key() {
|
|
|
|
let tree = lexer::tokenize("key = \"value\"\r\nkey1 = 128\nkey2 = [ 6, 7 ]");
|
|
|
|
let result = validator::validate(&tree);
|
|
|
|
assert_eq!(result.is_none(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-01-19 00:26:05 +00:00
|
|
|
#[should_panic]
|
2024-01-17 21:03:41 +00:00
|
|
|
fn lv_triple_key_missing_newline() {
|
|
|
|
let tree = lexer::tokenize("key = \"value\"key1 = 128\nkey2 = [ 6, 7 ]");
|
|
|
|
let result = validator::validate(&tree);
|
2024-01-19 00:26:05 +00:00
|
|
|
assert_eq!(result.is_none(), true);
|
2024-01-17 21:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-01-19 00:26:05 +00:00
|
|
|
#[should_panic]
|
2024-01-17 21:03:41 +00:00
|
|
|
fn lv_double_equals() {
|
|
|
|
let tree = lexer::tokenize("key = = \"value\"\r\nkey1 = 128\nkey2 = [ 6, 7 ]");
|
|
|
|
let result = validator::validate(&tree);
|
2024-01-19 00:26:05 +00:00
|
|
|
assert_eq!(result.is_none(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn full_stack_single_key() {
|
|
|
|
let tree = lexer::tokenize("key = \"value\"");
|
|
|
|
let result = validator::validate(&tree);
|
|
|
|
if result.is_some() {
|
|
|
|
panic!("{}", result.unwrap());
|
|
|
|
}
|
|
|
|
let hashmap = formatter::format(tree);
|
|
|
|
if !(hashmap.get("key").unwrap() == "value") {
|
|
|
|
panic!("Formatter error.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-19 00:32:58 +00:00
|
|
|
#[test]
|
|
|
|
fn full_stack_boolean() {
|
|
|
|
let tree = lexer::tokenize("key = true\r\nkey2 = false");
|
|
|
|
let result = validator::validate(&tree);
|
|
|
|
if result.is_some() {
|
|
|
|
panic!("{}", result.unwrap());
|
|
|
|
}
|
|
|
|
let hashmap = formatter::format(tree);
|
|
|
|
if !(hashmap.get("key").unwrap() == "true") || !(hashmap.get("key2").unwrap() == "false") {
|
|
|
|
panic!("Formatter error.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-19 00:26:05 +00:00
|
|
|
#[test]
|
|
|
|
fn full_stack_varied_array() {
|
|
|
|
let tree = lexer::tokenize("key = [ \"value\", 150, -30, \"\\\"value\" ]");
|
|
|
|
let result = validator::validate(&tree);
|
|
|
|
if result.is_some() {
|
|
|
|
panic!("{}", result.unwrap());
|
|
|
|
}
|
|
|
|
let hashmap = formatter::format(tree);
|
|
|
|
if !(hashmap.get("key").unwrap() == "4") || !(hashmap.get("key[0]").unwrap() == "value") || !(hashmap.get("key[1]").unwrap() == "150") || !(hashmap.get("key[2]").unwrap() == "-30") || !(hashmap.get("key[3]").unwrap() == "\"value") {
|
|
|
|
panic!("Formatter error.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn full_stack_single_key_double_equals() {
|
|
|
|
let tree = lexer::tokenize("key = = \"value\"");
|
|
|
|
let result = validator::validate(&tree);
|
|
|
|
if result.is_some() {
|
|
|
|
panic!("{}", result.unwrap());
|
|
|
|
}
|
|
|
|
let hashmap = formatter::format(tree);
|
|
|
|
if !(hashmap.get("key").unwrap() == "value") {
|
|
|
|
panic!("Formatter error.");
|
|
|
|
}
|
2024-01-17 21:03:41 +00:00
|
|
|
}
|