formatter can now do booleans and also more tests
This commit is contained in:
parent
8e191ee11a
commit
292f64144b
5 changed files with 16 additions and 4 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -4,4 +4,4 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "frostwalker"
|
||||
version = "0.0.7"
|
||||
version = "0.0.8"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "frostwalker"
|
||||
version = "0.0.7"
|
||||
version = "0.0.8"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -13,7 +13,7 @@ pub fn format(tree: Vec<Token>) -> HashMap<String, String> {
|
|||
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()));
|
||||
current_key = "".to_string();
|
||||
i = i + 1;
|
||||
|
|
|
@ -10,7 +10,6 @@ pub fn tokenize(source: &str) -> Vec<Token> {
|
|||
let mut tree: Vec<Token> = vec![];
|
||||
|
||||
for line in lines {
|
||||
println!("{}", line);
|
||||
let mut added = false;
|
||||
let mut words: Vec<&str> = line.split(" ").collect();
|
||||
let mut i = 0;
|
||||
|
|
|
@ -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]
|
||||
fn full_stack_varied_array() {
|
||||
let tree = lexer::tokenize("key = [ \"value\", 150, -30, \"\\\"value\" ]");
|
||||
|
|
Loading…
Reference in a new issue