Skip to content

Commit 321a877

Browse files
authored
Merge pull request #15 from ferdnyc/ferdnyc-patch-1
Fix is_iso_date pattern and add tests
2 parents 40e5fa7 + 3d90ec9 commit 321a877

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/saneyaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def is_float(s):
327327

328328

329329
# Return True if s is an iso date such as `2019-12-12`
330-
is_iso_date = re.compile(r'19|20[0-9]{2}-[0-1][0-9]-[0-3]?[1-9]').match
330+
is_iso_date = re.compile(r'(19|20)[0-9]{2}-[0-1][0-9]-[0-3][0-9]').match
331331

332332
SaneDumper.add_representer(int, SaneDumper.string_dumper)
333333
SaneDumper.add_representer(dict, SaneDumper.ordered_dumper)

tests/test_saneyaml.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ def test_load_ignore_aliases(self):
137137
])
138138
assert expected == result
139139

140+
def test_is_iso_date(self):
141+
assert saneyaml.is_iso_date('1994-01-01')
142+
assert saneyaml.is_iso_date('2004-01-01')
143+
assert not saneyaml.is_iso_date('1800-01-01')
144+
assert not saneyaml.is_iso_date('2100-01-01')
145+
assert saneyaml.is_iso_date('2004-01-30')
146+
assert not saneyaml.is_iso_date('2004-01-40')
147+
assert not saneyaml.is_iso_date('2004-01-4')
148+
assert not saneyaml.is_iso_date('2004-01-3a')
149+
assert not saneyaml.is_iso_date('1994-01-1')
150+
assert not saneyaml.is_iso_date('1994-1-1')
151+
assert not saneyaml.is_iso_date('193')
152+
# Hey, nothing's perfect
153+
assert saneyaml.is_iso_date('2003-02-29')
154+
assert saneyaml.is_iso_date('2004-01-35')
155+
140156

141157
safe_chars = re.compile(r'[\W_]', re.MULTILINE)
142158

0 commit comments

Comments
 (0)