diff options
author | Jason Beetham <beefers331@gmail.com> | 2021-01-25 16:55:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-26 00:55:49 +0100 |
commit | dde096ffdea2c551a9b00af533b13106528ac4a1 (patch) | |
tree | 62929e94b6b0fe70c54ff02e5d083508e644630e | |
parent | 25745ad195580772d4689a7c98f9b3f77f06cdd1 (diff) | |
download | Nim-dde096ffdea2c551a9b00af533b13106528ac4a1.tar.gz |
added enum indexed array support to json (#16807)
* added enum indexed array support to json * Added json test * Removed when statement for enum indexed arrays
-rw-r--r-- | lib/pure/json.nim | 2 | ||||
-rw-r--r-- | tests/stdlib/tjson_enum_index.nim | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim index a9d0ed4cb..ac3c3b194 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -1103,7 +1103,7 @@ when defined(nimFixedForwardGeneric): jsonPath.add '[' jsonPath.addInt i jsonPath.add ']' - initFromJson(dst[i], jsonNode[i], jsonPath) + initFromJson(dst[i.S], jsonNode[i], jsonPath) # `.S` for enum indexed arrays jsonPath.setLen originalJsonPathLen proc initFromJson[T](dst: var Table[string,T]; jsonNode: JsonNode; jsonPath: var string) = diff --git a/tests/stdlib/tjson_enum_index.nim b/tests/stdlib/tjson_enum_index.nim new file mode 100644 index 000000000..2c24f4f36 --- /dev/null +++ b/tests/stdlib/tjson_enum_index.nim @@ -0,0 +1,11 @@ +import json +type Test = enum + one, two, three, four, five +let a = [ + one: 300, + two: 20, + three: 10, + four: 0, + five: -10 +] +doAssert (%* a).to(a.typeof) == a \ No newline at end of file |