util 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +1 -0
- data/CECILL-C.EN +517 -0
- data/CECILL-C.FR +521 -0
- data/LICENSES.md +21 -0
- data/README.md +478 -0
- data/lib/util.rb +12 -0
- data/lib/util/args.rb +138 -0
- data/lib/util/communia.rb +8 -0
- data/lib/util/console_logger.rb +178 -0
- data/lib/util/downloader.rb +157 -0
- data/lib/util/i18n.rb +327 -0
- data/lib/util/lists.rb +6 -0
- data/lib/util/lists/iso639.rb +149 -0
- data/lib/util/result.rb +175 -0
- data/lib/util/test.rb +225 -0
- data/lib/util/yaml.rb +18 -0
- data/share/lists/iso639-3.yml +35528 -0
- data/test/unit.rb +20 -0
- data/test/unit/args.rb +22 -0
- data/test/unit/downloader.rb +145 -0
- data/test/unit/downloader/orig/simple.html +7 -0
- data/test/unit/i18n.rb +216 -0
- data/test/unit/i18n/CamelCase/eng.yml +2 -0
- data/test/unit/i18n/CamelCase/fra.yml +2 -0
- data/test/unit/i18n/aaj.yml +2 -0
- data/test/unit/i18n/en.yml +2 -0
- data/test/unit/i18n/fra.yml +2 -0
- data/test/unit/i18n/i18n +0 -0
- data/test/unit/i18n/prv.yml +2 -0
- data/test/unit/i18n/void/fra.yml/Yes-git-I-need-this-folder-even-if-it-is-empty +0 -0
- data/test/unit/i18n//316/261/316/273/316/271/316/261/317/202/fra.yml +2 -0
- data/test/unit/lists/iso639.rb +78 -0
- data/test/unit/result.rb +180 -0
- data/tools/create-iso639-3.rb +235 -0
- metadata +80 -0
data/test/unit.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'util/test'
|
|
2
|
+
|
|
3
|
+
$test = Util::Testing.new
|
|
4
|
+
|
|
5
|
+
paths = [File.join(__dir__, 'unit')]
|
|
6
|
+
files = []
|
|
7
|
+
begin
|
|
8
|
+
path = paths.shift
|
|
9
|
+
Dir[File.join path, '*'].each do |f|
|
|
10
|
+
next if f == '.' or f == '..'
|
|
11
|
+
paths << f if File.directory? f
|
|
12
|
+
files << f if File.file? f and File.extname(f) == '.rb'
|
|
13
|
+
end
|
|
14
|
+
end until paths.empty?
|
|
15
|
+
|
|
16
|
+
files.each do |f|
|
|
17
|
+
require_relative f.sub(__dir__, '')[1..-1]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
$test.run
|
data/test/unit/args.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
results = [nil, '', true, 42, 42.0, :nil, true, true, Util, NilClass, 'tata']
|
|
2
|
+
$test.register 'args-check', results do ||
|
|
3
|
+
require 'util/args'
|
|
4
|
+
[ Util::Args.check,
|
|
5
|
+
Util::Args.check(nil, String, '', nil, FalseClass),
|
|
6
|
+
Util::Args.check(42, Integer, 0, 42, Float, 0.0, 42, Symbol, :nil),
|
|
7
|
+
Util::Args.check(true, 'Boolean', false, 42, 'Boolean'),
|
|
8
|
+
Util::Args.check(Util, Module, Kernel, Util, Class, NilClass),
|
|
9
|
+
Util::Args.check('toto', 'NotAClass', 'tata')
|
|
10
|
+
].flatten
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
results = [nil, 'toto', 'tata', 42.0, NilClass]
|
|
14
|
+
$test.register 'opts-check', results do ||
|
|
15
|
+
require 'util/args'
|
|
16
|
+
opts = { :toto => 'tata', :titi => 42, 'tutu' => TrueClass }
|
|
17
|
+
[ Util::Opts.check(nil),
|
|
18
|
+
Util::Opts.check(nil, :toto, String),
|
|
19
|
+
Util::Opts.check(opts, :toto, String, '', :titi, Float, 0.0, \
|
|
20
|
+
:tutu, Class, NilClass),
|
|
21
|
+
].flatten
|
|
22
|
+
end
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
require 'open-uri'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
results = [nil, __dir__, false, 'fake.html', 'http://www.qwant.com']
|
|
5
|
+
results += ['http://www.fake.info', nil, __dir__, false, 'fake.html']
|
|
6
|
+
results += ['http://www.qwant.com', 'http://www.fake.info', nil, nil, __dir__]
|
|
7
|
+
results += ['.', true, 'drop.htm', '42']
|
|
8
|
+
$test.register 'downloader-setters-getters', results do ||
|
|
9
|
+
require 'util/downloader'
|
|
10
|
+
dl = Util::Downloader.new 'http://www.fake.info', dest: __dir__, \
|
|
11
|
+
name: 'fake.html', ref: 'http://www.qwant.com', force: 'true'
|
|
12
|
+
res = [dl.data, dl.dest, dl.force, dl.name, dl.ref, dl.url,
|
|
13
|
+
dl[:data], dl[:dest], dl[:force], dl[:name], dl[:ref], dl[:url],
|
|
14
|
+
dl[42], dl[:io], dl['dest']
|
|
15
|
+
]
|
|
16
|
+
dl.set_force.set_ref(42).unset_force.set_dest.set_name('drop.htm').set_force
|
|
17
|
+
res += [dl.dest, dl.force, dl.name, dl.ref]
|
|
18
|
+
res
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
results = [:no_url, :no_dir, :no_dir, :file_exists]
|
|
22
|
+
$test.register 'downloader-normal-errors', results do ||
|
|
23
|
+
require 'util/downloader'
|
|
24
|
+
path = File.join __dir__, 'downloader'
|
|
25
|
+
fake_path = File.join path, 'fake'
|
|
26
|
+
true_path = File.join path, 'orig'
|
|
27
|
+
not_a_dir = File.join path, 'orig', 'simple.html'
|
|
28
|
+
url = 'https://gitlab.com/uploads/-/system/user/avatar/5582173/avatar.png'
|
|
29
|
+
[ Util::Downloader.new('').download.error,
|
|
30
|
+
Util::Downloader.new(url).set_dest(fake_path).download.error,
|
|
31
|
+
Util::Downloader.new(url).set_dest(not_a_dir).download.error,
|
|
32
|
+
Util::Downloader.new(url).set_dest(true_path).set_name('simple.html')\
|
|
33
|
+
.download.error
|
|
34
|
+
]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
$test.register 'downloader-404', OpenURI::HTTPError, '404' do ||
|
|
38
|
+
require 'util/downloader'
|
|
39
|
+
path = File.join __dir__, 'downloader'
|
|
40
|
+
url = 'https://www.perdu.com/404'
|
|
41
|
+
Util::Downloader.new(url).set_dest(path).download.error
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
$test.register 'downloader-success' do ||
|
|
45
|
+
require 'util/downloader'
|
|
46
|
+
path = File.join __dir__, 'downloader'
|
|
47
|
+
url = 'https://www.perdu.com/'
|
|
48
|
+
Util::Downloader.new(url).set_dest(path).download.value.nil?
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
$test.register 'downloader-second-download', :file_exists do ||
|
|
52
|
+
require 'util/downloader'
|
|
53
|
+
path = File.join __dir__, 'downloader'
|
|
54
|
+
url = 'https://www.perdu.com/'
|
|
55
|
+
Util::Downloader.new(url).set_dest(path).download.error
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
$test.register 'downloader-third-download' do ||
|
|
59
|
+
require 'util/downloader'
|
|
60
|
+
path = File.join __dir__, 'downloader'
|
|
61
|
+
url = 'https://www.perdu.com/'
|
|
62
|
+
dl = Util::Downloader.new(url).set_dest(path).set_force.download.value.nil?
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
results = [204, '<html>', 'Perdu sur l\'Internet ?']
|
|
66
|
+
$test.register 'downloader-right-download', results do ||
|
|
67
|
+
path = File.join __dir__, 'downloader', 'index.html'
|
|
68
|
+
content = File.read path
|
|
69
|
+
File.delete path
|
|
70
|
+
[content.length, content[0..5], content[61..82]]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
begin
|
|
74
|
+
require 'rmagick'
|
|
75
|
+
|
|
76
|
+
results = [nil, 5798, 'PNG', 200, 200, '#D4D400001C1C']
|
|
77
|
+
$test.register 'downloader-rmagick', results do ||
|
|
78
|
+
require 'util/downloader'
|
|
79
|
+
url = 'https://gitlab.com/uploads/-/system/user/avatar/5582173/avatar.png'
|
|
80
|
+
dl = Util::Downloader.new(url).set_dest(Magick)
|
|
81
|
+
[ dl.download.value,
|
|
82
|
+
dl.data[0].filesize,
|
|
83
|
+
dl.data[0].format,
|
|
84
|
+
dl.data[0].rows,
|
|
85
|
+
dl.data[0].columns,
|
|
86
|
+
dl.data[0].pixel_color(79, 142).to_color,
|
|
87
|
+
]
|
|
88
|
+
end
|
|
89
|
+
rescue LoadError
|
|
90
|
+
$test.register 'downloader-RMAGICK-NOT-INSTALLED' do || true end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
begin
|
|
94
|
+
require 'nokogiri'
|
|
95
|
+
|
|
96
|
+
results = [nil, 'Vous Etes Perdu ?', 'Perdu sur l\'Internet ?']
|
|
97
|
+
$test.register 'downloader-nokogiri', results do ||
|
|
98
|
+
require 'util/downloader'
|
|
99
|
+
url = 'https://www.perdu.com/'
|
|
100
|
+
dl = Util::Downloader.new(url).set_dest(Nokogiri::HTML)
|
|
101
|
+
[ dl.download.value,
|
|
102
|
+
dl.data.title,
|
|
103
|
+
dl.data.at_css('h1').text
|
|
104
|
+
]
|
|
105
|
+
end
|
|
106
|
+
rescue LoadError
|
|
107
|
+
$test.register 'downloader-NOKOGIRI-NOT-INSTALLED' do || true end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
begin
|
|
111
|
+
require 'oga'
|
|
112
|
+
|
|
113
|
+
results = [nil, :html, 'Perdu sur l\'Internet ?']
|
|
114
|
+
$test.register 'downloader-oga', results do ||
|
|
115
|
+
require 'util/downloader'
|
|
116
|
+
url = 'https://www.perdu.com/'
|
|
117
|
+
dl = Util::Downloader.new(url).set_dest(Oga::HTML)
|
|
118
|
+
[ dl.download.value,
|
|
119
|
+
dl.data.type,
|
|
120
|
+
dl.data.at_css('h1').text
|
|
121
|
+
]
|
|
122
|
+
end
|
|
123
|
+
rescue LoadError
|
|
124
|
+
$test.register 'downloader-OGA-NOT-INSTALLED', nil do || end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
results = [nil, 'Browse the first website']
|
|
128
|
+
results += ['http://info.cern.ch/hypertext/WWW/TheProject.html']
|
|
129
|
+
$test.register 'downloader-rexml', results do ||
|
|
130
|
+
require 'util/downloader'
|
|
131
|
+
require 'rexml/document'
|
|
132
|
+
url = 'http://info.cern.ch'
|
|
133
|
+
dl = Util::Downloader.new(url).set_dest(REXML)
|
|
134
|
+
[ dl.download.value,
|
|
135
|
+
dl.data.root.get_elements('//ul/li/a')[0].text,
|
|
136
|
+
dl.data.root.get_elements('//ul/li/a')[0]['href'],
|
|
137
|
+
]
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
$test.register 'dowloader-yaml', YAML::SyntaxError, 'mapping values' do ||
|
|
141
|
+
require 'util/downloader'
|
|
142
|
+
url = 'https://gitlab.com/guillel/util-gem/-/blob/master' \
|
|
143
|
+
'/share/lists/iso639-3.yml'
|
|
144
|
+
Util::Downloader.new(url).set_dest(YAML).download.error
|
|
145
|
+
end
|
data/test/unit/i18n.rb
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
$test.register 'i18n-init', [false, true] do ||
|
|
2
|
+
require 'util/i18n'
|
|
3
|
+
result = []
|
|
4
|
+
result << Util::I18n.initialized?
|
|
5
|
+
Util::I18n.init
|
|
6
|
+
result << Util::I18n.initialized?
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
results = [true, :eng, true, :fra, true, :prv, true, :eng]
|
|
10
|
+
results += [true, :zho, true, :oci, true, :sqi, true, :qqa]
|
|
11
|
+
results += [false, :qqa, false, :qqa]
|
|
12
|
+
$test.register 'i18n-default-lang', results do ||
|
|
13
|
+
require 'util/i18n'
|
|
14
|
+
[ Util::I18n.set_default_lang(:eng),
|
|
15
|
+
Util::I18n.default_lang,
|
|
16
|
+
Util::I18n.set_default_lang('fra'), # String
|
|
17
|
+
Util::I18n.default_lang,
|
|
18
|
+
Util::I18n.set_default_lang(:PrV), # Non lowercase
|
|
19
|
+
Util::I18n.default_lang,
|
|
20
|
+
Util::I18n.set_default_lang('en_US.UTF-8'), # POSIX
|
|
21
|
+
Util::I18n.default_lang,
|
|
22
|
+
Util::I18n.set_default_lang('zh-Hant-344'), # IETF
|
|
23
|
+
Util::I18n.default_lang,
|
|
24
|
+
Util::I18n.set_default_lang(:oc), # ISO 639-1
|
|
25
|
+
Util::I18n.default_lang,
|
|
26
|
+
Util::I18n.set_default_lang(:alb), # ISO 639-2
|
|
27
|
+
Util::I18n.default_lang,
|
|
28
|
+
Util::I18n.set_default_lang(:qqa), # Private use
|
|
29
|
+
Util::I18n.default_lang,
|
|
30
|
+
Util::I18n.set_default_lang(:aaj), # Non existent code
|
|
31
|
+
Util::I18n.default_lang,
|
|
32
|
+
Util::I18n.set_default_lang(:afa), # ISO 639-2 code with
|
|
33
|
+
Util::I18n.default_lang, # no ISO 639-3 equivalent
|
|
34
|
+
]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
results = [[:set_def_unknown, :aaj], [:set_def_unknown, :afa], nil]
|
|
38
|
+
$test.register 'i18n-next-error', results do ||
|
|
39
|
+
require 'util/i18n'
|
|
40
|
+
Util::I18n.init # Purge all previous errors
|
|
41
|
+
Util::I18n.set_default_lang(:aaj)
|
|
42
|
+
Util::I18n.set_default_lang(:afa)
|
|
43
|
+
[Util::I18n.next_error, Util::I18n.next_error, Util::I18n.next_error]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
results = ['alias', '今日は', 'la-vie-de-ma-mère', 'ça-va-oui-et-toi']
|
|
47
|
+
results += ['Pz8hPw==', 'hello-darkneß-m41_0-d']
|
|
48
|
+
results += ['estie-de-tabarnak-ISHCpyE=', '']
|
|
49
|
+
$test.register 'i18n-slugify', results do ||
|
|
50
|
+
require 'util/i18n'
|
|
51
|
+
[ Util::I18n.send(:slugify, 'alias'),
|
|
52
|
+
Util::I18n.send(:slugify, '今日は'),
|
|
53
|
+
Util::I18n.send(:slugify, 'La vie de ma mère'),
|
|
54
|
+
Util::I18n.send(:slugify, 'Ça va? Oui, et toi?'),
|
|
55
|
+
Util::I18n.send(:slugify, '??!?'),
|
|
56
|
+
Util::I18n.send(:slugify, File.join('hello', 'Darkneß', 'm41_0!d')),
|
|
57
|
+
Util::I18n.send(:slugify, File.join('Estie', 'de', 'tabarnak', '!!§!')),
|
|
58
|
+
Util::I18n.send(:slugify, ''),
|
|
59
|
+
]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
results = [false, :reg_no_name, false, :reg_path_not_exist]
|
|
63
|
+
results += [false, :reg_path_not_exist, false, :reg_path_not_dir]
|
|
64
|
+
results += [false, :reg_path_not_dir, 'temp', (File::SEPARATOR + 'i18n')]
|
|
65
|
+
results += [true, false, true]
|
|
66
|
+
$test.register 'i18n-register-check-args', results do ||
|
|
67
|
+
require 'util/i18n'
|
|
68
|
+
Util::I18n.init # Purge all previous errors
|
|
69
|
+
res = [Util::I18n.register, Util::I18n.next_error[0]]
|
|
70
|
+
# No name given
|
|
71
|
+
base = File.dirname(File.expand_path __FILE__)
|
|
72
|
+
path = File.join base, 'i18n', 'CamelCase', 'temp.rb'
|
|
73
|
+
res += [Util::I18n.register('temp', path), Util::I18n.next_error[0]]
|
|
74
|
+
# Will search inside 'i18n/CamelCase/i18n', that does not exist
|
|
75
|
+
path = File.join base, 'i18n', 'CamelCase', 'i18n'
|
|
76
|
+
res += [Util::I18n.register('temp', path, false), Util::I18n.next_error[0]]
|
|
77
|
+
# Same with an absolute path
|
|
78
|
+
path = File.join base, 'i18n', 'temp.rb'
|
|
79
|
+
res += [Util::I18n.register('temp', path), Util::I18n.next_error[0]]
|
|
80
|
+
# Will search inside 'i18n/i18n', that is a file not a folder
|
|
81
|
+
path = File.join base, 'i18n', 'i18n'
|
|
82
|
+
res += [Util::I18n.register('temp', path, false), Util::I18n.next_error[0]]
|
|
83
|
+
# Same with an absolute path
|
|
84
|
+
temp = Util::I18n.send(:register_check_args, 'temp', __FILE__, true, false)
|
|
85
|
+
res += [temp[0], temp[1].sub(base, ''), temp[2], temp[3]]
|
|
86
|
+
# The normal most ordinary case
|
|
87
|
+
temp = Util::I18n.send(:register_check_args, 'temp', '', true, false)
|
|
88
|
+
if temp == false then
|
|
89
|
+
err_name, err_data = Util::I18n.next_error
|
|
90
|
+
right_err = (err_name == :reg_path_not_exist or :reg_path_not_dir)
|
|
91
|
+
err_data = err_data.sub(File.expand_path('.'), '')
|
|
92
|
+
right_path = err_data == (File::SEPARATOR + 'i18n')
|
|
93
|
+
res << (right_err and right_path)
|
|
94
|
+
else
|
|
95
|
+
path = temp[1].sub(File.expand_path('.'), '')
|
|
96
|
+
res << (temp[0] == 'temp' and path == (File::SEPARATOR + 'i18n') \
|
|
97
|
+
and temp[2] == true and temp[3] == false)
|
|
98
|
+
end # Much more difficult to check: when `path` is empty
|
|
99
|
+
res
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
path = File.join File.dirname(File.expand_path __FILE__), 'i18n'
|
|
103
|
+
results = [File.join(path, '*.yml'), 'temp']
|
|
104
|
+
results += [File.join(path, '*.yml'), 'temp']
|
|
105
|
+
results += [File.join(path, 'αλιας', '*.yml'), 'temp-αλιας']
|
|
106
|
+
results += [File.join(path, 'void', '*.yml'), 'temp-void']
|
|
107
|
+
results += [File.join(path, 'CamelCase', '*.yml'), 'temp-camelcase']
|
|
108
|
+
results += [File.join(path, 'void', 'fra.yml', '*.yml'), 'temp-void-fra-yml']
|
|
109
|
+
path = nil
|
|
110
|
+
$test.register 'i18n-register-get-locations', results do ||
|
|
111
|
+
require 'util/i18n'
|
|
112
|
+
path = File.join File.dirname(File.expand_path __FILE__), 'i18n'
|
|
113
|
+
[ Util::I18n.send(:register_get_locations, 'temp', path, false),
|
|
114
|
+
Util::I18n.send(:register_get_locations, 'temp', path, true)
|
|
115
|
+
].flatten
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
hash = { 'temp' => {} }
|
|
119
|
+
hash['temp'][:eng] = {
|
|
120
|
+
'toto' => 'tata mais en anglais',
|
|
121
|
+
'titi'=> 'tutu mais en anglais'
|
|
122
|
+
}
|
|
123
|
+
hash['temp'][:fra] = { 'toto' => 'tata', 'titi' => 'tutu' }
|
|
124
|
+
hash['temp'][:prv] = { 'toto' => 'pecaire', 'titi' => 'eh fada' }
|
|
125
|
+
results = [Marshal.load(Marshal.dump(hash))] # Deep copy
|
|
126
|
+
hash['temp'][:fra]['tété'] = 'toto'
|
|
127
|
+
results << Marshal.load(Marshal.dump(hash))
|
|
128
|
+
results += [{}, :reg_yaml_cant_open]
|
|
129
|
+
hash = nil
|
|
130
|
+
$test.register 'i18n-register-get-messages', results do ||
|
|
131
|
+
require 'util/i18n'
|
|
132
|
+
Util::I18n.init # Purge all previous errors
|
|
133
|
+
path = File.join File.dirname(File.expand_path __FILE__), 'i18n'
|
|
134
|
+
loc = [File.join(path, '*.yml'), 'temp']
|
|
135
|
+
messages = {}
|
|
136
|
+
res = [Util::I18n.send(:register_get_messages, loc, messages)]
|
|
137
|
+
# Normal registering
|
|
138
|
+
messages = { 'temp' => { :fra => { 'toto' => 'titi', 'tété' => 'toto' } } }
|
|
139
|
+
res << Util::I18n.send(:register_get_messages, loc, messages)
|
|
140
|
+
# When internationalization tokens have already been registered
|
|
141
|
+
loc = [File.join(path, 'void', '*.yml'), 'temp']
|
|
142
|
+
messages = {}
|
|
143
|
+
res << Util::I18n.send(:register_get_messages, loc, messages)
|
|
144
|
+
res << Util::I18n.next_error[0]
|
|
145
|
+
# 'i18n/void/fra.yml' is a directory, not a file
|
|
146
|
+
res
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
results = [false, :reg_yaml_cant_open, :reg_no_file]
|
|
150
|
+
hash = { 'temp' => {} }
|
|
151
|
+
hash['temp'][:eng] = {
|
|
152
|
+
'toto' => 'tata mais en anglais',
|
|
153
|
+
'titi'=> 'tutu mais en anglais'
|
|
154
|
+
}
|
|
155
|
+
hash['temp'][:fra] = { 'toto' => 'tata', 'titi' => 'tutu' }
|
|
156
|
+
hash['temp'][:prv] = { 'toto' => 'pecaire', 'titi' => 'eh fada' }
|
|
157
|
+
results += [true, Marshal.load(Marshal.dump(hash))] # Deep copy
|
|
158
|
+
hash['temp-αλιας'] = { :fra => hash['temp'][:fra] }
|
|
159
|
+
hash['temp-camelcase'] = {
|
|
160
|
+
:eng => hash['temp'][:eng],
|
|
161
|
+
:fra => { 'toto' => 'tata-bis', 'titi' => 'tutu' }
|
|
162
|
+
}
|
|
163
|
+
results += [true, Marshal.load(Marshal.dump(hash))]
|
|
164
|
+
hash = nil
|
|
165
|
+
$test.register 'i18n-register', results do ||
|
|
166
|
+
require 'util/i18n'
|
|
167
|
+
Util::I18n.init # Purge all previous errors
|
|
168
|
+
base = File.join File.dirname(File.expand_path __FILE__), 'i18n'
|
|
169
|
+
path = File.join base, 'void'
|
|
170
|
+
res = [Util::I18n.register('temp', path, false)]
|
|
171
|
+
res += [Util::I18n.next_error[0], Util::I18n.next_error[0]]
|
|
172
|
+
# No valid file inside 'i18n/void', because 'fra.yml' is a directory
|
|
173
|
+
res << Util::I18n.register('temp', __FILE__)
|
|
174
|
+
res << Util::I18n.instance_variable_get('@messages')
|
|
175
|
+
# Normal registering
|
|
176
|
+
Util::I18n.init # Reset the @messages variable
|
|
177
|
+
res << Util::I18n.register('temp', __FILE__, true, true)
|
|
178
|
+
res << Util::I18n.instance_variable_get('@messages')
|
|
179
|
+
# Registering recursively
|
|
180
|
+
res
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
results = ['', :messages_empty, true, :reg_yaml_cant_open]
|
|
184
|
+
results += ['', :msg_no_module_content, '', :msg_no_valid_lang]
|
|
185
|
+
results += [true, 'tata', 'pecaire', 'tata-bis', 'tata-bis']
|
|
186
|
+
results += ['tata-bis', '']
|
|
187
|
+
$test.register 'i18n-message', results do ||
|
|
188
|
+
require 'util/i18n'
|
|
189
|
+
Util::I18n.init # Reset the data and errors
|
|
190
|
+
Util::I18n.set_default_lang :sqi
|
|
191
|
+
ov, $VERBOSE = $VERBOSE, nil
|
|
192
|
+
Util::I18n.const_set :DEFAULT_LANG, :sqi
|
|
193
|
+
$VERBOSE = ov
|
|
194
|
+
[ Util::I18n.message('toto'), # Nothing_registered yet
|
|
195
|
+
Util::I18n.next_error[0],
|
|
196
|
+
Util::I18n.register('temp', __FILE__, true, true),
|
|
197
|
+
Util::I18n.next_error[0],
|
|
198
|
+
Util::I18n.message('toto', mod: 'camelcase'), # No such module
|
|
199
|
+
Util::I18n.next_error[0],
|
|
200
|
+
Util::I18n.message('toto', lang: :zho), # No such language, and the
|
|
201
|
+
Util::I18n.next_error[0], # default languages neither have messages
|
|
202
|
+
Util::I18n.set_default_lang(:fra),
|
|
203
|
+
Util::I18n.message('toto'), # Default settings
|
|
204
|
+
Util::I18n.message('toto', lang: :prv), # Different language
|
|
205
|
+
Util::I18n.message('toto', mod: 'temp-camelcase'), # Different module
|
|
206
|
+
Util::I18n.message('toto'), # Last used module has changed
|
|
207
|
+
Util::I18n.message('toto', lang: :zho), # Message not translated
|
|
208
|
+
Util::I18n.message('tata'), # Message does not exist
|
|
209
|
+
]
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
$test.register '', [] do ||
|
|
213
|
+
require 'util/lists/iso639'
|
|
214
|
+
Util::Lists::ISO639::P3.instance_variable_set '@complete', nil
|
|
215
|
+
# Put the ISO639 module back to its uninitialized state.
|
|
216
|
+
end
|
data/test/unit/i18n/i18n
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
$test.register 'iso639-init', [false, true] do ||
|
|
2
|
+
require 'util/lists/iso639'
|
|
3
|
+
result = []
|
|
4
|
+
result << Util::Lists::ISO639::P3.initialized?
|
|
5
|
+
Util::Lists::ISO639::P3.init
|
|
6
|
+
result << Util::Lists::ISO639::P3.initialized?
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
result = [true, true, true, true, false]
|
|
10
|
+
$test.register 'iso639-3-exist', result do ||
|
|
11
|
+
require 'util/lists/iso639'
|
|
12
|
+
[ Util::Lists::ISO639::P3.exist?(:fra),
|
|
13
|
+
Util::Lists::ISO639::P3.exist?('fra'),
|
|
14
|
+
Util::Lists::ISO639::P3.exist?(:prv),
|
|
15
|
+
Util::Lists::ISO639::P3.exist?(:qst),
|
|
16
|
+
Util::Lists::ISO639::P3.exist?(:aaj),
|
|
17
|
+
]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
result = [false, false, true, false, false]
|
|
21
|
+
$test.register 'iso639-3-deprecated', result do ||
|
|
22
|
+
require 'util/lists/iso639'
|
|
23
|
+
[ Util::Lists::ISO639::P3.deprecated?(:fra),
|
|
24
|
+
Util::Lists::ISO639::P3.deprecated?('fra'),
|
|
25
|
+
Util::Lists::ISO639::P3.deprecated?(:prv),
|
|
26
|
+
Util::Lists::ISO639::P3.deprecated?(:qst),
|
|
27
|
+
Util::Lists::ISO639::P3.deprecated?(:aaj),
|
|
28
|
+
]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
result = [false, false, false, true, false]
|
|
32
|
+
$test.register 'iso639-3-private', result do ||
|
|
33
|
+
require 'util/lists/iso639'
|
|
34
|
+
[ Util::Lists::ISO639::P3.private?(:fra),
|
|
35
|
+
Util::Lists::ISO639::P3.private?('fra'),
|
|
36
|
+
Util::Lists::ISO639::P3.private?(:prv),
|
|
37
|
+
Util::Lists::ISO639::P3.private?(:qst),
|
|
38
|
+
Util::Lists::ISO639::P3.private?(:aaj),
|
|
39
|
+
]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
result = [true, true, false, false, false]
|
|
43
|
+
$test.register 'iso639-3-valid', result do ||
|
|
44
|
+
require 'util/lists/iso639'
|
|
45
|
+
[ Util::Lists::ISO639::P3.valid?(:fra),
|
|
46
|
+
Util::Lists::ISO639::P3.valid?('fra'),
|
|
47
|
+
Util::Lists::ISO639::P3.valid?(:prv),
|
|
48
|
+
Util::Lists::ISO639::P3.valid?(:qst),
|
|
49
|
+
Util::Lists::ISO639::P3.valid?(:aaj),
|
|
50
|
+
]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
result = [:fra, :fra, :eng, nil, nil, nil]
|
|
54
|
+
$test.register 'iso639-3-from1', result do ||
|
|
55
|
+
require 'util/lists/iso639'
|
|
56
|
+
class Fr; end
|
|
57
|
+
[ Util::Lists::ISO639::P3.from1(:fr),
|
|
58
|
+
Util::Lists::ISO639::P3.from1('fr'),
|
|
59
|
+
Util::Lists::ISO639::P3.from1(:en),
|
|
60
|
+
Util::Lists::ISO639::P3.from1(:qs),
|
|
61
|
+
Util::Lists::ISO639::P3.from1(:pr),
|
|
62
|
+
Util::Lists::ISO639::P3.from2(Fr),
|
|
63
|
+
]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
result = [:fra, :fra, :fra, nil, nil, :qst, nil]
|
|
67
|
+
$test.register 'iso639-3-from2', result do ||
|
|
68
|
+
require 'util/lists/iso639'
|
|
69
|
+
class Fra; end
|
|
70
|
+
[ Util::Lists::ISO639::P3.from2(:fra),
|
|
71
|
+
Util::Lists::ISO639::P3.from2('fra'),
|
|
72
|
+
Util::Lists::ISO639::P3.from2(:fre),
|
|
73
|
+
Util::Lists::ISO639::P3.from2(:fr),
|
|
74
|
+
Util::Lists::ISO639::P3.from2(:prv),
|
|
75
|
+
Util::Lists::ISO639::P3.from2(:qst),
|
|
76
|
+
Util::Lists::ISO639::P3.from2(Fra),
|
|
77
|
+
]
|
|
78
|
+
end
|