Sha256: f0b4cc32c4db1a939f50b52608af929e83dc010bf91fca0e2a3c049a2a8ddb28

Contents?: true

Size: 1.63 KB

Versions: 15

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'
module WLang
  class Compiler
    describe ToRubyAbstraction do

      def optimize(source)
        ToRubyAbstraction.new.call(source)
      end

      let(:hello){[
        [:static, "Hello world"],
        [:static, "Hello world"]
      ]}
      let(:strconcat){[
        [:strconcat, [:static, "Hello "], [:static, "world"]],
        [:multi,     [:static, "Hello "], [:static, "world"]]
      ]}

      it 'let [:static, ...] unchanged' do
        optimize(hello.first).should eq(hello.last)
      end

      it 'transforms :strconcat to :multi' do
        optimize(strconcat.first).should eq(strconcat.last)
      end

      it 'recurses on :strconcat' do
        source   = [:strconcat, strconcat.first]
        expected = [:multi,     strconcat.last]
        optimize(source).should eq(expected)
      end

      it 'transforms :fn to :proc' do
        source   = [:fn, hello.first]
        expected = [:proc, hello.last]
        optimize(source).should eq(expected)
      end

      it 'recurses on :fn' do
        source   = [:fn, strconcat.first]
        expected = [:proc, strconcat.last]
        optimize(source).should eq(expected)
      end

      it "recurses on :template" do
        source   = [:template, strconcat.first]
        expected = [:template, strconcat.last]
        optimize(source).should eq(expected)
      end

      it 'transforms :wlang to :dispatch' do
        source   = [:wlang, '$', [:fn, strconcat.first]]
        expected = [:dispatch, :_tag_36, [:proc, strconcat.last]]
        optimize(source).should eq(expected)
      end

    end # describe ToRubyAbstraction
  end # class Compiler
end # module WLang

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
wlang-3.0.1 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-3.0.0 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.3.1 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.3.0 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.2.4 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.2.3 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.2.2 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.2.1 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.2.0 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.1.2 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.1.1 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.1.0 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.0.1 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.0.0 spec/unit/compiler/test_to_ruby_abstraction.rb
wlang-2.0.0.beta spec/unit/compiler/test_to_ruby_abstraction.rb