wwwjdic 15.0.0 → 16.0.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 +4 -4
- data/CHANGELOG +13 -0
- data/Gemfile +4 -0
- data/README.md +6 -7
- data/Rakefile +4 -0
- data/examples/basics.rb +4 -0
- data/examples/translate.rb +26 -0
- data/examples/uri.rb +16 -0
- data/html/CHANGELOG.html +37 -30
- data/html/COPYING_md.html +22 -30
- data/html/Gemfile.html +25 -31
- data/html/Object.html +825 -63
- data/html/README_md.html +27 -33
- data/html/Rakefile.html +25 -31
- data/html/WWWJDic.html +42 -124
- data/html/WWWJDic/ParsableDuckType.html +35 -57
- data/html/WWWJDic/Parser.html +48 -90
- data/html/WWWJDic/Parsers.html +28 -36
- data/html/WWWJDic/Parsers/Dict.html +47 -73
- data/html/WWWJDic/Parsers/Display.html +42 -68
- data/html/WWWJDic/Parsers/Key.html +42 -68
- data/html/WWWJDic/Parsers/Search.html +38 -61
- data/html/WWWJDic/Parsers/Server.html +42 -68
- data/html/WWWJDic/Splitter.html +76 -173
- data/html/WWWJDic/Utils.html +28 -36
- data/html/WWWJDic/Utils/Downloader.html +28 -36
- data/html/WWWJDic/Utils/Downloader/Downloader.html +41 -80
- data/html/WWWJDic/Utils/Raisers.html +42 -96
- data/html/WWWJDic/WWWJDic.html +160 -342
- data/html/copyright_md.html +22 -30
- data/html/created.rid +32 -54
- data/html/css/rdoc.css +1 -1
- data/html/index.html +26 -51
- data/html/js/darkfish.js +84 -84
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search.js +110 -110
- data/html/js/search_index.js +1 -1
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js +229 -229
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +153 -161
- data/lib/wwwjdic.rb +7 -4
- data/lib/wwwjdic/application.rb +52 -25
- data/lib/wwwjdic/constants.rb +33 -3
- data/lib/wwwjdic/locales/de.yml +2 -0
- data/lib/wwwjdic/locales/en.yml +2 -0
- data/lib/wwwjdic/locales/es.yml +2 -0
- data/lib/wwwjdic/locales/fr.yml +2 -0
- data/lib/wwwjdic/locales/hu.yml +2 -0
- data/lib/wwwjdic/locales/it.yml +2 -0
- data/lib/wwwjdic/locales/ja.yml +3 -1
- data/lib/wwwjdic/locales/nl.yml +2 -0
- data/lib/wwwjdic/locales/ru.yml +2 -0
- data/lib/wwwjdic/locales/sl.yml +2 -0
- data/lib/wwwjdic/locales/sv.yml +2 -0
- data/lib/wwwjdic/parser.rb +7 -4
- data/lib/wwwjdic/parsers/dict.rb +4 -1
- data/lib/wwwjdic/parsers/display.rb +4 -1
- data/lib/wwwjdic/parsers/key.rb +4 -1
- data/lib/wwwjdic/parsers/search.rb +4 -0
- data/lib/wwwjdic/parsers/server.rb +4 -1
- data/lib/wwwjdic/utils/downloader.rb +7 -8
- data/lib/wwwjdic/utils/raisers.rb +7 -13
- data/lib/wwwjdic/utils/splitter.rb +18 -9
- data/lib/wwwjdic/version.rb +5 -1
- data/test/test_helper.rb +4 -0
- data/test/test_wwwjdic.rb +4 -0
- data/test/wwwjdic/locales/de.yml +2 -0
- data/test/wwwjdic/locales/en.yml +2 -0
- data/test/wwwjdic/locales/es.yml +2 -0
- data/test/wwwjdic/locales/fr.yml +2 -0
- data/test/wwwjdic/locales/hu.yml +2 -0
- data/test/wwwjdic/locales/it.yml +2 -0
- data/test/wwwjdic/locales/ja.yml +2 -0
- data/test/wwwjdic/locales/nl.yml +2 -0
- data/test/wwwjdic/locales/ru.yml +2 -0
- data/test/wwwjdic/locales/sl.yml +2 -0
- data/test/wwwjdic/locales/sv.yml +2 -0
- data/test/wwwjdic/locales/test_locales.rb +35 -19
- data/test/wwwjdic/parsers/test_dict.rb +62 -36
- data/test/wwwjdic/parsers/test_display.rb +4 -0
- data/test/wwwjdic/parsers/test_key.rb +4 -0
- data/test/wwwjdic/parsers/test_server.rb +4 -0
- data/test/wwwjdic/test_application.rb +196 -148
- data/test/wwwjdic/test_parsable_duck_type.rb +4 -3
- data/test/wwwjdic/utils/test_downloader.rb +4 -0
- data/test/wwwjdic/utils/test_raisers.rb +42 -27
- data/wwwjdic.gemspec +14 -11
- metadata +19 -33
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# wwwjdic
|
5
|
+
# rubocop:disable Style/AsciiComments
|
3
6
|
# © 2014 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of wwwjdic.
|
6
10
|
#
|
@@ -24,200 +28,244 @@
|
|
24
28
|
|
25
29
|
require_relative '../test_helper'
|
26
30
|
|
27
|
-
|
28
|
-
describe 'when
|
31
|
+
def test_multilanguage(a_method)
|
32
|
+
describe 'when considering multiple languages' do
|
33
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), 'locales/', '*.yml')]
|
29
34
|
|
30
|
-
|
35
|
+
WWWJDic::AVAIL_LANGS.each_pair do |dict, number|
|
36
|
+
I18n.locale = dict.to_s
|
37
|
+
a_word = I18n.t('test.kotoba')
|
31
38
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
39
|
+
it 'shall create a saved file with the proper filename' do
|
40
|
+
filename = "File_#{a_word}"
|
41
|
+
subject.send(a_method, a_word, nil, filename)
|
42
|
+
_(File.exist?(filename)).must_equal true
|
43
|
+
File.delete filename
|
44
|
+
end
|
37
45
|
|
38
|
-
|
39
|
-
|
40
|
-
|
46
|
+
it "shall return the translated word '#{a_word}'" do
|
47
|
+
translation = subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
48
|
+
_(translation).wont_be_nil
|
49
|
+
_(translation).wont_be_empty
|
41
50
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
it 'shall raise an error' do
|
47
|
-
assert_raises ArgumentError do
|
48
|
-
subject.server = a_server
|
49
|
-
end
|
50
|
-
end
|
51
|
+
if a_method == :json_translate
|
52
|
+
_(JSON.parse(translation)).wont_include '<TITLE>'
|
53
|
+
_(JSON.parse(translation)).wont_include '<pre>'
|
54
|
+
_(JSON.parse(translation).keys).must_include a_word
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
56
|
+
an_uri = subject.raw_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
57
|
+
_(an_uri).must_include number
|
57
58
|
|
58
|
-
|
59
|
-
describe "when server '#{name}' is selected" do
|
60
|
-
it "shall return the proper '#{uri}'" do
|
61
|
-
subject.server = name
|
62
|
-
_(subject.server).must_equal uri
|
63
|
-
_(subject.to_s).must_include uri
|
64
|
-
end
|
59
|
+
_(JSON.parse(translation)[a_word]).must_equal an_uri
|
65
60
|
end
|
66
61
|
end
|
67
62
|
end
|
63
|
+
end
|
64
|
+
end
|
68
65
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
def test_get_translation
|
67
|
+
describe 'when asking to retrieve a translation' do
|
68
|
+
%i[translate json_translate].each do |a_method|
|
69
|
+
describe "when the translation is '#{a_method}'" do
|
70
|
+
['', nil].each do |a_word|
|
71
|
+
it "shall raise ArgumentError when an invalid word '#{a_word}' is proposed" do
|
74
72
|
assert_raises ArgumentError do
|
75
|
-
subject.
|
73
|
+
subject.send(a_method, a_word)
|
76
74
|
end
|
77
75
|
end
|
78
|
-
|
79
|
-
it 'shall return the reference URI' do
|
80
|
-
_(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
|
81
|
-
end
|
82
76
|
end
|
77
|
+
|
78
|
+
test_multilanguage(a_method)
|
83
79
|
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
84
83
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
84
|
+
def test_get_dictionary
|
85
|
+
describe 'when selecting a dictionary' do
|
86
|
+
['', nil].each do |a_dict|
|
87
|
+
describe "when an invalid dictionary '#{a_dict}' is selected" do
|
88
|
+
it 'shall raise an error' do
|
89
|
+
assert_raises ArgumentError do
|
90
|
+
subject.dictionary = a_dict
|
91
91
|
end
|
92
92
|
end
|
93
|
-
end
|
94
93
|
|
95
|
-
|
96
|
-
subject.dictionary = 'R'
|
97
|
-
subject.reset
|
98
|
-
_(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
|
99
|
-
_(subject.dictionary).must_equal WWWJDic::DICTIONARY_NAMES[0]
|
94
|
+
test_return_test_reference
|
100
95
|
end
|
96
|
+
end
|
101
97
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
98
|
+
WWWJDic::DICTIONARY_CODES.each do |dict_number|
|
99
|
+
describe "when dictionary '#{dict_number}' is selected" do
|
100
|
+
it "shall return the proper number '#{dict_number}'" do
|
101
|
+
subject.dictionary = dict_number
|
102
|
+
_(subject.dictionary).must_equal WWWJDic::DICTS_BY_CODES[dict_number]
|
103
|
+
_(subject.to_s).must_equal WWWJDic::URI_DEFAULT + dict_number + WWWJDic::DISPLAY[:regular]
|
109
104
|
end
|
110
105
|
end
|
111
|
-
|
112
|
-
it 'shall return the URI with basic dictionary when reset' do
|
113
|
-
subject.dictionary = 'Japanese-Italian'
|
114
|
-
subject.reset
|
115
|
-
_(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
|
116
|
-
_(subject.dictionary).must_equal WWWJDic::DICTIONARY_NAMES[0]
|
117
|
-
end
|
118
106
|
end
|
119
107
|
|
120
|
-
|
121
|
-
|
122
|
-
|
108
|
+
it 'shall return the URI with basic dictionary when reset' do
|
109
|
+
subject.dictionary = 'R'
|
110
|
+
subject.reset
|
111
|
+
_(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
|
112
|
+
_(subject.dictionary).must_equal WWWJDic::DICTIONARY_NAMES[0]
|
113
|
+
end
|
123
114
|
|
124
|
-
|
125
|
-
describe
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
115
|
+
WWWJDic::DICTIONARY_NAMES.each do |dict_name|
|
116
|
+
describe "when dictionary '#{dict_name}' is selected" do
|
117
|
+
it "shall return the proper name '#{dict_name}'" do
|
118
|
+
subject.dictionary = dict_name
|
119
|
+
_(subject.dictionary).must_equal dict_name
|
120
|
+
_(subject.to_s).must_equal WWWJDic::URI_DEFAULT +
|
121
|
+
WWWJDic::DICTS_BY_NAMES[dict_name] +
|
122
|
+
WWWJDic::DISPLAY[:regular]
|
136
123
|
end
|
124
|
+
end
|
125
|
+
end
|
137
126
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
127
|
+
it 'shall return the URI with basic dictionary when reset' do
|
128
|
+
subject.dictionary = 'Japanese-Italian'
|
129
|
+
subject.reset
|
130
|
+
_(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
|
131
|
+
_(subject.dictionary).must_equal WWWJDic::DICTIONARY_NAMES[0]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
142
135
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
136
|
+
def test_return_json(a_word, dict)
|
137
|
+
it "shall return correct JSON data containing '#{a_word}' and the proper URI" do
|
138
|
+
json = subject.json_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
139
|
+
an_uri = subject.uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
147
140
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
141
|
+
_(JSON.parse(json).keys).must_include a_word
|
142
|
+
_(JSON.parse(json)[a_word]).must_equal an_uri
|
143
|
+
end
|
144
|
+
end
|
152
145
|
|
153
|
-
|
154
|
-
|
155
|
-
|
146
|
+
def test_override_custom_params(a_word, dict)
|
147
|
+
it 'shall override user-custom display parameter for raw display' do
|
148
|
+
_(subject.raw_uri(a_word, display: :regular,
|
149
|
+
dict: WWWJDic::AVAIL_LANGS[dict])).must_include WWWJDic::DISPLAY[:raw]
|
150
|
+
end
|
151
|
+
end
|
156
152
|
|
157
|
-
|
158
|
-
|
159
|
-
|
153
|
+
def test_multiple_languages
|
154
|
+
describe 'when considering multiple languages' do
|
155
|
+
WWWJDic::AVAIL_LANGS.each_pair do |dict, number|
|
156
|
+
I18n.locale = dict.to_s
|
157
|
+
a_word = I18n.t('test.kotoba')
|
160
158
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
159
|
+
%i[uri raw_uri json_uri].each do |a_method|
|
160
|
+
it "shall return URI containing '#{number}' for a '#{dict}' word for '#{a_method}' request" do
|
161
|
+
_(subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict])).must_include number
|
162
|
+
_(subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict])).must_include CGI.escape(a_word).to_s
|
165
163
|
end
|
166
164
|
end
|
167
|
-
end
|
168
165
|
|
169
|
-
|
170
|
-
describe 'when asking to retrieve a translation' do
|
171
|
-
%i[translate json_translate].each do |a_method|
|
172
|
-
describe "when the translation is '#{a_method}'" do
|
173
|
-
['', nil].each do |a_word|
|
174
|
-
it "shall raise ArgumentError when an invalid word '#{a_word}' is proposed" do
|
175
|
-
assert_raises ArgumentError do
|
176
|
-
subject.send(a_method, a_word)
|
177
|
-
end
|
178
|
-
end
|
166
|
+
test_override_custom_params(a_word, dict)
|
179
167
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
end
|
185
|
-
end
|
168
|
+
test_return_json(a_word, dict)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
186
172
|
|
187
|
-
|
188
|
-
|
173
|
+
def test_raise_invalid_server_error(a_server)
|
174
|
+
it 'shall raise an error' do
|
175
|
+
assert_raises ArgumentError do
|
176
|
+
subject.server = a_server
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
189
180
|
|
190
|
-
|
191
|
-
|
192
|
-
|
181
|
+
def test_return_test_reference
|
182
|
+
it 'shall return the reference URI' do
|
183
|
+
_(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_invalid_server
|
188
|
+
describe 'when an invalid server is selected' do
|
189
|
+
['', nil, :invalid].each do |a_server|
|
190
|
+
test_raise_invalid_server_error(a_server)
|
193
191
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
File.delete filename
|
199
|
-
end
|
192
|
+
test_return_test_reference
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
200
196
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
197
|
+
def test_server
|
198
|
+
WWWJDic::URIS.each do |name, uri|
|
199
|
+
describe "when server '#{name}' is selected" do
|
200
|
+
it "shall return the proper '#{uri}'" do
|
201
|
+
subject.server = name
|
202
|
+
_(subject.server).must_equal uri
|
203
|
+
_(subject.to_s).must_include uri
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
205
208
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
_(JSON.parse(translation).keys).must_include a_word
|
209
|
+
def test_select_server
|
210
|
+
describe 'when selecting a server' do
|
211
|
+
test_invalid_server
|
210
212
|
|
211
|
-
|
212
|
-
|
213
|
+
test_server
|
214
|
+
end
|
215
|
+
end
|
213
216
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
217
|
+
def test_invalid_parameter(a_word)
|
218
|
+
describe "when providing an invalid parameter '#{a_word}'" do
|
219
|
+
%i[uri raw_uri json_uri].each do |a_method|
|
220
|
+
it "shall raise an error for #{a_method} request" do
|
221
|
+
assert_raises ArgumentError do
|
222
|
+
subject.send a_method
|
219
223
|
end
|
220
224
|
end
|
221
225
|
end
|
222
226
|
end
|
223
227
|
end
|
228
|
+
|
229
|
+
def test_ask_uri
|
230
|
+
describe 'when asking for URI' do
|
231
|
+
['', nil].each(&method(:test_invalid_parameter))
|
232
|
+
|
233
|
+
test_multiple_languages
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_ask_translation
|
238
|
+
describe 'when asking for a translation' do
|
239
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), './locales/', '*.yml')]
|
240
|
+
|
241
|
+
# Tests for translation URIs
|
242
|
+
test_ask_uri
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe WWWJDic::WWWJDic do
|
247
|
+
describe 'when created' do
|
248
|
+
subject { WWWJDic::WWWJDic.new(WWWJDic.parser) }
|
249
|
+
|
250
|
+
# Basic checks for instance and default results
|
251
|
+
it 'shall return a valid object' do
|
252
|
+
_(subject).wont_be_nil
|
253
|
+
_(subject).must_be_instance_of WWWJDic::WWWJDic
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'shall return the URI with basic language' do
|
257
|
+
_(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
|
258
|
+
end
|
259
|
+
|
260
|
+
# Tests for server selection
|
261
|
+
test_select_server
|
262
|
+
|
263
|
+
# Tests for dictionary selection
|
264
|
+
test_get_dictionary
|
265
|
+
|
266
|
+
# Tests for translations
|
267
|
+
test_ask_translation
|
268
|
+
|
269
|
+
test_get_translation
|
270
|
+
end
|
271
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# wwwjdic
|
5
|
+
# rubocop:disable Style/AsciiComments
|
3
6
|
# © 2014 Marco Bresciani
|
4
|
-
#
|
7
|
+
# rubocop:enable Style/AsciiComments
|
5
8
|
# This file is part of wwwjdic.
|
6
9
|
#
|
7
10
|
# wwwjdic is free software: you can redistribute it and/or modify it
|
@@ -23,7 +26,6 @@
|
|
23
26
|
#++
|
24
27
|
|
25
28
|
module WWWJDic
|
26
|
-
|
27
29
|
# This module represents the parsable duck type element for testing
|
28
30
|
# purposes.
|
29
31
|
#
|
@@ -31,7 +33,6 @@ module WWWJDic
|
|
31
33
|
# Copyright:: Copyright (C) 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
|
32
34
|
# License:: GNU General Public License version 3
|
33
35
|
module ParsableDuckType
|
34
|
-
|
35
36
|
# The method that tests the parsable duck type interface and its
|
36
37
|
# +parse+ method.
|
37
38
|
def test_parsable_duck_type
|