Skip to content

Commit 48bf564

Browse files
committed
[FIX] HashSet and OrderedSet not being decoded/encoded properly, thus tests failing
1 parent 24ff175 commit 48bf564

File tree

5 files changed

+119
-48
lines changed

5 files changed

+119
-48
lines changed

kdl.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "2.0.1"
3+
version = "2.0.2"
44
author = "Patitotective"
55
description = "KDL document language Nim implementation"
66
license = "MIT"

src/kdl/decoder.nim

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ runnableExamples:
8686
proc postHookKdl(v: var Foo) =
8787
inc v.x
8888

89-
assert parseKdl("x 1").decodeKdl(Foo) == Foo(x: 2) # 2 because x after postHook got incremented by one
89+
assert parseKdl("x 1").decodeKdl(Foo) == Foo(
90+
x: 2) # 2 because x after postHook got incremented by one
9091

9192
## #### Enum hook
9293
## Enum hooks are useful for parsing enums in a custom manner.
@@ -278,9 +279,11 @@ runnableExamples:
278279
""").decodeKdl(DateTime) == dateTime(2022, mOct, 15, 12, 10)
279280

280281
# Here we use the KdlNode overload
281-
assert parseKdl("date 2022 \"October\" 15 12 04 00").decodeKdl(DateTime, "date") == dateTime(2022, mOct, 15, 12, 04)
282+
assert parseKdl("date 2022 \"October\" 15 12 04 00").decodeKdl(DateTime,
283+
"date") == dateTime(2022, mOct, 15, 12, 04)
282284
# And here we use the KdlVal overload
283-
assert parseKdl("author birthday=\"2000-10-15\" name=\"Nobody\"")[0]["birthday"].decodeKdl(DateTime) == dateTime(2000, mOct, 15)
285+
assert parseKdl("author birthday=\"2000-10-15\" name=\"Nobody\"")[0][
286+
"birthday"].decodeKdl(DateTime) == dateTime(2000, mOct, 15)
284287
##
285288
## ----------
286289
##
@@ -345,8 +348,9 @@ proc decodeKdl*(a: KdlVal, v: var char)
345348
# proc decodeKdl*(a: KdlVal, v: var cstring)
346349
proc decodeKdl*[T: array](a: KdlVal, v: var T)
347350
proc decodeKdl*[T: not KdlNode](a: KdlVal, v: var seq[T])
348-
proc decodeKdl*(a: KdlVal, v: var Object)
349351
proc decodeKdl*[T](a: KdlVal, v: var SomeSet[T])
352+
proc decodeKdl*(a: KdlVal, v: var Object)
353+
proc decodeKdl*(a: KdlVal, v: var SomeTable)
350354
proc decodeKdl*[T: Ordinal](a: KdlVal, v: var set[T])
351355
proc decodeKdl*[T](a: KdlVal, v: var Option[T])
352356
proc decodeKdl*[T](a: KdlVal, v: var ref T)
@@ -745,16 +749,19 @@ proc decodeKdl*[T: not KdlNode](a: KdlVal, v: var seq[T]) =
745749
v.setLen 1
746750
decodeKdl(a, v[0])
747751

748-
proc decodeKdl*(a: KdlVal, v: var Object) =
749-
fail &"{$typeof(v)} not implemented for {$typeof(a)}"
750-
751752
proc decodeKdl*[T](a: KdlVal, v: var SomeSet[T]) =
752753
v.clear()
753754

754755
v.incl decodeKdl(a, T)
755756

756757
decodePostKdl(v)
757758

759+
proc decodeKdl*(a: KdlVal, v: var Object) =
760+
fail &"{$typeof(v)} not implemented for {$typeof(a)}"
761+
762+
proc decodeKdl*(a: KdlVal, v: var SomeTable) =
763+
fail &"{$typeof(v)} not implemented for {$typeof(a)}"
764+
758765
proc decodeKdl*[T: Ordinal](a: KdlVal, v: var set[T]) =
759766
v.reset()
760767

src/kdl/encoder.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ proc encodeKdl*[T: Ordinal](a: set[T], v: var KdlNode, name: string) =
204204
for e, i in enumerate(a):
205205
v.args[e] = encodeKdlVal(i)
206206

207-
proc encodeKdl*(a: SomeTable[string, auto] or SomeSet[auto], v: var KdlNode, name: string) =
207+
proc encodeKdl*(a: SomeTable[string, auto] or SomeSet[auto], v: var KdlNode,
208+
name: string) =
208209
v = initKNode(name)
209210
encodeKdl(a, v.children)
210211

src/kdl/utils.nim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
## Various utilities for internal use in the library.
2-
import std/[strformat, strutils, unicode, streams, tables, macros]
2+
import std/[strformat, strutils, unicode, streams, tables, macros, sets]
33

44
import types
55

66
type
77
Coord* = object
88
line*, col*, idx*: int
99

10-
Object* = ((object or tuple) and not KdlSome)
10+
Object* = ((object or tuple) and not KdlSome and not SomeTable and
11+
not List and not Value and not SomeSet)
1112
List* = (array or seq)
1213
Value* = (SomeNumber or string or bool) # or range
1314
KdlSome* = (KdlDoc or KdlNode or KdlVal)
@@ -47,7 +48,8 @@ proc cmpIgnoreStyle(a, b: openarray[char], ignoreChars = {'_', '-'}): int =
4748
inc i
4849
inc j
4950

50-
proc eqIdent*(v, a: openarray[char], ignoreChars = {'_', '-'}): bool = cmpIgnoreStyle(v, a, ignoreChars) == 0
51+
proc eqIdent*(v, a: openarray[char], ignoreChars = {'_',
52+
'-'}): bool = cmpIgnoreStyle(v, a, ignoreChars) == 0
5153

5254
# ----- Streams -----
5355

0 commit comments

Comments
 (0)