1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

I defeated all specs 🍻

This commit is contained in:
Takashi Kokubun 2015-03-29 22:02:08 +09:00
parent 7db8fea28b
commit 83d0472ba6
3 changed files with 26 additions and 2 deletions

View file

@ -1,5 +1,6 @@
require 'ripper'
# FIXME: this can be refactored
module Hamlit
module Concerns
module Balanceable
@ -42,6 +43,22 @@ module Hamlit
private
def balanced_braces_exist?(tokens)
open_count = 0
tokens.each do |token|
(row, col), type, str = token
case type
when :on_lbrace then open_count += 1
when :on_rbrace then open_count -= 1
end
break if open_count == 0
end
open_count == 0
end
def balanced_parens_exist?(tokens)
open_count = 0

View file

@ -20,6 +20,13 @@ module Hamlit
return [] unless scanner.match?(/{/)
tokens = Ripper.lex(scanner.rest)
until balanced_braces_exist?(tokens)
@current_lineno += 1
break unless @lines[@current_lineno]
scanner.concat(current_line)
tokens = Ripper.lex(scanner.rest)
end
tokens = fetch_balanced_braces(tokens)
scanner.pos += tokens.last.first.last + 1
[tokens.map(&:last).join]
@ -31,6 +38,7 @@ module Hamlit
tokens = Ripper.lex(scanner.rest)
until balanced_parens_exist?(tokens)
@current_lineno += 1
break unless @lines[@current_lineno]
scanner.concat(current_line)
tokens = Ripper.lex(scanner.rest)
end

View file

@ -518,8 +518,7 @@ describe "haml" do
assert_ugly(haml, locals, options)
end
# FIXME: it requires multiple-line attribute parser
pending "Ruby-style attributes separated with newlines" do
specify "Ruby-style attributes separated with newlines" do
haml = %q{%p{ :a => 'b',
'c' => 'd' }}
html = %q{<p a='b' c='d'></p>}