diff --git a/src/vm/values/comparison.nim b/src/vm/values/comparison.nim index 0bf0956456..f96097238b 100644 --- a/src/vm/values/comparison.nim +++ b/src/vm/values/comparison.nim @@ -185,7 +185,8 @@ proc `==`*(x: Value, y: Value): bool = if not (v==y.d[k]): return false return true - + of Unit: + return x.u == y.u of Object: if (let compareMethod = x.proto.methods.getOrDefault("compare", nil); not compareMethod.isNil): return x.proto.doCompare(x,y) == 0 @@ -391,6 +392,8 @@ proc `<`*(x: Value, y: Value): bool {.inline.}= return x.a.len < y.a.len of Dictionary: return false + of Unit: + return false of Object: if (let compareMethod = x.proto.methods.getOrDefault("compare", nil); not compareMethod.isNil): return x.proto.doCompare(x, y) == -1 @@ -501,6 +504,8 @@ proc `>`*(x: Value, y: Value): bool {.inline.}= return x.a.len > y.a.len of Dictionary: return false + of Unit: + return false of Object: if (let compareMethod = x.proto.methods.getOrDefault("compare", nil); not compareMethod.isNil): return x.proto.doCompare(x,y) == 1 diff --git a/tests/unittests/lib.comparison.art b/tests/unittests/lib.comparison.art index d6db21507d..d62ab1e0e7 100644 --- a/tests/unittests/lib.comparison.art +++ b/tests/unittests/lib.comparison.art @@ -645,6 +645,16 @@ do [ to :date .format: "MMM dd" "Jan 16" passed + topic « between? - :unit + + ensure -> between? `USD `USD `USD + ensure -> between? `USD `USD `EUR + ensure -> between? `EUR `USD `EUR + passed + + ; TODO: fix me soon + ; ensure -> not? between? `BRL `USD `EUR + ; passed ] @@ -1172,6 +1182,14 @@ do [ ensure -> 1 = compare e d passed + topic « compare - :unit + + ensure -> 0 = compare `USD `USD + ensure -> 1 = compare `USD `EUR + ensure -> 1 = compare `EUR `USD + passed + + ] topic « equal? @@ -2266,6 +2284,20 @@ do [ -> equal? var 'regex? {/regex?/} ] => not? passed + + topic « equal? - :unit + + ensure -> equal? `USD `USD + ensure -> equal? `EUR `EUR + ensure -> `USD = `USD + ensure -> `EUR = `EUR + passed + + ensure -> not? equal? `USD `EUR + ensure -> not? equal? `EUR `USD + ensure -> not? `EUR = `USD + passed + ] topic « greater? @@ -2967,6 +2999,18 @@ do [ passed + topic « greater? - :unit + + ensure -> not? greater? `USD `USD + ensure -> not? greater? `EUR `EUR + ensure -> not? greater? `USD `EUR + ensure -> not? greater? `EUR `USD + ensure -> not? `USD > `USD + ensure -> not? `EUR > `EUR + ensure -> not? `EUR > `USD + passed + + topic « greater? - incompatible types ; NOTES: @@ -4191,6 +4235,19 @@ do [ ensure -> not? greaterOrEqual? a d passed + topic « greaterOrEqual? - :unit + + ensure -> greaterOrEqual? `USD `USD + ensure -> greaterOrEqual? `EUR `EUR + ensure -> `USD >= `USD + ensure -> `EUR >= `EUR + passed + + ensure -> not? greaterOrEqual? `USD `EUR + ensure -> not? greaterOrEqual? `EUR `USD + ensure -> not? `EUR >= `USD + passed + topic « greaterOrEqual? - incompatible types @@ -5373,6 +5430,17 @@ do [ ensure -> not? less? a d passed + topic « less? - :unit + + ensure -> not? less? `USD `USD + ensure -> not? less? `EUR `EUR + ensure -> not? less? `USD `EUR + ensure -> not? less? `EUR `USD + ensure -> not? `USD < `USD + ensure -> not? `EUR < `EUR + ensure -> not? `EUR < `USD + passed + topic « less? - incompatible types @@ -6599,6 +6667,19 @@ do [ ensure -> not? lessOrEqual? a d passed + topic « lessOrEqual? - :unit + + ensure -> lessOrEqual? `USD `USD + ensure -> lessOrEqual? `EUR `EUR + ensure -> `USD =< `USD + ensure -> `EUR =< `EUR + passed + + ensure -> not? lessOrEqual? `USD `EUR + ensure -> not? equal? `EUR `USD + ensure -> not? `EUR =< `USD + passed + topic « lessOrEqual? - incompatible types @@ -7690,6 +7771,19 @@ do [ ensure -> notEqual? a\year c\year passed + topic « notEqual? - :unit + + ensure -> not? notEqual? `USD `USD + ensure -> not? notEqual? `EUR `EUR + ensure -> not? `USD <> `USD + ensure -> not? `EUR <> `EUR + passed + + ensure -> notEqual? `USD `EUR + ensure -> notEqual? `EUR `USD + ensure -> `EUR <> `USD + passed + topic « notEqual? - incompatible types @@ -8740,6 +8834,16 @@ do [ ensure -> not? same? a\year c\year passed + topic « same? - :unit + + ensure -> same? `USD `USD + ensure -> same? `EUR `EUR + passed + + ensure -> not? same? `USD `EUR + ensure -> not? same? `EUR `USD + passed + topic « same? - incompatible types diff --git a/tests/unittests/lib.comparison.res b/tests/unittests/lib.comparison.res index d4165fa84a..4a0afa451e 100644 --- a/tests/unittests/lib.comparison.res +++ b/tests/unittests/lib.comparison.res @@ -96,6 +96,9 @@ >> between? - :date [+] passed! +>> between? - :unit +[+] passed! + >> between? - test with reversed index [+] passed! [+] passed! @@ -208,6 +211,9 @@ [+] passed! [+] passed! +>> compare - :unit +[+] passed! + >> equal? >> equal? - :integer :floating :rational @@ -365,6 +371,10 @@ [+] passed! [+] passed! +>> equal? - :unit +[+] passed! +[+] passed! + >> greater? >> greater? - :integer :floating :rational @@ -496,6 +506,9 @@ [+] passed! [+] passed! +>> greater? - :unit +[+] passed! + >> greater? - incompatible types [+] passed! [+] passed! @@ -659,6 +672,10 @@ [+] passed! [+] passed! +>> greaterOrEqual? - :unit +[+] passed! +[+] passed! + >> greaterOrEqual? - incompatible types [+] passed! [+] passed! @@ -822,6 +839,9 @@ [+] passed! [+] passed! +>> less? - :unit +[+] passed! + >> less? - incompatible types [+] passed! [+] passed! @@ -984,6 +1004,10 @@ [+] passed! [+] passed! +>> lessOrEqual? - :unit +[+] passed! +[+] passed! + >> lessOrEqual? - incompatible types [+] passed! [+] passed! @@ -1139,6 +1163,10 @@ [+] passed! [+] passed! +>> notEqual? - :unit +[+] passed! +[+] passed! + >> notEqual? - incompatible types [+] passed! [+] passed! @@ -1299,6 +1327,10 @@ [+] passed! [+] passed! +>> same? - :unit +[+] passed! +[+] passed! + >> same? - incompatible types [+] passed! [+] passed!