summaryrefslogtreecommitdiff
path: root/test/prism/ruby_api_test.rb
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-12-01 12:22:01 -0500
committergit <svn-admin@ruby-lang.org>2023-12-01 20:53:34 +0000
commit492c82cb417a92d1941f10b52e77ec0c4b2cc8a6 (patch)
tree3358d814456f46c6adb80921e968d1fb5258ce04 /test/prism/ruby_api_test.rb
parentb77551adee831302f22dc7d9fdccd597923511c4 (diff)
[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. https://github.com/ruby/prism/commit/7014740118
Diffstat (limited to 'test/prism/ruby_api_test.rb')
-rw-r--r--test/prism/ruby_api_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/prism/ruby_api_test.rb b/test/prism/ruby_api_test.rb
index 54c5fd28e9..b934c26ff4 100644
--- a/test/prism/ruby_api_test.rb
+++ b/test/prism/ruby_api_test.rb
@@ -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