Sha256: 427dc24426747027bda9b9dcc0fafede56d3a3cc330f1508a2c0d498f887e7dd

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'


describe TodoNext::Tree, 'visiting the tree depth-first' do


  class SimpleVisitor < TodoNext::Tree::DepthFirstVisitorBase
    def process_terminal_node(curr_node, level)
      curr_node.text
    end

    def process_non_terminal_node(curr_node, level)
      result = curr_node.children.collect { |node| visit(node, 1+level) }.join(', ')
      "#{curr_node.text}=[#{result}]"
    end
  end


  it 'visits the tree depth-first' do
    expected = ['HEADER 1=[HEADER 2=[HEADER 3=[spec a, spec b]]]' ,
                'HEADER 4=[spec c]',
                'HEADER 5',
                'HEADER 6'
               ]

    source = 'HEADER 1'            + "\n" +
              '  HEADER 2'          + "\n" +
              '    HEADER 3'        + "\n" +
              '      spec a'        + "\n" +
              '      spec b'        + "\n" +
              'HEADER 4'            + "\n" +
              '  spec c'            + "\n" +
              'HEADER 5'            + "\n" +
              'HEADER 6'

    TodoNext::Parser.
        parse(source).
        visit(SimpleVisitor.new).
        should == expected
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
todo_next-0.0.1 spec/02_visit_the_tree_spec.rb