Functional Weave
Code in Rust

form.iso-date@1.0.0

vectors.json

5,853 bytes · view raw

[
  {"name": "a leap day from the picker", "args": ["2024-02-29", "Start date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2024-02-29", "message": null}},
  {"name": "29 February 2023 does not exist", "args": ["2023-02-29", "Start date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Start date must be a real date"}},
  {"name": "empty and required: GOV.UK's Enter message, label lower-cased", "args": ["", "Start date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Enter start date"}},
  {"name": "empty and not required is valid with no date", "args": ["", "Start date", false, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": null, "message": null}},
  {"name": "only whitespace counts as empty", "args": [" \t ", "Start date", false, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": null, "message": null}},
  {"name": "surrounding spaces and a trailing newline are trimmed", "args": [" 2024-01-05\n", "Start date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2024-01-05", "message": null}},
  {"name": "a UK-style date is not the picker's format", "args": ["05/01/2024", "Start date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Start date must be a real date"}},
  {"name": "unpadded month and day are not the picker's format", "args": ["2024-1-5", "Start date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Start date must be a real date"}},
  {"name": "Arabic-Indic digits are not a date", "args": ["٢٠٢٤-01-05", "Start date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Start date must be a real date"}},
  {"name": "a date and time is not a date", "args": ["2024-02-29T00:00:00Z", "Start date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Start date must be a real date"}},
  {"name": "month 13", "args": ["2024-13-01", "Start date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Start date must be a real date"}},
  {"name": "year 0000", "args": ["0000-01-01", "Start date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Start date must be a real date"}},
  {"name": "31 April", "args": ["2025-04-31", "Start date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Start date must be a real date"}},
  {"name": "an acronym label keeps its capitals", "args": ["", "UK arrival date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Enter UK arrival date"}},
  {"name": "past: today itself is not in the past", "args": ["2026-10-10", "Date of birth", true, {"today": "2026-10-10", "timing": "past", "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be in the past"}},
  {"name": "past: yesterday is", "args": ["2026-10-09", "Date of birth", true, {"today": "2026-10-10", "timing": "past", "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2026-10-09", "message": null}},
  {"name": "future-or-today accepts today", "args": ["2026-10-10", "Start date", true, {"today": "2026-10-10", "timing": "future-or-today", "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2026-10-10", "message": null}},
  {"name": "min and max: after the range", "args": ["2027-01-01", "Start date", true, {"today": null, "timing": null, "notBefore": "2026-01-01", "notAfter": "2026-12-31"}], "expect": {"valid": false, "date": null, "message": "Start date must be between 1 January 2026 and 31 December 2026"}},
  {"name": "min and max are inclusive", "args": ["2026-12-31", "Start date", true, {"today": null, "timing": null, "notBefore": "2026-01-01", "notAfter": "2026-12-31"}], "expect": {"valid": true, "date": "2026-12-31", "message": null}},
  {"name": "min only: the day before", "args": ["2025-12-31", "Start date", true, {"today": null, "timing": null, "notBefore": "2026-01-01", "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Start date must be the same as or after 1 January 2026"}},
  {"name": "max only: the day after", "args": ["2026-02-01", "End date", true, {"today": null, "timing": null, "notBefore": null, "notAfter": "2026-01-31"}], "expect": {"valid": false, "date": null, "message": "End date must be the same as or before 31 January 2026"}},
  {"name": "a label is needed even for an empty optional date", "args": ["", "  ", false, {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expectError": "a date needs a label"},
  {"name": "a timing rule needs today", "args": ["2026-01-01", "Start date", true, {"today": null, "timing": "past", "notBefore": null, "notAfter": null}], "expectError": "rules.today is needed to check that a date is past"},
  {"name": "min after max is the caller's mistake, whatever was typed", "args": ["", "Start date", false, {"today": null, "timing": null, "notBefore": "2026-02-01", "notAfter": "2026-01-01"}], "expectError": "must not be after rules.notAfter"}
]