summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_compile_prism.rb344
1 files changed, 244 insertions, 100 deletions
diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb
index 52099d87a7..d1543122cb 100644
--- a/test/ruby/test_compile_prism.rb
+++ b/test/ruby/test_compile_prism.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
+# This file is organized to match itemization in https://github.com/ruby/prism/issues/1335
module Prism
class TestCompilePrism < Test::Unit::TestCase
def test_empty_program
@@ -37,17 +38,6 @@ module Prism
test_prism_eval("010")
end
- def test_MatchLastLineNode
- test_prism_eval("if /foo/; end")
- test_prism_eval("if /foo/i; end")
- test_prism_eval("if /foo/x; end")
- test_prism_eval("if /foo/m; end")
- test_prism_eval("if /foo/im; end")
- test_prism_eval("if /foo/mx; end")
- test_prism_eval("if /foo/xi; end")
- test_prism_eval("if /foo/ixm; end")
- end
-
def test_NilNode
test_prism_eval("nil")
end
@@ -61,6 +51,19 @@ module Prism
test_prism_eval("self")
end
+ def test_SourceEncodingNode
+ test_prism_eval("__ENCODING__")
+ end
+
+ def test_SourceFileNode
+ test_prism_eval("__FILE__")
+ end
+
+ # TODO
+ def test_SourceLineNode
+ # test_prism_eval("__LINE__")
+ end
+
def test_TrueNode
test_prism_eval("true")
end
@@ -69,6 +72,10 @@ module Prism
# Reads #
############################################################################
+ def test_BackReferenceReadNode
+ # TOO
+ end
+
def test_ClassVariableReadNode
test_prism_eval("class Prism::TestCompilePrism; @@pit = 1; @@pit; end")
end
@@ -81,6 +88,10 @@ module Prism
test_prism_eval("Prism")
end
+ def test_DefinedNode
+ # TODO
+ end
+
def test_GlobalVariableReadNode
test_prism_eval("$pit = 1; $pit")
end
@@ -93,43 +104,41 @@ module Prism
test_prism_eval("pit = 1; pit")
end
+ def test_NumberedReferenceReadNode
+ # TODO
+ end
+
############################################################################
# Writes #
############################################################################
- def test_ClassVariableTargetNode
- test_prism_eval("class Prism::TestCompilePrism; @@pit, @@pit1 = 1; end")
- end
-
- def test_ClassVariableWriteNode
- test_prism_eval("class Prism::TestCompilePrism; @@pit = 1; end")
- end
-
def test_ClassVariableAndWriteNode
test_prism_eval("class Prism::TestCompilePrism; @@pit = 0; @@pit &&= 1; end")
end
+ def test_ClassVariableOperatorWriteNode
+ test_prism_eval("class Prism::TestCompilePrism; @@pit = 0; @@pit += 1; end")
+ end
+
def test_ClassVariableOrWriteNode
test_prism_eval("class Prism::TestCompilePrism; @@pit = 1; @@pit ||= 0; end")
test_prism_eval("class Prism::TestCompilePrism; @@pit = nil; @@pit ||= 1; end")
end
- def test_ClassVariableOperatorWriteNode
- test_prism_eval("class Prism::TestCompilePrism; @@pit = 0; @@pit += 1; end")
+ def test_ClassVariableWriteNode
+ test_prism_eval("class Prism::TestCompilePrism; @@pit = 1; end")
end
- def test_ConstantTargetNode
- # We don't call test_prism_eval directly in this case becuase we
- # don't want to assign the constant mutliple times if we run
- # with `--repeat-count`
- # Instead, we eval manually here, and remove the constant to
- constant_names = ["YCT", "YCT2"]
- source = "#{constant_names.join(",")} = 1"
- prism_eval = RubyVM::InstructionSequence.compile_prism(source).eval
- assert_equal prism_eval, 1
- constant_names.map { |name|
- Object.send(:remove_const, name)
- }
+ def test_ConstantAndWriteNode
+ # TODO
+ end
+
+ def test_ConstantOperatorWriteNode
+ # TODO
+ end
+
+ def test_ConstantOrWriteNode
+ # TODO
end
def test_ConstantWriteNode
@@ -144,91 +153,57 @@ module Prism
Object.send(:remove_const, constant_name)
end
- def test_ConstantPathTargetNode
- verbose = $VERBOSE
- # Create some temporary nested constants
- Object.send(:const_set, "MyFoo", Object)
- Object.const_get("MyFoo").send(:const_set, "Bar", Object)
-
- constant_names = ["MyBar", "MyFoo::Bar", "MyFoo::Bar::Baz"]
- source = "#{constant_names.join(",")} = Object"
- iseq = RubyVM::InstructionSequence.compile_prism(source)
- $VERBOSE = nil
- prism_eval = iseq.eval
- $VERBOSE = verbose
- assert_equal prism_eval, Object
-
- ensure
- ## Teardown temp constants
- Object.const_get("MyFoo").send(:remove_const, "Bar")
- Object.send(:remove_const, "MyFoo")
- Object.send(:remove_const, "MyBar")
- $VERBOSE = verbose
- end
-
def test_ConstantPathWriteNode
test_prism_eval("Prism::CPWN = 1")
test_prism_eval("::CPWN = 1")
end
- def test_GlobalVariableTargetNode
- test_prism_eval("$pit, $pit1 = 1")
- end
-
- def test_GlobalVariableWriteNode
- test_prism_eval("$pit = 1")
- end
-
def test_GlobalVariableAndWriteNode
test_prism_eval("$pit = 0; $pit &&= 1")
end
- def test_GlobalVariableOrWriteNode
- test_prism_eval("$pit ||= 1")
- end
-
def test_GlobalVariableOperatorWriteNode
test_prism_eval("$pit = 0; $pit += 1")
end
- def test_InstanceVariableTargetNode
- test_prism_eval("class Prism::TestCompilePrism; @pit, @pit1 = 1; end")
+ def test_GlobalVariableOrWriteNode
+ test_prism_eval("$pit ||= 1")
end
- def test_InstanceVariableWriteNode
- test_prism_eval("class Prism::TestCompilePrism; @pit = 1; end")
+ def test_GlobalVariableWriteNode
+ test_prism_eval("$pit = 1")
end
def test_InstanceVariableAndWriteNode
test_prism_eval("@pit = 0; @pit &&= 1")
end
- def test_InstanceVariableOrWriteNode
- test_prism_eval("@pit ||= 1")
- end
-
def test_InstanceVariableOperatorWriteNode
test_prism_eval("@pit = 0; @pit += 1")
end
- def test_LocalVariableTargetNode
- test_prism_eval("pit, pit1 = 1")
+ def test_InstanceVariableOrWriteNode
+ test_prism_eval("@pit ||= 1")
end
- def test_LocalVariableWriteNode
- test_prism_eval("pit = 1")
+ def test_InstanceVariableWriteNode
+ test_prism_eval("class Prism::TestCompilePrism; @pit = 1; end")
end
def test_LocalVariableAndWriteNode
test_prism_eval("pit = 0; pit &&= 1")
end
+ def test_LocalVariableOperatorWriteNode
+ test_prism_eval("pit = 0; pit += 1")
+ end
+
def test_LocalVariableOrWriteNode
test_prism_eval("pit ||= 1")
end
- def test_LocalVariableOperatorWriteNode
- test_prism_eval("pit = 0; pit += 1")
+ def test_LocalVariableWriteNode
+ test_prism_eval("pit = 1")
end
def test_MatchWriteNode
@@ -237,9 +212,72 @@ module Prism
end
############################################################################
+ # Multi-writes #
+ ############################################################################
+
+ def test_ClassVariableTargetNode
+ test_prism_eval("class Prism::TestCompilePrism; @@pit, @@pit1 = 1; end")
+ end
+
+ def test_ConstantTargetNode
+ # We don't call test_prism_eval directly in this case becuase we
+ # don't want to assign the constant mutliple times if we run
+ # with `--repeat-count`
+ # Instead, we eval manually here, and remove the constant to
+ constant_names = ["YCT", "YCT2"]
+ source = "#{constant_names.join(",")} = 1"
+ prism_eval = RubyVM::InstructionSequence.compile_prism(source).eval
+ assert_equal prism_eval, 1
+ constant_names.map { |name|
+ Object.send(:remove_const, name)
+ }
+ end
+
+ def test_ConstantPathTargetNode
+ verbose = $VERBOSE
+ # Create some temporary nested constants
+ Object.send(:const_set, "MyFoo", Object)
+ Object.const_get("MyFoo").send(:const_set, "Bar", Object)
+
+ constant_names = ["MyBar", "MyFoo::Bar", "MyFoo::Bar::Baz"]
+ source = "#{constant_names.join(",")} = Object"
+ iseq = RubyVM::InstructionSequence.compile_prism(source)
+ $VERBOSE = nil
+ prism_eval = iseq.eval
+ $VERBOSE = verbose
+ assert_equal prism_eval, Object
+ ensure
+ ## Teardown temp constants
+ Object.const_get("MyFoo").send(:remove_const, "Bar")
+ Object.send(:remove_const, "MyFoo")
+ Object.send(:remove_const, "MyBar")
+ $VERBOSE = verbose
+ end
+
+ def test_GlobalVariableTargetNode
+ test_prism_eval("$pit, $pit1 = 1")
+ end
+
+ def test_InstanceVariableTargetNode
+ test_prism_eval("class Prism::TestCompilePrism; @pit, @pit1 = 1; end")
+ end
+
+ def test_LocalVariableTargetNode
+ test_prism_eval("pit, pit1 = 1")
+ end
+
+ def test_MultiWriteNode
+ # TODO
+ end
+
+ ############################################################################
# String-likes #
############################################################################
+ def test_EmbeddedStatementsNode
+ # TODO
+ end
+
def test_EmbeddedVariableNode
test_prism_eval('class Prism::TestCompilePrism; @pit = 1; "#@pit"; end')
test_prism_eval('class Prism::TestCompilePrism; @@pit = 1; "#@@pit"; end')
@@ -272,6 +310,17 @@ module Prism
test_prism_eval('`printf #{"100"}`')
end
+ def test_MatchLastLineNode
+ test_prism_eval("if /foo/; end")
+ test_prism_eval("if /foo/i; end")
+ test_prism_eval("if /foo/x; end")
+ test_prism_eval("if /foo/m; end")
+ test_prism_eval("if /foo/im; end")
+ test_prism_eval("if /foo/mx; end")
+ test_prism_eval("if /foo/xi; end")
+ test_prism_eval("if /foo/ixm; end")
+ end
+
def test_RegularExpressionNode
test_prism_eval('/pit/')
test_prism_eval('/pit/i')
@@ -315,6 +364,14 @@ module Prism
test_prism_eval("%w[foo bar baz]")
end
+ def test_AssocNode
+ # TODO
+ end
+
+ def test_AssocSplatNode
+ # TODO
+ end
+
def test_HashNode
test_prism_eval("{}")
test_prism_eval("{ a: :a }")
@@ -326,6 +383,14 @@ module Prism
test_prism_eval("[ Prism: [:b, :c]]")
end
+ def test_ImplicitNode
+ # TODO
+ end
+
+ def test_RangeNode
+ # TODO
+ end
+
def test_SplatNode
test_prism_eval("*b = []")
end
@@ -339,16 +404,6 @@ module Prism
test_prism_eval("false && 1")
end
- def test_OrNode
- test_prism_eval("true || 1")
- test_prism_eval("false || 1")
- end
-
- def test_IfNode
- test_prism_eval("if true; 1; end")
- test_prism_eval("1 if true")
- end
-
def test_ElseNode
test_prism_eval("if false; 0; else; 1; end")
test_prism_eval("if true; 0; else; 1; end")
@@ -361,12 +416,50 @@ module Prism
test_prism_eval("not (1 == 1) ... (2 == 2)")
end
+ def test_IfNode
+ test_prism_eval("if true; 1; end")
+ test_prism_eval("1 if true")
+ end
+
+ def test_OrNode
+ test_prism_eval("true || 1")
+ test_prism_eval("false || 1")
+ end
+
+ def test_UnlessNode
+ # TODO
+ end
+
+ def test_UntilNode
+ # TODO
+ end
+
+ def test_WhileNode
+ # TODO
+ end
+
############################################################################
- # Calls / arugments #
+ # Throws #
############################################################################
- def test_BlockArgumentNode
- test_prism_eval("1.then(&:to_s)")
+ def test_BeginNode
+ # TODO
+ end
+
+ def test_BreakNode
+ # TODO
+ end
+
+ def test_NextNode
+ # TODO
+ end
+
+ def test_RedoNode
+ # TODO
+ end
+
+ def test_ReturnNode
+ # TODO
end
############################################################################
@@ -386,6 +479,15 @@ module Prism
)
end
+ def test_DefNode
+ test_prism_eval("def prism_method; end")
+ test_prism_eval("a = Object.new; def a.prism_singleton; :ok; end; a.prism_singleton")
+ end
+
+ def test_LambdaNode
+ # TODO
+ end
+
def test_ModuleNode
test_prism_eval("module M; end")
test_prism_eval("module M::N; end")
@@ -397,6 +499,42 @@ module Prism
test_prism_eval("(1)")
end
+ def test_ProgramNode
+ # TODO
+ end
+
+ def test_SingletonClassNode
+ # TODO
+ end
+
+ def test_StatementsNode
+ # TODO
+ end
+
+ def test_YieldNode
+ # TODO
+ end
+
+ ############################################################################
+ # Calls / arugments #
+ ############################################################################
+
+ def test_ArgumentsNode
+ # TODO
+ end
+
+ def test_BlockArgumentNode
+ test_prism_eval("1.then(&:to_s)")
+ end
+
+ def test_CallNode
+ # TODO
+ end
+
+ def test_KeywordHashNode
+ # TODO
+ end
+
############################################################################
# Methods / parameters #
############################################################################
@@ -409,9 +547,8 @@ module Prism
test_prism_eval("alias :prism_a :to_s")
end
- def test_DefNode
- test_prism_eval("def prism_method; end")
- test_prism_eval("a = Object.new; def a.prism_singleton; :ok; end; a.prism_singleton")
+ def test_OptionalParameterNode
+ # TODO
end
def test_UndefNode
@@ -432,7 +569,6 @@ module Prism
)
end
-
############################################################################
# Pattern matching #
############################################################################
@@ -514,11 +650,19 @@ module Prism
$VERBOSE = verbose_bak
end
end
- test_prism_eval("a = 1; tap do; { a: }; end")
- test_prism_eval("a = 1; def foo(a); a; end")
+ test_prism_eval("a = 1; tap do; { a: }; end")
+ test_prism_eval("a = 1; def foo(a); a; end")
end;
end
+ ############################################################################
+ # Errors #
+ ############################################################################
+
+ def test_MissingNode
+ # TODO
+ end
+
private
def compare_eval(source)