aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/v/tests/operator_overloading_cmp_test.v
diff options
context:
space:
mode:
Diffstat (limited to 'v_windows/v/vlib/v/tests/operator_overloading_cmp_test.v')
-rw-r--r--v_windows/v/vlib/v/tests/operator_overloading_cmp_test.v35
1 files changed, 35 insertions, 0 deletions
diff --git a/v_windows/v/vlib/v/tests/operator_overloading_cmp_test.v b/v_windows/v/vlib/v/tests/operator_overloading_cmp_test.v
new file mode 100644
index 0000000..ccf0673
--- /dev/null
+++ b/v_windows/v/vlib/v/tests/operator_overloading_cmp_test.v
@@ -0,0 +1,35 @@
+struct Foo {
+ i int
+}
+
+fn (a Foo) < (b Foo) bool {
+ return a.i < b.i
+}
+
+fn (a Foo) == (b Foo) bool {
+ return a.i == b.i
+}
+
+fn test_operator_overloading_cmp() {
+ a := Foo{
+ i: 38
+ }
+ b := Foo{
+ i: 38
+ }
+ mut arr := [a, b]
+
+ assert (a > b) == false
+ assert (a < b) == false
+ //// /// //
+ assert a >= b
+ assert a <= b
+ //// /// //
+ assert b >= a
+ assert b <= a
+ //// /// //
+ arr.sort(a > b)
+ assert arr[0].i == 38
+ arr.sort(a < b)
+ assert arr[0].i == 38
+}