Sha256: 1ebacdbee8bb9d267d26bbcfc70275158075c3262b1e234437631ecad066ac40

Contents?: true

Size: 1.77 KB

Versions: 11

Compression:

Stored size: 1.77 KB

Contents

require 'test_helper'

class BlockUnitTest < Minitest::Test
  include Liquid

  def test_blankspace
    template = Liquid::Template.parse("  ")
    assert_equal ["  "], template.root.nodelist
  end

  def test_variable_beginning
    template = Liquid::Template.parse("{{funk}}  ")
    assert_equal 2, template.root.nodelist.size
    assert_equal Variable, template.root.nodelist[0].class
    assert_equal String, template.root.nodelist[1].class
  end

  def test_variable_end
    template = Liquid::Template.parse("  {{funk}}")
    assert_equal 2, template.root.nodelist.size
    assert_equal String, template.root.nodelist[0].class
    assert_equal Variable, template.root.nodelist[1].class
  end

  def test_variable_middle
    template = Liquid::Template.parse("  {{funk}}  ")
    assert_equal 3, template.root.nodelist.size
    assert_equal String, template.root.nodelist[0].class
    assert_equal Variable, template.root.nodelist[1].class
    assert_equal String, template.root.nodelist[2].class
  end

  def test_variable_many_embedded_fragments
    template = Liquid::Template.parse("  {{funk}} {{so}} {{brother}} ")
    assert_equal 7, template.root.nodelist.size
    assert_equal [String, Variable, String, Variable, String, Variable, String],
                 block_types(template.root.nodelist)
  end

  def test_with_block
    template = Liquid::Template.parse("  {% comment %} {% endcomment %} ")
    assert_equal [String, Comment, String], block_types(template.root.nodelist)
    assert_equal 3, template.root.nodelist.size
  end

  def test_with_custom_tag
    Liquid::Template.register_tag("testtag", Block)
    assert Liquid::Template.parse( "{% testtag %} {% endtesttag %}")
  end

  private
    def block_types(nodelist)
      nodelist.collect { |node| node.class }
    end
end # VariableTest

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
locomotivecms-liquid-4.0.0 test/unit/block_unit_test.rb
liquid-3.0.6 test/unit/block_unit_test.rb
liquid-3.0.5 test/unit/block_unit_test.rb
liquid-3.0.4 test/unit/block_unit_test.rb
liquid-3.0.3 test/unit/block_unit_test.rb
liquid-3.0.2 test/unit/block_unit_test.rb
locomotivecms-liquid-4.0.0.alpha2 test/unit/block_unit_test.rb
locomotivecms-liquid-4.0.0.alpha1 test/unit/block_unit_test.rb
locomotivecms-liquid-4.0.0.alpha test/unit/block_unit_test.rb
liquid-3.0.1 test/unit/block_unit_test.rb
liquid-3.0.0 test/unit/block_unit_test.rb