ruby 在jruby-parser中添加context-blocks示例之前和之后。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 在jruby-parser中添加context-blocks示例之前和之后。相关的知识,希望对你有一定的参考价值。

with a faked failure resulting from altering the 'no assignment to the splat' spec to purposefully fail like this:

```ruby
        it "parses a splat that should recieve no assignment" do
          parse("a,*b,c,d = 1,2,3,4", v).find_node(:multipleasgn).tap do |masgn|
            masgn.should have_static_assignments([[:a, 1], [:b, []], [:c, 2], [:d, 3]])
          end
        end
```

```
$ rake spec
...build process output...

.........................................................................................................................................................F...F....................................................................................................................................

Failures:

  1) Java::OrgJrubyparser::Parser left-hand side splat multiple assignment [1.9] parses a splat that should recieve no assignment
     Failure/Error: masgn.should have_static_assignments([[:a, 1], [:b, []], [:c, 2], [:d, 3]])
       names: 
       values: [] != [2] 2 != 3 3 != 4 
     # ./spec/jruby-parser/static_analysis_spec.rb:50:in `(root)'
     # ./spec/jruby-parser/static_analysis_spec.rb:49:in `(root)'

  2) Java::OrgJrubyparser::Parser left-hand side splat multiple assignment [2.0] parses a splat that should recieve no assignment
     Failure/Error: masgn.should have_static_assignments([[:a, 1], [:b, []], [:c, 2], [:d, 3]])
       names: 
       values: [] != [2] 2 != 3 3 != 4 
     # ./spec/jruby-parser/static_analysis_spec.rb:50:in `(root)'
     # ./spec/jruby-parser/static_analysis_spec.rb:49:in `(root)'

Finished in 7.69 seconds
290 examples, 2 failures

Failed examples:

rspec ./spec/jruby-parser/static_analysis_spec.rb:48 # Java::OrgJrubyparser::Parser left-hand side splat multiple assignment [1.9] parses a splat that should recieve no assignment
rspec ./spec/jruby-parser/static_analysis_spec.rb:48 # Java::OrgJrubyparser::Parser left-hand side splat multiple assignment [2.0] parses a splat that should recieve no assignment
/home/eric/.rbenv/versions/jruby-1.7.4/bin/jruby -J-ea -Ilib -S rspec ./spec/ast/node/break_spec.rb ./spec/ast/node/comments_spec.rb ./spec/ast/node/find_scopes_spec.rb ./spec/ast/node/get_declaration_spec.rb ./spec/ast/node/get_defined_scope_spec.rb ./spec/ast/node/get_node_at_spec.rb ./spec/ast/node/get_occurences_spec.rb ./spec/ast/node/is_block_parameter_spec.rb ./spec/ast/node/is_method_parameter_spec.rb ./spec/ast/node/next_spec.rb ./spec/ast/node/return_spec.rb ./spec/jruby-parser/find_spec.rb ./spec/jruby-parser/parse_spec.rb ./spec/jruby-parser/rewriting_spec.rb ./spec/jruby-parser/static_analysis_spec.rb ./spec/parser/alias_spec.rb ./spec/parser/broken_spec.rb ./spec/positions/alias_spec.rb ./spec/positions/arg_spec.rb ./spec/positions/attr_asgn_spec.rb ./spec/positions/call_spec.rb ./spec/positions/conditionals_spec.rb ./spec/positions/hash_spec.rb ./spec/positions/heredoc_spec.rb ./spec/positions/name_spec.rb ./spec/positions/op_asgn_or_spec.rb ./spec/positions/str_spec.rb ./spec/util/node_diff_spec.rb failed
```
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(:multipleasgn).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(:multipleasgn).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(:multipleasgn).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(:multipleasgn).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(:multipleasgn).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(:multipleasgn).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(:multipleasgn).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(:multipleasgn).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(:multipleasgn).tap do |masgn|
          masgn.should have_static_assignments([[:a, 1], [:b, []], [:c, 2], [:d, 3]])
        end
      end
    end
  end
end
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(:multipleasgn).tap do |masgn|
          masgn.should have_static_assignments([[:a, 1], [:b, 2], [:c, 3]])
        end
      end

      context "left-hand side splat multiple assignment [#{v}]" do
        it "parses a splat as the last assignment" do
          parse("a,*b = 1,2,3", v).find_node(:multipleasgn).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(:multipleasgn).tap do |masgn|
            masgn.should have_static_assignments([[:a, 1], [:b, 2], [:c, [3,4]]])
          end
        end

        it "parses a splat as the first assignment" do
          parse("*a,b = 1,2,3", v).find_node(:multipleasgn).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(:multipleasgn).tap do |masgn|
            masgn.should have_static_assignments([[:a, [1, 2]], [:b, 3], [:c, 4]])
          end
        end

        it "parses a splat as the middle assignment" do
          parse("a,*b, c = 1,2,3,4", v).find_node(:multipleasgn).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(:multipleasgn).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(:multipleasgn).tap do |masgn|
            masgn.should have_static_assignments([[:a, 1], [:b, [2, 3]], [:c, 4], [:d, 5]])
          end
        end

        it "parses a splat that should recieve no assignment" do
          parse("a,*b,c,d = 1,2,3", v).find_node(:multipleasgn).tap do |masgn|
            masgn.should have_static_assignments([[:a, 1], [:b, []], [:c, 2], [:d, 3]])
          end
        end
      end
    end
  end
end

以上是关于ruby 在jruby-parser中添加context-blocks示例之前和之后。的主要内容,如果未能解决你的问题,请参考以下文章

ruby 在从JRuby-Parser添加context-blocks示例之前。

如何在数组 ruby​​ 中添加元素?

如何在 Ruby 中向异常消息中添加信息?

ruby 显示如何在RPG中转换为不同数据类型的示例(RPG源保存为Ruby代码以添加语法突出显示)。

在 ruby​​ 循环的结束标记中添加连字符是啥意思 <% -%>

如何在子类中添加命名参数或在 Ruby 2.2 中更改它们的默认值?