From 975268081d85ab6b9b6a5068bb8f83c81e1556e3 Mon Sep 17 00:00:00 2001 From: Vladislav Veselinov Date: Wed, 22 Mar 2023 14:48:57 +0000 Subject: [PATCH 1/3] add invalid value test --- tests/test_invalid_input.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/test_invalid_input.rs diff --git a/tests/test_invalid_input.rs b/tests/test_invalid_input.rs new file mode 100644 index 00000000..53f67a1b --- /dev/null +++ b/tests/test_invalid_input.rs @@ -0,0 +1,22 @@ +use lightningcss::{ + error::{Error, ParserError}, + stylesheet::{ParserOptions, StyleSheet}, +}; + +#[test] +fn invalid_hsla_value() { + let input = r#" + .corrupt { + color: hsla(120, 62.32%; + } + "#; + + let parsed = StyleSheet::parse(input, ParserOptions::default()).unwrap_err(); + + let expected = Error { + kind: ParserError::InvalidValue, + loc: None + }; + + assert_eq!(parsed.to_string(), expected.to_string()); +} From 1d659e15a3cc9f746e5e3d17cc3632e3d03ecb59 Mon Sep 17 00:00:00 2001 From: Vladislav Veselinov Date: Wed, 22 Mar 2023 14:55:47 +0000 Subject: [PATCH 2/3] add error location --- tests/test_invalid_input.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test_invalid_input.rs b/tests/test_invalid_input.rs index 53f67a1b..e3513882 100644 --- a/tests/test_invalid_input.rs +++ b/tests/test_invalid_input.rs @@ -1,5 +1,6 @@ use lightningcss::{ - error::{Error, ParserError}, + error::{Error, ErrorLocation, ParserError}, + rules::Location, stylesheet::{ParserOptions, StyleSheet}, }; @@ -15,7 +16,14 @@ fn invalid_hsla_value() { let expected = Error { kind: ParserError::InvalidValue, - loc: None + loc: Some(ErrorLocation::new( + Location { + line: 0, + column: 23, + source_index: 0, + }, + "".to_string(), + )), }; assert_eq!(parsed.to_string(), expected.to_string()); From 6abbf27d234af8b0fd5cd25d8f8f184418c72d47 Mon Sep 17 00:00:00 2001 From: Vladislav Veselinov Date: Wed, 22 Mar 2023 14:57:06 +0000 Subject: [PATCH 3/3] rename test --- tests/test_invalid_input.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_invalid_input.rs b/tests/test_invalid_input.rs index e3513882..465e2e25 100644 --- a/tests/test_invalid_input.rs +++ b/tests/test_invalid_input.rs @@ -5,7 +5,7 @@ use lightningcss::{ }; #[test] -fn invalid_hsla_value() { +fn value_missing_closing_brace() { let input = r#" .corrupt { color: hsla(120, 62.32%;