Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove indirection for builtin operator tests #2109

Merged
merged 13 commits into from
Sep 15, 2022
15 changes: 10 additions & 5 deletions explorer/testdata/operators/add_builtin.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
13 changes: 9 additions & 4 deletions explorer/testdata/operators/mod_builtin.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 10 additions & 5 deletions explorer/testdata/operators/mul_builtin.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
13 changes: 9 additions & 4 deletions explorer/testdata/operators/negate_builtin.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 10 additions & 5 deletions explorer/testdata/operators/sub_builtin.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}