Module: Localite::Backend::Tr::Etest

Defined in:
lib/localite/tr.rb

Instance Method Summary collapse

Instance Method Details

#evaluate(s) ⇒ Object



172
173
174
# File 'lib/localite/tr.rb', line 172

def evaluate(s)
  Localite::Backend::Tr.new("").send(:evaluate, s)
end

#test_eval_stringObject



187
188
189
190
191
192
193
# File 'lib/localite/tr.rb', line 187

def test_eval_string
  assert_equal "ab\nc", evaluate("'ab\nc'")
  assert_equal "ab\ncdef", evaluate('"ab\ncdef"')
  assert_equal "ab\tcd\nef", evaluate('"ab\tcd\nef"')
  assert_equal "abbcd", evaluate('"ab\bcd"')
  assert_equal "en/outer/inner/y1", evaluate("\"en/outer/inner/y1\"")
end

#test_eval_string_prereqObject



181
182
183
184
185
# File 'lib/localite/tr.rb', line 181

def test_eval_string_prereq
  assert_equal 34, '""'[0]
  assert_equal 34, '""'[-1]
  assert_equal 39, "''"[0]
end

#test_multiline_w_spacesObject



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/localite/tr.rb', line 271

def test_multiline_w_spaces
  tr = <<-TR
refresh:
title:        t1
info:           |
  line1
  line2

  line3
  line4
title:        t2
TR

  p = Localite::Backend::Tr.new(tr)
  d = p.parse
  p.stubs(:dlog) {}
 
  assert_equal "line1\nline2\n\nline3\nline4", d["refresh.info"]
  assert_equal "t2", d["refresh.title"]
end

#test_parse_from_ioObject



253
254
255
256
257
# File 'lib/localite/tr.rb', line 253

def test_parse_from_io
  tr = "  ml: mlober"
  d = Localite::Backend::Tr.parse(tr)
  assert_equal({"ml" => "mlober"}, d)
end

#test_parse_key_namesObject



259
260
261
262
263
264
265
266
267
268
269
# File 'lib/localite/tr.rb', line 259

def test_parse_key_names
  tr = <<TR
a: aa
  "b.c": abc
  "b\\nc": anlc
  b.c: dot
TR

  d = Localite::Backend::Tr.parse(tr)
  assert_equal({"a"=>"aa", "a.b.c"=>"dot", "a.b\nc"=>"anlc"}, d)
end

#test_parse_trObject



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/localite/tr.rb', line 195

def test_parse_tr
  tr = <<-TR
#
# comment
param: "{* xxx *}"
base: "en_only"
t: "en.t"
#
# another comment
outer:
inner:
  x1: "en/outer/inner/x1"
inner:
  y1: "en/outer/inner/y1"
title: "This is hypertext"
title2: "This is <> hypertext"

ml: |
mlmlml
ml: mlober

outer: |
A first multiline
entry
outer: Hey Ho!
outer: |
A multiline
entry
TR

  p = Localite::Backend::Tr.new(tr)
  p.stubs(:dlog) {}

  assert_equal(%w(base ml outer outer.inner.x1 outer.inner.y1 param t title title2), p.keys)
  data = p.parse

  assert_equal("en/outer/inner/x1", data["outer.inner.x1"])
  assert_equal(nil, data["outer.inner"])
  assert_equal("A multiline\nentry", data["outer"])
  assert_equal("mlober", data["ml"])
  assert_kind_of(Hash, data)
end

#test_parse_tr_invalidObject



238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/localite/tr.rb', line 238

def test_parse_tr_invalid
  tr = <<-TR

ml: | av
mlmlml
ml: mlober
TR

  p = Localite::Backend::Tr.new(tr)
  p.stubs(:dlog) {}
  assert_raise(RuntimeError) {
    p.parse
  }
end

#test_tr_fileObject



176
177
178
179
# File 'lib/localite/tr.rb', line 176

def test_tr_file
  d = Localite::Backend::Tr.load(File.dirname(__FILE__) + "/../../test/i18n/en.tr")
  assert_kind_of(Hash, d)
end