Sha256: 850cdb1019437bc930724797fe5366dcabc3333167d8970405e8fefb2c78a212

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'
module WLang
  describe Parser do

    def parse(input)
      WLang::Parser.new.call(input)
    end

    let(:expected) {
      [:template,
        [:fn,
          [:strconcat,
            [:static, "Hello "],
            [:wlang,  "$",
              [:fn,
                [:static, "who"]]],
            [:static, "!"]]]]
    }

    it 'should parse "Hello ${world}!" as expected' do
      parse(hello_tpl).should eq(expected)
    end

    it 'should support high-order wlang' do
      expected = \
      [:template,
        [:fn,
          [:wlang,  "$",
            [:fn,
              [:wlang, "$",
                [:fn,
                  [:static, "who"]]]]]]]
      parse("${${who}}").should eq(expected)
    end

    it 'should support mutli-block functions' do
      expected = \
      [:template,
        [:fn,
          [:wlang,  "$",
            [:fn, [:static, "first" ]],
            [:fn, [:static, "second"]]]]]
      parse("${first}{second}").should eq(expected)
    end

    it 'is idempotent' do
      parse(parse(hello_tpl)).should eq(expected)
    end

    it 'supports a path-like object' do
      parse(hello_path).should eq(expected)
    end

    it 'supports an IO object' do
      hello_io{|io| parse(io)}.should eq(expected)
    end

    it 'recognizes objects that respond to :to_path' do
      s = Struct.new(:to_path).new(hello_path)
      parse(s).should eq(expected)
    end

    it 'recognizes objects that respond to :to_str' do
      s = Struct.new(:to_str).new(hello_tpl)
      parse(s).should eq(expected)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wlang-2.0.1 spec/unit/compiler/test_parser.rb
wlang-2.0.0 spec/unit/compiler/test_parser.rb
wlang-2.0.0.beta spec/unit/compiler/test_parser.rb