Sha256: 66de27421810df4ac2207a7b7e5f22b54eb092ccc71078e625df5c5b6c7d347a

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

require "spec_helper"

describe Liquor::Context do
  before do
    @compiler = Liquor::Compiler.new
    @context  = Liquor::Context.new(@compiler, ['ext', 'ext2'])
  end

  it "declares variables" do
    @context.type('a').should == :free
    @context.declare 'a'
    @context.type('a').should == :variable
  end

  it "verifies variable names" do
    expect { @context.declare 'null' }.to raise_error(Liquor::NameError)
    expect { @context.declare 'a' }.not_to raise_error
    expect { @context.declare 'a' }.not_to raise_error
    expect { @context.declare 'ext' }.not_to raise_error
  end

  it "mangles names" do
    @context.declare '_env'
    @context.access('_env').should_not be_nil
    @context.access('_env').should_not == '_env'
  end

  it "supports nesting" do
    @context.nest do
      @context.declare 'test'
    end
    expect { @context.access 'test' }.to raise_error(Liquor::NameError)
  end

  it "shadows variables" do
    @context.declare 'test'
    var_a = @context.access 'test'

    var_b = @context.nest do
      @context.declare 'test'
      @context.access 'test'
    end

    var_c = @context.access 'test'

    var_a.should_not == var_b
    var_a.should == var_c
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
liquor-1.0.0 spec/context_spec.rb
liquor-0.9.6 spec/context_spec.rb
liquor-0.9.5 spec/context_spec.rb
liquor-0.9.4 spec/context_spec.rb
liquor-0.9.3 spec/context_spec.rb
liquor-0.9.2 spec/context_spec.rb
liquor-0.9.1 spec/context_spec.rb