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:
parent
292f64144b
commit
06aa0d275c
3 changed files with 13 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -4,4 +4,4 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "frostwalker"
|
||||
version = "0.0.8"
|
||||
version = "0.0.9"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "frostwalker"
|
||||
version = "0.0.8"
|
||||
version = "0.0.9"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -47,6 +47,7 @@ fn single_key_array() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn double_array() {
|
||||
let id = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) };
|
||||
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 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]
|
||||
|
@ -83,27 +84,28 @@ fn long_array() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stray_element_with_no_value() {
|
||||
let t1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) };
|
||||
let t2 = Token { class: Class::EQUALS, value: None };
|
||||
let t4 = Token { class: Class::EQUALS, value: None };
|
||||
let t3 = Token { class: Class::LITERAL, value: Some("10".to_string()) };
|
||||
let result = validator::validate(&vec![t1, t2, t4, t3]);
|
||||
let result = validator::validate(&vec![t1, t2]);
|
||||
|
||||
assert_eq!(result.unwrap_or("".to_string()), "EQUALS found where LITERALORSEPARATOR expected at line 1.".to_string());
|
||||
assert_eq!(result.is_none(), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn unknown_element() {
|
||||
let t1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) };
|
||||
let t4 = Token { class: Class::EQUALS, value: None };
|
||||
let t3 = Token { class: Class::UNKNOWN, value: Some("10".to_string()) };
|
||||
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]
|
||||
#[should_panic]
|
||||
fn stray_element_with_no_value_on_newline() {
|
||||
let at1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) };
|
||||
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 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]
|
||||
|
@ -133,6 +135,7 @@ fn triple_key() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn triple_key_no_newline() {
|
||||
let t1 = Token { class: Class::IDENTIFIER, value: Some("key".to_string()) };
|
||||
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 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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue