pyrmont / testament

A testing library for Janet
MIT License
28 stars 8 forks source link

Add match-like assertion #5

Closed pyrmont closed 3 years ago

pyrmont commented 3 years ago

@yumaikas has requested that Testament include a match-like assertion. The API would look like:

(assert-match expect-structure actual-value &opt note)

An example usage:

(assert-match { :month-day 28 } (os/date) "The date includes a `:month-day` key")

The assertion would pass if expect-structure partially matched the actual structure of actual-value (rather than an exact match).

pyrmont commented 3 years ago

@andrewchambers pointed out that Rust has a matches! macro that has a similar intended use.

(assert (matches (os/date) {:month-day 28}))
andrewchambers commented 3 years ago

my idea kind of relies on matches being added to the main janet to make sense.

pyrmont commented 3 years ago

@andrewchambers Since is is a macro in Testament, though, I think I could use the matches symbol to identify this as a call to (a hypothetical) assert-matches* function and perhaps do something similar :)