mtrudel / machete

Literate test matchers for ExUnit
MIT License
56 stars 2 forks source link

Feature request: ISO 8601 naive date time matcher support #30

Closed axelson closed 7 months ago

axelson commented 7 months ago

Machete has two DateTime matchers for structs:

But only one for strings:

Thus if you have a string like "2024-04-18 18:16:12.481210" then you can't use a machete matcher on it. If we're following the same pattern then we'd want to introduce a Machete.ISO8601NaiveDateTimeMatcher that can parse ""2024-04-18 18:16:12.481210".

Although instead of creating a whole new matcher it also might make sense to consider extending Machete.ISO8601DateTimeMatcher to match ISO8601 strings without a timezone so this could match, right now this is the behavior Machete has:

iex(8)> NaiveDateTime.to_iso8601(NaiveDateTime.utc_now()) ~>> Machete.ISO8601DateTimeMatcher.iso8601_datetime(roughly: :now)
[
  %Machete.Mismatch{
    path: [],
    message: "\"2024-04-20T19:37:31.381743\" is not a parseable ISO8601 datetime"
  }
]

Instead I'm proposing this:

iex(12)> NaiveDateTime.to_iso8601(NaiveDateTime.utc_now()) ~>> Machete.ISO8601DateTimeMatcher.iso8601_datetime(roughly: :now)
[]