Skip to content

Commit

Permalink
Updated parser and lexer to maintain current parsing state.
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerBrinks committed Feb 3, 2014
1 parent 9bd457b commit 928a09a
Show file tree
Hide file tree
Showing 85 changed files with 5,015 additions and 2,630 deletions.
10 changes: 5 additions & 5 deletions ExCSS.Tests/AtRuleFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class AtRuleFixture
public void Parser_Reads_Character_Sets_Symbols()
{
var parser = new Parser();
var css = parser.Parse("@charset utf-8;");
var css = parser.Parse("@charset 'utf-8';");

var charset = css.CharsetDirectives;

Expand Down Expand Up @@ -53,7 +53,7 @@ public void Parser_Reads_Imports_URL_Double_Quoted()

var imports = css.ImportDirectives;


Assert.AreEqual("@import url(style.css);", imports[0].ToString());
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public void Parser_Reads_Imports_With_Plain_And_Quoted_Meida()
var css = parser.Parse("@import url(style.css) screen \"Plain style\";");

var imports = css.ImportDirectives;

Assert.AreEqual("@import url(style.css) screen 'Plain style';", imports[0].ToString());
}

Expand Down Expand Up @@ -153,7 +153,7 @@ public void Parser_Reads_Keyframes()

var keyframes = css.KeyframeDirectives;

Assert.AreEqual(@"@keyframes test-keyframes{from {top:0px;} to {top:200px;}}", keyframes[0].ToString());
Assert.AreEqual(@"@keyframes test-keyframes{from{top:0px;}to{top:200px;}}", keyframes[0].ToString());
}
#endregion

Expand All @@ -166,7 +166,7 @@ public void Parser_Reads_Media_Queries()

var media = css.MediaDirectives;

Assert.AreEqual("@media print {body{font-size:12pt;} h1{font-size:24pt;}}", media[0].ToString());
Assert.AreEqual("@media print {body{font-size:12pt;}h1{font-size:24pt;}}", media[0].ToString());
}

#endregion
Expand Down
39 changes: 17 additions & 22 deletions ExCSS.Tests/ParserErrorHandlerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Lexer_Handles_Double_Quote_Backslash()
{
var stylesheet = new Parser().Parse("@import \\");

Assert.AreEqual(1, stylesheet.Errors.Count);
Assert.AreEqual(2, stylesheet.Errors.Count);
Assert.AreEqual(ParserError.EndOfFile, stylesheet.Errors[0].ParserError);
Assert.AreEqual(1, stylesheet.Errors[0].Line);
Assert.AreEqual(10, stylesheet.Errors[0].Column);
Expand All @@ -58,7 +58,7 @@ public void Lexer_Handles_Backslash_Newline()
{
var stylesheet = new Parser().Parse("@import \\\r\n");

Assert.AreEqual(1, stylesheet.Errors.Count);
Assert.AreEqual(2, stylesheet.Errors.Count);
Assert.AreEqual(ParserError.UnexpectedLineBreak, stylesheet.Errors[0].ParserError);
Assert.AreEqual(1, stylesheet.Errors[0].Line);
Assert.AreEqual(10, stylesheet.Errors[0].Column);
Expand All @@ -74,7 +74,7 @@ public void Lexer_Handles_URL_EoF()
Assert.AreEqual(ParserError.EndOfFile, stylesheet.Errors[0].ParserError);
Assert.AreEqual(1, stylesheet.Errors[0].Line);
Assert.AreEqual(19, stylesheet.Errors[0].Column);
Assert.AreEqual("Expected URL to terminate before end of file.", stylesheet.Errors[0].Message);
Assert.AreEqual("Expected URL to terminate before line break or end of file.", stylesheet.Errors[0].Message);
}

[Test]
Expand All @@ -86,24 +86,24 @@ public void Lexer_Handles_URL_New_Line()
Assert.AreEqual(ParserError.UnexpectedLineBreak, stylesheet.Errors[0].ParserError);
Assert.AreEqual(1, stylesheet.Errors[0].Line);
Assert.AreEqual(20, stylesheet.Errors[0].Column);
Assert.AreEqual("Expected URL to terminate before line break.", stylesheet.Errors[0].Message);
Assert.AreEqual("Expected URL to terminate before line break or end of file.", stylesheet.Errors[0].Message);

Assert.AreEqual(ParserError.EndOfFile, stylesheet.Errors[1].ParserError);
Assert.AreEqual(2, stylesheet.Errors[1].Line);
Assert.AreEqual(2, stylesheet.Errors[1].Column);
Assert.AreEqual("Expected URL to terminate before end of file.", stylesheet.Errors[1].Message);
Assert.AreEqual("Expected URL to terminate before line break or end of file.", stylesheet.Errors[1].Message);
}

[Test]
public void Lexer_Handles_URL_Backslash_EoF()
{
var stylesheet = new Parser().Parse(".class{ prop: url(\"\\");

Assert.AreEqual(2, stylesheet.Errors.Count);
Assert.AreEqual(3, stylesheet.Errors.Count);
Assert.AreEqual(ParserError.EndOfFile, stylesheet.Errors[0].ParserError);
Assert.AreEqual(1, stylesheet.Errors[0].Line);
Assert.AreEqual(19, stylesheet.Errors[0].Column);
Assert.AreEqual("Expected URL to terminate before end of file.", stylesheet.Errors[0].Message);
Assert.AreEqual("Expected URL to terminate before line break or end of file.", stylesheet.Errors[0].Message);

Assert.AreEqual(ParserError.EndOfFile, stylesheet.Errors[1].ParserError);
Assert.AreEqual(1, stylesheet.Errors[1].Line);
Expand Down Expand Up @@ -131,7 +131,7 @@ public void Lexer_Handles_URL_Single_Quote_Backslash_EOF()
{
var stylesheet = new Parser().Parse(".class{ prop: url('\\");

Assert.AreEqual(2, stylesheet.Errors.Count);
Assert.AreEqual(3, stylesheet.Errors.Count);
Assert.AreEqual(ParserError.EndOfFile, stylesheet.Errors[0].ParserError);
Assert.AreEqual(1, stylesheet.Errors[0].Line);
Assert.AreEqual(19, stylesheet.Errors[0].Column);
Expand All @@ -150,14 +150,14 @@ public void Lexer_Handles_Url_Unquoted()
Assert.AreEqual(ParserError.InvalidCharacter, stylesheet.Errors[0].ParserError);
Assert.AreEqual(1, stylesheet.Errors[0].Line);
Assert.AreEqual(16, stylesheet.Errors[0].Column);
Assert.AreEqual("Invalid quotation or open paren in URL.", stylesheet.Errors[0].Message);
Assert.AreEqual("Expected quotation or open paren in URL.", stylesheet.Errors[0].Message);

Assert.AreEqual(ParserError.InvalidCharacter, stylesheet.Errors[1].ParserError);
Assert.AreEqual(ParserError.UnexpectedLineBreak, stylesheet.Errors[1].ParserError);
Assert.AreEqual(1, stylesheet.Errors[1].Line);
Assert.AreEqual(18, stylesheet.Errors[1].Column);
Assert.AreEqual("Invalid character in declaration.", stylesheet.Errors[1].Message);
Assert.AreEqual("An unexpected error occurred.", stylesheet.Errors[1].Message);
}

[Test]
public void Lexer_Handles_Post_URL_Errant_Character()
{
Expand All @@ -175,16 +175,11 @@ public void Lexer_Handles_Hash_Backslash()
{
var stylesheet = new Parser().Parse("n#\\");

Assert.AreEqual(2, stylesheet.Errors.Count);
Assert.AreEqual(ParserError.InvalidCharacter, stylesheet.Errors[0].ParserError);
Assert.AreEqual(1, stylesheet.Errors.Count);
Assert.AreEqual(ParserError.EndOfFile, stylesheet.Errors[0].ParserError);
Assert.AreEqual(1, stylesheet.Errors[0].Line);
Assert.AreEqual(3, stylesheet.Errors[0].Column);
Assert.AreEqual("Invalid character after #.", stylesheet.Errors[0].Message);

Assert.AreEqual(ParserError.EndOfFile, stylesheet.Errors[1].ParserError);
Assert.AreEqual(1, stylesheet.Errors[1].Line);
Assert.AreEqual(4, stylesheet.Errors[1].Column);
Assert.AreEqual("Unexpected line break or EOF.", stylesheet.Errors[1].Message);
Assert.AreEqual(4, stylesheet.Errors[0].Column);
Assert.AreEqual("Unexpected line break or EOF.", stylesheet.Errors[0].Message);
}

[Test]
Expand All @@ -196,7 +191,7 @@ public void Lexer_Handles_Numeric_Backslash()
Assert.AreEqual(ParserError.InvalidCharacter, stylesheet.Errors[0].ParserError);
Assert.AreEqual(1, stylesheet.Errors[0].Line);
Assert.AreEqual(3, stylesheet.Errors[0].Column);
Assert.AreEqual("Invalid identifier after #.", stylesheet.Errors[0].Message);
Assert.AreEqual("Invalid character after #.", stylesheet.Errors[0].Message);

Assert.AreEqual(ParserError.EndOfFile, stylesheet.Errors[1].ParserError);
Assert.AreEqual(1, stylesheet.Errors[1].Line);
Expand Down
6 changes: 2 additions & 4 deletions ExCSS.Tests/PropertyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ public void Parser_Finds_Multiple_Properties()
var parser = new Parser();
var css = parser.Parse(".class{border: solid 1px red;height: 5px} .other{margin: 0;}");

var rules = css.Rulesets;

Assert.AreEqual(2, rules.Count);
Assert.AreEqual(2, rules[0].Declarations.Count);
Assert.AreEqual(2, css.Rules.Count);
Assert.AreEqual(2, css.StyleRules[0].Declarations.Count);
}
}
}
4 changes: 2 additions & 2 deletions ExCSS.Tests/RenderFormatFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class RenderFormatFixture
public void Stylesheet_Renders_Inline()
{
var parser = new Parser();

var css = parser.Parse(Resources.Css3);

Console.Write(css.ToString());
Assert.AreEqual(Resources.Css3Min, css.ToString());
}

Expand All @@ -23,7 +23,7 @@ public void Stylesheet_Renders_Friendly_Format()
{
var parser = new Parser();
var css = parser.Parse(Resources.Css3);

Assert.AreEqual(Resources.Css3Friendly, css.ToString(true));
}
}
Expand Down
Loading

0 comments on commit 928a09a

Please sign in to comment.