Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make tokenizer shift function to be public #209

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/liquid_c/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ void liquid_define_tokenizer(void)
rb_define_method(cLiquidTokenizer, "line_number", tokenizer_line_number_method, 0);
rb_define_method(cLiquidTokenizer, "for_liquid_tag", tokenizer_for_liquid_tag_method, 0);
rb_define_method(cLiquidTokenizer, "bug_compatible_whitespace_trimming!", tokenizer_bug_compatible_whitespace_trimming, 0);
rb_define_method(cLiquidTokenizer, "shift", tokenizer_shift_method, 0);

// For testing the internal token representation.
rb_define_private_method(cLiquidTokenizer, "shift", tokenizer_shift_method, 0);
rb_define_private_method(cLiquidTokenizer, "shift_trimmed", tokenizer_shift_trimmed_method, 0);
}

8 changes: 4 additions & 4 deletions test/unit/tokenizer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class TokenizerTest < Minitest::Test
def test_tokenizer_nil
tokenizer = new_tokenizer(nil)
assert_nil(tokenizer.send(:shift))
assert_nil(tokenizer.shift)
end

def test_tokenize_strings
Expand Down Expand Up @@ -60,10 +60,10 @@ def test_utf8_encoded_source
def test_utf8_compatible_source
source = String.new("ascii", encoding: Encoding::ASCII)
tokenizer = new_tokenizer(source)
output = tokenizer.send(:shift)
output = tokenizer.shift
assert_equal(Encoding::UTF_8, output.encoding)
assert_equal(source, output)
assert_nil(tokenizer.send(:shift))
assert_nil(tokenizer.shift)
end

def test_non_utf8_compatible_source
Expand Down Expand Up @@ -105,7 +105,7 @@ def new_tokenizer(source, parse_context: Liquid::ParseContext.new)
def tokenize(source, for_liquid_tag: false, trimmed: false)
tokenizer = Liquid::C::Tokenizer.new(source, 1, for_liquid_tag)
tokens = []
while (t = trimmed ? tokenizer.send(:shift_trimmed) : tokenizer.send(:shift))
while (t = trimmed ? tokenizer.send(:shift_trimmed) : tokenizer.shift)
tokens << t
end
tokens
Expand Down
Loading