Skip to content

Commit

Permalink
Merge pull request #1283 from ruby/update-fixtures
Browse files Browse the repository at this point in the history
Update fixtures
  • Loading branch information
kddnewton authored Aug 18, 2023
2 parents 9fa0760 + 9da0bc4 commit b1c3374
Show file tree
Hide file tree
Showing 77 changed files with 1,052 additions and 613 deletions.
2 changes: 2 additions & 0 deletions lib/yarp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ def self.yarp_locals(source)
locals << []
when PostExecutionNode
locals.push([], [])
when InterpolatedRegularExpressionNode
locals << [] if node.once?
end

stack.concat(node.child_nodes.compact)
Expand Down
54 changes: 41 additions & 13 deletions rakelib/seattlerb.rake
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
# frozen_string_literal: true

# These files are not valid Ruby
known_failures = %w(
test/fixtures/seattlerb/begin_else_return_value.txt
test/fixtures/seattlerb/block_yield.txt
test/fixtures/seattlerb/bug_begin_else.txt
test/fixtures/seattlerb/bug170.txt
test/fixtures/seattlerb/call_block_arg_unnamed.txt
test/fixtures/seattlerb/iter_array_curly.txt
test/fixtures/seattlerb/magic_encoding_comment__bad.txt
)

namespace :seattlerb do
desc "Ensure there's a local copy of seattlerb/ruby_parser"
file "tmp/seattlerb" do
Expand All @@ -24,6 +13,35 @@ namespace :seattlerb do

desc "Import the seattlerb tests"
task import: ["tmp/seattlerb", "test/fixtures/seattlerb"] do
require "base64"

# These files are not valid Ruby
known_failures = %w[
test/fixtures/seattlerb/args_dstar__anon_solo.txt
test/fixtures/seattlerb/args_dstar__anon_trailing.txt
test/fixtures/seattlerb/args_star__anon_solo.txt
test/fixtures/seattlerb/args_star__anon_trailing.txt
test/fixtures/seattlerb/begin_else_return_value.txt
test/fixtures/seattlerb/block_yield.txt
test/fixtures/seattlerb/bug_begin_else.txt
test/fixtures/seattlerb/bug170.txt
test/fixtures/seattlerb/call_block_arg_unnamed.txt
test/fixtures/seattlerb/iter_array_curly.txt
test/fixtures/seattlerb/magic_encoding_comment__bad.txt
]

# Cleaning up some file names
renames = [
"aGVyZWRvY193dGZfSV9oYXRlX3lvdQ==\n",
"aV9mdWNraW5nX2hhdGVf\n",
"aV9oYXZlX25vX2ZyZWFraW5fY2x1ZQ==\n",
"a2lsbF9tZQ==\n",
"bW90aGVyZnVja2lu\n",
"d3RmX2lfaGF0ZV95b3U=\n",
"d3Rm\n",
"em9tZ19zb21ldGltZXNfaV9oYXRlX3RoaXNfcHJvamVjdA==\n"
].map { Base64.decode64(_1) }

# The license is in the README
cp "tmp/seattlerb/README.rdoc", "test/fixtures/seattlerb/README.rdoc"

Expand All @@ -36,7 +54,7 @@ namespace :seattlerb do

def assert_parse(source, _)
entry = caller.find { _1.include?("test_ruby_parser.rb") }
name = entry[/\d+:in `(?:block in )?(?:assert_|test_)?(.+)'/, 1]
name = entry[/\d+:in `(?:block (?:\(\d+ levels\) )?in )?(?:assert_|test_|<module:)?(.+?)\>?'/, 1]

COLLECTED[name] << source
super
Expand All @@ -46,7 +64,17 @@ namespace :seattlerb do
RubyParserTestCase.prepend(Hook)
Minitest.after_run do
Hook::COLLECTED.each do |(name, codes)|
filepath = "test/fixtures/seattlerb/#{name.delete!('?')}.txt"
name = name.delete("?")

# Clean up the names a bit
renames.each_with_index do |rename, index|
if name.start_with?(rename)
name = "difficult#{index}_#{name.delete_prefix(rename)}"
break
end
end

filepath = "test/fixtures/seattlerb/#{name}.txt"
File.write(filepath, "#{codes.uniq.sort.join("\n\n")}\n")
end

Expand Down
10 changes: 5 additions & 5 deletions rakelib/unparser.rake
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# frozen_string_literal: true

# These files are not valid Ruby
known_failures = %w(
test/fixtures/unparser/corpus/literal/binary.txt
)

namespace :unparser do
desc "Ensure there's a local copy of mbj/unparser"
file "tmp/unparser" do
Expand All @@ -30,6 +25,11 @@ namespace :unparser do
filepath = "test/fixtures/unparser/corpus/literal/pattern.txt"
File.write(filepath, File.read(filepath).gsub("\"\#{\"a\"}\"", "\"a\""))

# These files are not valid Ruby
known_failures = %w[
test/fixtures/unparser/corpus/literal/binary.txt
]

# Remove all invalid Ruby files
known_failures.each { rm _1 }
end
Expand Down
14 changes: 7 additions & 7 deletions rakelib/whitequark.rake
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
# APIs provided to the test suite (for example the ParseHelper module below).
# This is obviously relatively brittle, but it's effective for now.

# These files are not valid Ruby
known_failures = %w(
test/fixtures/whitequark/range_endless.txt
test/fixtures/whitequark/control_meta_escape_chars_in_regexp__since_31.txt
test/fixtures/whitequark/pattern_match.txt
)

namespace :whitequark do
desc "Ensure there's a local copy of whitequark/parser"
file "tmp/whitequark" do
Expand Down Expand Up @@ -85,6 +78,13 @@ namespace :whitequark do
File.write("test/fixtures/whitequark/#{name}.txt", "#{codes.sort.join("\n\n")}\n")
end

# These files are not valid Ruby
known_failures = %w[
test/fixtures/whitequark/range_endless.txt
test/fixtures/whitequark/control_meta_escape_chars_in_regexp__since_31.txt
test/fixtures/whitequark/pattern_match.txt
]

# Remove all invalid Ruby files
known_failures.each { rm _1 }
end
Expand Down
70 changes: 34 additions & 36 deletions src/yarp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6671,7 +6671,7 @@ parser_lex(yp_parser_t *parser) {
((parser->current.end - parser->current.start) == 7) &&
current_token_starts_line(parser) &&
(strncmp(parser->current.start, "__END__", 7) == 0) &&
(*parser->current.end == '\n' || (*parser->current.end == '\r' && parser->current.end[1] == '\n'))
(parser->current.end == parser->end || *parser->current.end == '\n' || (*parser->current.end == '\r' && parser->current.end[1] == '\n'))
) {
parser->current.end = parser->end;
parser->current.type = YP_TOKEN___END__;
Expand Down Expand Up @@ -9011,7 +9011,7 @@ parse_conditional(yp_parser_t *parser, yp_context_t context) {
}

yp_token_t end_keyword = not_provided(parser);
yp_node_t *parent;
yp_node_t *parent = NULL;

switch (context) {
case YP_CONTEXT_IF:
Expand All @@ -9021,7 +9021,6 @@ parse_conditional(yp_parser_t *parser, yp_context_t context) {
parent = (yp_node_t *) yp_unless_node_create(parser, &keyword, predicate, statements);
break;
default:
parent = NULL;
assert(false && "unreachable");
break;
}
Expand Down Expand Up @@ -9067,50 +9066,49 @@ parse_conditional(yp_parser_t *parser, yp_context_t context) {
switch (context) {
case YP_CONTEXT_IF:
((yp_if_node_t *) current)->consequent = (yp_node_t *) else_node;
// Recurse down if nodes setting the appropriate end location in
// all cases.
yp_node_t *recursing_node = parent;
bool recursing = true;

while (recursing) {
switch (YP_NODE_TYPE(recursing_node)) {
case YP_NODE_IF_NODE:
yp_if_node_end_keyword_loc_set((yp_if_node_t *) recursing_node, &parser->previous);
recursing_node = ((yp_if_node_t *) recursing_node)->consequent;
break;
case YP_NODE_ELSE_NODE:
yp_else_node_end_keyword_loc_set((yp_else_node_t *) recursing_node, &parser->previous);
recursing = false;
break;
default: {
recursing = false;
break;
}
}
}
break;
case YP_CONTEXT_UNLESS:
((yp_unless_node_t *) parent)->consequent = else_node;
yp_unless_node_end_keyword_loc_set((yp_unless_node_t *) parent, &parser->previous);
break;
default:
assert(false && "unreachable");
break;
}
} else {
expect(parser, YP_TOKEN_KEYWORD_END, "Expected `end` to close `if` statement.");
expect(parser, YP_TOKEN_KEYWORD_END, "Expected `end` to close conditional statement.");
}

switch (context) {
case YP_CONTEXT_IF:
yp_if_node_end_keyword_loc_set((yp_if_node_t *) parent, &parser->previous);
break;
case YP_CONTEXT_UNLESS:
yp_unless_node_end_keyword_loc_set((yp_unless_node_t *) parent, &parser->previous);
break;
default:
assert(false && "unreachable");
break;
// Set the appropriate end location for all of the nodes in the subtree.
switch (context) {
case YP_CONTEXT_IF: {
yp_node_t *current = parent;
bool recursing = true;

while (recursing) {
switch (YP_NODE_TYPE(current)) {
case YP_NODE_IF_NODE:
yp_if_node_end_keyword_loc_set((yp_if_node_t *) current, &parser->previous);
current = ((yp_if_node_t *) current)->consequent;
recursing = current != NULL;
break;
case YP_NODE_ELSE_NODE:
yp_else_node_end_keyword_loc_set((yp_else_node_t *) current, &parser->previous);
recursing = false;
break;
default: {
recursing = false;
break;
}
}
}
break;
}
case YP_CONTEXT_UNLESS:
yp_unless_node_end_keyword_loc_set((yp_unless_node_t *) parent, &parser->previous);
break;
default:
assert(false && "unreachable");
break;
}

return parent;
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/regex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ foo /bar/
/(?#\))/ =~ "hi"

%r#pound#

/aaa #{bbb}/o
92 changes: 92 additions & 0 deletions test/fixtures/seattlerb/TestRubyParserShared.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
%I[


]

%I[
line2
line3
]

%W[


]

%W[
line2
line3
]

%i[


]

%i[
line2
line3
]

%r[


]

%w[


]

%w[
line2
line3
]

[
:line2,
:line3
]

class X # line 1
def self.y(a, # line 2
b) # line 3
a + b # line 4
end # line 5
end # line 6


class X # line 1
class Y # line 2
Z = 42 # line 3
end # line 4
end # line 5


class X # line 1
def y(a, # line 2
b) # line 3
a + b # line 4
end # line 5
end # line 6


module X
X = [
:line3,
:line4,
]
end


module X # line 1
module Y # line 2
Z = 42 # line 3
end # line 4
end # line 5


x(
:line2,
:line3
)
2 changes: 1 addition & 1 deletion test/fixtures/seattlerb/case_in.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
case :a
in "b":
in "b":
end

case :a
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/seattlerb/defn_forward_args__no_parens.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def f ...
m(...)
end
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if true then
p('a')
p("a")
b = 1
p b
c =1
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
a = <<~EOF
x

z
EOF

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/seattlerb/module_comments.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# blah 1

# blah 2

module X
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/seattlerb/parse_line_trailing_newlines.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
a
a
b
2 changes: 1 addition & 1 deletion test/fixtures/seattlerb/pct_Q_backslash_nl.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
%Q{ \
%q{ \
}
2 changes: 1 addition & 1 deletion test/fixtures/seattlerb/slashy_newlines_within_string.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ puts "hello\
friend"

a + b

Loading

0 comments on commit b1c3374

Please sign in to comment.