Skip to content

Commit

Permalink
improved readability of parsing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kimjoar committed Apr 11, 2012
1 parent 2b638da commit 8f480f4
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions test/parser_spec.coffee
Expand Up @@ -32,14 +32,17 @@ describe "Parser", ->
sheet.nodes[0].val.should.equal('"UTF-8"')

describe "parseRule", ->
checkRule = (input, type) ->
ensureSelector = (input) ->
parser = new Parser(input)
rule = parser.parseRule()
rule.nodes[0].should.be.an.instanceof(type)
isSelector(rule.nodes[0])

it "handles elements", -> checkRule "h1", nodes.Selector
it "handles ids", -> checkRule "#test", nodes.Selector
it "handles classes", -> checkRule ".test", nodes.Selector
isSelector = (node) ->
node.should.be.an.instanceof(nodes.Selector)

it "handles elements", -> ensureSelector "h1"
it "handles ids", -> ensureSelector "#test"
it "handles classes", -> ensureSelector ".test"

it "does not allow only whitespace", ->
parser = new Parser(" ")
Expand All @@ -58,8 +61,8 @@ describe "Parser", ->
rule = parser.parseRule()
ruleNodes = rule.nodes
ruleNodes.length.should.equal(3)
ruleNodes[0].should.be.an.instanceof(nodes.Selector)
ruleNodes[2].should.be.an.instanceof(nodes.Selector)
isSelector(ruleNodes[0])
isSelector(ruleNodes[2])

it "throws an error if token is unexpected", ->
parser = new Parser("property: value")
Expand Down

0 comments on commit 8f480f4

Please sign in to comment.