aboutsummaryrefslogtreecommitdiff
path: root/tests/atoms/integer.test.py
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-07-14 19:03:28 +0530
committerGitHub <[email protected]>2026-07-14 19:03:28 +0530
commit082325df2374340b4ccf6bdfd1b4842d2b9aa763 (patch)
tree27bb8bc42bf11521ac0534e6fcd7c08abc6405a3 /tests/atoms/integer.test.py
parentabdaeb4aad4284986f012efcce35a6e4189f2929 (diff)
parent3ebe0d7b2b61a908255a45118f4d07ef805a0e01 (diff)
downloadedify-082325df2374340b4ccf6bdfd1b4842d2b9aa763.tar.xz
edify-082325df2374340b4ccf6bdfd1b4842d2b9aa763.zip
feat(atoms): public edify.atoms — 83 composable Pattern fragments (#276)
Adds `edify.atoms`, a public module of unanchored `Pattern` fragments that snap into any builder via `.use()`. ## Usage ```python from edify import Pattern from edify.atoms import hostname, port, protocol url_shape = ( Pattern() .start_of_input() .use(protocol).string("://").use(hostname).char(":").use(port) .end_of_input() ) url_shape("https://example.com:8080") # True ``` ## The 83 atoms | Group | Count | Names | |---|---|---| | Character | 7 | `letter`, `lower`, `upper`, `alnum`, `printable`, `ascii`, `space` | | Numeric | 12 | `natural`, `integer`, `signed`, `unsigned`, `decimal`, `floatnum`, `scientific`, `percent`, `ratio`, `hexnum`, `binnum`, `octnum` | | Network | 12 | `octet`, `port`, `hostname`, `label`, `ipv4`, `ipv6`, `cidr`, `mac`, `protocol`, `scheme`, `tld`, `nibble` | | Temporal | 11 | `clock`, `clock12`, `isodate`, `isodatetime`, `epoch`, `year`, `month`, `day`, `weekday`, `timezone`, `duration` | | Identifier | 7 | `uuid`, `guid`, `ulid`, `oid`, `objectid`, `semver`, `slug` | | Text | 9 | `word`, `line`, `quoted`, `parens`, `brackets`, `braces`, `username`, `localpart`, `hexcolor` | | Path | 3 | `filename`, `filepath`, `extension` | | Crypto | 7 | `hexstring`, `base64`, `base64url`, `base32`, `base58`, `sha256`, `md5` | | Web | 7 | `url`, `uri`, `email`, `rgbcolor`, `httpmethod`, `httpstatus`, `mimetype` | | Financial | 5 | `iban`, `bic`, `currency`, `money`, `creditcard` | | Boolean | 3 | `yesno`, `truefalse`, `boolean` | Every atom is a `Pattern` instance built via the fluent chain (no raw regex). Every atom has a corpus test at `tests/atoms/<name>.test.py` covering: accepts a shape-conforming sample, rejects an off-shape input, composes cleanly under `Pattern().use(...)`, emits a non-empty regex fragment. Every filename is single-word (no underscores). Every attribute name avoids Python builtins. `edify/library/_support/atoms.py` (the previous private home of `octet` / `hex_any`) is deleted; the three library validators that used it (`address/ip`, `address/ptr`, `address/socket`) now import from `edify.atoms`. Closes #170 Closes #171 Closes #172 Closes #173 Closes #174
Diffstat (limited to 'tests/atoms/integer.test.py')
-rw-r--r--tests/atoms/integer.test.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/atoms/integer.test.py b/tests/atoms/integer.test.py
new file mode 100644
index 0000000..d5e9fa8
--- /dev/null
+++ b/tests/atoms/integer.test.py
@@ -0,0 +1,26 @@
+from edify import Pattern
+from edify.atoms import integer
+
+
+def _anchored():
+ return Pattern().start_of_input().use(integer).end_of_input()
+
+
+def test_accepts_sample_from_shape():
+ assert _anchored()("-42")
+
+
+def test_rejects_off_shape_input():
+ assert not _anchored()("abc")
+
+
+def test_atom_composes_inside_a_larger_pattern():
+ embedded = Pattern().start_of_input().string("v=").use(integer).end_of_input()
+ assert embedded("v=" + "-42")
+ assert not embedded("-42")
+
+
+def test_atom_regex_string_is_non_empty():
+ fragment = integer.to_regex_string()
+ assert fragment
+ assert isinstance(fragment, str)