Sha256: a719ef047f66053bf0296c7c60086c45096e8de2ca8f4b79fcf23649404dffd6

Contents?: true

Size: 1002 Bytes

Versions: 4

Compression:

Stored size: 1002 Bytes

Contents

require 'spec_helper'
module Gisele::Language
  describe ScopingHelper do

    let(:rw_class) do
      Class.new(Sexpr::Rewriter) do
        grammar Gisele::Language
        helper ScopingHelper

        def on_hello(node)
          scope_stack.dup
        end

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

      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

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
gisele-language-0.6.0 spec/language/processors/test_scoping_helper.rb
gisele-language-0.5.1 spec/language/processors/test_scoping_helper.rb
gisele-language-0.5.0 spec/language/processors/test_scoping_helper.rb
gisele-0.5.0 spec/unit/language/processors/test_scoping_helper.rb