wordlist 0.1.1 → 1.0.1
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 +28 -0
- data/.gitignore +6 -3
- data/ChangeLog.md +55 -1
- data/Gemfile +15 -0
- data/LICENSE.txt +1 -3
- data/README.md +301 -60
- 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 +13 -12
- data/lib/wordlist/abstract_wordlist.rb +25 -0
- data/lib/wordlist/builder.rb +172 -138
- data/lib/wordlist/cli.rb +459 -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 +177 -0
- data/lib/wordlist/format.rb +39 -0
- data/lib/wordlist/lexer/lang.rb +34 -0
- data/lib/wordlist/lexer/stop_words.rb +69 -0
- data/lib/wordlist/lexer.rb +221 -0
- data/lib/wordlist/list_methods.rb +462 -0
- data/lib/wordlist/modifiers/capitalize.rb +46 -0
- data/lib/wordlist/modifiers/downcase.rb +46 -0
- data/lib/wordlist/modifiers/gsub.rb +52 -0
- data/lib/wordlist/modifiers/modifier.rb +44 -0
- data/lib/wordlist/modifiers/mutate.rb +134 -0
- data/lib/wordlist/modifiers/mutate_case.rb +26 -0
- data/lib/wordlist/modifiers/sub.rb +98 -0
- data/lib/wordlist/modifiers/tr.rb +72 -0
- data/lib/wordlist/modifiers/upcase.rb +46 -0
- data/lib/wordlist/modifiers.rb +9 -0
- data/lib/wordlist/operators/binary_operator.rb +39 -0
- data/lib/wordlist/operators/concat.rb +48 -0
- data/lib/wordlist/operators/intersect.rb +56 -0
- data/lib/wordlist/operators/operator.rb +29 -0
- data/lib/wordlist/operators/power.rb +73 -0
- data/lib/wordlist/operators/product.rb +51 -0
- data/lib/wordlist/operators/subtract.rb +55 -0
- data/lib/wordlist/operators/unary_operator.rb +30 -0
- data/lib/wordlist/operators/union.rb +62 -0
- data/lib/wordlist/operators/unique.rb +53 -0
- data/lib/wordlist/operators.rb +8 -0
- data/lib/wordlist/unique_filter.rb +41 -61
- data/lib/wordlist/version.rb +4 -2
- data/lib/wordlist/words.rb +72 -0
- data/lib/wordlist.rb +104 -2
- data/spec/abstract_list_spec.rb +18 -0
- data/spec/builder_spec.rb +220 -76
- data/spec/cli_spec.rb +802 -0
- data/spec/compression/reader_spec.rb +137 -0
- data/spec/compression/writer_spec.rb +194 -0
- data/spec/file_spec.rb +269 -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 +718 -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/unary_operator_spec.rb +14 -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
- data/wordlist.gemspec +1 -0
- metadata +164 -126
- 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/classes/parser_class.rb +0 -7
- data/spec/classes/test_list.rb +0 -9
- 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,181 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/list_methods'
|
3
|
+
|
4
|
+
describe Wordlist::ListMethods do
|
5
|
+
module TestWordlist
|
6
|
+
class TestListMethods
|
7
|
+
include Wordlist::ListMethods
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
subject { TestWordlist::TestListMethods.new }
|
12
|
+
|
13
|
+
let(:other) { double(:other_list) }
|
14
|
+
|
15
|
+
describe "#concat" do
|
16
|
+
it "must return an Operators::Concat object with the list and the other list" do
|
17
|
+
expect(Operators::Concat).to receive(:new).with(subject,other)
|
18
|
+
|
19
|
+
subject.concat(other)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#subtract" do
|
24
|
+
it "must return an Operators::Subtract object with the list and the other list" do
|
25
|
+
expect(Operators::Subtract).to receive(:new).with(subject,other)
|
26
|
+
|
27
|
+
subject.subtract(other)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#product" do
|
32
|
+
it "must return an Operators::Product object with the list and the other list" do
|
33
|
+
expect(Operators::Product).to receive(:new).with(subject,other)
|
34
|
+
|
35
|
+
subject.product(other)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#power" do
|
40
|
+
let(:exponent) { 3 }
|
41
|
+
|
42
|
+
it "must return an Operators::Power object with the list and an exponent" do
|
43
|
+
expect(Operators::Power).to receive(:new).with(subject,exponent)
|
44
|
+
|
45
|
+
subject.power(exponent)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#intersect" do
|
50
|
+
it "must return an Operators::Intersect object with the list and the other list" do
|
51
|
+
expect(Operators::Intersect).to receive(:new).with(subject,other)
|
52
|
+
|
53
|
+
subject.intersect(other)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#union" do
|
58
|
+
it "must return an Operators::Union object with the list and the other list" do
|
59
|
+
expect(Operators::Union).to receive(:new).with(subject,other)
|
60
|
+
|
61
|
+
subject.union(other)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#uniq" do
|
66
|
+
it "must return an Operators::Uniq object with the list" do
|
67
|
+
expect(Operators::Unique).to receive(:new).with(subject)
|
68
|
+
|
69
|
+
subject.uniq
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#tr" do
|
74
|
+
let(:chars) { double(:chars) }
|
75
|
+
let(:replace) { double(:replace) }
|
76
|
+
|
77
|
+
it "must return an Modifiers::Tr object with the list, chars, and replace" do
|
78
|
+
expect(Modifiers::Tr).to receive(:new).with(subject,chars,replace)
|
79
|
+
|
80
|
+
subject.tr(chars,replace)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#sub" do
|
85
|
+
let(:pattern) { double(:pattern) }
|
86
|
+
let(:replace) { double(:replace) }
|
87
|
+
|
88
|
+
it "must return an Modifiers::Sub object with the list, pattern, and replace" do
|
89
|
+
expect(Modifiers::Sub).to receive(:new).with(subject,pattern,replace)
|
90
|
+
|
91
|
+
subject.sub(pattern,replace)
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when replace is nil and a block is given" do
|
95
|
+
let(:replace) { nil }
|
96
|
+
let(:block) { ->(match) { '0' } }
|
97
|
+
|
98
|
+
it "must return an Modifiers::Sub object with the list, pattern, and block" do
|
99
|
+
expect(Modifiers::Sub).to receive(:new).with(subject,pattern)
|
100
|
+
|
101
|
+
subject.sub(pattern,replace)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#gsub" do
|
107
|
+
let(:pattern) { double(:pattern) }
|
108
|
+
let(:replace) { double(:replace) }
|
109
|
+
|
110
|
+
it "must return an Modifiers::Gsub object with the list, pattern, and replace" do
|
111
|
+
expect(Modifiers::Gsub).to receive(:new).with(subject,pattern,replace)
|
112
|
+
|
113
|
+
subject.gsub(pattern,replace)
|
114
|
+
end
|
115
|
+
|
116
|
+
context "when replace is nil and a block is given" do
|
117
|
+
let(:replace) { nil }
|
118
|
+
let(:block) { ->(match) { '0' } }
|
119
|
+
|
120
|
+
it "must return an Modifiers::Gsub object with the list, pattern, and block" do
|
121
|
+
expect(Modifiers::Gsub).to receive(:new).with(subject,pattern)
|
122
|
+
|
123
|
+
subject.gsub(pattern,replace)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#capitalize" do
|
129
|
+
it "must return an Modifiers::Capitalize object with the list" do
|
130
|
+
expect(Modifiers::Capitalize).to receive(:new).with(subject)
|
131
|
+
|
132
|
+
subject.capitalize
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#upcase" do
|
137
|
+
it "must return an Modifiers::Upcase object with the list" do
|
138
|
+
expect(Modifiers::Upcase).to receive(:new).with(subject)
|
139
|
+
|
140
|
+
subject.upcase
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "#downcase" do
|
145
|
+
it "must return an Modifiers::Downcase object with the list" do
|
146
|
+
expect(Modifiers::Downcase).to receive(:new).with(subject)
|
147
|
+
|
148
|
+
subject.downcase
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "#mutate" do
|
153
|
+
let(:pattern) { double(:pattern) }
|
154
|
+
let(:replace) { double(:replace) }
|
155
|
+
|
156
|
+
it "must return an Modifiers::Mutate object with the list, pattern, and replace" do
|
157
|
+
expect(Modifiers::Mutate).to receive(:new).with(subject,pattern,replace)
|
158
|
+
|
159
|
+
subject.mutate(pattern,replace)
|
160
|
+
end
|
161
|
+
|
162
|
+
context "when replace is nil and a block is given" do
|
163
|
+
let(:replace) { nil }
|
164
|
+
let(:block) { ->(match) { '0' } }
|
165
|
+
|
166
|
+
it "must return an Modifiers::Mutate object with the list, pattern, and block" do
|
167
|
+
expect(Modifiers::Mutate).to receive(:new).with(subject,pattern)
|
168
|
+
|
169
|
+
subject.mutate(pattern,replace)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "#mutate_case" do
|
175
|
+
it "must return an Modifiers::MutateCase object with the list" do
|
176
|
+
expect(Modifiers::MutateCase).to receive(:new).with(subject)
|
177
|
+
|
178
|
+
subject.mutate_case
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/modifiers/capitalize'
|
3
|
+
|
4
|
+
describe Wordlist::Modifiers::Capitalize do
|
5
|
+
let(:wordlist) { %w[foo bar baz] }
|
6
|
+
|
7
|
+
subject { described_class.new(wordlist) }
|
8
|
+
|
9
|
+
describe "#each" do
|
10
|
+
let(:expected_words) { wordlist.map(&:capitalize) }
|
11
|
+
|
12
|
+
context "when given a block" do
|
13
|
+
it "must capitalize each word" do
|
14
|
+
expect { |b|
|
15
|
+
subject.each(&b)
|
16
|
+
}.to yield_successive_args(*expected_words)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when not given a block" do
|
21
|
+
it "must return an Enumerator object for #each" do
|
22
|
+
expect(subject.each).to be_kind_of(Enumerator)
|
23
|
+
expect(subject.each.to_a).to eq(expected_words)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/modifiers/downcase'
|
3
|
+
|
4
|
+
describe Wordlist::Modifiers::Downcase do
|
5
|
+
let(:wordlist) { %w[Foo BAR baz] }
|
6
|
+
|
7
|
+
subject { described_class.new(wordlist) }
|
8
|
+
|
9
|
+
describe "#each" do
|
10
|
+
let(:expected_words) { wordlist.map(&:downcase) }
|
11
|
+
|
12
|
+
context "when given a block" do
|
13
|
+
it "must downcase each word" do
|
14
|
+
expect { |b|
|
15
|
+
subject.each(&b)
|
16
|
+
}.to yield_successive_args(*expected_words)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when not given a block" do
|
21
|
+
it "must return an Enumerator object for #each" do
|
22
|
+
expect(subject.each).to be_kind_of(Enumerator)
|
23
|
+
expect(subject.each.to_a).to eq(expected_words)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/modifiers/gsub'
|
3
|
+
|
4
|
+
describe Wordlist::Modifiers::Gsub do
|
5
|
+
let(:wordlist) { %w[foo bar baz] }
|
6
|
+
|
7
|
+
let(:pattern) { /o/ }
|
8
|
+
let(:replace) { '0' }
|
9
|
+
|
10
|
+
subject { described_class.new(wordlist,pattern,replace) }
|
11
|
+
|
12
|
+
describe "#each" do
|
13
|
+
context "when initialized with a replacement String" do
|
14
|
+
let(:expected_words) do
|
15
|
+
wordlist.map { |word| word.gsub(pattern,replace) }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when given a block" do
|
19
|
+
it "must call #gsub on each word" do
|
20
|
+
expect { |b|
|
21
|
+
subject.each(&b)
|
22
|
+
}.to yield_successive_args(*expected_words)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when not given a block" do
|
27
|
+
it "must return an Enumerator object for #each" do
|
28
|
+
expect(subject.each).to be_kind_of(Enumerator)
|
29
|
+
expect(subject.each.to_a).to eq(expected_words)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when initialized with a replacement block" do
|
35
|
+
let(:block) { ->(word) { '0' } }
|
36
|
+
|
37
|
+
subject { described_class.new(wordlist,pattern,&block) }
|
38
|
+
|
39
|
+
let(:expected_words) do
|
40
|
+
wordlist.map { |word| word.gsub(pattern,&block) }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when given a block" do
|
44
|
+
it "must call #gsub on each word" do
|
45
|
+
expect { |b|
|
46
|
+
subject.each(&b)
|
47
|
+
}.to yield_successive_args(*expected_words)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when not given a block" do
|
52
|
+
it "must return an Enumerator object for #each" do
|
53
|
+
expect(subject.each).to be_kind_of(Enumerator)
|
54
|
+
expect(subject.each.to_a).to eq(expected_words)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/modifiers/modifier'
|
3
|
+
|
4
|
+
describe Wordlist::Modifiers::Modifier do
|
5
|
+
let(:wordlist) { %w[foo bar baz] }
|
6
|
+
|
7
|
+
subject { described_class.new(wordlist) }
|
8
|
+
|
9
|
+
it do
|
10
|
+
expect(described_class).to include(Enumerable)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#each" do
|
14
|
+
it do
|
15
|
+
expect {
|
16
|
+
subject.each
|
17
|
+
}.to raise_error(NotImplementedError,"#{described_class}#each was not implemented")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/modifiers/mutate_case'
|
3
|
+
|
4
|
+
describe Wordlist::Modifiers::MutateCase do
|
5
|
+
let(:wordlist) { %w[foo BaR] }
|
6
|
+
|
7
|
+
subject { described_class.new(wordlist) }
|
8
|
+
|
9
|
+
describe "#each" do
|
10
|
+
let(:expected_words) do
|
11
|
+
%w[
|
12
|
+
foo
|
13
|
+
Foo
|
14
|
+
fOo
|
15
|
+
foO
|
16
|
+
FOo
|
17
|
+
FoO
|
18
|
+
fOO
|
19
|
+
FOO
|
20
|
+
BaR
|
21
|
+
baR
|
22
|
+
BAR
|
23
|
+
Bar
|
24
|
+
bAR
|
25
|
+
bar
|
26
|
+
BAr
|
27
|
+
bAr
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when given a block" do
|
32
|
+
it "must enumerate through every possible uppercase/lowercase combination" do
|
33
|
+
expect { |b|
|
34
|
+
subject.each(&b)
|
35
|
+
}.to yield_successive_args(*expected_words)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when not given a block" do
|
40
|
+
it "must return an Enumerator object for #each" do
|
41
|
+
expect(subject.each).to be_kind_of(Enumerator)
|
42
|
+
expect(subject.each.to_a).to eq(expected_words)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/modifiers/mutate'
|
3
|
+
|
4
|
+
describe Wordlist::Modifiers::Mutate do
|
5
|
+
let(:wordlist) { %w[foo bar] }
|
6
|
+
|
7
|
+
let(:pattern) { /[oa]/ }
|
8
|
+
let(:replace) { {'o' => '0', 'a' => '@'} }
|
9
|
+
|
10
|
+
subject { described_class.new(wordlist,pattern,replace) }
|
11
|
+
|
12
|
+
describe "#each" do
|
13
|
+
let(:expected_words) do
|
14
|
+
%w[
|
15
|
+
foo
|
16
|
+
f0o
|
17
|
+
fo0
|
18
|
+
f00
|
19
|
+
bar
|
20
|
+
b@r
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when given a block" do
|
25
|
+
it "must enumerate through every possible string substitution combination" do
|
26
|
+
expect { |b|
|
27
|
+
subject.each(&b)
|
28
|
+
}.to yield_successive_args(*expected_words)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when not given a block" do
|
33
|
+
it "must return an Enumerator object for #each" do
|
34
|
+
expect(subject.each).to be_kind_of(Enumerator)
|
35
|
+
expect(subject.each.to_a).to eq(expected_words)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/modifiers/sub'
|
3
|
+
|
4
|
+
describe Wordlist::Modifiers::Sub do
|
5
|
+
let(:wordlist) { %w[foo bar baz] }
|
6
|
+
|
7
|
+
let(:pattern) { /o/ }
|
8
|
+
let(:replace) { '0' }
|
9
|
+
|
10
|
+
let(:block) do
|
11
|
+
proc { |match| match.swapcase }
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { described_class.new(wordlist,pattern,replace) }
|
15
|
+
|
16
|
+
describe "#initialize" do
|
17
|
+
it "must set #wordlist" do
|
18
|
+
expect(subject.wordlist).to eq(wordlist)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "must set #pattern" do
|
22
|
+
expect(subject.pattern).to eq(pattern)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "must set #replace" do
|
26
|
+
expect(subject.replace).to eq(replace)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "must default #block to nil" do
|
30
|
+
expect(subject.block).to be(nil)
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the replacement value is a String" do
|
34
|
+
it "must set #replace" do
|
35
|
+
expect(subject.replace).to eq(replace)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when the replacement value is a Hash" do
|
40
|
+
let(:replace) { {'o' => '0', 'e' => '3', 'a' => '@'} }
|
41
|
+
|
42
|
+
it "must set #replace" do
|
43
|
+
expect(subject.replace).to eq(replace)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the replacement value is nil" do
|
48
|
+
let(:replace) { nil }
|
49
|
+
|
50
|
+
it "must not set #replace" do
|
51
|
+
expect(subject.replace).to be(nil)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when a block is given" do
|
56
|
+
subject { described_class.new(wordlist,pattern,&block) }
|
57
|
+
|
58
|
+
it "must set #block" do
|
59
|
+
expect(subject.block).to eq(block)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#each" do
|
65
|
+
let(:expected_words) do
|
66
|
+
wordlist.map { |word| word.sub(pattern,replace) }
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when given a block" do
|
70
|
+
it "must call #sub on each word" do
|
71
|
+
expect { |b|
|
72
|
+
subject.each(&b)
|
73
|
+
}.to yield_successive_args(*expected_words)
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when initialized with no replacement String but with a block" do
|
77
|
+
subject { described_class.new(wordlist,pattern,&block) }
|
78
|
+
|
79
|
+
let(:expected_words) do
|
80
|
+
wordlist.map { |word| word.sub(pattern,&block) }
|
81
|
+
end
|
82
|
+
|
83
|
+
it "must pass the block to #sub" do
|
84
|
+
expect { |b|
|
85
|
+
subject.each(&b)
|
86
|
+
}.to yield_successive_args(*expected_words)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "when not given a block" do
|
92
|
+
it "must return an Enumerator object for #each" do
|
93
|
+
expect(subject.each).to be_kind_of(Enumerator)
|
94
|
+
expect(subject.each.to_a).to eq(expected_words)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/modifiers/tr'
|
3
|
+
|
4
|
+
describe Wordlist::Modifiers::Tr do
|
5
|
+
let(:wordlist) { %w[foo bar baz] }
|
6
|
+
|
7
|
+
let(:chars) { 'oa' }
|
8
|
+
let(:replace) { '0@' }
|
9
|
+
|
10
|
+
subject { described_class.new(wordlist,chars,replace) }
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
it "must set #wordlist" do
|
14
|
+
expect(subject.wordlist).to eq(wordlist)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "must set #chars" do
|
18
|
+
expect(subject.chars).to eq(chars)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "must set #replace" do
|
22
|
+
expect(subject.replace).to eq(replace)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#each" do
|
27
|
+
let(:expected_words) do
|
28
|
+
wordlist.map { |word| word.tr(chars,replace) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when given a block" do
|
32
|
+
it "must call #gsub on each word" do
|
33
|
+
expect { |b|
|
34
|
+
subject.each(&b)
|
35
|
+
}.to yield_successive_args(*expected_words)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when not given a block" do
|
40
|
+
it "must return an Enumerator object for #each" do
|
41
|
+
expect(subject.each).to be_kind_of(Enumerator)
|
42
|
+
expect(subject.each.to_a).to eq(expected_words)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/modifiers/upcase'
|
3
|
+
|
4
|
+
describe Wordlist::Modifiers::Upcase do
|
5
|
+
let(:wordlist) { %w[Foo BAR baz] }
|
6
|
+
|
7
|
+
subject { described_class.new(wordlist) }
|
8
|
+
|
9
|
+
describe "#each" do
|
10
|
+
let(:expected_words) { wordlist.map(&:upcase) }
|
11
|
+
|
12
|
+
context "when given a block" do
|
13
|
+
it "must downcase each word" do
|
14
|
+
expect { |b|
|
15
|
+
subject.each(&b)
|
16
|
+
}.to yield_successive_args(*expected_words)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when not given a block" do
|
21
|
+
it "must return an Enumerator object for #each" do
|
22
|
+
expect(subject.each).to be_kind_of(Enumerator)
|
23
|
+
expect(subject.each.to_a).to eq(expected_words)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/operators/binary_operator'
|
3
|
+
|
4
|
+
describe Wordlist::Operators::BinaryOperator do
|
5
|
+
let(:left) { %w[foo bar] }
|
6
|
+
let(:right) { %w[baz qux] }
|
7
|
+
|
8
|
+
subject { described_class.new(left,right) }
|
9
|
+
|
10
|
+
describe "#initialize" do
|
11
|
+
it "must set #left" do
|
12
|
+
expect(subject.left).to eq(left)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "must set #right" do
|
16
|
+
expect(subject.right).to eq(right)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/operators/concat'
|
3
|
+
|
4
|
+
describe Wordlist::Operators::Concat do
|
5
|
+
let(:left) { %w[foo bar] }
|
6
|
+
let(:right) { %w[baz qux] }
|
7
|
+
|
8
|
+
subject { described_class.new(left,right) }
|
9
|
+
|
10
|
+
describe "#each" do
|
11
|
+
context "when given a block" do
|
12
|
+
it "must yield each word from both wordlists" do
|
13
|
+
expect { |b|
|
14
|
+
subject.each(&b)
|
15
|
+
}.to yield_successive_args(*(left + right))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when not given a block" do
|
20
|
+
it "must return an Enumerator for the #each" do
|
21
|
+
expect(subject.each).to be_kind_of(Enumerator)
|
22
|
+
expect(subject.each.to_a).to eq(left + right)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/operators/intersect'
|
3
|
+
|
4
|
+
describe Wordlist::Operators::Intersect do
|
5
|
+
let(:left) { %w[foo bar] }
|
6
|
+
let(:right) { %w[bar baz] }
|
7
|
+
|
8
|
+
subject { described_class.new(left,right) }
|
9
|
+
|
10
|
+
describe "#each" do
|
11
|
+
context "when given a block" do
|
12
|
+
it "must yield the words which exist in both wordlists" do
|
13
|
+
expect { |b|
|
14
|
+
subject.each(&b)
|
15
|
+
}.to yield_successive_args(*(left & right))
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when the wordlists do not have any common words" do
|
19
|
+
let(:left) { %w[foo bar] }
|
20
|
+
let(:right) { %w[baz qux] }
|
21
|
+
|
22
|
+
it "must not yield any words" do
|
23
|
+
expect { |b|
|
24
|
+
subject.each(&b)
|
25
|
+
}.to_not yield_control
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when not given a block" do
|
31
|
+
it "must return an Enumerator for the #each" do
|
32
|
+
expect(subject.each).to be_kind_of(Enumerator)
|
33
|
+
expect(subject.each.to_a).to eq(left & right)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordlist/operators/operator'
|
3
|
+
|
4
|
+
describe Wordlist::Operators::Operator do
|
5
|
+
it do
|
6
|
+
expect(described_class).to include(Enumerable)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#each" do
|
10
|
+
it do
|
11
|
+
expect {
|
12
|
+
subject.each
|
13
|
+
}.to raise_error(NotImplementedError,"#{described_class}#each was not implemented")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|