You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide.md
+63Lines changed: 63 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,6 +134,7 @@ The framework includes built-in assertion methods accessible through `$t.assert`
134
134
135
135
### Basic Assertions
136
136
-`$t.assert.areEqual($t; $expected; $actual; $message)` - Values must be equal
137
+
-`$t.assert.areDeepEqual($t; $expected; $actual; $message; $maxDepth)` - Deep equality comparison for objects and collections (optional `$maxDepth`, default: 10)
137
138
-`$t.assert.isTrue($t; $value; $message)` - Value must be true
138
139
-`$t.assert.isFalse($t; $value; $message)` - Value must be false
139
140
-`$t.assert.isNull($t; $value; $message)` - Value must be null
@@ -157,6 +158,68 @@ Function test_calculations($t : cs.Testing.Testing)
157
158
$t.assert.isNotNull($t; $result; "Function should return a result")
158
159
```
159
160
161
+
### Deep Equality Assertions
162
+
163
+
The `areDeepEqual` function performs recursive comparison of nested objects and collections, providing detailed difference reporting when values don't match. This is especially useful for testing complex data structures.
164
+
165
+
**Basic Usage:**
166
+
```4d
167
+
Function test_object_comparison($t : cs.Testing.Testing)
168
+
var $expected; $actual : Object
169
+
$expected:={name: "John"; age: 30; address: {city: "New York"; zip: "10001"}}
170
+
$actual:={name: "John"; age: 30; address: {city: "New York"; zip: "10001"}}
171
+
172
+
// Deep comparison of nested structures
173
+
$t.assert.areDeepEqual($t; $expected; $actual; "Objects should match")
174
+
```
175
+
176
+
**With Custom Max Depth:**
177
+
```4d
178
+
Function test_deep_nesting($t : cs.Testing.Testing)
179
+
var $expected; $actual : Object
180
+
// ... very deeply nested objects ...
181
+
182
+
// Increase max depth for very deep structures (default is 10)
183
+
$t.assert.areDeepEqual($t; $expected; $actual; "Deep objects should match"; 20)
184
+
```
185
+
186
+
**Accessing Differences Programmatically:**
187
+
When a deep equality assertion fails, the framework stores detailed difference information in `$t.lastDeepEqualDifferences`:
188
+
189
+
```4d
190
+
Function test_with_difference_analysis($t : cs.Testing.Testing)
191
+
var $expected; $actual : Object
192
+
$expected:={name: "John"; age: 30}
193
+
$actual:={name: "John"; age: 25}
194
+
195
+
$t.assert.areDeepEqual($t; $expected; $actual; "Objects should match")
196
+
197
+
// If assertion fails, analyze differences
198
+
If ($t.failed)
199
+
var $diff : Object
200
+
For each ($diff; $t.lastDeepEqualDifferences)
201
+
$t.log("Difference at "+$diff.path+": "+$diff.type)
202
+
End for each
203
+
End if
204
+
```
205
+
206
+
**Features:**
207
+
-**Recursive Comparison**: Compares nested objects and collections at all levels
0 commit comments