refactor tests a little bit to be more standardised and make tests that should panic more obviously tests that should panic

This commit is contained in:
abbie 2024-01-19 00:38:54 +00:00
parent 292f64144b
commit 06aa0d275c
Signed by: threeoh6000
GPG key ID: 801FE4AD456E922C
3 changed files with 13 additions and 10 deletions

2
Cargo.lock generated
View file

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

View file

@ -1,6 +1,6 @@
[package] [package]
name = "frostwalker" name = "frostwalker"
version = "0.0.8" version = "0.0.9"
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

@ -47,6 +47,7 @@ fn single_key_array() {
} }
#[test] #[test]
#[should_panic]
fn double_array() { fn double_array() {
let id = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) }; let id = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) };
let op = Token { class: Class::EQUALS, value: None }; let op = Token { class: Class::EQUALS, value: None };
@ -59,7 +60,7 @@ fn double_array() {
let t5 = Token { class: Class::SEPARATOR, value: Some("]".to_string()) }; let t5 = Token { class: Class::SEPARATOR, value: Some("]".to_string()) };
let result = validator::validate(&vec![id, op, t1, strn, t2, t4, strn2, t3, t5]); let result = validator::validate(&vec![id, op, t1, strn, t2, t4, strn2, t3, t5]);
assert_eq!(result.unwrap_or("".to_string()), "SEPARATOR [ found where LITERAL expected at line 1."); assert_eq!(result.is_none(), true);
} }
#[test] #[test]
@ -83,27 +84,28 @@ fn long_array() {
} }
#[test] #[test]
#[should_panic]
fn stray_element_with_no_value() { fn stray_element_with_no_value() {
let t1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) }; let t1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) };
let t2 = Token { class: Class::EQUALS, value: None }; let t2 = Token { class: Class::EQUALS, value: None };
let t4 = Token { class: Class::EQUALS, value: None }; let result = validator::validate(&vec![t1, t2]);
let t3 = Token { class: Class::LITERAL, value: Some("10".to_string()) };
let result = validator::validate(&vec![t1, t2, t4, t3]);
assert_eq!(result.unwrap_or("".to_string()), "EQUALS found where LITERALORSEPARATOR expected at line 1.".to_string()); assert_eq!(result.is_none(), true);
} }
#[test] #[test]
#[should_panic]
fn unknown_element() { fn unknown_element() {
let t1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) }; let t1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) };
let t4 = Token { class: Class::EQUALS, value: None }; let t4 = Token { class: Class::EQUALS, value: None };
let t3 = Token { class: Class::UNKNOWN, value: Some("10".to_string()) }; let t3 = Token { class: Class::UNKNOWN, value: Some("10".to_string()) };
let result = validator::validate(&vec![t1, t4, t3]); let result = validator::validate(&vec![t1, t4, t3]);
assert_eq!(result.unwrap_or("".to_string()), "UNKNOWN 10 found where LITERALORSEPARATOR expected at line 1.".to_string()); assert_eq!(result.is_none(), true);
} }
#[test] #[test]
#[should_panic]
fn stray_element_with_no_value_on_newline() { fn stray_element_with_no_value_on_newline() {
let at1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) }; let at1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) };
let at2 = Token { class: Class::EQUALS, value: None }; let at2 = Token { class: Class::EQUALS, value: None };
@ -115,7 +117,7 @@ fn stray_element_with_no_value_on_newline() {
let t3 = Token { class: Class::LITERAL, value: Some("11".to_string()) }; let t3 = Token { class: Class::LITERAL, value: Some("11".to_string()) };
let result = validator::validate(&vec![at1, at2, at3, nl, t1, t2, t4, t3]); let result = validator::validate(&vec![at1, at2, at3, nl, t1, t2, t4, t3]);
assert_eq!(result.unwrap_or("".to_string()), "EQUALS found where LITERALORSEPARATOR expected at line 2.".to_string()); assert_eq!(result.is_none(), true);
} }
#[test] #[test]
@ -133,6 +135,7 @@ fn triple_key() {
} }
#[test] #[test]
#[should_panic]
fn triple_key_no_newline() { fn triple_key_no_newline() {
let t1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) }; let t1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) };
let t2 = Token { class: Class::EQUALS, value: None }; let t2 = Token { class: Class::EQUALS, value: None };
@ -142,5 +145,5 @@ fn triple_key_no_newline() {
let t6 = Token { class: Class::LITERAL, value: Some("13".to_string()) }; let t6 = Token { class: Class::LITERAL, value: Some("13".to_string()) };
let result = validator::validate(&vec![t1, t2, t3, t4, t5, t6]); let result = validator::validate(&vec![t1, t2, t3, t4, t5, t6]);
assert_eq!(result.unwrap_or("".to_string()), "IDENTIFIER key2 found where NEWLINE expected at line 1.".to_string()); assert_eq!(result.is_none(), true);
} }