Module: Localite::Template::Etest

Defined in:
lib/localite/template.rb

Defined Under Namespace

Classes: Name

Constant Summary collapse

Template =
Localite::Template

Instance Method Summary collapse

Instance Method Details

#test_html_envObject



127
128
129
130
131
132
# File 'lib/localite/template.rb', line 127

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

#test_nohashObject



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

def test_nohash
  assert_equal "abc",                   Template.text("{*name*}", Name.new("abc"))
end

#test_plObject



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/localite/template.rb', line 114

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



134
135
136
137
# File 'lib/localite/template.rb', line 134

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

#test_template_hash_missingObject



139
140
141
142
143
# File 'lib/localite/template.rb', line 139

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

#test_templatesObject



93
94
95
96
97
98
99
100
101
102
# File 'lib/localite/template.rb', line 93

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