rustfmt and empty styles css tests

This commit is contained in:
ConnorSkees 2020-01-07 19:58:38 -05:00
parent fb877fa524
commit 7611dce47a

View File

@ -27,8 +27,8 @@ use std::collections::HashMap;
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use std::fs; use std::fs;
use std::io; use std::io;
use std::path::Path;
use std::iter::{Iterator, Peekable}; use std::iter::{Iterator, Peekable};
use std::path::Path;
use crate::common::{AtRule, Keyword, Op, Pos, Symbol, Whitespace}; use crate::common::{AtRule, Keyword, Op, Pos, Symbol, Whitespace};
use crate::css::Css; use crate::css::Css;
@ -103,6 +103,7 @@ pub struct StyleSheet {
pub enum Stmt { pub enum Stmt {
Style(Style), Style(Style),
RuleSet(RuleSet), RuleSet(RuleSet),
// MultilineComment(String),
} }
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
@ -187,7 +188,7 @@ impl<'a> StyleSheetParser<'a> {
.next() .next()
.expect("this cannot occur as we have already peeked"); .expect("this cannot occur as we have already peeked");
self.devour_whitespace(); self.devour_whitespace();
if self if self
.lexer .lexer
.next() .next()
.unwrap_or_else(|| self.error(pos, "expected value after variable")) .unwrap_or_else(|| self.error(pos, "expected value after variable"))
@ -199,6 +200,10 @@ impl<'a> StyleSheetParser<'a> {
let val = self.eat_variable_value(); let val = self.eat_variable_value();
self.global_variables.insert(name, val); self.global_variables.insert(name, val);
} }
TokenKind::MultilineComment(comment) => {
todo!("MultilineComment");
// rules.push(Stmt::MultilineComment(comment));
}
TokenKind::AtRule(_) => self.eat_at_rule(), TokenKind::AtRule(_) => self.eat_at_rule(),
_ => todo!("unexpected toplevel token"), _ => todo!("unexpected toplevel token"),
}; };
@ -238,11 +243,17 @@ impl<'a> StyleSheetParser<'a> {
pos.line(), pos.line(),
pos.column() pos.column()
); );
let padding = vec![' '; format!("{}", pos.line()).len() + 1].iter().collect::<String>(); let padding = vec![' '; format!("{}", pos.line()).len() + 1]
.iter()
.collect::<String>();
eprintln!("{}|", padding); eprintln!("{}|", padding);
eprint!("{} | ", pos.line()); eprint!("{} | ", pos.line());
eprintln!("todo! get line to print as error"); eprintln!("todo! get line to print as error");
eprintln!("{}| {}^", padding, vec![' '; pos.column() as usize].iter().collect::<String>()); eprintln!(
"{}| {}^",
padding,
vec![' '; pos.column() as usize].iter().collect::<String>()
);
eprintln!("{}|", padding); eprintln!("{}|", padding);
std::process::exit(1); std::process::exit(1);
} }
@ -256,7 +267,11 @@ impl<'a> StyleSheetParser<'a> {
.collect::<Vec<Token>>(); .collect::<Vec<Token>>();
let mut iter2 = Vec::with_capacity(iter1.len()); let mut iter2 = Vec::with_capacity(iter1.len());
for tok in iter1 { for tok in iter1 {
if let Token { kind: TokenKind::Variable(ref name), ref pos } = tok { if let Token {
kind: TokenKind::Variable(ref name),
ref pos,
} = tok
{
iter2.extend( iter2.extend(
self.global_variables self.global_variables
.get(name) .get(name)
@ -409,4 +424,6 @@ mod test_css {
test!(basic_style, "a {\n color: red;\n}\n"); test!(basic_style, "a {\n color: red;\n}\n");
test!(two_styles, "a {\n color: red;\n color: blue;\n}\n"); test!(two_styles, "a {\n color: red;\n color: blue;\n}\n");
test!(selector_mul, "a, b {\n color: red;\n}\n"); test!(selector_mul, "a, b {\n color: red;\n}\n");
test!(removes_empty_outer_styles, "a {\n b {\n color: red;\n }\n", "a b {\n color: red;\n}\n");
test!(removes_empty_styles, "a {}\n", "");
} }