regexp-collection 2.0.0 → 2.0.1
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 +4 -4
- data/README.md +110 -1
- data/lib/regexp_collection/version.rb +1 -1
- data/regexp-collection.gemspec +1 -1
- metadata +2 -3
- data/repomix-output.xml +0 -569
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 44087b7816dde7fdcc2953fa0968b3c52ac3be1bff3f7b85f466e92a7854d031
|
|
4
|
+
data.tar.gz: b225846a85bd09e8e56063c068be553a31442f67dabd5ff8fbb794f69b8fee7b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f3868f59c895f42b68aeef0b5df88727f555d7108093ac4eb703f812cb0cd17691dcd9dd6b5e28a2ebd054619358343e6e955fd3da8f7307b213526ee9d540f
|
|
7
|
+
data.tar.gz: 4d8202fd3c2fd673548bbb40e74d39e624c95af1445657b88de59ecd379ce351f265b0b93ebb2e3c44945ad6a9ac5ce80fb1dec075e184c644177bb75f4acf1c
|
data/README.md
CHANGED
|
@@ -1,3 +1,112 @@
|
|
|
1
1
|
# regexp-collection
|
|
2
2
|
|
|
3
|
-
A gem providing pre-made and tested typical regular expressions for applications
|
|
3
|
+
A gem providing pre-made and tested typical regular expressions for Ruby applications
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
* Ruby >= 2.7.0
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Add this line to your application's `Gemfile`:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem "regexp-collection", "~> 2.0"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
And then execute:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
$ bundle install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or install it yourself as:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
$ gem install regexp-collection
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
The library is divided into logical modules. All regular expressions are frozen (`.freeze`) for safe and optimal use as constants
|
|
32
|
+
|
|
33
|
+
### Numbers (`Regexp::Collection::Number`)
|
|
34
|
+
|
|
35
|
+
Strict validation for numeric formats, preventing injections and incorrect structures (like leading zeros or `-0`)
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
require "regexp_collection"
|
|
39
|
+
|
|
40
|
+
# Matches integers (-10, 0, 42). Rejects leading zeros and "-0".
|
|
41
|
+
"-42".match?(Regexp::Collection::Number.integer) # => true
|
|
42
|
+
"-0".match?(Regexp::Collection::Number.integer) # => false
|
|
43
|
+
|
|
44
|
+
# Matches decimals (-0.5, 0.0, 12.34). Rejects "-0.0".
|
|
45
|
+
"12.34".match?(Regexp::Collection::Number.decimal) # => true
|
|
46
|
+
|
|
47
|
+
# Matches natural numbers
|
|
48
|
+
"0".match?(Regexp::Collection::Number.natural(true)) # => true (including zero)
|
|
49
|
+
"0".match?(Regexp::Collection::Number.natural(false)) # => false (excluding zero)
|
|
50
|
+
"42".match?(Regexp::Collection::Number.natural_excluding_zero) # => true
|
|
51
|
+
|
|
52
|
+
# Matches hexadecimal strings (0x or 0X prefix)
|
|
53
|
+
"0x1a2B3c".match?(Regexp::Collection::Number.hexadecimal) # => true
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Time (`Regexp::Collection::Time`)
|
|
57
|
+
|
|
58
|
+
Validation for 24-hour time formats
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
# HH:MM:SS format
|
|
62
|
+
"23:59:59".match?(Regexp::Collection::Time.seconds_required) # => true
|
|
63
|
+
"23:59".match?(Regexp::Collection::Time.seconds_required) # => false
|
|
64
|
+
|
|
65
|
+
# HH:MM format
|
|
66
|
+
"23:59".match?(Regexp::Collection::Time.seconds_not_permitted) # => true
|
|
67
|
+
|
|
68
|
+
# HH:MM or HH:MM:SS format
|
|
69
|
+
"23:59".match?(Regexp::Collection::Time.seconds_optional) # => true
|
|
70
|
+
"23:59:59".match?(Regexp::Collection::Time.seconds_optional) # => true
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Crypto (`Regexp::Collection::Crypto`)
|
|
74
|
+
|
|
75
|
+
Validation for various blockchain wallet addresses and transaction hashes
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
# EVM (Ethereum, BSC, Polygon, etc.)
|
|
79
|
+
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045".match?(Regexp::Collection::Crypto.evm_wallet_address) # => true
|
|
80
|
+
"0x5c504ed432cb51138b309d43e110f94f6470077cbe40191498b82a8763046ad1".match?(Regexp::Collection::Crypto.evm_transaction_hash) # => true
|
|
81
|
+
|
|
82
|
+
# TRON (Base58Check)
|
|
83
|
+
"TNDzfERD73nNqaTTrvNX7moW2GFp3W5amz".match?(Regexp::Collection::Crypto.trx_wallet_address_base58) # => true
|
|
84
|
+
|
|
85
|
+
# TX (Bech32)
|
|
86
|
+
"core1023456789acdefghjklmnpqrstuvwxyz023456".match?(Regexp::Collection::Crypto.tx_mainnet_wallet_address_bech32) # => true
|
|
87
|
+
"testcore1023456789acdefghjklmnpqrstuvwxyz023456".match?(Regexp::Collection::Crypto.tx_testnet_wallet_address_bech32) # => true
|
|
88
|
+
|
|
89
|
+
# XRP Ledger (Custom Base58)
|
|
90
|
+
"rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn".match?(Regexp::Collection::Crypto.xrp_wallet_address_bech32) # => true
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### UUID (`Regexp::Collection::UUID`)
|
|
94
|
+
|
|
95
|
+
Strict validation for UUID identifiers
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
# Strict UUID v4 validation
|
|
99
|
+
"123e4567-e89b-42d3-a456-426614174000".match?(Regexp::Collection::UUID.v4) # => true
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Development and Testing
|
|
103
|
+
|
|
104
|
+
To run the test suite
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
$ rake test
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT)
|
data/regexp-collection.gemspec
CHANGED
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
|
12
12
|
s.homepage = "https://github.com/yivo/regexp-collection"
|
|
13
13
|
s.license = "MIT"
|
|
14
14
|
|
|
15
|
-
s.required_ruby_version = [">=
|
|
15
|
+
s.required_ruby_version = [">= 2.7.0", "< 5.0"]
|
|
16
16
|
|
|
17
17
|
s.files = Dir.chdir File.expand_path(__dir__) do
|
|
18
18
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: regexp-collection
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yaroslav Konoplov
|
|
@@ -55,7 +55,6 @@ files:
|
|
|
55
55
|
- lib/regexp_collection.rb
|
|
56
56
|
- lib/regexp_collection/version.rb
|
|
57
57
|
- regexp-collection.gemspec
|
|
58
|
-
- repomix-output.xml
|
|
59
58
|
homepage: https://github.com/yivo/regexp-collection
|
|
60
59
|
licenses:
|
|
61
60
|
- MIT
|
|
@@ -67,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
67
66
|
requirements:
|
|
68
67
|
- - ">="
|
|
69
68
|
- !ruby/object:Gem::Version
|
|
70
|
-
version:
|
|
69
|
+
version: 2.7.0
|
|
71
70
|
- - "<"
|
|
72
71
|
- !ruby/object:Gem::Version
|
|
73
72
|
version: '5.0'
|
data/repomix-output.xml
DELETED
|
@@ -1,569 +0,0 @@
|
|
|
1
|
-
This file is a merged representation of the entire codebase, combined into a single document by Repomix.
|
|
2
|
-
|
|
3
|
-
<file_summary>
|
|
4
|
-
This section contains a summary of this file.
|
|
5
|
-
|
|
6
|
-
<purpose>
|
|
7
|
-
This file contains a packed representation of the entire repository's contents.
|
|
8
|
-
It is designed to be easily consumable by AI systems for analysis, code review,
|
|
9
|
-
or other automated processes.
|
|
10
|
-
</purpose>
|
|
11
|
-
|
|
12
|
-
<file_format>
|
|
13
|
-
The content is organized as follows:
|
|
14
|
-
1. This summary section
|
|
15
|
-
2. Repository information
|
|
16
|
-
3. Directory structure
|
|
17
|
-
4. Repository files (if enabled)
|
|
18
|
-
5. Multiple file entries, each consisting of:
|
|
19
|
-
- File path as an attribute
|
|
20
|
-
- Full contents of the file
|
|
21
|
-
</file_format>
|
|
22
|
-
|
|
23
|
-
<usage_guidelines>
|
|
24
|
-
- This file should be treated as read-only. Any changes should be made to the
|
|
25
|
-
original repository files, not this packed version.
|
|
26
|
-
- When processing this file, use the file path to distinguish
|
|
27
|
-
between different files in the repository.
|
|
28
|
-
- Be aware that this file may contain sensitive information. Handle it with
|
|
29
|
-
the same level of security as you would the original repository.
|
|
30
|
-
</usage_guidelines>
|
|
31
|
-
|
|
32
|
-
<notes>
|
|
33
|
-
- Some files may have been excluded based on .gitignore rules and Repomix's configuration
|
|
34
|
-
- Binary files are not included in this packed representation. Please refer to the Repository Structure section for a complete list of file paths, including binary files
|
|
35
|
-
- Files matching patterns in .gitignore are excluded
|
|
36
|
-
- Files matching default ignore patterns are excluded
|
|
37
|
-
- Files are sorted by Git change count (files with more changes are at the bottom)
|
|
38
|
-
</notes>
|
|
39
|
-
|
|
40
|
-
</file_summary>
|
|
41
|
-
|
|
42
|
-
<directory_structure>
|
|
43
|
-
lib/
|
|
44
|
-
regexp_collection/
|
|
45
|
-
version.rb
|
|
46
|
-
regexp_collection.rb
|
|
47
|
-
regexp-collection.rb
|
|
48
|
-
test/
|
|
49
|
-
test_helper.rb
|
|
50
|
-
test_regexp_collection.rb
|
|
51
|
-
.gitignore
|
|
52
|
-
.ruby-version
|
|
53
|
-
Gemfile
|
|
54
|
-
LICENSE
|
|
55
|
-
Rakefile
|
|
56
|
-
README.md
|
|
57
|
-
regexp-collection.gemspec
|
|
58
|
-
</directory_structure>
|
|
59
|
-
|
|
60
|
-
<files>
|
|
61
|
-
This section contains the contents of the repository's files.
|
|
62
|
-
|
|
63
|
-
<file path="lib/regexp_collection/version.rb">
|
|
64
|
-
# frozen_string_literal: true
|
|
65
|
-
|
|
66
|
-
module Regexp::Collection
|
|
67
|
-
VERSION = "2.0.0"
|
|
68
|
-
end
|
|
69
|
-
</file>
|
|
70
|
-
|
|
71
|
-
<file path="lib/regexp_collection.rb">
|
|
72
|
-
# frozen_string_literal: true
|
|
73
|
-
|
|
74
|
-
module Regexp::Collection
|
|
75
|
-
module Number
|
|
76
|
-
class << self
|
|
77
|
-
attr_accessor :integer, :decimal, :natural_including_zero, :natural_excluding_zero, :hexadecimal
|
|
78
|
-
|
|
79
|
-
def natural(zero = false)
|
|
80
|
-
zero ? natural_including_zero : natural_excluding_zero
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# Matches integers without leading zeros (except single 0), e.g., -10, 0, 42
|
|
85
|
-
self.integer = /\A(?:-?[1-9]\d*|0)\z/.freeze
|
|
86
|
-
|
|
87
|
-
# Matches decimals: integers or numbers with a dot followed by digits.
|
|
88
|
-
# Correctly supports negative decimals while rejecting -0 and -0.0
|
|
89
|
-
self.decimal = /\A(?:-?[1-9]\d*(?:\.\d+)?|-0\.\d*[1-9]\d*|0(?:\.\d+)?)\z/.freeze
|
|
90
|
-
|
|
91
|
-
# Matches natural numbers including 0
|
|
92
|
-
self.natural_including_zero = /\A(?:0|[1-9]\d*)\z/.freeze
|
|
93
|
-
|
|
94
|
-
# Matches natural numbers strictly greater than 0
|
|
95
|
-
self.natural_excluding_zero = /\A[1-9]\d*\z/.freeze
|
|
96
|
-
|
|
97
|
-
# Matches hexadecimal literals with 0x or 0X prefix (case-insensitive hex digits)
|
|
98
|
-
self.hexadecimal = /\A0[xX][a-fA-F0-9]+\z/.freeze
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
module Time
|
|
102
|
-
class << self
|
|
103
|
-
attr_accessor :seconds_required, :seconds_not_permitted, :seconds_optional
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
# HH:MM:SS (hour 0-23, single digit permitted: 0-9)
|
|
107
|
-
self.seconds_required = /\A(?:[01]?\d|2[0-3]):[0-5]\d:[0-5]\d\z/.freeze
|
|
108
|
-
|
|
109
|
-
# HH:MM
|
|
110
|
-
self.seconds_not_permitted = /\A(?:[01]?\d|2[0-3]):[0-5]\d\z/.freeze
|
|
111
|
-
|
|
112
|
-
# HH:MM or HH:MM:SS
|
|
113
|
-
self.seconds_optional = /\A(?:[01]?\d|2[0-3]):[0-5]\d(?::[0-5]\d)?\z/.freeze
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
module Crypto
|
|
117
|
-
class << self
|
|
118
|
-
attr_accessor \
|
|
119
|
-
:trx_wallet_address_base58,
|
|
120
|
-
:evm_wallet_address,
|
|
121
|
-
:evm_transaction_hash,
|
|
122
|
-
:tx_mainnet_wallet_address_bech32,
|
|
123
|
-
:tx_testnet_wallet_address_bech32
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
# Tron Base58Check address: starts with T, 34 chars total, excludes 0, O, I, l
|
|
127
|
-
self.trx_wallet_address_base58 = /\AT[1-9A-HJ-NP-Za-km-z]{33}\z/.freeze
|
|
128
|
-
|
|
129
|
-
# EVM address: 0x followed by exactly 40 hexadecimal characters
|
|
130
|
-
self.evm_wallet_address = /\A0x[a-fA-F0-9]{40}\z/.freeze
|
|
131
|
-
|
|
132
|
-
# EVM transaction hash: 0x followed by exactly 64 hexadecimal characters
|
|
133
|
-
self.evm_transaction_hash = /\A0x[a-fA-F0-9]{64}\z/.freeze
|
|
134
|
-
|
|
135
|
-
self.tx_mainnet_wallet_address_bech32 = /\Acore1[02-9ac-hj-np-z]{38}\z/.freeze
|
|
136
|
-
|
|
137
|
-
self.tx_testnet_wallet_address_bech32 = /\Atestcore1[02-9ac-hj-np-z]{38}\z/.freeze
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
</file>
|
|
141
|
-
|
|
142
|
-
<file path="test/test_helper.rb">
|
|
143
|
-
# frozen_string_literal: true
|
|
144
|
-
|
|
145
|
-
require "test-unit"
|
|
146
|
-
require "regexp_collection"
|
|
147
|
-
|
|
148
|
-
Test::Unit::TestCase.test_order = :random
|
|
149
|
-
</file>
|
|
150
|
-
|
|
151
|
-
<file path="test/test_regexp_collection.rb">
|
|
152
|
-
# frozen_string_literal: true
|
|
153
|
-
|
|
154
|
-
require_relative "test_helper"
|
|
155
|
-
|
|
156
|
-
class RegexpCollectionTest < Test::Unit::TestCase
|
|
157
|
-
test "Version constant" do
|
|
158
|
-
assert_not_nil Regexp::Collection::VERSION
|
|
159
|
-
assert_true Regexp::Collection::VERSION.match?(/\A\d+\.\d+\.\d+\z/)
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
test "Number.integer" do
|
|
163
|
-
regexp = Regexp::Collection::Number.integer
|
|
164
|
-
|
|
165
|
-
# Valid
|
|
166
|
-
assert_true "0".match?(regexp)
|
|
167
|
-
assert_true "1".match?(regexp)
|
|
168
|
-
assert_true "2".match?(regexp)
|
|
169
|
-
assert_true "-1".match?(regexp)
|
|
170
|
-
assert_true "10".match?(regexp)
|
|
171
|
-
assert_true "100".match?(regexp)
|
|
172
|
-
assert_true "1000".match?(regexp)
|
|
173
|
-
assert_true "9999".match?(regexp)
|
|
174
|
-
assert_true "-9999".match?(regexp)
|
|
175
|
-
assert_true "9000000".match?(regexp)
|
|
176
|
-
|
|
177
|
-
# Invalid - zero variations
|
|
178
|
-
assert_false "-0".match?(regexp)
|
|
179
|
-
assert_false "+0".match?(regexp)
|
|
180
|
-
assert_false "00".match?(regexp)
|
|
181
|
-
assert_false "-00".match?(regexp)
|
|
182
|
-
assert_false "+00".match?(regexp)
|
|
183
|
-
|
|
184
|
-
# Invalid - leading plus and leading zeros
|
|
185
|
-
assert_false "+1".match?(regexp)
|
|
186
|
-
assert_false "+42".match?(regexp)
|
|
187
|
-
assert_false "01".match?(regexp)
|
|
188
|
-
assert_false "-01".match?(regexp)
|
|
189
|
-
|
|
190
|
-
# Invalid - characters and formatting
|
|
191
|
-
assert_false "".match?(regexp)
|
|
192
|
-
assert_false " ".match?(regexp)
|
|
193
|
-
assert_false "-".match?(regexp)
|
|
194
|
-
assert_false "1xx".match?(regexp)
|
|
195
|
-
assert_false "xx1".match?(regexp)
|
|
196
|
-
assert_false "-x1".match?(regexp)
|
|
197
|
-
assert_false "-1x".match?(regexp)
|
|
198
|
-
assert_false "1,000".match?(regexp)
|
|
199
|
-
assert_false "1.0".match?(regexp)
|
|
200
|
-
|
|
201
|
-
# Edge cases - multiline injection checks (\A and \z)
|
|
202
|
-
assert_false "1\n".match?(regexp)
|
|
203
|
-
assert_false "\n1".match?(regexp)
|
|
204
|
-
assert_false "1\n2".match?(regexp)
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
test "Number.decimal" do
|
|
208
|
-
regexp = Regexp::Collection::Number.decimal
|
|
209
|
-
|
|
210
|
-
# Valid - integers
|
|
211
|
-
assert_true "0".match?(regexp)
|
|
212
|
-
assert_true "1".match?(regexp)
|
|
213
|
-
assert_true "-1".match?(regexp)
|
|
214
|
-
assert_true "100".match?(regexp)
|
|
215
|
-
|
|
216
|
-
# Valid - standard decimals
|
|
217
|
-
assert_true "0.0".match?(regexp)
|
|
218
|
-
assert_true "0.5".match?(regexp)
|
|
219
|
-
assert_true "0.12345".match?(regexp)
|
|
220
|
-
assert_true "1.0".match?(regexp)
|
|
221
|
-
assert_true "-1.0".match?(regexp)
|
|
222
|
-
assert_true "12.34".match?(regexp)
|
|
223
|
-
assert_true "-12.34".match?(regexp)
|
|
224
|
-
|
|
225
|
-
# Valid - negative fractions strictly less than 0
|
|
226
|
-
assert_true "-0.5".match?(regexp)
|
|
227
|
-
assert_true "-0.01".match?(regexp)
|
|
228
|
-
assert_true "-0.00001".match?(regexp)
|
|
229
|
-
|
|
230
|
-
# Invalid - zero forms
|
|
231
|
-
assert_false "-0".match?(regexp)
|
|
232
|
-
assert_false "+0".match?(regexp)
|
|
233
|
-
assert_false "-0.0".match?(regexp)
|
|
234
|
-
assert_false "-0.00".match?(regexp)
|
|
235
|
-
assert_false "+0.0".match?(regexp)
|
|
236
|
-
assert_false "+00.0".match?(regexp)
|
|
237
|
-
|
|
238
|
-
# Invalid - leading plus and leading zeros
|
|
239
|
-
assert_false "+1".match?(regexp)
|
|
240
|
-
assert_false "+1.0".match?(regexp)
|
|
241
|
-
assert_false "+0.5".match?(regexp)
|
|
242
|
-
assert_false "01".match?(regexp)
|
|
243
|
-
assert_false "01.5".match?(regexp)
|
|
244
|
-
|
|
245
|
-
# Invalid - structure
|
|
246
|
-
assert_false ".".match?(regexp)
|
|
247
|
-
assert_false ".5".match?(regexp)
|
|
248
|
-
assert_false "-.5".match?(regexp)
|
|
249
|
-
assert_false "1.".match?(regexp)
|
|
250
|
-
assert_false "1.2.3".match?(regexp)
|
|
251
|
-
assert_false "-1.5x".match?(regexp)
|
|
252
|
-
assert_false "1e5".match?(regexp)
|
|
253
|
-
assert_false "".match?(regexp)
|
|
254
|
-
|
|
255
|
-
# Edge cases - multiline injection checks
|
|
256
|
-
assert_false "1.5\n".match?(regexp)
|
|
257
|
-
assert_false "\n1.5".match?(regexp)
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
test "Number.natural" do
|
|
261
|
-
# Default argument must equal natural(false)
|
|
262
|
-
assert_equal Regexp::Collection::Number.natural(false), Regexp::Collection::Number.natural
|
|
263
|
-
|
|
264
|
-
# natural(true) - including zero
|
|
265
|
-
reg_with_zero = Regexp::Collection::Number.natural(true)
|
|
266
|
-
assert_true "0".match?(reg_with_zero)
|
|
267
|
-
assert_true "1".match?(reg_with_zero)
|
|
268
|
-
assert_true "16".match?(reg_with_zero)
|
|
269
|
-
assert_true "999999".match?(reg_with_zero)
|
|
270
|
-
assert_false "-0".match?(reg_with_zero)
|
|
271
|
-
assert_false "+0".match?(reg_with_zero)
|
|
272
|
-
assert_false "00".match?(reg_with_zero)
|
|
273
|
-
assert_false "-1".match?(reg_with_zero)
|
|
274
|
-
assert_false "+1".match?(reg_with_zero)
|
|
275
|
-
assert_false "0.0".match?(reg_with_zero)
|
|
276
|
-
assert_false "1.0".match?(reg_with_zero)
|
|
277
|
-
assert_false "0foo".match?(reg_with_zero)
|
|
278
|
-
assert_false "0\n".match?(reg_with_zero)
|
|
279
|
-
|
|
280
|
-
# natural(false) - excluding zero
|
|
281
|
-
reg_without_zero = Regexp::Collection::Number.natural(false)
|
|
282
|
-
assert_false "0".match?(reg_without_zero)
|
|
283
|
-
assert_true "1".match?(reg_without_zero)
|
|
284
|
-
assert_true "16".match?(reg_without_zero)
|
|
285
|
-
assert_false "-1".match?(reg_without_zero)
|
|
286
|
-
assert_false "+1".match?(reg_without_zero)
|
|
287
|
-
assert_false "01".match?(reg_without_zero)
|
|
288
|
-
assert_false "".match?(reg_without_zero)
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
test "Number.hexadecimal" do
|
|
292
|
-
regexp = Regexp::Collection::Number.hexadecimal
|
|
293
|
-
|
|
294
|
-
# Valid
|
|
295
|
-
assert_true "0x0".match?(regexp)
|
|
296
|
-
assert_true "0x1".match?(regexp)
|
|
297
|
-
assert_true "0xabcdef".match?(regexp)
|
|
298
|
-
assert_true "0xABCDEF".match?(regexp)
|
|
299
|
-
assert_true "0x1a2B3c".match?(regexp)
|
|
300
|
-
assert_true "0X1a2b".match?(regexp)
|
|
301
|
-
assert_true "0XDEADBEEF".match?(regexp)
|
|
302
|
-
|
|
303
|
-
# Invalid
|
|
304
|
-
assert_false "".match?(regexp)
|
|
305
|
-
assert_false "0x".match?(regexp)
|
|
306
|
-
assert_false "0X".match?(regexp)
|
|
307
|
-
assert_false "abcdef".match?(regexp)
|
|
308
|
-
assert_false "x12".match?(regexp)
|
|
309
|
-
assert_false "0x12g".match?(regexp)
|
|
310
|
-
assert_false "0x12Z".match?(regexp)
|
|
311
|
-
assert_false "-0x12".match?(regexp)
|
|
312
|
-
assert_false " 0x12".match?(regexp)
|
|
313
|
-
assert_false "0x12\n".match?(regexp)
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
test "Time.seconds_required" do
|
|
317
|
-
regexp = Regexp::Collection::Time.seconds_required
|
|
318
|
-
|
|
319
|
-
# Valid
|
|
320
|
-
assert_true "00:00:00".match?(regexp)
|
|
321
|
-
assert_true "01:00:00".match?(regexp)
|
|
322
|
-
assert_true "1:00:00".match?(regexp)
|
|
323
|
-
assert_true "12:11:10".match?(regexp)
|
|
324
|
-
assert_true "12:10:09".match?(regexp)
|
|
325
|
-
assert_true "23:59:59".match?(regexp)
|
|
326
|
-
|
|
327
|
-
# Invalid - missing or excess parts
|
|
328
|
-
assert_false "".match?(regexp)
|
|
329
|
-
assert_false "12".match?(regexp)
|
|
330
|
-
assert_false "12:11".match?(regexp)
|
|
331
|
-
assert_false "12:11:".match?(regexp)
|
|
332
|
-
assert_false ":12:11:10".match?(regexp)
|
|
333
|
-
assert_false "12:0:0".match?(regexp)
|
|
334
|
-
assert_false "12:10:09.111".match?(regexp)
|
|
335
|
-
|
|
336
|
-
# Invalid - boundaries
|
|
337
|
-
assert_false "24:00:00".match?(regexp)
|
|
338
|
-
assert_false "25:00:00".match?(regexp)
|
|
339
|
-
assert_false "12:60:00".match?(regexp)
|
|
340
|
-
assert_false "12:11:60".match?(regexp)
|
|
341
|
-
|
|
342
|
-
# Edge cases
|
|
343
|
-
assert_false "+12:11:10".match?(regexp)
|
|
344
|
-
assert_false "12:11:10foo".match?(regexp)
|
|
345
|
-
assert_false "12:11:10\n".match?(regexp)
|
|
346
|
-
end
|
|
347
|
-
|
|
348
|
-
test "Time.seconds_optional" do
|
|
349
|
-
regexp = Regexp::Collection::Time.seconds_optional
|
|
350
|
-
|
|
351
|
-
# Valid
|
|
352
|
-
assert_true "00:00".match?(regexp)
|
|
353
|
-
assert_true "00:00:00".match?(regexp)
|
|
354
|
-
assert_true "1:00".match?(regexp)
|
|
355
|
-
assert_true "1:00:00".match?(regexp)
|
|
356
|
-
assert_true "12:11".match?(regexp)
|
|
357
|
-
assert_true "12:11:10".match?(regexp)
|
|
358
|
-
assert_true "23:59".match?(regexp)
|
|
359
|
-
assert_true "23:59:59".match?(regexp)
|
|
360
|
-
|
|
361
|
-
# Invalid
|
|
362
|
-
assert_false "".match?(regexp)
|
|
363
|
-
assert_false "12".match?(regexp)
|
|
364
|
-
assert_false "12:".match?(regexp)
|
|
365
|
-
assert_false "12:11:".match?(regexp)
|
|
366
|
-
assert_false "24:00".match?(regexp)
|
|
367
|
-
assert_false "24:00:00".match?(regexp)
|
|
368
|
-
assert_false "12:60".match?(regexp)
|
|
369
|
-
assert_false "12:11:60".match?(regexp)
|
|
370
|
-
assert_false "12:11:10\n".match?(regexp)
|
|
371
|
-
end
|
|
372
|
-
|
|
373
|
-
test "Time.seconds_not_permitted" do
|
|
374
|
-
regexp = Regexp::Collection::Time.seconds_not_permitted
|
|
375
|
-
|
|
376
|
-
# Valid
|
|
377
|
-
assert_true "00:00".match?(regexp)
|
|
378
|
-
assert_true "01:00".match?(regexp)
|
|
379
|
-
assert_true "1:00".match?(regexp)
|
|
380
|
-
assert_true "12:11".match?(regexp)
|
|
381
|
-
assert_true "23:59".match?(regexp)
|
|
382
|
-
|
|
383
|
-
# Invalid
|
|
384
|
-
assert_false "".match?(regexp)
|
|
385
|
-
assert_false "12:11:10".match?(regexp)
|
|
386
|
-
assert_false "01:00:00".match?(regexp)
|
|
387
|
-
assert_false "24:00".match?(regexp)
|
|
388
|
-
assert_false "12:60".match?(regexp)
|
|
389
|
-
assert_false "12:11\n".match?(regexp)
|
|
390
|
-
end
|
|
391
|
-
|
|
392
|
-
test "Crypto.trx_wallet_address_base58" do
|
|
393
|
-
regexp = Regexp::Collection::Crypto.trx_wallet_address_base58
|
|
394
|
-
|
|
395
|
-
# Valid TRON Base58 addresses (starts with T, 34 chars)
|
|
396
|
-
assert_true "TNDzfERD73nNqaTTrvNX7moW2GFp3W5amz".match?(regexp)
|
|
397
|
-
assert_true "TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9".match?(regexp)
|
|
398
|
-
assert_true "TLyqzVGLV1srkB7dToTAEqgDSfPtXRJZYH".match?(regexp)
|
|
399
|
-
|
|
400
|
-
# Invalid - wrong prefix
|
|
401
|
-
assert_false "ANDzfERD73nNqaTTrvNX7moW2GFp3W5amz".match?(regexp)
|
|
402
|
-
assert_false "41DzfERD73nNqaTTrvNX7moW2GFp3W5amz".match?(regexp)
|
|
403
|
-
|
|
404
|
-
# Invalid - incorrect length
|
|
405
|
-
assert_false "TNDzfERD73nNqaTTrvNX7moW2GFp3W5am".match?(regexp) # 33 chars
|
|
406
|
-
assert_false "TNDzfERD73nNqaTTrvNX7moW2GFp3W5amzz".match?(regexp) # 35 chars
|
|
407
|
-
|
|
408
|
-
# Invalid - non-Base58 characters (0, O, I, l)
|
|
409
|
-
assert_false "T0DzfERD73nNqaTTrvNX7moW2GFp3W5amz".match?(regexp)
|
|
410
|
-
assert_false "TODzfERD73nNqaTTrvNX7moW2GFp3W5amz".match?(regexp)
|
|
411
|
-
assert_false "TIDzfERD73nNqaTTrvNX7moW2GFp3W5amz".match?(regexp)
|
|
412
|
-
assert_false "TlDzfERD73nNqaTTrvNX7moW2GFp3W5amz".match?(regexp)
|
|
413
|
-
|
|
414
|
-
# Invalid - spaces and newlines
|
|
415
|
-
assert_false " TNDzfERD73nNqaTTrvNX7moW2GFp3W5amz".match?(regexp)
|
|
416
|
-
assert_false "TNDzfERD73nNqaTTrvNX7moW2GFp3W5amz\n".match?(regexp)
|
|
417
|
-
assert_false "".match?(regexp)
|
|
418
|
-
end
|
|
419
|
-
|
|
420
|
-
test "Crypto.evm_wallet_address" do
|
|
421
|
-
regexp = Regexp::Collection::Crypto.evm_wallet_address
|
|
422
|
-
|
|
423
|
-
# Valid (40 hex chars after 0x)
|
|
424
|
-
assert_true "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045".match?(regexp)
|
|
425
|
-
assert_true "0x0000000000000000000000000000000000000000".match?(regexp)
|
|
426
|
-
assert_true "0xffffffffffffffffffffffffffffffffffffffff".match?(regexp)
|
|
427
|
-
assert_true "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".match?(regexp)
|
|
428
|
-
|
|
429
|
-
# Invalid - non-hex characters (g-z, G-Z)
|
|
430
|
-
assert_false "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA9604G".match?(regexp)
|
|
431
|
-
assert_false "0xZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ".match?(regexp)
|
|
432
|
-
|
|
433
|
-
# Invalid - missing prefix
|
|
434
|
-
assert_false "d8dA6BF26964aF9D7eEd9e03E53415D37aA96045".match?(regexp)
|
|
435
|
-
|
|
436
|
-
# Invalid - incorrect length
|
|
437
|
-
assert_false "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA9604".match?(regexp) # 39 chars
|
|
438
|
-
assert_false "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA960455".match?(regexp) # 41 chars
|
|
439
|
-
|
|
440
|
-
# Invalid - spaces and newlines
|
|
441
|
-
assert_false " 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045".match?(regexp)
|
|
442
|
-
assert_false "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\n".match?(regexp)
|
|
443
|
-
assert_false "".match?(regexp)
|
|
444
|
-
end
|
|
445
|
-
|
|
446
|
-
test "Crypto.evm_transaction_hash" do
|
|
447
|
-
regexp = Regexp::Collection::Crypto.evm_transaction_hash
|
|
448
|
-
|
|
449
|
-
# Valid (64 hex chars after 0x)
|
|
450
|
-
assert_true "0x5c504ed432cb51138b309d43e110f94f6470077cbe40191498b82a8763046ad1".match?(regexp)
|
|
451
|
-
assert_true "0x5C504ED432CB51138B309D43E110F94F6470077CBE40191498B82A8763046AD1".match?(regexp)
|
|
452
|
-
assert_true "0x0000000000000000000000000000000000000000000000000000000000000000".match?(regexp)
|
|
453
|
-
|
|
454
|
-
# Invalid - non-hex characters
|
|
455
|
-
assert_false "0x5c504ed432cb51138b309d43e110f94f6470077cbe40191498b82a8763046adG".match?(regexp)
|
|
456
|
-
|
|
457
|
-
# Invalid - missing prefix
|
|
458
|
-
assert_false "5c504ed432cb51138b309d43e110f94f6470077cbe40191498b82a8763046ad1".match?(regexp)
|
|
459
|
-
|
|
460
|
-
# Invalid - length
|
|
461
|
-
assert_false "0x5c504ed432cb51138b309d43e110f94f6470077cbe40191498b82a8763046ad".match?(regexp) # 63 chars
|
|
462
|
-
assert_false "0x5c504ed432cb51138b309d43e110f94f6470077cbe40191498b82a8763046ad11".match?(regexp) # 65 chars
|
|
463
|
-
|
|
464
|
-
# Invalid - spaces and newlines
|
|
465
|
-
assert_false "0x5c504ed432cb51138b309d43e110f94f6470077cbe40191498b82a8763046ad1\n".match?(regexp)
|
|
466
|
-
assert_false "".match?(regexp)
|
|
467
|
-
end
|
|
468
|
-
end
|
|
469
|
-
</file>
|
|
470
|
-
|
|
471
|
-
<file path=".gitignore">
|
|
472
|
-
*.gem
|
|
473
|
-
.bundle
|
|
474
|
-
pkg/
|
|
475
|
-
tmp/
|
|
476
|
-
/.idea
|
|
477
|
-
</file>
|
|
478
|
-
|
|
479
|
-
<file path="Gemfile">
|
|
480
|
-
# frozen_string_literal: true
|
|
481
|
-
|
|
482
|
-
source "https://rubygems.org"
|
|
483
|
-
|
|
484
|
-
gemspec
|
|
485
|
-
</file>
|
|
486
|
-
|
|
487
|
-
<file path="Rakefile">
|
|
488
|
-
# frozen_string_literal: true
|
|
489
|
-
|
|
490
|
-
require "bundler/gem_tasks"
|
|
491
|
-
require "rake/testtask"
|
|
492
|
-
|
|
493
|
-
ENV["TESTOPTS"] = "--verbose"
|
|
494
|
-
Rake::TestTask.new do |t|
|
|
495
|
-
t.libs << "test"
|
|
496
|
-
t.pattern = "test/**/test_*.rb"
|
|
497
|
-
end
|
|
498
|
-
|
|
499
|
-
task default: :test
|
|
500
|
-
</file>
|
|
501
|
-
|
|
502
|
-
<file path="lib/regexp-collection.rb">
|
|
503
|
-
# frozen_string_literal: true
|
|
504
|
-
|
|
505
|
-
require_relative "regexp_collection"
|
|
506
|
-
</file>
|
|
507
|
-
|
|
508
|
-
<file path=".ruby-version">
|
|
509
|
-
4.0.7
|
|
510
|
-
</file>
|
|
511
|
-
|
|
512
|
-
<file path="LICENSE">
|
|
513
|
-
The MIT License (MIT)
|
|
514
|
-
|
|
515
|
-
Copyright (c) 2018 Yaroslav Konoplov
|
|
516
|
-
|
|
517
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
518
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
519
|
-
in the Software without restriction, including without limitation the rights
|
|
520
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
521
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
522
|
-
furnished to do so, subject to the following conditions:
|
|
523
|
-
|
|
524
|
-
The above copyright notice and this permission notice shall be included in all
|
|
525
|
-
copies or substantial portions of the Software.
|
|
526
|
-
|
|
527
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
528
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
529
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
530
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
531
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
532
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
533
|
-
SOFTWARE.
|
|
534
|
-
</file>
|
|
535
|
-
|
|
536
|
-
<file path="README.md">
|
|
537
|
-
# regexp-collection
|
|
538
|
-
|
|
539
|
-
A gem providing pre-made and tested typical regular expressions for applications.
|
|
540
|
-
</file>
|
|
541
|
-
|
|
542
|
-
<file path="regexp-collection.gemspec">
|
|
543
|
-
# frozen_string_literal: true
|
|
544
|
-
|
|
545
|
-
require_relative "lib/regexp_collection/version"
|
|
546
|
-
|
|
547
|
-
Gem::Specification.new do |s|
|
|
548
|
-
s.name = "regexp-collection"
|
|
549
|
-
s.version = Regexp::Collection::VERSION
|
|
550
|
-
s.authors = ["Yaroslav Konoplov"]
|
|
551
|
-
s.email = ["eahome00@gmail.com"]
|
|
552
|
-
s.summary = "Regular expression collection for Ruby"
|
|
553
|
-
s.description = "A gem providing pre-made and tested typical regular expressions for applications"
|
|
554
|
-
s.homepage = "https://github.com/yivo/regexp-collection"
|
|
555
|
-
s.license = "MIT"
|
|
556
|
-
|
|
557
|
-
s.required_ruby_version = [">= 3.0", "< 5.0"]
|
|
558
|
-
|
|
559
|
-
s.files = Dir.chdir File.expand_path(__dir__) do
|
|
560
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
561
|
-
end
|
|
562
|
-
s.require_paths = ["lib"]
|
|
563
|
-
|
|
564
|
-
s.add_development_dependency "rake", "~> 13.4"
|
|
565
|
-
s.add_development_dependency "test-unit", "~> 3.7"
|
|
566
|
-
end
|
|
567
|
-
</file>
|
|
568
|
-
|
|
569
|
-
</files>
|