wordlist 0.1.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +28 -0
  3. data/.gitignore +6 -3
  4. data/ChangeLog.md +55 -1
  5. data/Gemfile +15 -0
  6. data/LICENSE.txt +1 -3
  7. data/README.md +301 -60
  8. data/Rakefile +7 -32
  9. data/benchmarks.rb +115 -0
  10. data/bin/wordlist +4 -7
  11. data/data/stop_words/ar.txt +104 -0
  12. data/data/stop_words/bg.txt +259 -0
  13. data/data/stop_words/bn.txt +363 -0
  14. data/data/stop_words/ca.txt +126 -0
  15. data/data/stop_words/cs.txt +138 -0
  16. data/data/stop_words/da.txt +101 -0
  17. data/data/stop_words/de.txt +129 -0
  18. data/data/stop_words/el.txt +79 -0
  19. data/data/stop_words/en.txt +175 -0
  20. data/data/stop_words/es.txt +178 -0
  21. data/data/stop_words/eu.txt +98 -0
  22. data/data/stop_words/fa.txt +332 -0
  23. data/data/stop_words/fi.txt +747 -0
  24. data/data/stop_words/fr.txt +116 -0
  25. data/data/stop_words/ga.txt +109 -0
  26. data/data/stop_words/gl.txt +160 -0
  27. data/data/stop_words/he.txt +499 -0
  28. data/data/stop_words/hi.txt +97 -0
  29. data/data/stop_words/hr.txt +179 -0
  30. data/data/stop_words/hu.txt +35 -0
  31. data/data/stop_words/hy.txt +45 -0
  32. data/data/stop_words/id.txt +357 -0
  33. data/data/stop_words/it.txt +134 -0
  34. data/data/stop_words/ja.txt +44 -0
  35. data/data/stop_words/ko.txt +677 -0
  36. data/data/stop_words/ku.txt +63 -0
  37. data/data/stop_words/lt.txt +507 -0
  38. data/data/stop_words/lv.txt +163 -0
  39. data/data/stop_words/mr.txt +99 -0
  40. data/data/stop_words/nl.txt +48 -0
  41. data/data/stop_words/no.txt +172 -0
  42. data/data/stop_words/pl.txt +138 -0
  43. data/data/stop_words/pt.txt +147 -0
  44. data/data/stop_words/ro.txt +281 -0
  45. data/data/stop_words/ru.txt +421 -0
  46. data/data/stop_words/sk.txt +173 -0
  47. data/data/stop_words/sv.txt +386 -0
  48. data/data/stop_words/th.txt +115 -0
  49. data/data/stop_words/tr.txt +114 -0
  50. data/data/stop_words/uk.txt +28 -0
  51. data/data/stop_words/ur.txt +513 -0
  52. data/data/stop_words/zh.txt +125 -0
  53. data/gemspec.yml +13 -12
  54. data/lib/wordlist/abstract_wordlist.rb +25 -0
  55. data/lib/wordlist/builder.rb +172 -138
  56. data/lib/wordlist/cli.rb +459 -0
  57. data/lib/wordlist/compression/reader.rb +72 -0
  58. data/lib/wordlist/compression/writer.rb +80 -0
  59. data/lib/wordlist/exceptions.rb +31 -0
  60. data/lib/wordlist/file.rb +177 -0
  61. data/lib/wordlist/format.rb +39 -0
  62. data/lib/wordlist/lexer/lang.rb +34 -0
  63. data/lib/wordlist/lexer/stop_words.rb +69 -0
  64. data/lib/wordlist/lexer.rb +221 -0
  65. data/lib/wordlist/list_methods.rb +462 -0
  66. data/lib/wordlist/modifiers/capitalize.rb +46 -0
  67. data/lib/wordlist/modifiers/downcase.rb +46 -0
  68. data/lib/wordlist/modifiers/gsub.rb +52 -0
  69. data/lib/wordlist/modifiers/modifier.rb +44 -0
  70. data/lib/wordlist/modifiers/mutate.rb +134 -0
  71. data/lib/wordlist/modifiers/mutate_case.rb +26 -0
  72. data/lib/wordlist/modifiers/sub.rb +98 -0
  73. data/lib/wordlist/modifiers/tr.rb +72 -0
  74. data/lib/wordlist/modifiers/upcase.rb +46 -0
  75. data/lib/wordlist/modifiers.rb +9 -0
  76. data/lib/wordlist/operators/binary_operator.rb +39 -0
  77. data/lib/wordlist/operators/concat.rb +48 -0
  78. data/lib/wordlist/operators/intersect.rb +56 -0
  79. data/lib/wordlist/operators/operator.rb +29 -0
  80. data/lib/wordlist/operators/power.rb +73 -0
  81. data/lib/wordlist/operators/product.rb +51 -0
  82. data/lib/wordlist/operators/subtract.rb +55 -0
  83. data/lib/wordlist/operators/unary_operator.rb +30 -0
  84. data/lib/wordlist/operators/union.rb +62 -0
  85. data/lib/wordlist/operators/unique.rb +53 -0
  86. data/lib/wordlist/operators.rb +8 -0
  87. data/lib/wordlist/unique_filter.rb +41 -61
  88. data/lib/wordlist/version.rb +4 -2
  89. data/lib/wordlist/words.rb +72 -0
  90. data/lib/wordlist.rb +104 -2
  91. data/spec/abstract_list_spec.rb +18 -0
  92. data/spec/builder_spec.rb +220 -76
  93. data/spec/cli_spec.rb +802 -0
  94. data/spec/compression/reader_spec.rb +137 -0
  95. data/spec/compression/writer_spec.rb +194 -0
  96. data/spec/file_spec.rb +269 -0
  97. data/spec/fixtures/wordlist.txt +15 -0
  98. data/spec/fixtures/wordlist.txt.bz2 +0 -0
  99. data/spec/fixtures/wordlist.txt.gz +0 -0
  100. data/spec/fixtures/wordlist.txt.xz +0 -0
  101. data/spec/fixtures/wordlist_with_ambiguous_format +3 -0
  102. data/spec/fixtures/wordlist_with_comments.txt +19 -0
  103. data/spec/fixtures/wordlist_with_empty_lines.txt +19 -0
  104. data/spec/format_spec.rb +50 -0
  105. data/spec/helpers/text.rb +3 -3
  106. data/spec/helpers/wordlist.rb +2 -2
  107. data/spec/lexer/lang_spec.rb +70 -0
  108. data/spec/lexer/stop_words_spec.rb +77 -0
  109. data/spec/lexer_spec.rb +718 -0
  110. data/spec/list_methods_spec.rb +181 -0
  111. data/spec/modifiers/capitalize_spec.rb +27 -0
  112. data/spec/modifiers/downcase_spec.rb +27 -0
  113. data/spec/modifiers/gsub_spec.rb +59 -0
  114. data/spec/modifiers/modifier_spec.rb +20 -0
  115. data/spec/modifiers/mutate_case_spec.rb +46 -0
  116. data/spec/modifiers/mutate_spec.rb +39 -0
  117. data/spec/modifiers/sub_spec.rb +98 -0
  118. data/spec/modifiers/tr_spec.rb +46 -0
  119. data/spec/modifiers/upcase_spec.rb +27 -0
  120. data/spec/operators/binary_operator_spec.rb +19 -0
  121. data/spec/operators/concat_spec.rb +26 -0
  122. data/spec/operators/intersect_spec.rb +37 -0
  123. data/spec/operators/operator_spec.rb +16 -0
  124. data/spec/operators/power_spec.rb +57 -0
  125. data/spec/operators/product_spec.rb +39 -0
  126. data/spec/operators/subtract_spec.rb +37 -0
  127. data/spec/operators/unary_operator_spec.rb +14 -0
  128. data/spec/operators/union_spec.rb +37 -0
  129. data/spec/operators/unique_spec.rb +25 -0
  130. data/spec/spec_helper.rb +2 -1
  131. data/spec/unique_filter_spec.rb +108 -18
  132. data/spec/wordlist_spec.rb +55 -3
  133. data/spec/words_spec.rb +41 -0
  134. data/wordlist.gemspec +1 -0
  135. metadata +164 -126
  136. data/lib/wordlist/builders/website.rb +0 -216
  137. data/lib/wordlist/builders.rb +0 -1
  138. data/lib/wordlist/flat_file.rb +0 -47
  139. data/lib/wordlist/list.rb +0 -162
  140. data/lib/wordlist/mutator.rb +0 -113
  141. data/lib/wordlist/parsers.rb +0 -74
  142. data/lib/wordlist/runners/list.rb +0 -116
  143. data/lib/wordlist/runners/runner.rb +0 -67
  144. data/lib/wordlist/runners.rb +0 -2
  145. data/scripts/benchmark +0 -59
  146. data/scripts/text/comedy_of_errors.txt +0 -4011
  147. data/spec/classes/parser_class.rb +0 -7
  148. data/spec/classes/test_list.rb +0 -9
  149. data/spec/flat_file_spec.rb +0 -25
  150. data/spec/list_spec.rb +0 -58
  151. data/spec/mutator_spec.rb +0 -43
  152. 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,269 @@
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
+
24
+ context "and the path is relative" do
25
+ let(:path) { 'does/not/exist.txt' }
26
+ let(:absolute_path) { File.expand_path(path) }
27
+
28
+ it "must include the absolute path in the exception message" do
29
+ expect {
30
+ described_class.new(path)
31
+ }.to raise_error(Wordlist::WordlistNotFound,"wordlist file does not exist: #{absolute_path.inspect}")
32
+ end
33
+ end
34
+ end
35
+
36
+ context "when given a relative path" do
37
+ let(:relative_path) { ::File.join(__FILE__,"../fixtures/wordlist.txt") }
38
+
39
+ subject { described_class.new(relative_path) }
40
+
41
+ it "must expand the given path" do
42
+ expect(subject.path).to eq(::File.expand_path(relative_path))
43
+ end
44
+ end
45
+
46
+ context "when format: is not given" do
47
+ context "and the path ends in .txt" do
48
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt') }
49
+
50
+ it "must set #format to :txt" do
51
+ expect(subject.format).to eq(:txt)
52
+ end
53
+ end
54
+
55
+ context "and the path ends in .gz" do
56
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.gz') }
57
+
58
+ it "must set #format to :gzip" do
59
+ expect(subject.format).to eq(:gzip)
60
+ end
61
+ end
62
+
63
+ context "and the path ends in .bz2" do
64
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.bz2') }
65
+
66
+ it "must set #format to :bzip2" do
67
+ expect(subject.format).to eq(:bzip2)
68
+ end
69
+ end
70
+
71
+ context "and the path ends in .xz" do
72
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.xz') }
73
+
74
+ it "must set #format to :xz" do
75
+ expect(subject.format).to eq(:xz)
76
+ end
77
+ end
78
+ end
79
+
80
+ context "when format: is given" do
81
+ let(:format) { :gzip }
82
+
83
+ subject { described_class.new(path, format: format) }
84
+
85
+ it "must set #format" do
86
+ expect(subject.format).to eq(format)
87
+ end
88
+
89
+ context "but it's an unknown format" do
90
+ let(:format) { :foo }
91
+
92
+ it do
93
+ expect {
94
+ described_class.new(path, format: format)
95
+ }.to raise_error(Wordlist::UnknownFormat,"unknown format given: #{format.inspect}")
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ describe ".open" do
102
+ subject { described_class.open(path) }
103
+
104
+ it { expect(subject).to be_kind_of(described_class) }
105
+
106
+ it "must initialize #path" do
107
+ expect(subject.path).to eq(path)
108
+ end
109
+ end
110
+
111
+ let(:expected_contents) { ::File.read(path) }
112
+ let(:expected_lines) { expected_contents.lines }
113
+ let(:expected_words) { expected_lines.map(&:chomp) }
114
+
115
+ describe ".read" do
116
+ subject { described_class }
117
+
118
+ it "must open the wordlist and enumerate over each word" do
119
+ expect { |b|
120
+ subject.read(path,&b)
121
+ }.to yield_successive_args(*expected_words)
122
+ end
123
+ end
124
+
125
+ describe "#each_line" do
126
+ context "when given a block" do
127
+ it "must yield each read line of the file" do
128
+ expect { |b|
129
+ subject.each_line(&b)
130
+ }.to yield_successive_args(*expected_lines)
131
+ end
132
+
133
+ context "and the wordlist format is gzip" do
134
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.gz') }
135
+ let(:expected_contents) { `zcat #{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 bzip2" do
145
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.bz2') }
146
+ let(:expected_contents) { `bzcat #{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
+
155
+ context "and the wordlist format is xz" do
156
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.xz') }
157
+ let(:expected_contents) { `xzcat #{Shellwords.shellescape(path)}` }
158
+
159
+ it "must read the uncompressed gzip data" do
160
+ expect { |b|
161
+ subject.each_line(&b)
162
+ }.to yield_successive_args(*expected_lines)
163
+ end
164
+ end
165
+ end
166
+
167
+ context "when not given a block" do
168
+ it "must return an Enumerator" do
169
+ expect(subject.each_line).to be_kind_of(Enumerator)
170
+ expect(subject.each_line.to_a).to eq(expected_lines)
171
+ end
172
+
173
+ context "and the wordlist format is gzip" do
174
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.gz') }
175
+ let(:expected_contents) { `zcat #{Shellwords.shellescape(path)}` }
176
+
177
+ it "must return an Enumerator of the uncompressed gzip data" do
178
+ expect(subject.each_line).to be_kind_of(Enumerator)
179
+ expect(subject.each_line.to_a).to eq(expected_lines)
180
+ end
181
+ end
182
+
183
+ context "and the wordlist format is bzip2" do
184
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.bz2') }
185
+ let(:expected_contents) { `bzcat #{Shellwords.shellescape(path)}` }
186
+
187
+ it "must return an Enumerator of the compressed gzip data" do
188
+ expect(subject.each_line).to be_kind_of(Enumerator)
189
+ expect(subject.each_line.to_a).to eq(expected_lines)
190
+ end
191
+ end
192
+
193
+ context "and the wordlist format is xz" do
194
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.xz') }
195
+ let(:expected_contents) { `xzcat #{Shellwords.shellescape(path)}` }
196
+
197
+ it "must return an Enumerator of the compressed gzip data" do
198
+ expect(subject.each_line).to be_kind_of(Enumerator)
199
+ expect(subject.each_line.to_a).to eq(expected_lines)
200
+ end
201
+ end
202
+ end
203
+ end
204
+
205
+ describe "#each" do
206
+ it "must yield each word on each line" do
207
+ expect { |b|
208
+ subject.each(&b)
209
+ }.to yield_successive_args(*expected_words)
210
+ end
211
+
212
+ context "and the wordlist format is gzip" do
213
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.gz') }
214
+ let(:expected_contents) { `zcat #{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 bzip2" do
224
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.bz2') }
225
+ let(:expected_contents) { `bzcat #{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 "and the wordlist format is xz" do
235
+ let(:path) { ::File.join(fixtures_dir,'wordlist.txt.xz') }
236
+ let(:expected_contents) { `xzcat #{Shellwords.shellescape(path)}` }
237
+
238
+ it "must read the uncompressed gzip data" do
239
+ expect { |b|
240
+ subject.each_line(&b)
241
+ }.to yield_successive_args(*expected_lines)
242
+ end
243
+ end
244
+
245
+ context "when the wordlist contains empty lines" do
246
+ let(:expected_words) do
247
+ super().reject { |w| w.empty? }
248
+ end
249
+
250
+ it "must omit empty lines" do
251
+ expect { |b|
252
+ subject.each(&b)
253
+ }.to yield_successive_args(*expected_words)
254
+ end
255
+ end
256
+
257
+ context "when the wordlist contains comment lines" do
258
+ let(:expected_words) do
259
+ super().reject { |w| w.start_with?('#') }
260
+ end
261
+
262
+ it "must omit lines beginning with a '#'" do
263
+ expect { |b|
264
+ subject.each(&b)
265
+ }.to yield_successive_args(*expected_words)
266
+ end
267
+ end
268
+ end
269
+ end
@@ -0,0 +1,15 @@
1
+ foo
2
+ bar
3
+ baz
4
+ qux
5
+ quux
6
+ quuz
7
+ corge
8
+ grault
9
+ garply
10
+ waldo
11
+ fred
12
+ plugh
13
+ plugh
14
+ xyzzy
15
+ thud
Binary file
Binary file
Binary file
@@ -0,0 +1,3 @@
1
+ foo
2
+ bar
3
+ baz
@@ -0,0 +1,19 @@
1
+ foo
2
+ bar
3
+ baz
4
+ qux
5
+ # comment1
6
+ quux
7
+ quuz
8
+ corge
9
+ grault
10
+ # comment2
11
+ #
12
+ # comment3
13
+ garply
14
+ waldo
15
+ fred
16
+ plugh
17
+ plugh
18
+ xyzzy
19
+ thud
@@ -0,0 +1,19 @@
1
+ foo
2
+ bar
3
+ baz
4
+ qux
5
+ quux
6
+
7
+ quuz
8
+ corge
9
+ grault
10
+ garply
11
+ waldo
12
+
13
+
14
+ fred
15
+ plugh
16
+ plugh
17
+ xyzzy
18
+ thud
19
+