chars 0.3.1 → 0.3.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b408bb91d6c66422ccb57e66af6cdeceeb97d50c610628a9b99780319f4af57
4
- data.tar.gz: '039bef18f59a8ea05fd2a259839432e9ad2eee15c692969bf611d11b15255b75'
3
+ metadata.gz: 33adb9b0d02cf5d9c694e80e824bb4835b1503769e00d7f62ab901b35a46df64
4
+ data.tar.gz: ab56f3ae9533e9e5903aee56c491f6b40760694e4adc3d6ec364725182ccaeed
5
5
  SHA512:
6
- metadata.gz: 803264ba7bafc4546df334bd2a508389f525c9814ab0452ef7b2b7c9b75cc0fb952c729f0b5b093cbede36d60be5badeb29ada0e29ee5b12ae3d681878aeb163
7
- data.tar.gz: 2e9f1c229d9987e5cb1dfc0caada8c71582e0c72e8c03e7b39313c4bc1e9e447bdbdfcf641009174de47b4e0e94384296dc26cf8a136f72881bfd664fa311720
6
+ metadata.gz: de94222563f4de2c9c68660d95af2d6d0cdc54ee53ac61b726022c02f064fbe493ec3a208937ec2dcb52593560ea4bf6e7935ad0e4ac8b7f7ecfa22afd55f3f4
7
+ data.tar.gz: 172429354850160c92ac11d563effa5c8379d062c8fd1615a9db567abf7f1548528847af12f084ce20b16e7e654854ddcd857e0082ea677f41356fcf2c33bb5d
data/ChangeLog.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 0.3.2 / 2022-12-02
2
+
3
+ * Ensure all character Strings within the {Chars} character sets are encoded as
4
+ ASCII-8bit. This prevents transcoding issues when calling
5
+ `Chars::ASCII.random_string(length)`.
6
+ * Changed {Chars::CharSet#initialize} to encode bytes greater than 256 as UTF-8.
7
+ Otherwise, bytes less than 256 will be encoded as ASCII-8bit.
8
+
1
9
  ### 0.3.1 / 2022-12-01
2
10
 
3
11
  * Removed the space character from {Chars::PUNCTUATION}, as spaces are not
@@ -17,7 +17,13 @@ module Chars
17
17
  def initialize(*arguments)
18
18
  super()
19
19
 
20
- @chars = Hash.new { |hash,key| hash[key] = key.chr(Encoding::UTF_8) }
20
+ @chars = Hash.new do |hash,key|
21
+ hash[key] = if key > 0xff
22
+ key.chr(Encoding::UTF_8)
23
+ else
24
+ key.chr(Encoding::ASCII_8BIT)
25
+ end
26
+ end
21
27
 
22
28
  arguments.each do |subset|
23
29
  case subset
data/lib/chars/chars.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: ASCII-8BIT
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require 'chars/char_set'
data/lib/chars/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Chars
2
2
  # chars version
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
@@ -42,6 +42,18 @@ describe Chars::CharSet do
42
42
  it "must populate the char set using the Integers as bytes" do
43
43
  expect(integers.all? { |i| subject.include?(i) }).to be(true)
44
44
  end
45
+
46
+ it "must encode them as ASCII 8bit Strings" do
47
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
48
+ end
49
+
50
+ context "when one of the Integers is greater than 0xff" do
51
+ let(:integers) { [0x100, 0xffff] }
52
+
53
+ it "must encode the Integer as a UTF-8 String" do
54
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::UTF_8))
55
+ end
56
+ end
45
57
  end
46
58
 
47
59
  context "when given an Array of Integers" do
@@ -50,6 +62,18 @@ describe Chars::CharSet do
50
62
  it "must populate the char set using the Integers as bytes" do
51
63
  expect(integers.all? { |i| subject.include?(i) }).to be(true)
52
64
  end
65
+
66
+ it "must encode them as ASCII 8bit Strings" do
67
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
68
+ end
69
+
70
+ context "when one of the Integers is greater than 0xff" do
71
+ let(:integers) { [0x100, 0xffff] }
72
+
73
+ it "must encode the Integer as a UTF-8 String" do
74
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::UTF_8))
75
+ end
76
+ end
53
77
  end
54
78
 
55
79
  context "when given a Range of Integers" do
@@ -58,6 +82,18 @@ describe Chars::CharSet do
58
82
  it "must populate the char set by enumerating over the Integer's bytes" do
59
83
  expect(integers.all? { |i| subject.include?(i) }).to be(true)
60
84
  end
85
+
86
+ it "must encode them as ASCII 8bit Strings" do
87
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
88
+ end
89
+
90
+ context "when one of the Integers is greater than 0xff" do
91
+ let(:integer_range) { (0x100..0x200) }
92
+
93
+ it "must encode the Integer as a UTF-8 String" do
94
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::UTF_8))
95
+ end
96
+ end
61
97
  end
62
98
  end
63
99
 
data/spec/chars_spec.rb CHANGED
@@ -10,6 +10,10 @@ describe Chars do
10
10
  it "must contain numeric characters" do
11
11
  expect(subject.chars).to match_array(numeric_chars)
12
12
  end
13
+
14
+ it "must only contain ASCII-8bit encoded characters" do
15
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
16
+ end
13
17
  end
14
18
 
15
19
  describe "DIGITS" do
@@ -18,6 +22,10 @@ describe Chars do
18
22
  it "must equal NUMERIC" do
19
23
  expect(subject).to be(described_class::NUMERIC)
20
24
  end
25
+
26
+ it "must only contain ASCII-8bit encoded characters" do
27
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
28
+ end
21
29
  end
22
30
 
23
31
  describe "OCTAL" do
@@ -26,6 +34,10 @@ describe Chars do
26
34
  it "must contain all octal characters" do
27
35
  expect(subject.chars).to match_array("01234567".chars)
28
36
  end
37
+
38
+ it "must only contain ASCII-8bit encoded characters" do
39
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
40
+ end
29
41
  end
30
42
 
31
43
  let(:uppercase_hex_chars) { "0123456789ABCDEF".chars }
@@ -36,6 +48,10 @@ describe Chars do
36
48
  it "must contain all upper-case hexadecimal characters" do
37
49
  expect(subject.chars).to match_array(uppercase_hex_chars)
38
50
  end
51
+
52
+ it "must only contain ASCII-8bit encoded characters" do
53
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
54
+ end
39
55
  end
40
56
 
41
57
  let(:lowercase_hex_chars) { "0123456789abcdef".chars }
@@ -46,6 +62,10 @@ describe Chars do
46
62
  it "must contain all lower-case hexadecimal characters" do
47
63
  expect(subject.chars).to match_array(lowercase_hex_chars)
48
64
  end
65
+
66
+ it "must only contain ASCII-8bit encoded characters" do
67
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
68
+ end
49
69
  end
50
70
 
51
71
  describe "HEXADECIMAL" do
@@ -54,6 +74,10 @@ describe Chars do
54
74
  it "must contain both upper-case and lower-case hexadecimal characters" do
55
75
  expect(subject.chars).to match_array(uppercase_hex_chars | lowercase_hex_chars)
56
76
  end
77
+
78
+ it "must only contain ASCII-8bit encoded characters" do
79
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
80
+ end
57
81
  end
58
82
 
59
83
  let(:uppercase_alpha_chars) { "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars }
@@ -64,6 +88,10 @@ describe Chars do
64
88
  it "must contain all upper-case alpha characters" do
65
89
  expect(subject.chars).to match_array(uppercase_alpha_chars)
66
90
  end
91
+
92
+ it "must only contain ASCII-8bit encoded characters" do
93
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
94
+ end
67
95
  end
68
96
 
69
97
  let(:lowercase_alpha_chars) { "abcdefghijklmnopqrstuvwxyz".chars }
@@ -74,6 +102,10 @@ describe Chars do
74
102
  it "must contain all lower-case alpha characters" do
75
103
  expect(subject.chars).to match_array(lowercase_alpha_chars)
76
104
  end
105
+
106
+ it "must only contain ASCII-8bit encoded characters" do
107
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
108
+ end
77
109
  end
78
110
 
79
111
  let(:alpha_chars) { uppercase_alpha_chars | lowercase_alpha_chars }
@@ -84,6 +116,10 @@ describe Chars do
84
116
  it "must contain all alpha characters" do
85
117
  expect(subject.chars).to match_array(alpha_chars)
86
118
  end
119
+
120
+ it "must only contain ASCII-8bit encoded characters" do
121
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
122
+ end
87
123
  end
88
124
 
89
125
  let(:alpha_numeric_chars) { alpha_chars | numeric_chars }
@@ -94,6 +130,10 @@ describe Chars do
94
130
  it "must contain all alpha-numeric characters" do
95
131
  expect(subject.chars).to match_array(alpha_numeric_chars)
96
132
  end
133
+
134
+ it "must only contain ASCII-8bit encoded characters" do
135
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
136
+ end
97
137
  end
98
138
 
99
139
  let(:punctuation_chars) { "!\"'(),-.:;?[]`{}~".chars }
@@ -104,6 +144,10 @@ describe Chars do
104
144
  it "must contain all punctuation characters" do
105
145
  expect(subject.chars).to match_array(punctuation_chars)
106
146
  end
147
+
148
+ it "must only contain ASCII-8bit encoded characters" do
149
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
150
+ end
107
151
  end
108
152
 
109
153
  let(:symbolic_chars) { "!\"\#$%&'()*+,-./:;<=>?@[\\]^_`{|}~".chars }
@@ -114,6 +158,10 @@ describe Chars do
114
158
  it "must contain all symbolic characters" do
115
159
  expect(subject.chars).to match_array(symbolic_chars)
116
160
  end
161
+
162
+ it "must only contain ASCII-8bit encoded characters" do
163
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
164
+ end
117
165
  end
118
166
 
119
167
  let(:whitespace_chars) { "\t\n\v\f\r ".chars }
@@ -124,6 +172,10 @@ describe Chars do
124
172
  it "must contain all white-space characters" do
125
173
  expect(subject.chars).to match_array(whitespace_chars)
126
174
  end
175
+
176
+ it "must only contain ASCII-8bit encoded characters" do
177
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
178
+ end
127
179
  end
128
180
 
129
181
  describe "SPACE" do
@@ -132,6 +184,10 @@ describe Chars do
132
184
  it "must equal WHITESPACE" do
133
185
  expect(subject).to be(described_class::WHITESPACE)
134
186
  end
187
+
188
+ it "must only contain ASCII-8bit encoded characters" do
189
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
190
+ end
135
191
  end
136
192
 
137
193
  describe "VISIBLE" do
@@ -140,6 +196,10 @@ describe Chars do
140
196
  it "must contain all all alpha-numeric, symbols, and some punctuation" do
141
197
  expect(subject.chars).to match_array(alpha_numeric_chars | "!\"\#$%&'()*+,-./:;<=>?@[\\]^_`{|}~".chars)
142
198
  end
199
+
200
+ it "must only contain ASCII-8bit encoded characters" do
201
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
202
+ end
143
203
  end
144
204
 
145
205
  describe "PRINTABLE" do
@@ -153,6 +213,10 @@ describe Chars do
153
213
  [' ']
154
214
  )
155
215
  end
216
+
217
+ it "must only contain ASCII-8bit encoded characters" do
218
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
219
+ end
156
220
  end
157
221
 
158
222
  describe "CONTROL" do
@@ -161,6 +225,10 @@ describe Chars do
161
225
  it "must contain ASCII bytes 0x00 - 0x1f and 0x7f" do
162
226
  expect(subject.bytes).to eq([*0x00..0x1f, 0x7f])
163
227
  end
228
+
229
+ it "must only contain ASCII-8bit encoded characters" do
230
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
231
+ end
164
232
  end
165
233
 
166
234
  describe "SIGNED_ASCII" do
@@ -169,6 +237,10 @@ describe Chars do
169
237
  it "must contain ASCII bytes 0x00 - 0x7f" do
170
238
  expect(subject.bytes).to eq([*0x00..0x7f])
171
239
  end
240
+
241
+ it "must only contain ASCII-8bit encoded characters" do
242
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
243
+ end
172
244
  end
173
245
 
174
246
  describe "ASCII" do
@@ -177,6 +249,10 @@ describe Chars do
177
249
  it "must contain ASCII bytes 0x00 - 0xff" do
178
250
  expect(subject.bytes).to eq([*0x00..0xff])
179
251
  end
252
+
253
+ it "must only contain ASCII-8bit encoded characters" do
254
+ expect(subject.chars.map(&:encoding)).to all(be(Encoding::ASCII_8BIT))
255
+ end
180
256
  end
181
257
 
182
258
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-01 00:00:00.000000000 Z
11
+ date: 2022-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 3.3.7
90
+ rubygems_version: 3.3.26
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: A Ruby library for working with various character sets