wordlist 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +27 -0
- data/.gitignore +6 -3
- data/ChangeLog.md +45 -1
- data/Gemfile +13 -0
- data/LICENSE.txt +1 -3
- data/README.md +266 -61
- data/Rakefile +7 -32
- data/benchmarks.rb +115 -0
- data/bin/wordlist +4 -7
- data/data/stop_words/ar.txt +104 -0
- data/data/stop_words/bg.txt +259 -0
- data/data/stop_words/bn.txt +363 -0
- data/data/stop_words/ca.txt +126 -0
- data/data/stop_words/cs.txt +138 -0
- data/data/stop_words/da.txt +101 -0
- data/data/stop_words/de.txt +129 -0
- data/data/stop_words/el.txt +79 -0
- data/data/stop_words/en.txt +175 -0
- data/data/stop_words/es.txt +178 -0
- data/data/stop_words/eu.txt +98 -0
- data/data/stop_words/fa.txt +332 -0
- data/data/stop_words/fi.txt +747 -0
- data/data/stop_words/fr.txt +116 -0
- data/data/stop_words/ga.txt +109 -0
- data/data/stop_words/gl.txt +160 -0
- data/data/stop_words/he.txt +499 -0
- data/data/stop_words/hi.txt +97 -0
- data/data/stop_words/hr.txt +179 -0
- data/data/stop_words/hu.txt +35 -0
- data/data/stop_words/hy.txt +45 -0
- data/data/stop_words/id.txt +357 -0
- data/data/stop_words/it.txt +134 -0
- data/data/stop_words/ja.txt +44 -0
- data/data/stop_words/ko.txt +677 -0
- data/data/stop_words/ku.txt +63 -0
- data/data/stop_words/lt.txt +507 -0
- data/data/stop_words/lv.txt +163 -0
- data/data/stop_words/mr.txt +99 -0
- data/data/stop_words/nl.txt +48 -0
- data/data/stop_words/no.txt +172 -0
- data/data/stop_words/pl.txt +138 -0
- data/data/stop_words/pt.txt +147 -0
- data/data/stop_words/ro.txt +281 -0
- data/data/stop_words/ru.txt +421 -0
- data/data/stop_words/sk.txt +173 -0
- data/data/stop_words/sv.txt +386 -0
- data/data/stop_words/th.txt +115 -0
- data/data/stop_words/tr.txt +114 -0
- data/data/stop_words/uk.txt +28 -0
- data/data/stop_words/ur.txt +513 -0
- data/data/stop_words/zh.txt +125 -0
- data/gemspec.yml +4 -10
- data/lib/wordlist/abstract_wordlist.rb +24 -0
- data/lib/wordlist/builder.rb +170 -138
- data/lib/wordlist/cli.rb +458 -0
- data/lib/wordlist/compression/reader.rb +72 -0
- data/lib/wordlist/compression/writer.rb +80 -0
- data/lib/wordlist/exceptions.rb +31 -0
- data/lib/wordlist/file.rb +176 -0
- data/lib/wordlist/format.rb +38 -0
- data/lib/wordlist/lexer/lang.rb +32 -0
- data/lib/wordlist/lexer/stop_words.rb +68 -0
- data/lib/wordlist/lexer.rb +218 -0
- data/lib/wordlist/list_methods.rb +462 -0
- data/lib/wordlist/modifiers/capitalize.rb +45 -0
- data/lib/wordlist/modifiers/downcase.rb +45 -0
- data/lib/wordlist/modifiers/gsub.rb +51 -0
- data/lib/wordlist/modifiers/modifier.rb +44 -0
- data/lib/wordlist/modifiers/mutate.rb +133 -0
- data/lib/wordlist/modifiers/mutate_case.rb +25 -0
- data/lib/wordlist/modifiers/sub.rb +97 -0
- data/lib/wordlist/modifiers/tr.rb +71 -0
- data/lib/wordlist/modifiers/upcase.rb +45 -0
- data/lib/wordlist/modifiers.rb +8 -0
- data/lib/wordlist/operators/binary_operator.rb +38 -0
- data/lib/wordlist/operators/concat.rb +47 -0
- data/lib/wordlist/operators/intersect.rb +55 -0
- data/lib/wordlist/operators/operator.rb +29 -0
- data/lib/wordlist/operators/power.rb +72 -0
- data/lib/wordlist/operators/product.rb +50 -0
- data/lib/wordlist/operators/subtract.rb +54 -0
- data/lib/wordlist/operators/unary_operator.rb +29 -0
- data/lib/wordlist/operators/union.rb +61 -0
- data/lib/wordlist/operators/unique.rb +52 -0
- data/lib/wordlist/operators.rb +7 -0
- data/lib/wordlist/unique_filter.rb +40 -61
- data/lib/wordlist/version.rb +1 -1
- data/lib/wordlist/words.rb +71 -0
- data/lib/wordlist.rb +103 -2
- data/spec/abstract_list_spec.rb +18 -0
- data/spec/builder_spec.rb +220 -76
- data/spec/cli_spec.rb +801 -0
- data/spec/compression/reader_spec.rb +137 -0
- data/spec/compression/writer_spec.rb +194 -0
- data/spec/file_spec.rb +258 -0
- data/spec/fixtures/wordlist.txt +15 -0
- data/spec/fixtures/wordlist.txt.bz2 +0 -0
- data/spec/fixtures/wordlist.txt.gz +0 -0
- data/spec/fixtures/wordlist.txt.xz +0 -0
- data/spec/fixtures/wordlist_with_ambiguous_format +3 -0
- data/spec/fixtures/wordlist_with_comments.txt +19 -0
- data/spec/fixtures/wordlist_with_empty_lines.txt +19 -0
- data/spec/format_spec.rb +50 -0
- data/spec/helpers/text.rb +3 -3
- data/spec/helpers/wordlist.rb +2 -2
- data/spec/lexer/lang_spec.rb +70 -0
- data/spec/lexer/stop_words_spec.rb +77 -0
- data/spec/lexer_spec.rb +652 -0
- data/spec/list_methods_spec.rb +181 -0
- data/spec/modifiers/capitalize_spec.rb +27 -0
- data/spec/modifiers/downcase_spec.rb +27 -0
- data/spec/modifiers/gsub_spec.rb +59 -0
- data/spec/modifiers/modifier_spec.rb +20 -0
- data/spec/modifiers/mutate_case_spec.rb +46 -0
- data/spec/modifiers/mutate_spec.rb +39 -0
- data/spec/modifiers/sub_spec.rb +98 -0
- data/spec/modifiers/tr_spec.rb +46 -0
- data/spec/modifiers/upcase_spec.rb +27 -0
- data/spec/operators/binary_operator_spec.rb +19 -0
- data/spec/operators/concat_spec.rb +26 -0
- data/spec/operators/intersect_spec.rb +37 -0
- data/spec/operators/operator_spec.rb +16 -0
- data/spec/operators/power_spec.rb +57 -0
- data/spec/operators/product_spec.rb +39 -0
- data/spec/operators/subtract_spec.rb +37 -0
- data/spec/operators/union_spec.rb +37 -0
- data/spec/operators/unique_spec.rb +25 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/unique_filter_spec.rb +108 -18
- data/spec/wordlist_spec.rb +55 -3
- data/spec/words_spec.rb +41 -0
- metadata +183 -120
- data/lib/wordlist/builders/website.rb +0 -216
- data/lib/wordlist/builders.rb +0 -1
- data/lib/wordlist/flat_file.rb +0 -47
- data/lib/wordlist/list.rb +0 -162
- data/lib/wordlist/mutator.rb +0 -113
- data/lib/wordlist/parsers.rb +0 -74
- data/lib/wordlist/runners/list.rb +0 -116
- data/lib/wordlist/runners/runner.rb +0 -67
- data/lib/wordlist/runners.rb +0 -2
- data/scripts/benchmark +0 -59
- data/scripts/text/comedy_of_errors.txt +0 -4011
- data/spec/flat_file_spec.rb +0 -25
- data/spec/list_spec.rb +0 -58
- data/spec/mutator_spec.rb +0 -43
- data/spec/parsers_spec.rb +0 -118
data/spec/builder_spec.rb
CHANGED
@@ -1,127 +1,271 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'wordlist/builder'
|
2
3
|
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
describe Wordlist::Builder do
|
7
|
+
let(:fixtures_dir) { ::File.join(__dir__,'fixtures') }
|
8
|
+
let(:path) { ::File.join(fixtures_dir,'new_wordlist.txt') }
|
9
|
+
|
10
|
+
subject { described_class.new(path) }
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
it "must initialize the #path" do
|
14
|
+
expect(subject.path).to eq(path)
|
15
|
+
end
|
7
16
|
|
8
|
-
|
9
|
-
|
17
|
+
context "when the path ends in '.txt'" do
|
18
|
+
let(:path) { ::File.join(fixtures_dir,'new_wordlist.txt') }
|
10
19
|
|
11
|
-
|
12
|
-
|
13
|
-
|
20
|
+
it "must default #format to :txt" do
|
21
|
+
expect(subject.format).to eq(:txt)
|
22
|
+
end
|
14
23
|
end
|
15
24
|
|
16
|
-
|
17
|
-
|
25
|
+
context "when the path ends in '.gz'" do
|
26
|
+
let(:path) { ::File.join(fixtures_dir,'new_wordlist.gz') }
|
27
|
+
|
28
|
+
it "must default #format to :gzip" do
|
29
|
+
expect(subject.format).to eq(:gzip)
|
30
|
+
end
|
18
31
|
end
|
19
32
|
|
20
|
-
|
21
|
-
|
33
|
+
context "when the path ends in '.bz2'" do
|
34
|
+
let(:path) { ::File.join(fixtures_dir,'new_wordlist.bz2') }
|
22
35
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
36
|
+
it "must default #format to :bzip2" do
|
37
|
+
expect(subject.format).to eq(:bzip2)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when the path ends in '.xz'" do
|
42
|
+
let(:path) { ::File.join(fixtures_dir,'new_wordlist.xz') }
|
43
|
+
|
44
|
+
it "must default #format to :xz" do
|
45
|
+
expect(subject.format).to eq(:xz)
|
46
|
+
end
|
27
47
|
end
|
28
48
|
|
29
|
-
|
30
|
-
|
49
|
+
context "when format: :txt is given" do
|
50
|
+
subject { described_class.new(path, format: :txt) }
|
51
|
+
|
52
|
+
it "must set #format to :txt" do
|
53
|
+
expect(subject.format).to eq(:txt)
|
54
|
+
end
|
31
55
|
end
|
32
56
|
|
33
|
-
|
57
|
+
context "when format: :gzip is given" do
|
58
|
+
subject { described_class.new(path, format: :gzip) }
|
59
|
+
|
60
|
+
it "must set #format to :gzip" do
|
61
|
+
expect(subject.format).to eq(:gzip)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when format: :bzip2 is given" do
|
66
|
+
subject { described_class.new(path, format: :bzip2) }
|
67
|
+
|
68
|
+
it "must set #format to :bzip2" do
|
69
|
+
expect(subject.format).to eq(:bzip2)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when format: :xz is given" do
|
74
|
+
subject { described_class.new(path, format: :xz) }
|
75
|
+
|
76
|
+
it "must set #format to :xz" do
|
77
|
+
expect(subject.format).to eq(:xz)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "must default #append? to false" do
|
82
|
+
expect(subject.append?).to be(false)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "#unique_filter must be empty" do
|
86
|
+
expect(subject.unique_filter).to be_empty
|
87
|
+
end
|
88
|
+
|
89
|
+
it "must open the wordlist file" do
|
90
|
+
expect(subject).to_not be_closed
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when given append: true" do
|
94
|
+
context "and the wordlist file already exists" do
|
95
|
+
let(:path) { ::File.join(fixtures_dir,'pre_existing_wordlist.txt') }
|
96
|
+
let(:pre_existing_words) { %w[foo bar] }
|
97
|
+
|
98
|
+
subject { described_class.new(path, append: true) }
|
99
|
+
|
100
|
+
before do
|
101
|
+
::File.open(path,'w') do |file|
|
102
|
+
pre_existing_words.each do |word|
|
103
|
+
file.puts word
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "must add the pre-existing words to the #unique_filter" do
|
109
|
+
expect(pre_existing_words.all? { |word|
|
110
|
+
subject.unique_filter.include?(word)
|
111
|
+
}).to be(true)
|
112
|
+
end
|
113
|
+
|
114
|
+
after { ::FileUtils.rm_f(path) }
|
115
|
+
end
|
116
|
+
end
|
34
117
|
end
|
35
118
|
|
36
|
-
describe "
|
37
|
-
|
38
|
-
|
119
|
+
describe "#lexer" do
|
120
|
+
it "must be a Lexer" do
|
121
|
+
expect(subject.lexer).to be_kind_of(Wordlist::Lexer)
|
39
122
|
end
|
123
|
+
end
|
40
124
|
|
41
|
-
|
42
|
-
|
125
|
+
describe "#unique_filter" do
|
126
|
+
it "must be a UniqueFilter" do
|
127
|
+
expect(subject.unique_filter).to be_kind_of(Wordlist::UniqueFilter)
|
43
128
|
end
|
129
|
+
end
|
130
|
+
|
131
|
+
let(:added_words) { ::File.readlines(path).map(&:chomp) }
|
44
132
|
|
45
|
-
|
46
|
-
@builder.enqueue('dog')
|
47
|
-
@builder.enqueue('cat')
|
133
|
+
before { ::FileUtils.rm_f(path) }
|
48
134
|
|
49
|
-
|
135
|
+
describe "#add" do
|
136
|
+
let(:word) { 'foo' }
|
137
|
+
|
138
|
+
before do
|
139
|
+
described_class.open(path) do |builder|
|
140
|
+
builder.add(word)
|
141
|
+
end
|
50
142
|
end
|
51
143
|
|
52
|
-
it "
|
53
|
-
|
54
|
-
|
55
|
-
|
144
|
+
it "must add the word to the file" do
|
145
|
+
expect(added_words).to eq([word])
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when the same word is added multiple times" do
|
149
|
+
before do
|
150
|
+
described_class.open(path) do |builder|
|
151
|
+
builder.add(word)
|
152
|
+
builder.add(word)
|
153
|
+
end
|
154
|
+
end
|
56
155
|
|
57
|
-
|
156
|
+
it "must filter out duplicate words" do
|
157
|
+
expect(File.readlines(path).map(&:chomp)).to eq([word])
|
158
|
+
end
|
58
159
|
end
|
59
160
|
end
|
60
161
|
|
61
|
-
describe "
|
62
|
-
|
63
|
-
|
162
|
+
describe "#append" do
|
163
|
+
let(:words) { %w[foo bar baz] }
|
164
|
+
|
165
|
+
before do
|
166
|
+
described_class.open(path) do |builder|
|
167
|
+
builder.append(words)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
it "must add the words to the file" do
|
172
|
+
expect(added_words).to eq(words)
|
64
173
|
end
|
65
174
|
|
66
|
-
|
67
|
-
|
68
|
-
builder.enqueue('dog')
|
175
|
+
context "when there are duplicate words in the given Array" do
|
176
|
+
let(:words) { %w[foo bar bar baz] }
|
69
177
|
|
70
|
-
|
71
|
-
words.
|
178
|
+
it "must filter out duplicate words" do
|
179
|
+
expect(added_words).to eq(words.uniq)
|
72
180
|
end
|
73
181
|
end
|
182
|
+
end
|
74
183
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
builder.enqueue('cat')
|
79
|
-
builder.enqueue('dat')
|
184
|
+
describe "#parse" do
|
185
|
+
let(:words) { %w[foo bar baz] }
|
186
|
+
let(:text) { "foo bar, baz." }
|
80
187
|
|
81
|
-
|
82
|
-
|
188
|
+
before do
|
189
|
+
described_class.open(path) do |builder|
|
190
|
+
builder.parse(text)
|
83
191
|
end
|
84
192
|
end
|
85
193
|
|
86
|
-
it "
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
194
|
+
it "must parse the text into words and add them to the file" do
|
195
|
+
expect(added_words).to eq(words)
|
196
|
+
end
|
197
|
+
|
198
|
+
context "when the text contains duplicate words" do
|
199
|
+
let(:text) { "foo bar bar, baz baz." }
|
91
200
|
|
92
|
-
|
93
|
-
|
201
|
+
it "must filter out duplicate words" do
|
202
|
+
expect(added_words).to eq(words)
|
94
203
|
end
|
95
204
|
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "#parse_file" do
|
208
|
+
let(:text_file) { ::File.join(fixtures_dir,'text_file.txt') }
|
96
209
|
|
97
|
-
|
98
|
-
|
99
|
-
builder.enqueue('dog')
|
100
|
-
builder.enqueue('cat')
|
101
|
-
builder.enqueue('dat')
|
210
|
+
let(:words) { %w[foo bar baz] }
|
211
|
+
let(:text) { "foo bar, baz." }
|
102
212
|
|
103
|
-
|
104
|
-
|
213
|
+
before do
|
214
|
+
::File.write(text_file,text)
|
215
|
+
|
216
|
+
described_class.open(path) do |builder|
|
217
|
+
builder.parse(text)
|
105
218
|
end
|
106
219
|
end
|
107
220
|
|
108
|
-
it "
|
109
|
-
|
110
|
-
|
111
|
-
builder.enqueue('cat')
|
112
|
-
builder.enqueue('dat')
|
221
|
+
it "must parse the text file into words and add them to the file" do
|
222
|
+
expect(added_words).to eq(words)
|
223
|
+
end
|
113
224
|
|
114
|
-
|
225
|
+
context "when the text file contains duplicate words" do
|
226
|
+
let(:text) { "foo bar bar, baz baz." }
|
115
227
|
|
116
|
-
|
117
|
-
|
228
|
+
it "must filter out duplicate words" do
|
229
|
+
expect(added_words).to eq(words)
|
118
230
|
end
|
231
|
+
end
|
232
|
+
|
233
|
+
after { ::FileUtils.rm_f(text_file) }
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "#close" do
|
237
|
+
let(:word) { 'foo' }
|
238
|
+
|
239
|
+
it "must close the wordlist file" do
|
240
|
+
expect(::File.file?(path)).to be(false)
|
241
|
+
|
242
|
+
subject.add(word)
|
243
|
+
subject.close
|
244
|
+
|
245
|
+
expect(::File.file?(path)).to be(true)
|
246
|
+
expect(::File.size(path)).to be > 0
|
247
|
+
end
|
119
248
|
|
120
|
-
|
121
|
-
|
122
|
-
'cat dat',
|
123
|
-
'dog cat dat'
|
124
|
-
]
|
249
|
+
it "must clear the unique filter" do
|
250
|
+
expect(subject.unique_filter).to be_empty
|
125
251
|
end
|
126
252
|
end
|
253
|
+
|
254
|
+
describe "#closed?" do
|
255
|
+
context "when the builder was been initialized" do
|
256
|
+
it "must return false" do
|
257
|
+
expect(subject.closed?).to be(false)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
context "when #close has been called" do
|
262
|
+
before { subject.close }
|
263
|
+
|
264
|
+
it "must return true" do
|
265
|
+
expect(subject.closed?).to be(true)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
after { ::FileUtils.rm_f(path) }
|
127
271
|
end
|