Skip to content

Commit 2c8d798

Browse files
ChickenPropphadej
authored andcommitted
Improve Arbitrary Value instance.
Fixes #980. As discussed there, simply changing `n <= 0` to `n <= 1` gives good generation of strings, bools, numbers and null. Turns out it also forbids `[]` and `{}` from being generated, so I added those explicitly to that case. My understanding is this requires a major version bump, as a change in behavior of an exported function.
1 parent a0e735f commit 2c8d798

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ For the latest version of this document, please see [https://github.com/haskell/
77
* Remove `cffi` flag. Then the C implementation for string unescaping was used for `text <2` versions.
88
The new native Haskell implementation introduced in version 2.0.3.0 is at least as fast.
99
* Drop instances for `attoparsec.Number`.
10+
* Improve `Arbitrary Value` instance.
1011

1112
### 2.1.2.1
1213

src/Data/Aeson/Types/Internal.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,13 @@ type RepValue
439439

440440
arbValue :: Int -> QC.Gen Value
441441
arbValue n
442-
| n <= 0 = QC.oneof
442+
| n <= 1 = QC.oneof
443443
[ pure Null
444444
, Bool <$> QC.arbitrary
445445
, String <$> arbText
446446
, Number <$> arbScientific
447+
, pure emptyObject
448+
, pure emptyArray
447449
]
448450

449451
| otherwise = QC.oneof

0 commit comments

Comments
 (0)