formatter can now do booleans and also more tests

This commit is contained in:
abbie 2024-01-19 00:32:58 +00:00
parent 8e191ee11a
commit 292f64144b
Signed by: threeoh6000
GPG key ID: 801FE4AD456E922C
5 changed files with 16 additions and 4 deletions

2
Cargo.lock generated
View file

@ -4,4 +4,4 @@ version = 3
[[package]] [[package]]
name = "frostwalker" name = "frostwalker"
version = "0.0.7" version = "0.0.8"

View file

@ -1,6 +1,6 @@
[package] [package]
name = "frostwalker" name = "frostwalker"
version = "0.0.7" version = "0.0.8"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -13,7 +13,7 @@ pub fn format(tree: Vec<Token>) -> HashMap<String, String> {
continue; continue;
} }
if tree[i].class == Class::LITERAL && current_key != "".to_string() { if (tree[i].class == Class::LITERAL || tree[i].class == Class::BOOLEAN) && current_key != "".to_string() {
output.insert(current_key, tree[i].value.clone().unwrap_or("".to_string())); output.insert(current_key, tree[i].value.clone().unwrap_or("".to_string()));
current_key = "".to_string(); current_key = "".to_string();
i = i + 1; i = i + 1;

View file

@ -10,7 +10,6 @@ pub fn tokenize(source: &str) -> Vec<Token> {
let mut tree: Vec<Token> = vec![]; let mut tree: Vec<Token> = vec![];
for line in lines { for line in lines {
println!("{}", line);
let mut added = false; let mut added = false;
let mut words: Vec<&str> = line.split(" ").collect(); let mut words: Vec<&str> = line.split(" ").collect();
let mut i = 0; let mut i = 0;

View file

@ -45,6 +45,19 @@ fn full_stack_single_key() {
} }
} }
#[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.");
}
}
#[test] #[test]
fn full_stack_varied_array() { fn full_stack_varied_array() {
let tree = lexer::tokenize("key = [ \"value\", 150, -30, \"\\\"value\" ]"); let tree = lexer::tokenize("key = [ \"value\", 150, -30, \"\\\"value\" ]");