Skip to content

Commit 696c0e9

Browse files
committed
Added test and note about value comparison.
1 parent b2e66ed commit 696c0e9

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ try new Person({
198198
}
199199
```
200200

201+
## Equality comparison
202+
203+
Use a library like [deep_equal](https://lib.haxe.org/p/deep_equal/) for value comparison between DataClass objects.
204+
201205
## JSON/Date conversion
202206

203207
DataClass can ease the JSON conversion process, especially when using `Date`. When defining `-D dataclass-date-auto-conversion`, strings and numbers will be automatically converted to `Date`, so you can basically create DataClass objects directly from JSON:

tests-node.hxml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
-lib hxnodejs
44
-lib travix
55
-lib dataclass
6+
-lib deep_equal
67
-cp ./tests/
78
-cp ./src/
89
-main Tests2

tests.hxml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-lib buddy
22
-lib deepstate
3+
-lib deep_equal
34
-cp ./tests/
45
-cp ./src/
56
-main Tests2

tests/Tests2.hx

+19
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ class WishItemData implements DataClass {
138138
public final item_price:Float;
139139
}
140140

141+
class DataclassContainer implements DataClass {
142+
public final item : WishItemData;
143+
public final id : Int;
144+
}
145+
141146
/*
142147
// This should fail due to a validator on a static field.
143148
class WishItemData2 implements DataClass {
@@ -239,6 +244,20 @@ class Tests2 extends BuddySuite implements Buddy<[
239244
new WishItemData({item_price: 12.34}).should.not.be(null);
240245
});
241246

247+
it("should be compatible with deep_equal", {
248+
final test1 = new DataclassContainer({
249+
item: new WishItemData({item_price: 10}),
250+
id: 123
251+
});
252+
253+
final test2 = new DataclassContainer({
254+
item: new WishItemData({item_price: 10}),
255+
id: 123
256+
});
257+
258+
deepequal.DeepEqual.compare(test1, test2).isSuccess().should.be(true);
259+
});
260+
242261
///////////////////////////////////////////////////////////////////
243262

244263
describe("With non-null fields", {

0 commit comments

Comments
 (0)