diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2023-12-01 12:22:01 -0500 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-12-01 20:53:34 +0000 |
| commit | 492c82cb417a92d1941f10b52e77ec0c4b2cc8a6 (patch) | |
| tree | 3358d814456f46c6adb80921e968d1fb5258ce04 /test | |
| parent | b77551adee831302f22dc7d9fdccd597923511c4 (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')
| -rw-r--r-- | test/prism/ruby_api_test.rb | 12 |
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 |
