~ubuntu-branches/ubuntu/trusty/ruby-slim/trusty

« back to all changes in this revision

Viewing changes to test/translator/test_translator.rb

  • Committer: Package Import Robot
  • Author(s): Jérémy Bobbio
  • Date: 2013-04-13 08:20:54 UTC
  • Revision ID: package-import@ubuntu.com-20130413082054-zr326qb62of78z1g
Tags: upstream-2.0.0~pre6
Import upstream version 2.0.0~pre6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'helper'
 
2
require 'slim/translator'
 
3
 
 
4
class TestSlimTranslator < TestSlim
 
5
  def setup
 
6
    super
 
7
    Slim::Engine.set_default_options :tr => true, :tr_fn => 'TestSlimTranslator.tr'
 
8
  end
 
9
 
 
10
  def self.tr(s)
 
11
    s.upcase
 
12
  end
 
13
 
 
14
  def self.tr_reverse(s)
 
15
    s.reverse.gsub(/(\d+)%/, '%\1')
 
16
  end
 
17
 
 
18
  def test_no_translation_of_embedded
 
19
    source = %q{
 
20
markdown:
 
21
  #Header
 
22
  Hello from #{"Markdown!"}
 
23
 
 
24
  #{1+2}
 
25
 
 
26
  * one
 
27
  * two
 
28
}
 
29
    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
 
30
    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
 
31
  end
 
32
 
 
33
  def test_no_translation_of_attrs
 
34
    source = %q{
 
35
' this is
 
36
  a link to
 
37
a href="link" page
 
38
}
 
39
 
 
40
    assert_html "THIS IS\nA LINK TO <a href=\"link\">PAGE</a>", source, :tr_mode => :dynamic
 
41
    assert_html "THIS IS\nA LINK TO <a href=\"link\">PAGE</a>", source, :tr_mode => :static
 
42
  end
 
43
 
 
44
  def test_translation_and_interpolation
 
45
    source = %q{
 
46
p translate #{hello_world} this
 
47
  second line
 
48
  third #{1+2} line
 
49
}
 
50
 
 
51
    assert_html "<p>translate Hello World from @env this\nsecond line\nthird 3 line</p>", source, :tr => false
 
52
    assert_html "<p>TRANSLATE Hello World from @env THIS\nSECOND LINE\nTHIRD 3 LINE</p>", source, :tr_mode => :dynamic
 
53
    assert_html "<p>TRANSLATE Hello World from @env THIS\nSECOND LINE\nTHIRD 3 LINE</p>", source, :tr_mode => :static
 
54
  end
 
55
 
 
56
  def test_translation_reverse
 
57
    source = %q{
 
58
' alpha #{1} beta #{2} gamma #{3}
 
59
}
 
60
 
 
61
    assert_html "3 ammag 2 ateb 1 ahpla ", source, :tr_mode => :dynamic, :tr_fn => 'TestSlimTranslator.tr_reverse'
 
62
    assert_html "3 ammag 2 ateb 1 ahpla ", source, :tr_mode => :static, :tr_fn => 'TestSlimTranslator.tr_reverse'
 
63
  end
 
64
end