chars 0.1.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,62 +2,221 @@ require 'chars/chars'
2
2
 
3
3
  class String
4
4
 
5
+ #
6
+ # Determines whether the String belongs to the decimal-digit character set.
7
+ #
8
+ # @return [Boolean]
9
+ # Specifies whether the String belongs to the decimal-digit character
10
+ # set.
11
+ #
12
+ # @see Chars.numeric
13
+ #
5
14
  def numeric?
6
15
  Chars::NUMERIC === self
7
16
  end
8
17
 
18
+ #
19
+ # Determines whether the String belongs to the octal-digit character set.
20
+ #
21
+ # @return [Boolean]
22
+ # Specifies whether the String belongs to the octal-digit character
23
+ # set.
24
+ #
25
+ # @see Chars.octal
26
+ #
9
27
  def octal?
10
28
  Chars::OCTAL === self
11
29
  end
12
30
 
31
+ #
32
+ # Determines whether the String belongs to the upper-case hexadecimal
33
+ # character set.
34
+ #
35
+ # @return [Boolean]
36
+ # Specifies whether the String belongs to the upper-case hexadecimal
37
+ # character set.
38
+ #
39
+ # @see Chars.uppercase_hexadecimal
40
+ #
13
41
  def uppercase_hex?
14
42
  Chars::UPPERCASE_HEXADECIMAL === self
15
43
  end
16
44
 
45
+ #
46
+ # Determines whether the String belongs to the lower-case hexadecimal
47
+ # character set.
48
+ #
49
+ # @return [Boolean]
50
+ # Specifies whether the String belongs to the lower-case hexadecimal
51
+ # character set.
52
+ #
53
+ # @see Chars.lowercase_hexadecimal
54
+ #
17
55
  def lowercase_hex?
18
56
  Chars::LOWERCASE_HEXADECIMAL === self
19
57
  end
20
58
 
59
+ #
60
+ # Determines whether the String belongs to the hexadecimal character set.
61
+ #
62
+ # @return [Boolean]
63
+ # Specifies whether the String belongs to the hexadecimal character set.
64
+ #
65
+ # @see Chars.hexadecimal
66
+ #
21
67
  def hex?
22
68
  Chars::HEXADECIMAL === self
23
69
  end
24
70
 
71
+ #
72
+ # Determines whether the String belongs to the upper-case alphabetic
73
+ # character set.
74
+ #
75
+ # @return [Boolean]
76
+ # Specifies whether the String belongs to the upper-case alphabetic
77
+ # character set.
78
+ #
79
+ # @see Chars.uppercase_alpha
80
+ #
25
81
  def uppercase_alpha?
26
82
  Chars::UPPERCASE_ALPHA === self
27
83
  end
28
84
 
85
+ #
86
+ # Determines whether the String belongs to the lower-case alphabetic
87
+ # character set.
88
+ #
89
+ # @return [Boolean]
90
+ # Specifies whether the String belongs to the lower-case alphabetic
91
+ # character set.
92
+ #
93
+ # @see Chars.lowercase_alpha
94
+ #
29
95
  def lowercase_alpha?
30
96
  Chars::LOWERCASE_ALPHA === self
31
97
  end
32
98
 
99
+ #
100
+ # Determines whether the String belongs to the alphabetic character set.
101
+ #
102
+ # @return [Boolean]
103
+ # Specifies whether the String belongs to the alphabetic character set.
104
+ #
105
+ # @see Chars.alpha
106
+ #
33
107
  def alpha?
34
108
  Chars::ALPHA === self
35
109
  end
36
110
 
111
+ #
112
+ # Determines whether the String belongs to the alpha-numeric character
113
+ # set.
114
+ #
115
+ # @return [Boolean]
116
+ # Specifies whether the String belongs to the alpha-numeric character
117
+ # set.
118
+ #
119
+ # @see Chars.alpha_numeric
120
+ #
37
121
  def alpha_numeric?
38
122
  Chars::ALPHA_NUMERIC === self
39
123
  end
40
124
 
125
+ #
126
+ # Determines whether the String belongs to the punctuation character set.
127
+ #
128
+ # @return [Boolean]
129
+ # Specifies whether the String belongs to the punctuation character set.
130
+ #
131
+ # @see Chars.punctuation
132
+ #
41
133
  def punctuation?
42
134
  Chars::PUNCTUATION === self
43
135
  end
44
136
 
137
+ #
138
+ # Determines whether the String belongs to the symbolic character set.
139
+ #
140
+ # @return [Boolean]
141
+ # Specifies whether the String belongs to the symbolic character set.
142
+ #
143
+ # @see Chars.symbols
144
+ #
45
145
  def symbolic?
46
146
  Chars::SYMBOLS === self
47
147
  end
48
148
 
149
+ #
150
+ # Determines whether the String belongs to the white-space character set.
151
+ #
152
+ # @return [Boolean]
153
+ # Specifies whether the String belongs to the white-space character set.
154
+ #
155
+ # @see Chars.space
156
+ #
49
157
  def space?
50
158
  Chars::SPACE === self
51
159
  end
52
160
 
161
+ #
162
+ # Determines whether the String belongs to the visible character set.
163
+ #
164
+ # @return [Boolean]
165
+ # Specifies whether the String belongs to the visible character set.
166
+ #
167
+ # @see Chars.visible
168
+ #
169
+ def visible?
170
+ Chars::VISIBLE === self
171
+ end
172
+
173
+ #
174
+ # Determines whether the String belongs to the printable character set.
175
+ #
176
+ # @return [Boolean]
177
+ # Specifies whether the String belongs to the printable character set.
178
+ #
179
+ # @see Chars.printable
180
+ #
53
181
  def printable?
54
182
  Chars::PRINTABLE === self
55
183
  end
56
184
 
185
+ #
186
+ # Determines whether the String belongs to the control-character
187
+ # character set.
188
+ #
189
+ # @return [Boolean]
190
+ # Specifies whether the String belongs to the control-character
191
+ # character set.
192
+ #
193
+ # @see Chars.control
194
+ #
57
195
  def control?
58
196
  Chars::CONTROL === self
59
197
  end
60
198
 
199
+ #
200
+ # Determines whether the String belongs to the signed-ASCII character set.
201
+ #
202
+ # @return [Boolean]
203
+ # Specifies whether the String belongs to the signed-ASCII character
204
+ # set.
205
+ #
206
+ # @see Chars.signed_ascii
207
+ #
208
+ def signed_ascii?
209
+ Chars::SIGNED_ASCII === self
210
+ end
211
+
212
+ #
213
+ # Determines whether the String belongs to the ASCII character set.
214
+ #
215
+ # @return [Boolean]
216
+ # Specifies whether the String belongs to the ASCII character set.
217
+ #
218
+ # @see Chars.ascii
219
+ #
61
220
  def ascii?
62
221
  Chars::ASCII === self
63
222
  end
@@ -1,4 +1,4 @@
1
1
  module Chars
2
- # Chars version
3
- VERSION = '0.1.1'
2
+ # chars version
3
+ VERSION = '0.2.3'
4
4
  end
@@ -1,186 +1,214 @@
1
- require 'chars/chars'
2
-
3
1
  require 'spec_helper'
2
+ require 'chars/chars'
4
3
 
5
4
  describe Chars::CharSet do
6
- before(:all) do
7
- @integer_range = (0x41..0x43)
8
- @string_range = ('A'..'C')
9
- @integers = @integer_range.to_a
10
- @strings = @string_range.to_a
5
+ let(:integer_range) { (0x41..0x43) }
6
+ let(:string_range) { ('A'..'Z') }
7
+ let(:integers) { integer_range.to_a }
8
+ let(:strings) { string_range.to_a }
11
9
 
12
- @char_set = Chars::CharSet.new(*@strings)
13
- end
10
+ subject { described_class.new(*strings) }
14
11
 
15
- it "may be created with String arguments" do
16
- @chars = Chars::CharSet.new(*@strings)
12
+ describe "#initialize" do
13
+ it "may be created with String arguments" do
14
+ set = described_class.new(*strings)
17
15
 
18
- @strings.each do |s|
19
- @chars.include_char?(s).should == true
16
+ expect(strings.all? { |s| set.include_char?(s) }).to be(true)
20
17
  end
21
- end
22
18
 
23
- it "may be created with an Array of Strings" do
24
- @chars = Chars::CharSet.new(@strings)
19
+ it "may be created with an Array of Strings" do
20
+ set = described_class.new(strings)
25
21
 
26
- @strings.each do |s|
27
- @chars.include_char?(s).should == true
22
+ expect(strings.all? { |s| set.include_char?(s) }).to be(true)
28
23
  end
29
- end
30
24
 
31
- it "may be created with a Range of Strings" do
32
- @chars = Chars::CharSet.new(@string_range)
25
+ it "may be created with a Range of Strings" do
26
+ set = described_class.new(string_range)
33
27
 
34
- @strings.each do |s|
35
- @chars.include_char?(s).should == true
28
+ expect(strings.all? { |s| set.include_char?(s) }).to be(true)
36
29
  end
37
- end
38
30
 
39
- it "may be created with Integer arguments" do
40
- @chars = Chars::CharSet.new(*@integers)
31
+ it "may be created with Integer arguments" do
32
+ set = described_class.new(*integers)
41
33
 
42
- @integers.each do |i|
43
- @chars.include?(i).should == true
34
+ expect(integers.all? { |i| set.include?(i) }).to be(true)
44
35
  end
45
- end
46
36
 
47
- it "may be created with an Array of Integers" do
48
- @chars = Chars::CharSet.new(@integers)
37
+ it "may be created with an Array of Integers" do
38
+ set = described_class.new(integers)
49
39
 
50
- @integers.each do |i|
51
- @chars.include?(i).should == true
40
+ expect(integers.all? { |i| set.include?(i) }).to be(true)
52
41
  end
53
- end
54
42
 
55
- it "may be created with a Range of Integers" do
56
- @chars = Chars::CharSet.new(@integer_range)
43
+ it "may be created with a Range of Integers" do
44
+ set = described_class.new(integer_range)
57
45
 
58
- @integers.each do |i|
59
- @chars.include?(i).should == true
46
+ expect(integers.all? { |i| set.include?(i) }).to be(true)
60
47
  end
61
48
  end
62
49
 
63
50
  it "should include Strings" do
64
- @char_set.include_char?('A').should == true
51
+ expect(subject.include_char?('A')).to be(true)
65
52
  end
66
53
 
67
54
  it "should include Integers" do
68
- @char_set.include?(0x41).should == true
55
+ expect(subject).to include(0x41)
69
56
  end
70
57
 
71
58
  it "should be able to select bytes" do
72
- @sub_chars = @char_set.select_bytes { |c| c <= 0x42 }
59
+ sub_set = subject.select_bytes { |c| c <= 0x42 }
73
60
 
74
- @sub_chars.should == [0x41, 0x42]
61
+ expect(sub_set).to be == [0x41, 0x42]
75
62
  end
76
63
 
77
64
  it "should be able to select chars" do
78
- @sub_chars = @char_set.select_chars { |c| c <= 'B' }
65
+ sub_set = subject.select_chars { |c| c <= 'B' }
79
66
 
80
- @sub_chars.should == ['A', 'B']
67
+ expect(sub_set).to be == ['A', 'B']
81
68
  end
82
69
 
83
70
  it "should return a random byte" do
84
- @char_set.include?(@char_set.random_byte).should == true
71
+ expect(subject).to include(subject.random_byte)
85
72
  end
86
73
 
87
74
  it "should return a random char" do
88
- @char_set.include_char?(@char_set.random_char).should == true
75
+ expect(subject.include_char?(subject.random_char)).to be(true)
89
76
  end
90
77
 
91
78
  it "should iterate over n random bytes" do
92
- @char_set.each_random_byte(10) do |b|
93
- @char_set.include?(b).should == true
94
- end
79
+ expect(subject.each_random_byte(10).all? { |b|
80
+ subject.include?(b)
81
+ }).to be(true)
95
82
  end
96
83
 
97
84
  it "should iterate over n random chars" do
98
- @char_set.each_random_char(10) do |c|
99
- @char_set.include_char?(c).should == true
100
- end
85
+ expect(subject.each_random_char(10).all? { |c|
86
+ subject.include_char?(c)
87
+ }).to be(true)
101
88
  end
102
89
 
103
- it "should return a random Array of bytes" do
104
- bytes = @char_set.random_bytes(10)
90
+ describe "#random_bytes" do
91
+ it "should return a random Array of bytes" do
92
+ bytes = subject.random_bytes(10)
105
93
 
106
- bytes.each do |b|
107
- @char_set.include?(b).should == true
94
+ expect(bytes.all? { |b| subject.include?(b) }).to be(true)
108
95
  end
109
- end
110
96
 
111
- it "should return a random Array of chars" do
112
- chars = @char_set.random_chars(10)
97
+ context "with a range of lengths" do
98
+ it "should return a random Array of bytes with a varying length" do
99
+ bytes = subject.random_bytes(5..10)
113
100
 
114
- chars.each do |c|
115
- @char_set.include_char?(c).should == true
101
+ expect(bytes.length).to be_between(5, 10)
102
+ expect(bytes.all? { |b| subject.include?(b) }).to be(true)
103
+ end
116
104
  end
117
105
  end
118
106
 
119
- it "should return a random Array of bytes with a varying length" do
120
- bytes = @char_set.random_bytes(5..10)
107
+ describe "#random_chars" do
108
+ it "should return a random Array of chars" do
109
+ chars = subject.random_chars(10)
121
110
 
122
- bytes.length.between?(5, 10).should == true
123
- bytes.each do |b|
124
- @char_set.include?(b).should == true
111
+ expect(chars.all? { |c| subject.include_char?(c) }).to be(true)
112
+ end
113
+
114
+ context "with a range of lengths" do
115
+ it "should return a random Array of chars with a varying length" do
116
+ chars = subject.random_chars(5..10)
117
+
118
+ expect(chars.length).to be_between(5, 10)
119
+ expect(chars.all? { |c| subject.include_char?(c) }).to be(true)
120
+ end
125
121
  end
126
122
  end
127
123
 
128
- it "should return a random Array of chars with a varying length" do
129
- chars = @char_set.random_chars(5..10)
124
+ describe "#random_string" do
125
+ it "should return a random String of chars" do
126
+ string = subject.random_string(10)
127
+
128
+ expect(string.chars.all? { |b| subject.include_char?(b) }).to be(true)
129
+ end
130
+
131
+ context "with a range of lengths" do
132
+ it "should return a random String of chars with a varying length" do
133
+ string = subject.random_string(5..10)
130
134
 
131
- chars.length.between?(5, 10).should == true
132
- chars.each do |c|
133
- @char_set.include_char?(c).should == true
135
+ expect(string.length).to be_between(5, 10)
136
+ expect(string.chars.all? { |b| subject.include_char?(b) }).to be(true)
137
+ end
134
138
  end
135
139
  end
140
+
141
+ describe "#random_distinct_bytes" do
142
+ it "should return a random Array of unique bytes" do
143
+ bytes = subject.random_distinct_bytes(10)
144
+
145
+ expect(bytes.uniq).to be == bytes
146
+ expect(bytes.all? { |b| subject.include?(b) }).to be(true)
147
+ end
148
+
149
+ context "with a range of lengths" do
150
+ it "should return a random Array of unique bytes with a varying length" do
151
+ bytes = subject.random_distinct_bytes(5..10)
136
152
 
137
- it "should return a random String of chars" do
138
- @char_set.random_string(10).each_byte do |b|
139
- @char_set.include?(b).should == true
153
+ expect(bytes.uniq).to be == bytes
154
+ expect(bytes.length).to be_between(5, 10)
155
+ expect(bytes.all? { |b| subject.include?(b) }).to be(true)
156
+ end
140
157
  end
141
158
  end
142
159
 
143
- it "should return a random String of chars with a varying length" do
144
- string = @char_set.random_string(5..10)
160
+ describe "#random_distinct_chars" do
161
+ it "should return a random Array of unique chars" do
162
+ chars = subject.random_distinct_chars(10)
145
163
 
146
- string.length.between?(5, 10)
147
- string.each_byte do |b|
148
- @char_set.include?(b).should == true
164
+ expect(chars.uniq).to be == chars
165
+ expect(chars.all? { |c| subject.include_char?(c) }).to be(true)
166
+ end
167
+
168
+ context "with a range of lengths" do
169
+ it "should return a random Array of unique chars with a varying length" do
170
+ chars = subject.random_distinct_chars(5..10)
171
+
172
+ expect(chars.uniq).to be == chars
173
+ expect(chars.length).to be_between(5, 10)
174
+ expect(chars.all? { |c| subject.include_char?(c) }).to be(true)
175
+ end
149
176
  end
150
177
  end
151
178
 
152
179
  it "should be able to be compared with another set of chars" do
153
- (@char_set == Chars::CharSet['A', 'B', 'C']).should == true
154
- (@char_set == Chars::CharSet['A', 'C', 'B']).should == true
180
+ expect(subject).to be == described_class['A'..'Z']
155
181
  end
156
182
 
157
183
  it "should be able to be unioned with another set of chars" do
158
- super_set = (@char_set | Chars::CharSet['D'])
184
+ super_set = (subject | described_class['D'])
159
185
 
160
- super_set.class.should == Chars::CharSet
161
- super_set.should == Chars::CharSet['A', 'B', 'C', 'D']
186
+ expect(super_set).to be_kind_of(described_class)
187
+ expect(super_set).to be == described_class['A'..'Z', 'D']
162
188
  end
163
189
 
164
190
  it "should be able to be removed from another set of chars" do
165
- sub_set = (@char_set - Chars::CharSet['B'])
191
+ sub_set = (subject - described_class['B'])
166
192
 
167
- sub_set.class.should == Chars::CharSet
168
- sub_set.subset?(@char_set).should == true
193
+ expect(sub_set).to be_kind_of(described_class)
194
+ expect(sub_set).to be_subset(subject)
169
195
  end
170
196
 
171
- it "should find one sub-string from a String belonging to the char set" do
172
- @char_set.strings_in("AAAA").should == ["AAAA"]
173
- end
197
+ describe "#strings_in" do
198
+ it "should find one sub-string from a String belonging to the char set" do
199
+ expect(subject.strings_in("AAAA")).to be == ["AAAA"]
200
+ end
174
201
 
175
- it "should find sub-strings from a String belonging to the char set" do
176
- @char_set.strings_in("AAAAXBXCCCCCC").should == [
177
- "AAAA",
178
- "CCCCCC"
179
- ]
202
+ it "should find sub-strings from a String belonging to the char set" do
203
+ expect(subject.strings_in("AAAA!B!CCCCCC")).to be == [
204
+ "AAAA",
205
+ "CCCCCC"
206
+ ]
207
+ end
180
208
  end
181
209
 
182
210
  it "should determine if a String is made up of the characters from the char set" do
183
- (@char_set === "AABCBAA").should == true
184
- (@char_set === "AADDEE").should_not == true
211
+ expect(subject).to be === "AABCBAA"
212
+ expect(subject).to_not be === "AA!!EE"
185
213
  end
186
214
  end