-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.nim
More file actions
64 lines (55 loc) · 1.29 KB
/
Copy pathexample.nim
File metadata and controls
64 lines (55 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pkg/testdiff
type
TestEnum = enum
A, B, C
TestObj = object
intVal: int
seqVal: seq[int]
enumVal: TestEnum
floatVal: float
strVal: string
sub: TestObjRef
TestObjRef = ref TestObj
let d = diff(
TestObj(
intVal: 5,
seqVal: @[1, 2, 3],
enumVal: B, # this value is different in the second object
floatVal: 5.5,
strVal: "Hello world",
sub: TestObjRef(
intVal: 3,
enumVal: C, # this value is missing in the second object, so defaults to A
floatVal: 5.5,
strVal: "Hello world"
)
),
TestObj(
intVal: 5,
seqVal: @[1, 2], # this value is different
floatVal: 5.5,
strVal: "Hello world",
sub: TestObjRef(
intVal: 3,
floatVal: 5.6, # this value is different
strVal: "Hello world"
)
)
)
# stringify diff to get a list of differences
doAssert $d == """difference at path seqVal: 3 != 2 (seq[int].len)
difference at path enumVal: B != A (TestEnum)
difference at path sub.enumVal: C != A (TestEnum)
difference at path sub.floatVal: 5.5 != 5.6 (float)
"""
# check amount of errors
doAssert d.errorCount == 4
# check exact error paths
doAssert d.errorPaths == @[
"seqVal",
"enumVal",
"sub.enumVal",
"sub.floatVal"
]
# check if the two values are the same
doAssert not d.same