Sha256: 817e97f1760a4a88212cbec34630ae0dc46c21cf6381a7f6f6c081dfff96fe40

Contents?: true

Size: 1.96 KB

Versions: 59

Compression:

Stored size: 1.96 KB

Contents

require 'helper'

describe Temple::HTML::AttributeSorter do
  before do
    @ordered   = Temple::HTML::AttributeSorter.new
    @unordered = Temple::HTML::AttributeSorter.new :sort_attrs => false
  end

  it 'should sort html attributes by name by default, when :sort_attrs is true' do
    @ordered.call([:html, :tag,
      'meta',
      [:html, :attrs, [:html, :attr, 'c', [:static, '1']],
                      [:html, :attr, 'd', [:static, '2']],
                      [:html, :attr, 'a', [:static, '3']],
                      [:html, :attr, 'b', [:static, '4']]]
    ]).should.equal [:html, :tag, 'meta',
                     [:html, :attrs,
                      [:html, :attr, 'a', [:static, '3']],
                      [:html, :attr, 'b', [:static, '4']],
                      [:html, :attr, 'c', [:static, '1']],
                      [:html, :attr, 'd', [:static, '2']]]]
  end

  it 'should preserve the order of html attributes when :sort_attrs is false' do
    @unordered.call([:html, :tag,
      'meta',
      [:html, :attrs, [:html, :attr, 'c', [:static, '1']],
                      [:html, :attr, 'd', [:static, '2']],
                      [:html, :attr, 'a', [:static, '3']],
                      [:html, :attr, 'b', [:static, '4']]]
    ]).should.equal [:html, :tag, 'meta',
                     [:html, :attrs,
                      [:html, :attr, 'c', [:static, '1']],
                      [:html, :attr, 'd', [:static, '2']],
                      [:html, :attr, 'a', [:static, '3']],
                      [:html, :attr, 'b', [:static, '4']]]]

    # Use case:
    @unordered.call([:html, :tag,
      'meta',
      [:html, :attrs, [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
                      [:html, :attr, 'content', [:static, '']]]
    ]).should.equal [:html, :tag, 'meta',
                     [:html, :attrs,
                      [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
                      [:html, :attr, 'content', [:static, '']]]]
  end
end

Version data entries

59 entries across 59 versions & 2 rubygems

Version Path
classiccms-0.6.4 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
temple-0.5.5 test/html/test_attribute_sorter.rb
classiccms-0.6.3 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.6.2 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.6.1 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.6.0 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
temple-0.5.4 test/html/test_attribute_sorter.rb
classiccms-0.5.17 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.5.16 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.5.15 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.5.14 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.5.13 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
temple-0.4.1 test/html/test_attribute_sorter.rb
classiccms-0.5.12 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.5.11 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.5.10 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.5.9 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.5.8 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.5.7 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb
classiccms-0.5.6 vendor/bundle/gems/temple-0.4.0/test/html/test_attribute_sorter.rb