Sha256: 0f773c7d92661df9691b84f26f1e4fd82add22efb14530112d7849fec01adb11

Contents?: true

Size: 1.26 KB

Versions: 11

Compression:

Stored size: 1.26 KB

Contents

require 'test_helper'

class AssignTest < Minitest::Test
  include Liquid

  def test_assign_with_hyphen_in_variable_name
    template_source = <<-END_TEMPLATE
    {% assign this-thing = 'Print this-thing' %}
    {{ this-thing }}
    END_TEMPLATE
    template = Template.parse(template_source)
    rendered = template.render!
    assert_equal "Print this-thing", rendered.strip
  end

  def test_assigned_variable
    assert_template_result('.foo.',
      '{% assign foo = values %}.{{ foo[0] }}.',
      'values' => %w(foo bar baz))

    assert_template_result('.bar.',
      '{% assign foo = values %}.{{ foo[1] }}.',
      'values' => %w(foo bar baz))
  end

  def test_assign_with_filter
    assert_template_result('.bar.',
      '{% assign foo = values | split: "," %}.{{ foo[1] }}.',
      'values' => "foo,bar,baz")
  end

  def test_assign_syntax_error
    assert_match_syntax_error(/assign/,
      '{% assign foo not values %}.',
      'values' => "foo,bar,baz")
  end

  def test_assign_uses_error_mode
    with_error_mode(:strict) do
      assert_raises(SyntaxError) do
        Template.parse("{% assign foo = ('X' | downcase) %}")
      end
    end
    with_error_mode(:lax) do
      assert Template.parse("{% assign foo = ('X' | downcase) %}")
    end
  end
end # AssignTest

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
liquid-4.0.4 test/integration/assign_test.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/liquid-4.0.3/test/integration/assign_test.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/liquid-4.0.3/test/integration/assign_test.rb
liquid-4.0.3 test/integration/assign_test.rb
liquid-4.0.2 test/integration/assign_test.rb
liquid-4-0-2-4.0.2 test/integration/assign_test.rb
liquid-4.0.1 test/integration/assign_test.rb
liquid-4.0.0 test/integration/assign_test.rb
liquid-4.0.0.rc3 test/integration/assign_test.rb
liquid-4.0.0.rc2 test/integration/assign_test.rb
liquid-4.0.0.rc1 test/integration/assign_test.rb