Exemple
Validate an Elixir keyword option list with NimbleOptions and know the exact error message a caller sees for an unknown key, a wrong type, a missing required key and a bad nested key
sha256:41ea393de638c575f2f87f965ec5c0d67ac71f5700421b440ef9ae4eae3ec768
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Cas
- Objectif
- Validate an Elixir keyword option list with NimbleOptions and know the exact error message a caller sees for an unknown key, a wrong type, a missing required key and a bad nested key HOW
- Paquets
- nimble_options 1.1.1
- Environnement
- elixir 1
- Créé
- 2026-08-14T20:11:20Z
Contrat
- assert a valid option list returns an :ok tuple with a keyword list whose defaults are filled, including nested defaults reached through the parent key's own default, and that defaults come out in reverse schema order ahead of the caller's keys so the result must be read by key and never by position
- assert an unknown key is rejected with the exact message unknown options [:retires], valid options are: [:url, :retries, :mode, :pool], that error.key holds a list rather than the atom its docs promise, and that unknown keys are checked before required ones
- assert a duplicated key is reported as an unknown option in a message that also lists that key as valid, because the check subtracts key lists and -- removes only one occurrence
- assert a type mismatch names the key and spells out the expected type, and that the wording is inconsistent across types: :non_neg_integer says non negative while :timeout says non-negative
- assert required: true reports the missing key together with the caller's original option keys and not the defaults already filled in behind them, that what makes a key optional is required defaulting to false rather than the presence of a default, and that writing required: true and a default on one key is accepted silently and leaves the default unreachable
- assert new!/1 accepts a default that violates its own type, contradicting the library's own documentation, and that the error surfaces lazily only for callers who omit that option
- assert nested :keyword_list schemas validate, that keys_path carries the path while the message field does not and only Exception.message joins them, and that a nested required key is checked only when the parent key is present
- assert validate returns a tuple while validate! raises NimbleOptions.ValidationError with the identical message, and that validate! returns the bare normalized list rather than an :ok tuple
- assert a map of options validates only against a compiled %NimbleOptions{} and raises FunctionClauseError against a raw keyword-list schema, despite the @spec on validate/2 accepting keyword() or map()
- assert docs/1 renders the :doc text before the default sentence, a bare Required. for required keys, and no type link at all for {:in, choices}
Fichiers
- csx.json
- lib/csx_options.ex
- mix.exs
- mix.lock
- test/contract_test.exs
- test/test_helper.exs
Télécharger l'artefact vérifié (tar.gz) — les octets exacts sur lesquels le contrat s'est exécuté
Seeder d'origine
Reçus de vérification
- elixir 1 · CONTAINER_RUN · compile:PASS · contract:PASS · load:PASS · resolve:PASS · hex@1 · 2026-08-14 · ed25519:a2ec939a4c60e243