Module: Localite::Template::Etest

Defined in:
lib/localite/template.rb

Constant Summary collapse

Template =
Localite::Template

Instance Method Summary collapse

Instance Method Details

#test_html_envObject



109
110
111
112
113
114
# File 'lib/localite/template.rb', line 109

def test_html_env
  assert_equal "a>c",                 Template.run(:text, "{*xyz*}", :xyz => "a>c")
  assert_equal "a>c",              Template.run(:html, "{*xyz*}", :xyz => "a>c")
  assert_equal "> a>c",               Template.run(:text, "> {*xyz*}", :xyz => "a>c")
  assert_equal "> a>c",            Template.run(:html, "> {*xyz*}", :xyz => "a>c")
end

#test_plObject



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/localite/template.rb', line 96

def test_pl
  h = Object.new.extend(Localite::Template::Env::Helpers)
  assert_equal      "1 apple", h.pl("apple", 1)
  assert_equal      "2 apples", h.pl("apple", 2)
  assert_equal      "1 apple", h.pl("apples", 1)
  assert_equal      "2 apples", h.pl("apples", 2)

  assert_equal      "apples", h.pl("apples")
  assert_equal      "apples", h.pl("apple")
  
  assert_equal      "3 Strings", h.pl(%w(apple peach cherry))
end

#test_template_hashObject



116
117
118
119
# File 'lib/localite/template.rb', line 116

def test_template_hash
  assert_equal "a>c",                 Template.run(:text, "{*xyz*}", :xyz => "a>c")
  assert_equal "a>c",                 Template.run(:text, "{*xyz*}", "xyz" => "a>c")
end

#test_template_hash_missingObject



121
122
123
124
125
# File 'lib/localite/template.rb', line 121

def test_template_hash_missing
  assert_raise(NameError) {
    Template.run(:text, "{*abc*}", :xyz => "a>c")
  }
end

#test_templatesObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/localite/template.rb', line 85

def test_templates
  assert_equal "abc",                   Template.run(:text, "{*xyz*}", :xyz => "abc")
  assert_equal "3 items",               Template.run(:text, "{*pl 'item', xyz.length*}", :xyz => "abc")
  assert_equal "xyz",                   Template.run(:text, "xyz", :xyz => "abc")
  assert_equal "abc",                   Template.run(:text, "{*xyz*}", :xyz => "abc")
  assert_equal "3",                     Template.run(:text, "{*xyz.length*}", :xyz => "abc")
  assert_equal "3",                     Template.run(:text, "{*xyz.length*}", :xyz => "abc")
  assert_equal "3 Fixnums",             Template.run(:text, "{*pl xyz*}", :xyz => [1, 2, 3])
  assert_equal "3 Fixnums and 1 Float", Template.run(:text, "{*pl xyz*} and {*pl fl*}", :xyz => [1, 2, 3], :fl => [1.0])
end