summaryrefslogtreecommitdiffstats
path: root/vendor/overload/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
commit2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch)
treed325add32978dbdc1db975a438b3a77d571b1ab8 /vendor/overload/tests
parentReleasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff)
downloadrustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz
rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/overload/tests')
-rw-r--r--vendor/overload/tests/assignment.rs89
-rw-r--r--vendor/overload/tests/binary.rs72
-rw-r--r--vendor/overload/tests/unary.rs21
3 files changed, 182 insertions, 0 deletions
diff --git a/vendor/overload/tests/assignment.rs b/vendor/overload/tests/assignment.rs
new file mode 100644
index 000000000..9657b4bd4
--- /dev/null
+++ b/vendor/overload/tests/assignment.rs
@@ -0,0 +1,89 @@
+extern crate overload;
+use overload::overload;
+use std::ops;
+
+#[derive(PartialEq, Debug)]
+struct A(i32);
+
+#[derive(PartialEq, Debug)]
+struct B(i32);
+
+overload!((a: &mut A) += (b: B) { a.0 += b.0; });
+#[test]
+fn add_assign() {
+ let mut a = A(3);
+ a += B(4);
+ assert_eq!(A(3 + 4), a);
+}
+
+overload!((a: &mut A) -= (b: B) { a.0 -= b.0; });
+#[test]
+fn sub_assign() {
+ let mut a = A(3);
+ a -= B(4);
+ assert_eq!(A(3 - 4), a);
+}
+
+overload!((a: &mut A) *= (b: B) { a.0 *= b.0; });
+#[test]
+fn mul_assign() {
+ let mut a = A(3);
+ a *= B(4);
+ assert_eq!(A(3 * 4), a);
+}
+
+overload!((a: &mut A) /= (b: B) { a.0 /= b.0; });
+#[test]
+fn div_assign() {
+ let mut a = A(6);
+ a /= B(3);
+ assert_eq!(A(6 / 3), a);
+}
+
+overload!((a: &mut A) %= (b: B) { a.0 %= b.0; });
+#[test]
+fn rem_assign() {
+ let mut a = A(6);
+ a %= B(4);
+ assert_eq!(A(6 % 4), a);
+}
+
+overload!((a: &mut A) &= (b: B) { a.0 &= b.0; });
+#[test]
+fn bitand_assign() {
+ let mut a = A(6);
+ a &= B(4);
+ assert_eq!(A(6 & 4), a);
+}
+
+overload!((a: &mut A) |= (b: B) { a.0 |= b.0; });
+#[test]
+fn bitor_assign() {
+ let mut a = A(6);
+ a |= B(4);
+ assert_eq!(A(6 | 4), a);
+}
+
+overload!((a: &mut A) ^= (b: B) { a.0 ^= b.0; });
+#[test]
+fn bitxor_assign() {
+ let mut a = A(6);
+ a ^= B(4);
+ assert_eq!(A(6 ^ 4), a);
+}
+
+overload!((a: &mut A) <<= (b: B) { a.0 <<= b.0; });
+#[test]
+fn shl_assign() {
+ let mut a = A(6);
+ a <<= B(4);
+ assert_eq!(A(6 << 4), a);
+}
+
+overload!((a: &mut A) >>= (b: B) { a.0 >>= b.0; });
+#[test]
+fn shr_assign() {
+ let mut a = A(6);
+ a >>= B(4);
+ assert_eq!(A(6 >> 4), a);
+}
diff --git a/vendor/overload/tests/binary.rs b/vendor/overload/tests/binary.rs
new file mode 100644
index 000000000..2fb209ad3
--- /dev/null
+++ b/vendor/overload/tests/binary.rs
@@ -0,0 +1,72 @@
+extern crate overload;
+use overload::overload;
+use std::ops;
+
+#[derive(PartialEq, Debug)]
+struct A(i32);
+
+#[derive(PartialEq, Debug)]
+struct B(i32);
+
+#[derive(PartialEq, Debug)]
+struct C(i32);
+
+overload!((a: A) + (b: B) -> C { C(a.0 + b.0) });
+#[test]
+fn add() {
+ assert_eq!(A(3) + B(4), C(3 + 4));
+}
+
+overload!((a: A) - (b: B) -> C { C(a.0 - b.0) });
+#[test]
+fn sub() {
+ assert_eq!(A(3) - B(4), C(3 - 4));
+}
+
+overload!((a: A) * (b: B) -> C { C(a.0 * b.0) });
+#[test]
+fn mul() {
+ assert_eq!(A(3) * B(4), C(3 * 4));
+}
+
+overload!((a: A) / (b: B) -> C { C(a.0 / b.0) });
+#[test]
+fn div() {
+ assert_eq!(A(6) / B(3), C(6 / 3));
+}
+
+overload!((a: A) % (b: B) -> C { C(a.0 % b.0) });
+#[test]
+fn rem() {
+ assert_eq!(A(6) % B(4), C(6 % 4));
+}
+
+overload!((a: A) & (b: B) -> C { C(a.0 & b.0) });
+#[test]
+fn bitand() {
+ assert_eq!(A(6) & B(4), C(6 & 4));
+}
+
+overload!((a: A) | (b: B) -> C { C(a.0 | b.0) });
+#[test]
+fn bitor() {
+ assert_eq!(A(6) | B(4), C(6 | 4));
+}
+
+overload!((a: A) ^ (b: B) -> C { C(a.0 ^ b.0) });
+#[test]
+fn bitxor() {
+ assert_eq!(A(6) ^ B(4), C(6 ^ 4));
+}
+
+overload!((a: A) << (b: B) -> C { C(a.0 << b.0) });
+#[test]
+fn shl() {
+ assert_eq!(A(6) << B(4), C(6 << 4));
+}
+
+overload!((a: A) >> (b: B) -> C { C(a.0 >> b.0) });
+#[test]
+fn shr() {
+ assert_eq!(A(6) >> B(4), C(6 >> 4));
+}
diff --git a/vendor/overload/tests/unary.rs b/vendor/overload/tests/unary.rs
new file mode 100644
index 000000000..76a3925fe
--- /dev/null
+++ b/vendor/overload/tests/unary.rs
@@ -0,0 +1,21 @@
+extern crate overload;
+use overload::overload;
+use std::ops;
+
+#[derive(PartialEq, Debug)]
+struct A(i32);
+
+#[derive(PartialEq, Debug)]
+struct B(i32);
+
+overload!(- (a: A) -> B { B(-a.0) });
+#[test]
+fn neg() {
+ assert_eq!(-A(3), B(-3));
+}
+
+overload!(! (a: A) -> B { B(!a.0) });
+#[test]
+fn not() {
+ assert_eq!(!A(3), B(!3));
+}