fixed test tempfile naming
This commit is contained in:
parent
be4d02490c
commit
428599f091
@ -64,7 +64,7 @@ fn find_import(file_path: &PathBuf, name: &OsStr, load_paths: &[&Path]) -> Optio
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Parser<'a> {
|
impl<'a> Parser<'a> {
|
||||||
pub fn _parse_single_import(&mut self, file_name: &str, span: Span) -> SassResult<Vec<Stmt>> {
|
fn parse_single_import(&mut self, file_name: &str, span: Span) -> SassResult<Vec<Stmt>> {
|
||||||
let path: &Path = file_name.as_ref();
|
let path: &Path = file_name.as_ref();
|
||||||
|
|
||||||
let path_buf = if path.is_absolute() {
|
let path_buf = if path.is_absolute() {
|
||||||
@ -76,6 +76,7 @@ impl<'a> Parser<'a> {
|
|||||||
.unwrap_or_else(|| Path::new(""))
|
.unwrap_or_else(|| Path::new(""))
|
||||||
.join(path)
|
.join(path)
|
||||||
};
|
};
|
||||||
|
|
||||||
let name = path_buf.file_name().unwrap_or_else(|| OsStr::new(".."));
|
let name = path_buf.file_name().unwrap_or_else(|| OsStr::new(".."));
|
||||||
|
|
||||||
if let Some(name) = find_import(&path_buf, name, &self.options.load_paths) {
|
if let Some(name) = find_import(&path_buf, name, &self.options.load_paths) {
|
||||||
@ -108,8 +109,10 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
Err(("Can't find stylesheet to import.", span).into())
|
Err(("Can't find stylesheet to import.", span).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn import(&mut self) -> SassResult<Vec<Stmt>> {
|
pub(super) fn import(&mut self) -> SassResult<Vec<Stmt>> {
|
||||||
self.whitespace();
|
self.whitespace();
|
||||||
|
|
||||||
match self.toks.peek() {
|
match self.toks.peek() {
|
||||||
Some(Token { kind: '\'', .. })
|
Some(Token { kind: '\'', .. })
|
||||||
| Some(Token { kind: '"', .. })
|
| Some(Token { kind: '"', .. })
|
||||||
@ -127,14 +130,14 @@ impl<'a> Parser<'a> {
|
|||||||
if s.ends_with(".css") || s.starts_with("http://") || s.starts_with("https://") {
|
if s.ends_with(".css") || s.starts_with("http://") || s.starts_with("https://") {
|
||||||
Ok(vec![Stmt::Import(format!("\"{}\"", s))])
|
Ok(vec![Stmt::Import(format!("\"{}\"", s))])
|
||||||
} else {
|
} else {
|
||||||
self._parse_single_import(&s, span)
|
self.parse_single_import(&s, span)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::String(s, QuoteKind::None) => {
|
Value::String(s, QuoteKind::None) => {
|
||||||
if s.starts_with("url(") {
|
if s.starts_with("url(") {
|
||||||
Ok(vec![Stmt::Import(s)])
|
Ok(vec![Stmt::Import(s)])
|
||||||
} else {
|
} else {
|
||||||
self._parse_single_import(&s, span)
|
self.parse_single_import(&s, span)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::List(v, Comma, _) => {
|
Value::List(v, Comma, _) => {
|
||||||
@ -148,14 +151,14 @@ impl<'a> Parser<'a> {
|
|||||||
{
|
{
|
||||||
list_of_imports.push(Stmt::Import(format!("\"{}\"", s)));
|
list_of_imports.push(Stmt::Import(format!("\"{}\"", s)));
|
||||||
} else {
|
} else {
|
||||||
list_of_imports.append(&mut self._parse_single_import(&s, span)?);
|
list_of_imports.append(&mut self.parse_single_import(&s, span)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::String(s, QuoteKind::None) => {
|
Value::String(s, QuoteKind::None) => {
|
||||||
if s.starts_with("url(") {
|
if s.starts_with("url(") {
|
||||||
list_of_imports.push(Stmt::Import(s));
|
list_of_imports.push(Stmt::Import(s));
|
||||||
} else {
|
} else {
|
||||||
list_of_imports.append(&mut self._parse_single_import(&s, span)?);
|
list_of_imports.append(&mut self.parse_single_import(&s, span)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => return Err(("Expected string.", span).into()),
|
_ => return Err(("Expected string.", span).into()),
|
||||||
|
@ -83,10 +83,10 @@ fn single_quotes_import() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn comma_seperated_import() {
|
fn comma_separated_import() {
|
||||||
let input = "@import 'firsta', 'seconda';\na {\n color: $a;\n}";
|
let input = "@import 'comma_separated_import_first', 'comma_separated_import_second';\na {\n color: $a;\n}";
|
||||||
tempfile!("firsta", "$a: red;");
|
tempfile!("comma_separated_import_first", "$a: red;");
|
||||||
tempfile!("seconda", "p { color: blue; }");
|
tempfile!("comma_separated_import_second", "p { color: blue; }");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"p {\n color: blue;\n}\n\na {\n color: red;\n}\n",
|
"p {\n color: blue;\n}\n\na {\n color: red;\n}\n",
|
||||||
&grass::from_string(input.to_string(), &grass::Options::default()).expect(input)
|
&grass::from_string(input.to_string(), &grass::Options::default()).expect(input)
|
||||||
@ -94,10 +94,11 @@ fn comma_seperated_import() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn comma_seperated_import_order() {
|
fn comma_separated_import_order() {
|
||||||
let input = "@import 'firstb', 'secondb', url(third);";
|
let input =
|
||||||
tempfile!("firstb", "p { color: red; }");
|
"@import 'comma_separated_import_order1', 'comma_separated_import_order2', url(third);";
|
||||||
tempfile!("secondb", "p { color: blue; }");
|
tempfile!("comma_separated_import_order1", "p { color: red; }");
|
||||||
|
tempfile!("comma_separated_import_order2", "p { color: blue; }");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"p {\n color: red;\n}\n\np {\n color: blue;\n}\n@import url(third);\n",
|
"p {\n color: red;\n}\n\np {\n color: blue;\n}\n@import url(third);\n",
|
||||||
&grass::from_string(input.to_string(), &grass::Options::default()).expect(input)
|
&grass::from_string(input.to_string(), &grass::Options::default()).expect(input)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user