describe Ass::Parser do before :each do @parser = Ass::Parser.new end it "should determine indentations (2 spaces)" do @parser.indents_in('none').should == 0 @parser.indents_in(' one').should == 1 @parser.indents_in(' two').should == 2 end it "should determine sub selectors" do @parser.nested_selector?(' sub', 'primary').should be_true @parser.nested_selector?('primary', 'primary').should be_false end it "should splice sub selectors" do @parser.splice_selectors('a', ':hover').should == 'a:hover' @parser.splice_selectors('h1', 'a').should == 'h1 a' @parser.splice_selectors('h1, h2, h3', ':hover').should == 'h1:hover, h2:hover, h3:hover' @parser.splice_selectors('h1, h2, h3', 'a').should == 'h1 a, h2 a, h3 a' end it "should populate constants" do @parser.ass = <<-ASS :primary_color = #fff :primary_size = 15px :tertiary_size = 9em ASS @parser.parse! @parser.constants[:primary_color].should == '#fff' @parser.constants[:primary_size].should == '15px' @parser.constants[:tertiary_size].should == '9em' end it "should populate output undefined constant" do @parser.ass = <<-ASS.deindent :color = #fff body background :color font :font_size ASS @parser.parse! @parser.css.should == <<-CSS.deindent body { background: #fff; font: undefined_constant; } CSS end it "should translate ass document from file" do Ass::Parser.parse_file(File.dirname(__FILE__) + '/../fixtures/test.ass').should == <<-ASS.deindent body.some-class { margin: 0; } ASS end it "should fail when parsing a file that does not exist" do lambda { Ass::Parser.parse_file('does_not_exist.ass') }.should raise_error end it "should translate an ass document" do ass = <<-ASS.deindent /* Inline comment // Literal imports @import 'something.css' // Constants :primary_color = #fff :heading_size = 16px // Mixins +large font font-size 16px font-weight bold +add color color :primary_color +clearfix display block content '.' height 0 clear both visibility hidden +add color +large font // Stylesheet body font 12px color :primary_color h1, h2, h3 font-weight bold font-size :heading_size color #fff a color black :hover color blue #primary .content margin 15px #comments padding 5px font-size 11px color gray .comment border white 1px solid a color black !important #footer +clearfix ASS Ass::Parser.parse(ass).should == <<-CSS.deindent /* Inline comment */ @import 'something.css' body { font: 12px; color: #fff; } h1, h2, h3 { font-weight: bold; font-size: 16px; color: #fff; } a { color: black; } a:hover { color: blue; } #primary .content { margin: 15px; } #primary .content #comments { padding: 5px; font-size: 11px; color: gray; } #primary .content #comments .comment { border: white 1px solid; } #primary .content #comments .comment a { color: black !important; } #footer { font-size: 16px; font-weight: bold; color: #fff; display: block; content: '.'; height: 0; clear: both; visibility: hidden; } CSS end end