Sha256: 87bd8127ca649661e5cfbe72caf2cfe7300db102105d42938e7230fce93df491

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'spec_helper'
module Gisele::Language
  class Rewriter
    describe Scoping do

      let(:rw_class) do
        Class.new(Rewriter) do

          def on_hello(node)
            scope_stack.dup
          end

          def on_missing(node)
            call(node.children.last)
          end

          Scoping.install_on self
        end
      end
      let(:rw){ rw_class.new }

      it 'installs the methods on the rewriter' do
        rw.respond_to?(:scope_stack).should be_true
      end

      it 'does nothing special on non _def nodes' do
        node = [:hello, "world"]
        rw.call(node).should eq([])
      end

      it 'keeps _def nodes as successive scopes' do
        second = [:task_def, [:hello]]
        first  = [:task_def, second]
        rw.call(first).should eq([first, second])
      end

      it 'pops scopes when returning along the stack' do
        second = [:task_def, [:hello]]
        first  = [:task_def, second]
        rw.call(first)
        rw.scope_stack.should eq([])
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gisele-0.4.0 spec/unit/language/rewriter/test_scoping.rb
gisele-0.3.0 spec/unit/language/rewriter/test_scoping.rb