forked from ruby/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filepath to yp_parse_serialize metadata
This adds the ability to pass the filepath through the yp_parse_serialize function in the metadata. It also adds documentation about this new API and fixes a couple of places that were calling it with the old signature. Finally, it adds a specific test to ensure yp_parse_serialize doesn't break.
- Loading branch information
Showing
7 changed files
with
140 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
#include <yarp.h> | ||
|
||
void | ||
harness (const char *input, size_t size) { | ||
yp_buffer_t *buffer = malloc (sizeof (yp_buffer_t)); | ||
yp_buffer_init (buffer); | ||
yp_parse_serialize ((const char *)input, size, buffer); | ||
yp_buffer_free (buffer); | ||
free (buffer); | ||
harness(const char *input, size_t size) { | ||
yp_buffer_t buffer; | ||
yp_buffer_init(&buffer); | ||
yp_parse_serialize(input, size, &buffer, NULL); | ||
yp_buffer_free(&buffer); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require "yarp_test_helper" | ||
|
||
class ParseSerializeTest < Test::Unit::TestCase | ||
def test_parse_serialize | ||
dumped = YARP.const_get(:Debug).parse_serialize_file(__FILE__) | ||
result = YARP.load(File.read(__FILE__), dumped) | ||
|
||
assert_kind_of YARP::ProgramNode, result, "Expected the root node to be a ProgramNode" | ||
assert_equal __FILE__, find_file_node(result)&.filepath, "Expected the filepath to be set correctly" | ||
end | ||
|
||
private | ||
|
||
def find_file_node(program) | ||
queue = [program] | ||
|
||
while (node = queue.shift) | ||
return node if node.is_a?(YARP::SourceFileNode) | ||
queue.concat(node.child_nodes.compact) | ||
end | ||
|
||
nil | ||
end | ||
end |