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



123
124
125
126
127
128
# File 'lib/localite/template.rb', line 123

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_nohashObject



106
107
108
# File 'lib/localite/template.rb', line 106

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

#test_plObject



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/localite/template.rb', line 110

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



130
131
132
133
# File 'lib/localite/template.rb', line 130

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



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

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

#test_templatesObject



89
90
91
92
93
94
95
96
97
98
# File 'lib/localite/template.rb', line 89

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