mirror of
https://github.com/ruby/ruby.git
synced 2025-08-26 22:45:03 +02:00
[ruby/prism] Prism.parse_success?(source)
A lot of tools use Ripper/RubyVM::AbstractSyntaxTree to determine
if a source is valid. These tools both create an AST instead of
providing an API that will return a boolean only.
This new API only creates the C structs, but doesn't bother
reifying them into Ruby/the serialization API. Instead it only
returns true/false, which is significantly more efficient.
7014740118
This commit is contained in:
parent
b77551adee
commit
492c82cb41
6 changed files with 133 additions and 1 deletions
|
@ -20,6 +20,18 @@ module Prism
|
|||
assert_equal_nodes ast2, ast3
|
||||
end
|
||||
|
||||
def test_parse_success?
|
||||
assert Prism.parse_success?("1")
|
||||
refute Prism.parse_success?("<>")
|
||||
|
||||
assert Prism.parse_success?("m //", verbose: false)
|
||||
refute Prism.parse_success?("m //", verbose: true)
|
||||
end
|
||||
|
||||
def test_parse_file_success?
|
||||
assert Prism.parse_file_success?(__FILE__)
|
||||
end
|
||||
|
||||
def test_options
|
||||
assert_equal "", Prism.parse("__FILE__").value.statements.body[0].filepath
|
||||
assert_equal "foo.rb", Prism.parse("__FILE__", filepath: "foo.rb").value.statements.body[0].filepath
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue