mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:30:12 +01:00
Remove indirection for builtin operator tests (#2109)
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
360f905755
commit
005ab78766
+10
-5
@@ -7,13 +7,18 @@
|
||||
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
|
||||
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
|
||||
// AUTOUPDATE: %{explorer} %s
|
||||
// CHECK: result: 3
|
||||
// CHECK: Interface: 5
|
||||
// CHECK: Op: 5
|
||||
// CHECK: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
// TODO: T:! Add
|
||||
fn DoAdd[T:! AddWith(.Self) where .Result == .Self](x: T, y: T) -> T { return x + y; }
|
||||
|
||||
fn Main() -> i32 {
|
||||
return DoAdd(1, 2);
|
||||
var lhs: i32 = 3;
|
||||
var rhs: i32 = 2;
|
||||
// Make sure that both the interface and operator work with i32. These rely on
|
||||
// builtin arithmetic more directly.
|
||||
Print("Interface: {0}", lhs.(AddWith(i32).Op)(rhs));
|
||||
Print("Op: {0}", lhs + rhs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+9
-4
@@ -7,13 +7,18 @@
|
||||
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
|
||||
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
|
||||
// AUTOUPDATE: %{explorer} %s
|
||||
// CHECK: Interface: 2
|
||||
// CHECK: Op: 2
|
||||
// CHECK: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
// TODO: T:! Mod
|
||||
fn DoMod[T:! ModWith(.Self) where .Result == .Self](x: T, y: T) -> T { return x % y; }
|
||||
|
||||
fn Main() -> i32 {
|
||||
return DoMod(4, 2);
|
||||
var lhs: i32 = 8;
|
||||
var rhs: i32 = 3;
|
||||
// Make sure that both the interface and operator work with i32. These rely on
|
||||
// builtin arithmetic more directly.
|
||||
Print("Interface: {0}", lhs.(ModWith(i32).Op)(rhs));
|
||||
Print("Op: {0}", lhs % rhs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+10
-5
@@ -7,13 +7,18 @@
|
||||
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
|
||||
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
|
||||
// AUTOUPDATE: %{explorer} %s
|
||||
// CHECK: result: 6
|
||||
// CHECK: Interface: 6
|
||||
// CHECK: Op: 6
|
||||
// CHECK: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
// TODO: T:! Mul
|
||||
fn DoMul[T:! MulWith(.Self) where .Result == .Self](x: T, y: T) -> T { return x * y; }
|
||||
|
||||
fn Main() -> i32 {
|
||||
return DoMul(2, 3);
|
||||
var lhs: i32 = 3;
|
||||
var rhs: i32 = 2;
|
||||
// Make sure that both the interface and operator work with i32. These rely on
|
||||
// builtin arithmetic more directly.
|
||||
Print("Interface: {0}", lhs.(MulWith(i32).Op)(rhs));
|
||||
Print("Op: {0}", lhs * rhs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+9
-4
@@ -7,12 +7,17 @@
|
||||
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
|
||||
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
|
||||
// AUTOUPDATE: %{explorer} %s
|
||||
// CHECK: result: -3
|
||||
// CHECK: Interface: -3
|
||||
// CHECK: Op: -3
|
||||
// CHECK: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
fn DoNegate[T:! Negate where .Result == .Self](x: T) -> T { return -x; }
|
||||
|
||||
fn Main() -> i32 {
|
||||
return DoNegate(3);
|
||||
var val: i32 = 3;
|
||||
// Make sure that both the interface and operator work with i32. These rely on
|
||||
// builtin arithmetic more directly.
|
||||
Print("Interface: {0}", val.(Negate.Op)());
|
||||
Print("Op: {0}", -val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+10
-5
@@ -7,13 +7,18 @@
|
||||
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
|
||||
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
|
||||
// AUTOUPDATE: %{explorer} %s
|
||||
// CHECK: result: 1
|
||||
// CHECK: Interface: 5
|
||||
// CHECK: Op: 5
|
||||
// CHECK: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
// TODO: T:! Sub
|
||||
fn DoSub[T:! SubWith(.Self) where .Result == .Self](x: T, y: T) -> T { return x - y; }
|
||||
|
||||
fn Main() -> i32 {
|
||||
return DoSub(3, 2);
|
||||
var lhs: i32 = 8;
|
||||
var rhs: i32 = 3;
|
||||
// Make sure that both the interface and operator work with i32. These rely on
|
||||
// builtin arithmetic more directly.
|
||||
Print("Interface: {0}", lhs.(SubWith(i32).Op)(rhs));
|
||||
Print("Op: {0}", lhs - rhs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user