Skip to content

Commit

Permalink
Change Tokenizer test to fetch tokens instead of exposing ivar
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravmc committed Jun 4, 2015
1 parent 79d7dd0 commit fc8e6c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 0 additions & 2 deletions lib/liquid/tokenizer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module Liquid
class Tokenizer
attr_reader :tokens

def initialize(source, line_numbers = false)
@source, @line_numbers = source, line_numbers
@tokens = tokenize
Expand Down
20 changes: 11 additions & 9 deletions test/unit/tokenizer_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ def test_tokenize_blocks
end

def test_calculate_line_numbers_per_token_with_profiling
template = Liquid::Template.parse("", :profile => true)

assert_equal [1], template.send(:tokenize, "{{funk}}").tokens.map(&:line_number)
assert_equal [1, 1, 1], template.send(:tokenize, " {{funk}} ").tokens.map(&:line_number)
assert_equal [1, 2, 2], template.send(:tokenize, "\n{{funk}}\n").tokens.map(&:line_number)
assert_equal [1, 1, 3], template.send(:tokenize, " {{\n funk \n}} ").tokens.map(&:line_number)
assert_equal [1], tokenize("{{funk}}", true).map(&:line_number)
assert_equal [1, 1, 1], tokenize(" {{funk}} ", true).map(&:line_number)
assert_equal [1, 2, 2], tokenize("\n{{funk}}\n", true).map(&:line_number)
assert_equal [1, 1, 3], tokenize(" {{\n funk \n}} ", true).map(&:line_number)
end

private

def tokenize(source)
tokenizer = Liquid::Tokenizer.new(source)
tokenizer.tokens
def tokenize(source, line_numbers = false)
tokenizer = Liquid::Tokenizer.new(source, line_numbers)
tokens = []
while t = tokenizer.shift
tokens << t
end
tokens
end
end

0 comments on commit fc8e6c8

Please sign in to comment.