Sha256: 36ff9c5e315b818ab1109efb761069444a2b2a22e3cf2de8a086c6a819dea84b

Contents?: true

Size: 1.82 KB

Versions: 8

Compression:

Stored size: 1.82 KB

Contents

require 'helper'
require 'slim/translator'

class TestSlimTranslator < TestSlim
  def setup
    super
    Slim::Engine.set_default_options :tr => true, :tr_fn => 'TestSlimTranslator.tr'
  end

  def self.tr(s)
    s.upcase
  end

  def self.tr_reverse(s)
    s.reverse.gsub(/(\d+)%/, '%\1')
  end

  def test_no_translation_of_embedded
    source = %q{
markdown:
  #Header
  Hello from #{"Markdown!"}

  #{1+2}

  * one
  * two
}
    assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n  <li>one</li>\n  <li>two</li>\n</ul>\n", source, :tr_mode => :dynamic
    assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n  <li>one</li>\n  <li>two</li>\n</ul>\n", source, :tr_mode => :static
  end

  def test_no_translation_of_attrs
    source = %q{
' this is
  a link to
a href="link" page
}

    assert_html "THIS IS\nA LINK TO <a href=\"link\">PAGE</a>", source, :tr_mode => :dynamic
    assert_html "THIS IS\nA LINK TO <a href=\"link\">PAGE</a>", source, :tr_mode => :static
  end

  def test_translation_and_interpolation
    source = %q{
p translate #{hello_world} this
  second line
  third #{1+2} line
}

    assert_html "<p>translate Hello World from @env this\nsecond line\nthird 3 line</p>", source, :tr => false
    assert_html "<p>TRANSLATE Hello World from @env THIS\nSECOND LINE\nTHIRD 3 LINE</p>", source, :tr_mode => :dynamic
    assert_html "<p>TRANSLATE Hello World from @env THIS\nSECOND LINE\nTHIRD 3 LINE</p>", source, :tr_mode => :static
  end

  def test_translation_reverse
    source = %q{
' alpha #{1} beta #{2} gamma #{3}
}

    assert_html "3 ammag 2 ateb 1 ahpla ", source, :tr_mode => :dynamic, :tr_fn => 'TestSlimTranslator.tr_reverse'
    assert_html "3 ammag 2 ateb 1 ahpla ", source, :tr_mode => :static, :tr_fn => 'TestSlimTranslator.tr_reverse'
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
slim-1.3.9 test/translator/test_translator.rb
slim-1.3.8 test/translator/test_translator.rb
slim-1.3.6 test/translator/test_translator.rb
slim-1.3.5 test/translator/test_translator.rb
slim-1.3.4 test/translator/test_translator.rb
slim-1.3.3 test/translator/test_translator.rb
slim-1.3.2 test/translator/test_translator.rb
slim-1.3.0 test/slim/translator/test_translator.rb