| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Add a WithNow patcher that replaces now() calls with a fixed time, exposed via the expr.MockNow option. This makes it easy to test expressions that depend on now() by getting deterministic results, without having to write a custom patcher or disable the builtin. It composes with Timezone. Closes expr-lang#754
There was a problem hiding this comment.
The composition is order-dependent. MockNow replaces now() with a ConstantNode, so a later Timezone visitor has no BuiltinNode to modify. expr.Compile(code, expr.MockNow(now), expr.Timezone("Asia/Kamchatka")) therefore keeps the original location even though the docs say the options can be combined.
Please make both option orders work, or document the required order and add a regression test for it.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #754.
now() makes expressions hard to test because it returns a different value on every run. As suggested in the issue, this adds a small patcher (following the WithTimezone pattern) plus a public option so now() can be pinned to a fixed time.
Usage
The compiled program now always sees that fixed time for now(), so tests are deterministic. No boilerplate patcher and no need to DisableBuiltin("now") + re-register a function.
What's included
Notes