diff --git a/src/common.rs b/src/common.rs index 62250f7..05f60d1 100644 --- a/src/common.rs +++ b/src/common.rs @@ -682,4 +682,4 @@ impl Display for Pos { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "line:{} col:{}", self.line, self.column) } -} \ No newline at end of file +} diff --git a/src/error.rs b/src/error.rs index 69ae29b..438aae6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -6,16 +6,22 @@ use std::io; #[derive(Debug)] pub struct SassError { message: String, - pos: Pos + pos: Pos, } impl SassError { pub fn new>(message: S, pos: Pos) -> Self { - SassError { message: message.into(), pos } + SassError { + message: message.into(), + pos, + } } pub fn unexpected_eof(pos: Pos) -> Self { - SassError { message: String::from("unexpected eof"), pos } + SassError { + message: String::from("unexpected eof"), + pos, + } } } @@ -27,7 +33,10 @@ impl Display for SassError { impl From for SassError { fn from(error: io::Error) -> Self { - SassError{ pos: Pos::new(), message: format!("{}", error) } + SassError { + pos: Pos::new(), + message: format!("{}", error), + } } } diff --git a/src/format.rs b/src/format.rs index e857bb2..4a35f9c 100644 --- a/src/format.rs +++ b/src/format.rs @@ -99,7 +99,8 @@ mod test_scss { #[test] fn $func() { let mut buf = Vec::new(); - StyleSheet::new($input).expect(concat!("failed to parse on ", $input)) + StyleSheet::new($input) + .expect(concat!("failed to parse on ", $input)) .pretty_print(&mut buf) .expect(concat!("failed to pretty print on ", $input)); assert_eq!( @@ -112,7 +113,8 @@ mod test_scss { #[test] fn $func() { let mut buf = Vec::new(); - StyleSheet::new($input).expect(concat!("failed to parse on ", $input)) + StyleSheet::new($input) + .expect(concat!("failed to parse on ", $input)) .pretty_print(&mut buf) .expect(concat!("failed to pretty print on ", $input)); assert_eq!( @@ -216,6 +218,11 @@ mod test_scss { "$a: 1px;\n$b: $a; $a: 2px;\na {\n height: $b;\n}\n", "a {\n height: 1px;\n}\n" ); + test!( + variable_shadowing_val_does_not_change_complex, + "a {\n}\n$y: before;\n$x: 1 2 $y;\n$y: after;\nfoo {\n a: $x;\n}", + "a {\n}\nfoo {\n a: 1 2 before;\n}\n" + ); test!( variable_whitespace, "$a : 1px ;\na {\n height: $a;\n}\n", @@ -237,12 +244,22 @@ mod test_scss { "a {\n height: 1 1px;\n}\n" ); + test!( + removes_single_line_comment, + "// a { color: red }\na {\n height: 1 1px;\n}\n", + "a {\n height: 1 1px;\n}\n" + ); + test!(keyword_important, "a {\n height: 1 !important;\n}\n"); test!( keyword_important_uppercase, "a {\n height: 1 !IMPORTANT;\n}\n", "a {\n height: 1 !important;\n}\n" ); + test!( + keyword_important_not_at_end, + "a {\n height: !important 1;\n}\n" + ); test!( combines_hyphens, diff --git a/src/selector.rs b/src/selector.rs index b8fc4d6..9805d80 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -1,8 +1,8 @@ use crate::common::Symbol; use crate::{Token, TokenKind}; +use std::fmt::{self, Display}; use std::iter::Peekable; use std::slice::Iter; -use std::fmt::{self, Display}; #[derive(Clone, Debug, Eq, PartialEq)] pub enum Selector {