ruby 在从JRuby-Parser添加context-blocks示例之前。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 在从JRuby-Parser添加context-blocks示例之前。相关的知识,希望对你有一定的参考价值。
require_relative '../helpers'
describe Parser do
VERSIONS.each do |v|
if v == 2.0
it "test 2.0" do
parse("def foo(a:1); p a; end", v)
end
end
if v != 1.8
it "parses a simple multiple assignment [#{v}]" do
parse("a,b,c = 1,2,3", v).find_node(:multipleasgn19).tap do |masgn|
masgn.should have_static_assignments([[:a, 1], [:b, 2], [:c, 3]])
end
end
it "parses a simple lhs splat multiple assignment [#{v}]" do
parse("a,*b = 1,2,3", v).find_node(:multipleasgn19).tap do |masgn|
masgn.should have_static_assignments([[:a, 1], [:b, [2, 3]]])
end
parse("a,b,*c = 1,2,3,4", v).find_node(:multipleasgn19).tap do |masgn|
masgn.should have_static_assignments([[:a, 1], [:b, 2], [:c, [3,4]]])
end
end
it "parses a simple lhs splat multiple assignment [#{v}]" do
parse("*a,b = 1,2,3", v).find_node(:multipleasgn19).tap do |masgn|
masgn.should have_static_assignments([[:a, [1, 2]], [:b, 3]])
end
parse("*a,b,c = 1,2,3,4", v).find_node(:multipleasgn19).tap do |masgn|
masgn.should have_static_assignments([[:a, [1, 2]], [:b, 3], [:c, 4]])
end
end
it "parses a simple lhs splat multiple assignment [#{v}]" do
parse("a,*b, c = 1,2,3,4", v).find_node(:multipleasgn19).tap do |masgn|
masgn.should have_static_assignments([[:a, 1], [:b, [2, 3]], [:c, 4]])
end
parse("a, b, *c, d = 1,2,3,4,5", v).find_node(:multipleasgn19).tap do |masgn|
masgn.should have_static_assignments([[:a, 1], [:b, 2], [:c, [3, 4]], [:d, 5]])
end
parse("a, *b, c, d = 1,2,3,4,5", v).find_node(:multipleasgn19).tap do |masgn|
masgn.should have_static_assignments([[:a, 1], [:b, [2, 3]], [:c, 4], [:d, 5]])
end
end
it "parses a simple lhs splat multiple assignment [#{v}]" do
parse("a,*b,c,d = 1,2,3", v).find_node(:multipleasgn19).tap do |masgn|
masgn.should have_static_assignments([[:a, 1], [:b, []], [:c, 2], [:d, 3]])
end
end
it "parses a simple rhs splat multiple assignment [#{v}]" do
ast = parse("a,*b = 1,*foo", v)
foo = ast.find_node(:vcall)
ast.find_node(:multipleasgn19).tap do |masgn|
masgn.should have_static_assignments([[:a, 1], [:b, foo]])
end
end
it "parses a simple rhs splat multiple assignment [#{v}]" do
ast = parse("*a,b = *foo,1", v)
splatted_foo = ast.find_node(:splat)
ast.find_node(:multipleasgn19).tap do |masgn|
masgn.should have_static_assignments([[:a, splatted_foo], [:b, 1]])
end
end
end
it "method: can parse an empty body method with unused param [#{v}]" do
parse("def foo(a)\nend").find_node(:defn) do |defn|
defn.args.get_normative_parameter_name_list(true).each do |parameter|
defn.is_parameter_used(parameter).should == false
end
end
end
it "method: Can detect simple parameter is used" do
parse("def foo(a); a; end").find_node(:defn) do |defn|
defn.args.get_normative_parameter_name_list(true).each do |parameter|
defn.is_parameter_used(parameter).should == true
end
end
parse("def foo(a,b); a; b; end").find_node(:defn) do |defn|
defn.args.get_normative_parameter_name_list(true).each do |parameter|
defn.is_parameter_used(parameter).should == true
end
end
parse("def foo(a,b); a=1; b; end").find_node(:defn) do |defn|
defn.is_parameter_used("a").should == false
defn.is_parameter_used("b").should == true
end
end
it "method: Can detect some simple parameters are used" do
parse("def foo(a,b); b; end").find_node(:defn) do |defn|
defn.is_parameter_used("a").should == false
defn.is_parameter_used("b").should == true
end
parse("def foo(a,b); b if true; end").find_node(:defn) do |defn|
defn.is_parameter_used("a").should == false
defn.is_parameter_used("b").should == true
end
parse("def foo(a,b); proc { b if true }; end").find_node(:defn) do |defn|
defn.is_parameter_used("a").should == false
defn.is_parameter_used("b").should == true
end
parse("def foo a, b, c\nputs a, b, c\nend").find_node(:defn) do |defn|
defn.is_parameter_used("a").should == true
defn.is_parameter_used("b").should == true
defn.is_parameter_used("c").should == true
end
parse("def foo(a, b); b.each_answer {|n| data if n == a }; end") do |defn|
defn.is_parameter_used("a").should == true
defn.is_parameter_used("b").should == true
end
end
it "method: Can detect some simple optarg params are used" do
parse("def foo(a,b = {}); b; end").find_node(:defn) do |defn|
defn.is_parameter_used("a").should == false
defn.is_parameter_used("b").should == true
end
end
it "method: Can detect zsuper usage" do
parse("def foo(a,b = {}); super; end").find_node(:defn) do |defn|
defn.is_parameter_used("a").should == true
defn.is_parameter_used("b").should == true
end
end
it "block/iter: can parse an empty proc body with unused param [#{v}]" do
parse("proc do |a|\nend").find_node(:iter) do |iter|
iter.is_parameter_used("a").should == false
end
end
it "block/iter: Can detect simple parameter is used" do
parse("proc { |a, b| a; b }").find_node(:iter) do |iter|
iter.is_parameter_used("a").should == true
iter.is_parameter_used("b").should == true
end
end
it "block/iter: Can detect simple parameter is used" do
parse("proc { |a, b| a=1; b }").find_node(:iter) do |iter|
iter.is_parameter_used("a").should == false
iter.is_parameter_used("b").should == true
end
end
it "block/iter: Can detect some simple parameters are used" do
parse("proc {|a,b| b }").find_node(:iter) do |iter|
iter.is_parameter_used("a").should == false
iter.is_parameter_used("b").should == true
end
parse("proc {|a,b| b if true }").find_node(:iter) do |iter|
iter.is_parameter_used("a").should == false
iter.is_parameter_used("b").should == true
end
parse("proc {|a,b| proc { b if true } }").find_node(:iter) do |iter|
iter.is_parameter_used("a").should == false
iter.is_parameter_used("b").should == true
end
parse("proc {|a, b, c| puts a, b, c }").find_node(:iter) do |iter|
iter.is_parameter_used("a").should == true
iter.is_parameter_used("b").should == true
iter.is_parameter_used("c").should == true
end
parse("proc {|a, b| b.each_answer {|n| data if n == a } }") do |iter|
iter.is_parameter_used("a").should == true
iter.is_parameter_used("b").should == true
end
end
end
end
以上是关于ruby 在从JRuby-Parser添加context-blocks示例之前。的主要内容,如果未能解决你的问题,请参考以下文章
ruby 在jruby-parser中添加context-blocks示例之前和之后。
如何将在从控制台获取的 URL 中找到的特定字符串替换为在 Ruby 文本文件中写入的每一行中找到的文件内容?
使用适用于Ruby on Rails的AWS CI / CI流程进行部署
禁用添加对象的选项,该对象已经在从 NSUserDefaults 加载的数组中