From 06aa0d275cb1462e435132544d3d16ba60161b54 Mon Sep 17 00:00:00 2001 From: threeoh6000 Date: Fri, 19 Jan 2024 00:38:54 +0000 Subject: [PATCH] refactor tests a little bit to be more standardised and make tests that should panic more obviously tests that should panic --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/validator_tests.rs | 19 +++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c07822..5d9101e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "frostwalker" -version = "0.0.8" +version = "0.0.9" diff --git a/Cargo.toml b/Cargo.toml index d8f4d0b..b44bd3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/validator_tests.rs b/src/validator_tests.rs index b460fbc..2f33433 100644 --- a/src/validator_tests.rs +++ b/src/validator_tests.rs @@ -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); }