Sha256: c830851f8c06ce2aa416e6cf5e3f93c03d213c422369ef1680fc30b70678e3e7

Contents?: true

Size: 1.92 KB

Versions: 55

Compression:

Stored size: 1.92 KB

Contents

require 'helper'

describe Temple::Filters::ControlFlow do
  before do
    @filter = Temple::Filters::ControlFlow.new
  end

  it 'should process blocks' do
    @filter.call([:block, 'loop do',
      [:static, 'Hello']
    ]).should.equal [:multi,
                     [:code, 'loop do'],
                     [:static, 'Hello'],
                     [:code, 'end']]
  end

  it 'should process if' do
    @filter.call([:if, 'condition',
      [:static, 'Hello']
    ]).should.equal [:multi,
      [:code, 'if condition'],
      [:static, 'Hello'],
      [:code, 'end']
    ]
  end

  it 'should process if with else' do
    @filter.call([:if, 'condition',
      [:static, 'True'],
      [:static, 'False']
    ]).should.equal [:multi,
      [:code, 'if condition'],
      [:static, 'True'],
      [:code, 'else'],
      [:static, 'False'],
      [:code, 'end']
    ]
  end

  it 'should create elsif' do
    @filter.call([:if, 'condition1',
      [:static, '1'],
      [:if, 'condition2',
       [:static, '2'],
       [:static, '3']]
    ]).should.equal [:multi,
      [:code, 'if condition1'],
      [:static, '1'],
      [:code, 'elsif condition2'],
      [:static, '2'],
      [:code, 'else'],
      [:static, '3'],
      [:code, 'end']
    ]
  end

  it 'should process cond' do
    @filter.call([:cond,
      ['cond1', [:exp1]],
      ['cond2', [:exp2]],
      [:else,   [:exp3]],
    ]).should.equal [:multi,
      [:code, 'case'],
      [:code, 'when cond1'],
      [:exp1],
      [:code, 'when cond2'],
      [:exp2],
      [:code, 'else'],
      [:exp3],
      [:code, 'end']
    ]
  end

  it 'should process case' do
    @filter.call([:case, 'var',
      ['Array',  [:exp1]],
      ['String', [:exp2]],
      [:else,    [:exp3]],
    ]).should.equal [:multi,
      [:code, 'case (var)'],
      [:code, 'when Array'],
      [:exp1],
      [:code, 'when String'],
      [:exp2],
      [:code, 'else'],
      [:exp3],
      [:code, 'end']
    ]
  end
end

Version data entries

55 entries across 55 versions & 6 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/test/filters/test_control_flow.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/test/filters/test_control_flow.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/test/filters/test_control_flow.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/temple-0.8.2/test/filters/test_control_flow.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/temple-0.8.2/test/filters/test_control_flow.rb
temple-0.9.0 test/filters/test_control_flow.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/temple-0.8.0/test/filters/test_control_flow.rb
temple-0.8.2 test/filters/test_control_flow.rb
temple-0.8.1 test/filters/test_control_flow.rb
brakeman-4.3.1 bundle/ruby/2.5.0/gems/temple-0.7.7/test/filters/test_control_flow.rb
brakeman-4.3.0 bundle/ruby/2.5.0/gems/temple-0.7.7/test/filters/test_control_flow.rb
brakeman-4.2.1 bundle/ruby/2.5.0/gems/temple-0.7.7/test/filters/test_control_flow.rb
brakeman-4.2.0 bundle/ruby/2.3.0/gems/temple-0.7.7/test/filters/test_control_flow.rb
brakeman-4.1.1 bundle/ruby/2.3.0/gems/temple-0.7.7/test/filters/test_control_flow.rb
brakeman-4.1.0 bundle/ruby/2.3.0/gems/temple-0.7.7/test/filters/test_control_flow.rb
brakeman-4.0.1 bundle/ruby/2.3.0/gems/temple-0.7.7/test/filters/test_control_flow.rb
brakeman-4.0.1.pre1 bundle/ruby/2.3.0/gems/temple-0.7.7/test/filters/test_control_flow.rb
brakeman-4.0.0 bundle/ruby/2.3.0/gems/temple-0.7.7/test/filters/test_control_flow.rb
brakeman-3.7.2 bundle/ruby/2.3.0/gems/temple-0.7.7/test/filters/test_control_flow.rb
brakeman-3.7.1 bundle/ruby/2.3.0/gems/temple-0.7.7/test/filters/test_control_flow.rb