Added TODOs on all implemented nodes, matched ordering

This commit is contained in:
Jemma Issroff 2023-10-18 17:43:13 -03:00
parent a426a230de
commit 40624d4921

View File

@ -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,29 +104,119 @@ 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_ConstantAndWriteNode
# TODO
end
def test_ConstantOperatorWriteNode
# TODO
end
def test_ConstantOrWriteNode
# TODO
end
def test_ConstantWriteNode
# 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_name = "YCT"
source = "#{constant_name} = 1"
prism_eval = RubyVM::InstructionSequence.compile_prism(source).eval
assert_equal prism_eval, 1
Object.send(:remove_const, constant_name)
end
def test_ConstantPathWriteNode
test_prism_eval("Prism::CPWN = 1")
test_prism_eval("::CPWN = 1")
end
def test_GlobalVariableAndWriteNode
test_prism_eval("$pit = 0; $pit &&= 1")
end
def test_GlobalVariableOperatorWriteNode
test_prism_eval("$pit = 0; $pit += 1")
end
def test_GlobalVariableOrWriteNode
test_prism_eval("$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_InstanceVariableOperatorWriteNode
test_prism_eval("@pit = 0; @pit += 1")
end
def test_InstanceVariableOrWriteNode
test_prism_eval("@pit ||= 1")
end
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_LocalVariableWriteNode
test_prism_eval("pit = 1")
end
def test_MatchWriteNode
test_prism_eval("/(?<foo>bar)(?<baz>bar>)/ =~ 'barbar'")
test_prism_eval("/(?<foo>bar)/ =~ 'barbar'")
end
############################################################################
# Multi-writes #
############################################################################
def test_ClassVariableTargetNode
test_prism_eval("class Prism::TestCompilePrism; @@pit, @@pit1 = 1; end")
end
def test_ConstantTargetNode
@ -132,18 +233,6 @@ module Prism
}
end
def test_ConstantWriteNode
# 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_name = "YCT"
source = "#{constant_name} = 1"
prism_eval = RubyVM::InstructionSequence.compile_prism(source).eval
assert_equal prism_eval, 1
Object.send(:remove_const, constant_name)
end
def test_ConstantPathTargetNode
verbose = $VERBOSE
# Create some temporary nested constants
@ -157,7 +246,6 @@ module Prism
prism_eval = iseq.eval
$VERBOSE = verbose
assert_equal prism_eval, Object
ensure
## Teardown temp constants
Object.const_get("MyFoo").send(:remove_const, "Bar")
@ -166,80 +254,30 @@ module Prism
$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")
end
def test_InstanceVariableWriteNode
test_prism_eval("class Prism::TestCompilePrism; @pit = 1; end")
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")
end
def test_LocalVariableWriteNode
test_prism_eval("pit = 1")
end
def test_LocalVariableAndWriteNode
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")
end
def test_MatchWriteNode
test_prism_eval("/(?<foo>bar)(?<baz>bar>)/ =~ 'barbar'")
test_prism_eval("/(?<foo>bar)/ =~ 'barbar'")
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)