Make @import
tests work
This commit is contained in:
parent
ba955c464a
commit
d85f9d32f6
@ -356,11 +356,7 @@ impl<'a> Lexer<'a> {
|
|||||||
.next()
|
.next()
|
||||||
.expect("this is impossible because we have already peeked");
|
.expect("this is impossible because we have already peeked");
|
||||||
self.pos.next_char();
|
self.pos.next_char();
|
||||||
if tok == '_' {
|
string.push(tok);
|
||||||
string.push('-');
|
|
||||||
} else {
|
|
||||||
string.push(tok);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(kw) = Keyword::try_from(string.as_ref()) {
|
if let Ok(kw) = Keyword::try_from(string.as_ref()) {
|
||||||
|
27
src/lib.rs
27
src/lib.rs
@ -228,7 +228,7 @@ impl StyleSheet {
|
|||||||
) -> SassResult<(Vec<Stmt>, Scope)> {
|
) -> SassResult<(Vec<Stmt>, Scope)> {
|
||||||
Ok(StyleSheetParser {
|
Ok(StyleSheetParser {
|
||||||
global_scope: Scope::new(),
|
global_scope: Scope::new(),
|
||||||
lexer: Lexer::new(&fs::read_to_string(p.as_ref())?).peekable(),
|
lexer: Lexer::new(&String::from_utf8(fs::read(p.as_ref())?)?).peekable(),
|
||||||
rules: Vec::new(),
|
rules: Vec::new(),
|
||||||
scope: 0,
|
scope: 0,
|
||||||
file: p.into(),
|
file: p.into(),
|
||||||
@ -255,13 +255,13 @@ impl StyleSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write the internal representation as CSS to `buf`
|
/// Write the internal representation as CSS to `buf`
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use std::io::{BufWriter, stdout};
|
/// use std::io::{BufWriter, stdout};
|
||||||
/// use grass::{SassResult, StyleSheet};
|
/// use grass::{SassResult, StyleSheet};
|
||||||
/// # use tempfile::Builder;
|
/// # use tempfile::Builder;
|
||||||
/// # use std::io::Write;
|
/// # use std::io::Write;
|
||||||
///
|
///
|
||||||
/// fn main() -> SassResult<()> {
|
/// fn main() -> SassResult<()> {
|
||||||
/// # let mut file = Builder::new().prefix("input.scss").tempfile().unwrap();
|
/// # let mut file = Builder::new().prefix("input.scss").tempfile().unwrap();
|
||||||
/// # write!(file, "a {{\n color: red}}")?;
|
/// # write!(file, "a {{\n color: red}}")?;
|
||||||
@ -730,6 +730,11 @@ mod test_variables {
|
|||||||
"a {\n $c: red;\nb {\n $c: blue;\n }\n color: $c;\n}\n",
|
"a {\n $c: red;\nb {\n $c: blue;\n }\n color: $c;\n}\n",
|
||||||
"a {\n color: blue;\n}\n"
|
"a {\n color: blue;\n}\n"
|
||||||
);
|
);
|
||||||
|
// test!(
|
||||||
|
// nested_interpolation,
|
||||||
|
// "$a: red; a {\n color: #{#{$a}};\n}\n",
|
||||||
|
// "a {\n color: red;\n}\n"
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -1210,11 +1215,11 @@ mod test_imports {
|
|||||||
#[test]
|
#[test]
|
||||||
fn $func() {
|
fn $func() {
|
||||||
$(
|
$(
|
||||||
write!(Builder::new().prefix($name).tempfile().unwrap(), $content).unwrap();
|
write!(Builder::new().rand_bytes(0).prefix("").suffix($name).tempfile_in("").unwrap(), $content).unwrap();
|
||||||
)*
|
)*
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
StyleSheet::new($input)
|
StyleSheet::new($input)
|
||||||
.expect(concat!("failed to parse on ", $input))
|
.expect(concat!("failed to parse in "))
|
||||||
.print_as_css(&mut buf)
|
.print_as_css(&mut buf)
|
||||||
.expect(concat!("failed to pretty print on ", $input));
|
.expect(concat!("failed to pretty print on ", $input));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -1225,11 +1230,9 @@ mod test_imports {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// redundant test to ensure that the import tests are working
|
// we have to use test name as filename because tests are run multithreaded in the same directory, so some names may conflict
|
||||||
test_import!(basic, "a {\n color: red;\n}\n" => "a {\n color: red;\n}\n" | );
|
test_import!(imports_variable, "@import \"imports_variable\";\na {\n color: $a;\n}" => "a {\n color: red;\n}\n" | "imports_variable"("$a: red;"));
|
||||||
|
test_import!(single_quotes_import, "@import 'single_quotes_import';\na {\n color: $a;\n}" => "a {\n color: red;\n}\n" | "single_quotes_import"("$a: red;"));
|
||||||
test_import!(imports_variable, "@import \"foo\";\na {\n color: $a;\n}" => "a {\n color: red;\n}\n" | "foo"("$a: red;"));
|
test_import!(finds_name_scss, "@import \"finds_name_scss\";\na {\n color: $a;\n}" => "a {\n color: red;\n}\n" | "finds_name_scss.scss"("$a: red;"));
|
||||||
test_import!(single_quotes_import, "@import 'foo';\na {\n color: $a;\n}" => "a {\n color: red;\n}\n" | "foo"("$a: red;"));
|
test_import!(finds_underscore_name_scss, "@import \"finds_underscore_name_scss\";\na {\n color: $a;\n}" => "a {\n color: red;\n}\n" | "_finds_underscore_name_scss.scss"("$a: red;"));
|
||||||
test_import!(finds_name_scss, "@import \"foo\";\na {\n color: $a;\n}" => "a {\n color: red;\n}\n" | "foo.scss"("$a: red;"));
|
|
||||||
test_import!(finds_underscore_name_scss, "@import \"foo\";\na {\n color: $a;\n}" => "a {\n color: red;\n}\n" | "_foo.scss"("$a: red;"));
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,9 @@ pub(crate) trait IsWhitespace {
|
|||||||
fn is_whitespace(&self) -> bool;
|
fn is_whitespace(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn devour_whitespace<I: Iterator<Item = W>, W: IsWhitespace>(s: &mut Peekable<I>) -> bool {
|
pub(crate) fn devour_whitespace<I: Iterator<Item = W>, W: IsWhitespace>(
|
||||||
|
s: &mut Peekable<I>,
|
||||||
|
) -> bool {
|
||||||
let mut found_whitespace = false;
|
let mut found_whitespace = false;
|
||||||
while let Some(w) = s.peek() {
|
while let Some(w) = s.peek() {
|
||||||
if !w.is_whitespace() {
|
if !w.is_whitespace() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user