summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2023-11-02 14:01:20 -0400
committerKevin Newton <[email protected]>2023-11-03 10:13:49 -0400
commit05f5c545d232554b6ffb183d6948ad37f46df53b (patch)
tree43ab5b181b7fb31e5421a9adda59f822e0d65c45 /test
parentca7297efd389eca792c706326d1af138acf5a4f6 (diff)
[ruby/prism] Wire up options through the FFI API
https://github.com/ruby/prism/commit/f0aa8ad93b
Diffstat (limited to 'test')
-rw-r--r--test/prism/parse_serialize_test.rb38
-rw-r--r--test/prism/ruby_api_test.rb13
2 files changed, 13 insertions, 38 deletions
diff --git a/test/prism/parse_serialize_test.rb b/test/prism/parse_serialize_test.rb
deleted file mode 100644
index 001518c14d..0000000000
--- a/test/prism/parse_serialize_test.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# frozen_string_literal: true
-
-require_relative "test_helper"
-
-return if Prism::BACKEND == :FFI
-
-module Prism
- class ParseSerializeTest < TestCase
- def test_parse_serialize
- dumped = Debug.parse_serialize_file(__FILE__)
- result = Prism.load(File.read(__FILE__), dumped)
-
- assert_kind_of ParseResult, result, "Expected the return value to be a ParseResult"
- assert_equal __FILE__, find_file_node(result)&.filepath, "Expected the filepath to be set correctly"
- end
-
- def test_parse_serialize_with_locals
- filepath = __FILE__
- metadata = [filepath.bytesize, filepath.b, 1, 1, 1, "foo".b].pack("LA*LLLA*")
-
- dumped = Debug.parse_serialize_file_metadata(filepath, metadata)
- result = Prism.load(File.read(__FILE__), dumped)
-
- assert_kind_of ParseResult, result, "Expected the return value to be a ParseResult"
- end
-
- private
-
- def find_file_node(result)
- queue = [result.value]
-
- while (node = queue.shift)
- return node if node.is_a?(SourceFileNode)
- queue.concat(node.compact_child_nodes)
- end
- end
- end
-end
diff --git a/test/prism/ruby_api_test.rb b/test/prism/ruby_api_test.rb
index efe8bc1c1b..844a7796a3 100644
--- a/test/prism/ruby_api_test.rb
+++ b/test/prism/ruby_api_test.rb
@@ -20,6 +20,19 @@ module Prism
assert_equal_nodes ast2, ast3
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
+
+ refute Prism.parse("\"foo\"").value.statements.body[0].frozen?
+ assert Prism.parse("\"foo\"", frozen_string_literal: true).value.statements.body[0].frozen?
+ refute Prism.parse("\"foo\"", frozen_string_literal: false).value.statements.body[0].frozen?
+
+ assert_kind_of Prism::CallNode, Prism.parse("foo").value.statements.body[0]
+ assert_kind_of Prism::LocalVariableReadNode, Prism.parse("foo", scopes: [[:foo]]).value.statements.body[0]
+ assert_equal 2, Prism.parse("foo", scopes: [[:foo], []]).value.statements.body[0].depth
+ end
+
def test_literal_value_method
assert_equal 123, parse_expression("123").value
assert_equal 3.14, parse_expression("3.14").value