|
| 1 | +# ruff: noqa: S101 # Asserts are ok in tests |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from edtf.natlang.en import text_to_edtf |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.parametrize( |
| 9 | + "input_text,expected_output", |
| 10 | + [ |
| 11 | + ("active late 17th-19th centuries", "16XX/18XX"), |
| 12 | + ("active 17-19th Centuries", "16XX/18XX"), |
| 13 | + ("", None), |
| 14 | + ("this isn't a date", None), |
| 15 | + ("23rd Dynasty", None), |
| 16 | + ("90", "1990"), |
| 17 | + ("1860", "1860"), |
| 18 | + ("the year 1800", "1800"), |
| 19 | + ("January 2008", "2008-01"), |
| 20 | + ("January 12, 1940", "1940-01-12"), |
| 21 | + ("1860?", "1860?"), |
| 22 | + ("1862 (uncertain)", "1862?"), |
| 23 | + ("maybe 1862", "1862?"), |
| 24 | + ("~ Feb 1812", "1812-02~"), |
| 25 | + ("c1860", "1860~"), |
| 26 | + ("c.1860", "1860~"), |
| 27 | + ("c 1860", "1860~"), |
| 28 | + ("1860s", "186X"), |
| 29 | + ("ca. 1860s", "186X~"), |
| 30 | + ("January 12", "XXXX-01-12"), |
| 31 | + ("January", "XXXX-01"), |
| 32 | + ("10/7/2008", "2008-10-07"), |
| 33 | + ("7/2008", "2008-07"), |
| 34 | + ("Spring 1872", "1872-21"), |
| 35 | + ("Summer 1872", "1872-22"), |
| 36 | + ("Autumn 1872", "1872-23"), |
| 37 | + ("Winter 1872", "1872-24"), |
| 38 | + ("earlier than 1928", "/1928"), |
| 39 | + ("before 1928", "/1928"), |
| 40 | + ("after 1928", "1928/"), |
| 41 | + ("before January 1928", "/1928-01"), |
| 42 | + ("after approx January 1928", "1928-01~/"), |
| 43 | + ("2nd century bc", "-01XX"), |
| 44 | + ("1 AD", "0001"), |
| 45 | + ], |
| 46 | +) |
| 47 | +def test_natlang(input_text, expected_output): |
| 48 | + result = text_to_edtf(input_text) |
| 49 | + assert result == expected_output, ( |
| 50 | + f"Failed for input: {input_text} - expected {expected_output}, got {result}" |
| 51 | + ) |
0 commit comments