test(base64): add QuickCheck round-trip properties - #4007
Open
Yu-zh wants to merge 1 commit into
Open
Conversation
Five properties anchored on the encoder's output, all driven by arbitrary `Bytes`: - `decode(encode(b)) == b`, padded and unpadded - padded and unpadded encodings decode to the same bytes - arbitrary ASCII whitespace spliced at arbitrary positions (including between the two `=`) still decodes with `ignore_whitespace=true` - arbitrary non-alphabet characters spliced in are skipped by `decode_lossy` The perturbing splices are driven by a generated `Array[(Int, Int)]` of (position, char-choice) pairs, so placement and count shrink along with the input. Indices are wrapped into range rather than filtered, so no case is discarded.
Collaborator
Coverage Report for CI Build 5849Coverage increased (+0.03%) to 90.322%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
encoding/base64/quickcheck_test.mbtwith five property-based round-trip tests, plus a test-onlyquickcheckimport inencoding/base64/moon.pkg. No change topkg.generated.mbti.All properties are driven by arbitrary
Bytesand anchored on the encoder's output:encode then decode is the identitydecode(encode(b)) == b… without paddingdecode(encode(b, padding=false)) == bpadded and unpadded encodings decode alikewhitespace anywhere survives the round trip=and after them — still decodes withignore_whitespace=truedecode_lossy round trips through invalid charactersdecode_lossyThe last two use a
splicehelper driven by a generatedArray[(Int, Int)]of (position, char-choice) pairs, so the number and placement of perturbations are themselves generated and shrink with the counterexample. Indices are wrapped into range withwrap_indexrather than filtered, so the driver never discards a case.Verification
moon test -p moonbitlang/core/encoding/base64→ 16 passed, 0 failedmoon check encoding/base64→ cleanmoon info && moon fmt→.mbtiunchanged (test-only change)ignore_whitespace=trueand adding a falsebytes.length() < 3conjunct made both properties fail with shrunk counterexamples ((<Bytes: []>, [(0, 0)], false)and a 3-byte case), confirming the properties are not vacuous and that the spliced edits really reach the decoder.