-
-
Notifications
You must be signed in to change notification settings - Fork 73
Parser: add public API method extract_ruby_with_semicolons_to_herb #675
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
Open
Lusqinha
wants to merge
11
commits into
marcoroth:main
Choose a base branch
from
Lusqinha:enhancement/add_method_extract_ruby_with_semicolons_to_Herb_module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
79b66c6
feat: add method `extract_ruby_with_semicolons` to extension.c on herb
Lusqinha a53adec
feat: add `extract_ruby_with_semicolons` method to Herb module
Lusqinha b2f1026
test: add tests for `extract_ruby_with_semicolons` method in Extracto…
Lusqinha d0bb8c1
Merge branch 'main' into enhancement/add_method_extract_ruby_with_sem…
Lusqinha c239764
add with semicolons argument to extract ruby
felixefelip fa0952b
Add `with_semicolons` argument to `extract_ruby`
felixefelip c516b91
Merge branch 'main' into enhancement/add_method_extract_ruby_with_sem…
felixefelip aa42d20
Use the same tests of test_extract.c in extract_ruby_semicolons_test.rb
felixefelip 7e64745
rename keywordarg with_semicolumn to semicolons
felixefelip cb85360
apply clang-format
felixefelip 4919bf2
Merge branch 'main' into enhancement/add_method_extract_ruby_with_sem…
felixefelip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative "../test_helper" | ||
|
|
||
| module Extractor | ||
| class ExtractRubySemicolonsTest < Minitest::Spec | ||
| test "extract_ruby_single_erb_no_semicolon" do | ||
| source = "<% if %>\n<% end %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| expected = " if \n end " | ||
| assert_equal expected, result | ||
| end | ||
|
|
||
| test "extract_ruby_multiple_erb_same_line_with_semicolon" do | ||
| source = "<% x = 1 %> <% y = 2 %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| assert_equal " x = 1 ; y = 2 ", result | ||
| end | ||
|
|
||
| test "extract_ruby_three_erb_same_line_with_semicolons" do | ||
| source = "<% a = 1 %> <% b = 2 %> <% c = 3 %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| assert_equal " a = 1 ; b = 2 ; c = 3 ", result | ||
| end | ||
|
|
||
| test "extract_ruby_different_lines_no_semicolons" do | ||
| source = "<% x = 1 %>\n<% y = 2 %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| expected = " x = 1 \n y = 2 " | ||
| assert_equal expected, result | ||
| end | ||
|
|
||
| test "extract_ruby_mixed_lines" do | ||
| source = "<% a = 1 %> <% b = 2 %>\n<% c = 3 %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| expected = " a = 1 ; b = 2 \n c = 3 " | ||
| assert_equal expected, result | ||
| end | ||
|
|
||
| test "extract_ruby_output_tags_same_line" do | ||
| source = "<%= x %> <%= y %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| assert_equal " x ; y ", result | ||
| end | ||
|
|
||
| test "extract_ruby_empty_erb_same_line" do | ||
| source = "<% %> <% %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| assert_equal " ; ", result | ||
| end | ||
|
|
||
| test "extract_ruby_comments_skipped" do | ||
| source = "<%# comment %> <% code %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| assert_equal " code ", result | ||
| end | ||
|
|
||
| test "extract_ruby_issue_135_if_without_condition" do | ||
| source = "<% if %>\n<% end %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| expected = " if \n end " | ||
| assert_equal expected, result | ||
| end | ||
|
|
||
| test "extract_ruby_inline_comment_same_line" do | ||
| source = "<% if true %><% # Comment here %><% end %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| assert_equal " if true ; end ", result | ||
| end | ||
|
|
||
| test "extract_ruby_inline_comment_with_newline" do | ||
| source = "<% if true %><% # Comment here %>\n<% end %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| expected = " if true ; \n end " | ||
| assert_equal expected, result | ||
| end | ||
|
|
||
| test "extract_ruby_inline_comment_with_spaces" do | ||
| source = "<% # Comment %> <% code %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| assert_equal " code ", result | ||
| end | ||
|
|
||
| test "extract_ruby_inline_comment_multiline" do | ||
| source = "<% # Comment\nmore %> <% code %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| expected = " # Comment\nmore ; code " | ||
| assert_equal expected, result | ||
| end | ||
|
|
||
| test "extract_ruby_inline_comment_between_code" do | ||
| source = "<% if true %><% # Comment here %><%= hello %><% end %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| assert_equal " if true ; hello ; end ", result | ||
| end | ||
|
|
||
| test "extract_ruby_inline_comment_complex" do | ||
| source = "<% # Comment here %><% if true %><% # Comment here %><%= hello %><% end %>" | ||
| result = Herb.extract_ruby(source, semicolons: true) | ||
|
|
||
| assert_equal " if true ; hello ; end ", result | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I basically copied these C tests https://github.com/marcoroth/herb/blob/main/test/c/test_extract.c