From 430bed16f566ba5413b7eb5aea2d40c8ef02bd86 Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Mon, 2 May 2022 18:43:19 +0200 Subject: [PATCH] return lists with byValue results when is set for an object --- source/fluentasserts/core/evaluation.d | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/source/fluentasserts/core/evaluation.d b/source/fluentasserts/core/evaluation.d index a4dba30..c504665 100644 --- a/source/fluentasserts/core/evaluation.d +++ b/source/fluentasserts/core/evaluation.d @@ -273,6 +273,12 @@ class ObjectEquable(T) : EquableValue { } EquableValue[] toArray() { + static if(__traits(hasMember, T, "byValue")) { + try { + return value.byValue.map!(a => a.equableValue(SerializerRegistry.instance.serialize(a))).array; + } catch(Exception) {} + } + return [ this ]; } @@ -285,6 +291,20 @@ class ObjectEquable(T) : EquableValue { } } +/// an object with byValue method should return an array with all elements +unittest { + class TestObject { + auto byValue() { + auto items = [1, 2]; + return items.inputRangeObject; + } + } + + auto value = equableValue(new TestObject(), "[1, 2]").toArray; + assert(value.length == 2, "invalid length"); + assert(value[0].toString == "Equable.1", value[0].toString ~ " != Equable.1"); + assert(value[1].toString == "Equable.2", value[1].toString ~ " != Equable.2"); +} /// class ArrayEquable(U: T[], T) : EquableValue { @@ -314,6 +334,7 @@ class ArrayEquable(U: T[], T) : EquableValue { } @trusted EquableValue[] toArray() { + try { "array.toArray".writeln; } catch(Exception) {} static if(is(T == void)) { return []; } else { @@ -328,7 +349,7 @@ class ArrayEquable(U: T[], T) : EquableValue { } EquableValue generalize() { - return this; + return this; } override string toString() { @@ -336,7 +357,6 @@ class ArrayEquable(U: T[], T) : EquableValue { } } - /// class AssocArrayEquable(U: T[V], T, V) : ArrayEquable!(string[], string) { this(T[V] values, string serialized) {