Sha256: 8dd43fbd498520b711af1b87b8a173ece0696cccd03ead5e70f609e9ab2e5590

Contents?: true

Size: 1.15 KB

Versions: 21

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true
require 'pp'
require 'stringio'

include YARD::Parser::Ruby

RSpec.describe YARD::Parser::Ruby::AstNode do
  describe "#jump" do
    it "jumps to the first specific inner node if found" do
      ast = s(:paren, s(:paren, s(:params, s(s(:ident, "hi"), s(:ident, "bye")))))
      expect(ast.jump(:params)[0][0].type).to equal(:ident)
    end

    it "returns the original ast if no inner node is found" do
      ast = s(:paren, s(:list, s(:list, s(s(:ident, "hi"), s(:ident, "bye")))))
      expect(ast.jump(:params).object_id).to eq ast.object_id
    end
  end

  describe "#pretty_print" do
    it "shows a list of nodes" do
      obj = YARD::Parser::Ruby::RubyParser.parse("# x\nbye", "x").ast
      out = StringIO.new
      PP.pp(obj, out)
      vcall = RUBY_VERSION >= '1.9.3' ? 'vcall' : 'var_ref'
      expect(out.string).to eq "s(s(:#{vcall},\n" \
                               "      s(:ident, \"bye\", line: 2..2, source: 4..6),\n" \
                               "      docstring: \"x\",\n" \
                               "      line: 2..2,\n" \
                               "      source: 4..6))\n"
    end
  end
end if HAVE_RIPPER

Version data entries

21 entries across 20 versions & 4 rubygems

Version Path
yard-0.9.24 spec/parser/ruby/ast_node_spec.rb
yard-0.9.23 spec/parser/ruby/ast_node_spec.rb
yard-0.9.22 spec/parser/ruby/ast_node_spec.rb
yard-0.9.21 spec/parser/ruby/ast_node_spec.rb
yard-0.9.20 spec/parser/ruby/ast_node_spec.rb
yard-0.9.19 spec/parser/ruby/ast_node_spec.rb
yard-0.9.16 spec/parser/ruby/ast_node_spec.rb
yard-0.9.15 spec/parser/ruby/ast_node_spec.rb
yard-0.9.14 spec/parser/ruby/ast_node_spec.rb
yard-0.9.13 spec/parser/ruby/ast_node_spec.rb
yard-0.9.12 spec/parser/ruby/ast_node_spec.rb
yard-0.9.11 spec/parser/ruby/ast_node_spec.rb
yard-0.9.10 spec/parser/ruby/ast_node_spec.rb
yard-0.9.9 spec/parser/ruby/ast_node_spec.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/yard-0.9.8/spec/parser/ruby/ast_node_spec.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/yard-0.9.8/spec/parser/ruby/ast_node_spec.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/yard-0.9.8/spec/parser/ruby/ast_node_spec.rb
yard-0.9.8 spec/parser/ruby/ast_node_spec.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.7/spec/parser/ruby/ast_node_spec.rb
yard-0.9.7 spec/parser/ruby/ast_node_spec.rb