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
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/compression/reader'
|
3
|
+
|
4
|
+
describe Wordlist::Compression::Reader do
|
5
|
+
describe ".command" do
|
6
|
+
let(:path) { 'path/to/file' }
|
7
|
+
|
8
|
+
context "when given format: :gzip" do
|
9
|
+
subject { described_class.command(path, format: :gzip) }
|
10
|
+
|
11
|
+
it "must return 'zcat path/to/file'" do
|
12
|
+
expect(subject).to eq("zcat #{path}")
|
13
|
+
end
|
14
|
+
|
15
|
+
context "and the file contains special characters" do
|
16
|
+
let(:path) { 'path/to/the file' }
|
17
|
+
|
18
|
+
it "must shellescape them" do
|
19
|
+
expect(subject).to eq("zcat #{Shellwords.shellescape(path)}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when given format: :bzip2" do
|
25
|
+
subject { described_class.command(path, format: :bzip2) }
|
26
|
+
|
27
|
+
it "must return 'bzcat path/to/file'" do
|
28
|
+
expect(subject).to eq("bzcat #{path}")
|
29
|
+
end
|
30
|
+
|
31
|
+
context "and the file contains special characters" do
|
32
|
+
let(:path) { 'path/to/the file' }
|
33
|
+
|
34
|
+
it "must shellescape them" do
|
35
|
+
expect(subject).to eq("bzcat #{Shellwords.shellescape(path)}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when given format: :xz" do
|
41
|
+
subject { described_class.command(path, format: :xz) }
|
42
|
+
|
43
|
+
it "must return 'xzcat path/to/file'" do
|
44
|
+
expect(subject).to eq("xzcat #{path}")
|
45
|
+
end
|
46
|
+
|
47
|
+
context "and the file contains special characters" do
|
48
|
+
let(:path) { 'path/to/the file' }
|
49
|
+
|
50
|
+
it "must shellescape them" do
|
51
|
+
expect(subject).to eq("xzcat #{Shellwords.shellescape(path)}")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when given an unknown format: value" do
|
57
|
+
let(:format) { :foo }
|
58
|
+
|
59
|
+
it do
|
60
|
+
expect {
|
61
|
+
subject.command(path, format: format)
|
62
|
+
}.to raise_error(Wordlist::UnknownFormat,"unsupported format: #{format.inspect}")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe ".open" do
|
68
|
+
let(:fixtures_dir) { ::File.join(__dir__,'..','fixtures') }
|
69
|
+
|
70
|
+
context "when given format: :gzip" do
|
71
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.gz') }
|
72
|
+
let(:expected_contents) { `zcat #{Shellwords.shellescape(path)}` }
|
73
|
+
|
74
|
+
subject { described_class.open(path, format: :gzip) }
|
75
|
+
|
76
|
+
it "must return an IO object" do
|
77
|
+
expect(subject).to be_kind_of(IO)
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when read from" do
|
81
|
+
it "must read the uncompressed contents of the wordllist" do
|
82
|
+
expect(subject.read).to eq(expected_contents)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when given format: :bzip2" do
|
88
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.bz2') }
|
89
|
+
let(:expected_contents) { `bzcat #{Shellwords.shellescape(path)}` }
|
90
|
+
|
91
|
+
subject { described_class.open(path, format: :bzip2) }
|
92
|
+
|
93
|
+
it "must return an IO object" do
|
94
|
+
expect(subject).to be_kind_of(IO)
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when read from" do
|
98
|
+
it "must read the uncompressed contents of the wordllist" do
|
99
|
+
expect(subject.read).to eq(expected_contents)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "when given format: :xz" do
|
105
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.xz') }
|
106
|
+
let(:expected_contents) { `xzcat #{Shellwords.shellescape(path)}` }
|
107
|
+
|
108
|
+
subject { described_class.open(path, format: :xz) }
|
109
|
+
|
110
|
+
it "must return an IO object" do
|
111
|
+
expect(subject).to be_kind_of(IO)
|
112
|
+
end
|
113
|
+
|
114
|
+
context "when read from" do
|
115
|
+
it "must read the uncompressed contents of the wordllist" do
|
116
|
+
expect(subject.read).to eq(expected_contents)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when the command is not installed" do
|
122
|
+
let(:format) { :gzip }
|
123
|
+
let(:command) { Shellwords.shelljoin(['zcat', path]) }
|
124
|
+
let(:path) { 'path/to/wordlist.gz' }
|
125
|
+
|
126
|
+
before do
|
127
|
+
expect(IO).to receive(:popen).with(command).and_raise(Errno::ENOENT)
|
128
|
+
end
|
129
|
+
|
130
|
+
it do
|
131
|
+
expect {
|
132
|
+
described_class.open(path, format: format)
|
133
|
+
}.to raise_error(Wordlist::CommandNotFound,"#{command.inspect} command not found")
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/compression/writer'
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
describe Wordlist::Compression::Writer do
|
7
|
+
describe ".command" do
|
8
|
+
let(:path) { 'path/to/file' }
|
9
|
+
|
10
|
+
context "when given format: :gzip" do
|
11
|
+
subject { described_class.command(path, format: :gzip) }
|
12
|
+
|
13
|
+
it "must return 'gzip > path/to/file'" do
|
14
|
+
expect(subject).to eq("gzip > #{path}")
|
15
|
+
end
|
16
|
+
|
17
|
+
context "and given append: true" do
|
18
|
+
subject { described_class.command(path, format: :gzip, append: true) }
|
19
|
+
|
20
|
+
it "must return 'gzip >> path/to/file'" do
|
21
|
+
expect(subject).to eq("gzip >> #{path}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "and the file contains special characters" do
|
26
|
+
let(:path) { 'path/to/the file' }
|
27
|
+
|
28
|
+
it "must shellescape them" do
|
29
|
+
expect(subject).to eq("gzip > #{Shellwords.shellescape(path)}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when given format: :bzip2" do
|
35
|
+
subject { described_class.command(path, format: :bzip2) }
|
36
|
+
|
37
|
+
it "must return 'bzip2 > path/to/file'" do
|
38
|
+
expect(subject).to eq("bzip2 > #{path}")
|
39
|
+
end
|
40
|
+
|
41
|
+
context "and given append: true" do
|
42
|
+
subject { described_class.command(path, format: :bzip2, append: true) }
|
43
|
+
|
44
|
+
it "must return 'bzip2 >> path/to/file'" do
|
45
|
+
expect(subject).to eq("bzip2 >> #{path}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "and the file contains special characters" do
|
50
|
+
let(:path) { 'path/to/the file' }
|
51
|
+
|
52
|
+
it "must shellescape them" do
|
53
|
+
expect(subject).to eq("bzip2 > #{Shellwords.shellescape(path)}")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when given format: :xz" do
|
59
|
+
subject { described_class.command(path, format: :xz) }
|
60
|
+
|
61
|
+
it "must return 'xz > path/to/file'" do
|
62
|
+
expect(subject).to eq("xz > #{path}")
|
63
|
+
end
|
64
|
+
|
65
|
+
context "and given append: true" do
|
66
|
+
subject { described_class.command(path, format: :xz, append: true) }
|
67
|
+
|
68
|
+
it "must return 'xz >> path/to/file'" do
|
69
|
+
expect(subject).to eq("xz >> #{path}")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "and the file contains special characters" do
|
74
|
+
let(:path) { 'path/to/the file' }
|
75
|
+
|
76
|
+
it "must shellescape them" do
|
77
|
+
expect(subject).to eq("xz > #{Shellwords.shellescape(path)}")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when given an unknown format: value" do
|
83
|
+
let(:format) { :foo }
|
84
|
+
|
85
|
+
it do
|
86
|
+
expect {
|
87
|
+
subject.command(path, format: format)
|
88
|
+
}.to raise_error(Wordlist::UnknownFormat,"unsupported format: #{format.inspect}")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe ".open" do
|
94
|
+
let(:fixtures_dir) { ::File.join(__dir__,'..','fixtures') }
|
95
|
+
|
96
|
+
let(:words) { %w[foo bar] }
|
97
|
+
|
98
|
+
context "when given format: :gzip" do
|
99
|
+
let(:path) { ::File.join(fixtures_dir,'new_wordlist.txt.gz') }
|
100
|
+
|
101
|
+
subject { described_class.open(path, format: :gzip) }
|
102
|
+
|
103
|
+
it "must return an IO object" do
|
104
|
+
expect(subject).to be_kind_of(IO)
|
105
|
+
end
|
106
|
+
|
107
|
+
context "when written to" do
|
108
|
+
before do
|
109
|
+
subject.puts words
|
110
|
+
subject.close
|
111
|
+
end
|
112
|
+
|
113
|
+
let(:written_contents) { `zcat #{Shellwords.shellescape(path)}` }
|
114
|
+
let(:written_words) { written_contents.lines.map(&:chomp) }
|
115
|
+
|
116
|
+
it "must writing gzip compressed data to the file" do
|
117
|
+
expect(written_words).to eq(words)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
after { ::FileUtils.rm_f(path) }
|
122
|
+
end
|
123
|
+
|
124
|
+
context "when given format: :bzip2" do
|
125
|
+
let(:path) { ::File.join(fixtures_dir,'new_wordlist.txt.bz2') }
|
126
|
+
|
127
|
+
subject { described_class.open(path, format: :bzip2) }
|
128
|
+
|
129
|
+
it "must return an IO object" do
|
130
|
+
expect(subject).to be_kind_of(IO)
|
131
|
+
end
|
132
|
+
|
133
|
+
context "when written to" do
|
134
|
+
before do
|
135
|
+
subject.puts words
|
136
|
+
subject.close
|
137
|
+
end
|
138
|
+
|
139
|
+
let(:written_contents) { `bzcat #{Shellwords.shellescape(path)}` }
|
140
|
+
let(:written_words) { written_contents.lines.map(&:chomp) }
|
141
|
+
|
142
|
+
it "must writing bzip2 compressed data to the file" do
|
143
|
+
expect(written_words).to eq(words)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
after { ::FileUtils.rm_f(path) }
|
148
|
+
end
|
149
|
+
|
150
|
+
context "when given format: :xz" do
|
151
|
+
let(:path) { ::File.join(fixtures_dir,'new_wordlist.txt.xz') }
|
152
|
+
|
153
|
+
subject { described_class.open(path, format: :xz) }
|
154
|
+
|
155
|
+
it "must return an IO object" do
|
156
|
+
expect(subject).to be_kind_of(IO)
|
157
|
+
end
|
158
|
+
|
159
|
+
context "when written to" do
|
160
|
+
before do
|
161
|
+
subject.puts words
|
162
|
+
subject.close
|
163
|
+
end
|
164
|
+
|
165
|
+
let(:written_contents) { `xzcat #{Shellwords.shellescape(path)}` }
|
166
|
+
let(:written_words) { written_contents.lines.map(&:chomp) }
|
167
|
+
|
168
|
+
it "must writing xz compressed data to the file" do
|
169
|
+
expect(written_words).to eq(words)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
after { ::FileUtils.rm_f(path) }
|
174
|
+
end
|
175
|
+
|
176
|
+
context "when the command is not installed" do
|
177
|
+
let(:format) { :gzip }
|
178
|
+
let(:command) { "gzip > #{Shellwords.shellescape(path)}" }
|
179
|
+
let(:path) { ::File.join(fixtures_dir,'new_wordlist.txt.gz') }
|
180
|
+
|
181
|
+
before do
|
182
|
+
expect(IO).to receive(:popen).with(command,'w').and_raise(Errno::ENOENT)
|
183
|
+
end
|
184
|
+
|
185
|
+
it do
|
186
|
+
expect {
|
187
|
+
described_class.open(path, format: format)
|
188
|
+
}.to raise_error(Wordlist::CommandNotFound,"#{command.inspect} command not found")
|
189
|
+
end
|
190
|
+
|
191
|
+
after { ::FileUtils.rm_f(path) }
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
data/spec/file_spec.rb
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/file'
|
3
|
+
|
4
|
+
describe Wordlist::File do
|
5
|
+
let(:fixtures_dir) { ::File.join(__dir__,'fixtures') }
|
6
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt') }
|
7
|
+
|
8
|
+
subject { described_class.new(path) }
|
9
|
+
|
10
|
+
describe "#initialize" do
|
11
|
+
it "must set #path" do
|
12
|
+
expect(subject.path).to eq(path)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when initialized with non-existant path" do
|
16
|
+
let(:path) { '/does/not/exist.txt' }
|
17
|
+
|
18
|
+
it do
|
19
|
+
expect {
|
20
|
+
described_class.new(path)
|
21
|
+
}.to raise_error(Wordlist::WordlistNotFound,"wordlist file does not exist: #{path.inspect}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when given a relative path" do
|
26
|
+
let(:relative_path) { ::File.join(__FILE__,"../fixtures/wordlist.txt") }
|
27
|
+
|
28
|
+
subject { described_class.new(relative_path) }
|
29
|
+
|
30
|
+
it "must expand the given path" do
|
31
|
+
expect(subject.path).to eq(::File.expand_path(relative_path))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when format: is not given" do
|
36
|
+
context "and the path ends in .txt" do
|
37
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt') }
|
38
|
+
|
39
|
+
it "must set #format to :txt" do
|
40
|
+
expect(subject.format).to eq(:txt)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "and the path ends in .gz" do
|
45
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.gz') }
|
46
|
+
|
47
|
+
it "must set #format to :gzip" do
|
48
|
+
expect(subject.format).to eq(:gzip)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "and the path ends in .bz2" do
|
53
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.bz2') }
|
54
|
+
|
55
|
+
it "must set #format to :bzip2" do
|
56
|
+
expect(subject.format).to eq(:bzip2)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "and the path ends in .xz" do
|
61
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.xz') }
|
62
|
+
|
63
|
+
it "must set #format to :xz" do
|
64
|
+
expect(subject.format).to eq(:xz)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when format: is given" do
|
70
|
+
let(:format) { :gzip }
|
71
|
+
|
72
|
+
subject { described_class.new(path, format: format) }
|
73
|
+
|
74
|
+
it "must set #format" do
|
75
|
+
expect(subject.format).to eq(format)
|
76
|
+
end
|
77
|
+
|
78
|
+
context "but it's an unknown format" do
|
79
|
+
let(:format) { :foo }
|
80
|
+
|
81
|
+
it do
|
82
|
+
expect {
|
83
|
+
described_class.new(path, format: format)
|
84
|
+
}.to raise_error(Wordlist::UnknownFormat,"unknown format given: #{format.inspect}")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe ".open" do
|
91
|
+
subject { described_class.open(path) }
|
92
|
+
|
93
|
+
it { expect(subject).to be_kind_of(described_class) }
|
94
|
+
|
95
|
+
it "must initialize #path" do
|
96
|
+
expect(subject.path).to eq(path)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
let(:expected_contents) { ::File.read(path) }
|
101
|
+
let(:expected_lines) { expected_contents.lines }
|
102
|
+
let(:expected_words) { expected_lines.map(&:chomp) }
|
103
|
+
|
104
|
+
describe ".read" do
|
105
|
+
subject { described_class }
|
106
|
+
|
107
|
+
it "must open the wordlist and enumerate over each word" do
|
108
|
+
expect { |b|
|
109
|
+
subject.read(path,&b)
|
110
|
+
}.to yield_successive_args(*expected_words)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#each_line" do
|
115
|
+
context "when given a block" do
|
116
|
+
it "must yield each read line of the file" do
|
117
|
+
expect { |b|
|
118
|
+
subject.each_line(&b)
|
119
|
+
}.to yield_successive_args(*expected_lines)
|
120
|
+
end
|
121
|
+
|
122
|
+
context "and the wordlist format is gzip" do
|
123
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.gz') }
|
124
|
+
let(:expected_contents) { `zcat #{Shellwords.shellescape(path)}` }
|
125
|
+
|
126
|
+
it "must read the uncompressed gzip data" do
|
127
|
+
expect { |b|
|
128
|
+
subject.each_line(&b)
|
129
|
+
}.to yield_successive_args(*expected_lines)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "and the wordlist format is bzip2" do
|
134
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.bz2') }
|
135
|
+
let(:expected_contents) { `bzcat #{Shellwords.shellescape(path)}` }
|
136
|
+
|
137
|
+
it "must read the uncompressed gzip data" do
|
138
|
+
expect { |b|
|
139
|
+
subject.each_line(&b)
|
140
|
+
}.to yield_successive_args(*expected_lines)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "and the wordlist format is xz" do
|
145
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.xz') }
|
146
|
+
let(:expected_contents) { `xzcat #{Shellwords.shellescape(path)}` }
|
147
|
+
|
148
|
+
it "must read the uncompressed gzip data" do
|
149
|
+
expect { |b|
|
150
|
+
subject.each_line(&b)
|
151
|
+
}.to yield_successive_args(*expected_lines)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when not given a block" do
|
157
|
+
it "must return an Enumerator" do
|
158
|
+
expect(subject.each_line).to be_kind_of(Enumerator)
|
159
|
+
expect(subject.each_line.to_a).to eq(expected_lines)
|
160
|
+
end
|
161
|
+
|
162
|
+
context "and the wordlist format is gzip" do
|
163
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.gz') }
|
164
|
+
let(:expected_contents) { `zcat #{Shellwords.shellescape(path)}` }
|
165
|
+
|
166
|
+
it "must return an Enumerator of the uncompressed gzip data" do
|
167
|
+
expect(subject.each_line).to be_kind_of(Enumerator)
|
168
|
+
expect(subject.each_line.to_a).to eq(expected_lines)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "and the wordlist format is bzip2" do
|
173
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.bz2') }
|
174
|
+
let(:expected_contents) { `bzcat #{Shellwords.shellescape(path)}` }
|
175
|
+
|
176
|
+
it "must return an Enumerator of the compressed gzip data" do
|
177
|
+
expect(subject.each_line).to be_kind_of(Enumerator)
|
178
|
+
expect(subject.each_line.to_a).to eq(expected_lines)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "and the wordlist format is xz" do
|
183
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.xz') }
|
184
|
+
let(:expected_contents) { `xzcat #{Shellwords.shellescape(path)}` }
|
185
|
+
|
186
|
+
it "must return an Enumerator of the compressed gzip data" do
|
187
|
+
expect(subject.each_line).to be_kind_of(Enumerator)
|
188
|
+
expect(subject.each_line.to_a).to eq(expected_lines)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "#each" do
|
195
|
+
it "must yield each word on each line" do
|
196
|
+
expect { |b|
|
197
|
+
subject.each(&b)
|
198
|
+
}.to yield_successive_args(*expected_words)
|
199
|
+
end
|
200
|
+
|
201
|
+
context "and the wordlist format is gzip" do
|
202
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.gz') }
|
203
|
+
let(:expected_contents) { `zcat #{Shellwords.shellescape(path)}` }
|
204
|
+
|
205
|
+
it "must read the uncompressed gzip data" do
|
206
|
+
expect { |b|
|
207
|
+
subject.each_line(&b)
|
208
|
+
}.to yield_successive_args(*expected_lines)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "and the wordlist format is bzip2" do
|
213
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.bz2') }
|
214
|
+
let(:expected_contents) { `bzcat #{Shellwords.shellescape(path)}` }
|
215
|
+
|
216
|
+
it "must read the uncompressed gzip data" do
|
217
|
+
expect { |b|
|
218
|
+
subject.each_line(&b)
|
219
|
+
}.to yield_successive_args(*expected_lines)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "and the wordlist format is xz" do
|
224
|
+
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.xz') }
|
225
|
+
let(:expected_contents) { `xzcat #{Shellwords.shellescape(path)}` }
|
226
|
+
|
227
|
+
it "must read the uncompressed gzip data" do
|
228
|
+
expect { |b|
|
229
|
+
subject.each_line(&b)
|
230
|
+
}.to yield_successive_args(*expected_lines)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context "when the wordlist contains empty lines" do
|
235
|
+
let(:expected_words) do
|
236
|
+
super().reject { |w| w.empty? }
|
237
|
+
end
|
238
|
+
|
239
|
+
it "must omit empty lines" do
|
240
|
+
expect { |b|
|
241
|
+
subject.each(&b)
|
242
|
+
}.to yield_successive_args(*expected_words)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context "when the wordlist contains comment lines" do
|
247
|
+
let(:expected_words) do
|
248
|
+
super().reject { |w| w.start_with?('#') }
|
249
|
+
end
|
250
|
+
|
251
|
+
it "must omit lines beginning with a '#'" do
|
252
|
+
expect { |b|
|
253
|
+
subject.each(&b)
|
254
|
+
}.to yield_successive_args(*expected_words)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
data/spec/format_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/format'
|
3
|
+
|
4
|
+
describe Wordlist::Format do
|
5
|
+
describe ".infer" do
|
6
|
+
context "when given a path ending in '.txt'" do
|
7
|
+
it "must return :txt" do
|
8
|
+
expect(subject.infer("path/to/file.txt")).to eq(:txt)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when given a path ending in '.gz'" do
|
13
|
+
it "must return :gzip" do
|
14
|
+
expect(subject.infer("path/to/file.gz")).to eq(:gzip)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when given a path ending in '.bz2'" do
|
19
|
+
it "must return :bzip2" do
|
20
|
+
expect(subject.infer("path/to/file.bz2")).to eq(:bzip2)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when given a path ending in '.xz'" do
|
25
|
+
it "must return :xz" do
|
26
|
+
expect(subject.infer("path/to/file.xz")).to eq(:xz)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when given a path ending in another file extension" do
|
31
|
+
let(:path) { "path/to/file.foo" }
|
32
|
+
|
33
|
+
it do
|
34
|
+
expect {
|
35
|
+
subject.infer(path)
|
36
|
+
}.to raise_error(Wordlist::UnknownFormat,"could not infer the format of file: #{path.inspect}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when given a path has no file extension" do
|
41
|
+
let(:path) { "path/to/file" }
|
42
|
+
|
43
|
+
it do
|
44
|
+
expect {
|
45
|
+
subject.infer(path)
|
46
|
+
}.to raise_error(Wordlist::UnknownFormat,"could not infer the format of file: #{path.inspect}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|