test: Add a test for interesting module template polymorphism
This commit is contained in:
parent
979a225598
commit
611061b6c3
|
@ -0,0 +1 @@
|
|||
type T = f32;
|
|
@ -0,0 +1 @@
|
|||
type T = f64;
|
|
@ -0,0 +1 @@
|
|||
type T = float;
|
|
@ -0,0 +1,3 @@
|
|||
fn plus(x: T, y: T) -> T {
|
||||
x + y
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
#[no_core];
|
||||
|
||||
|
||||
#[path = "module-polymorphism-files"]
|
||||
mod float {
|
||||
|
||||
// The type of the float
|
||||
import inst::T;
|
||||
|
||||
// Define T as float
|
||||
#[path = "inst_float.rs"]
|
||||
mod inst;
|
||||
|
||||
// Add in the implementation from a single source file
|
||||
#[path = "template.rs"]
|
||||
mod template;
|
||||
|
||||
}
|
||||
|
||||
#[path = "module-polymorphism-files"]
|
||||
mod f64 {
|
||||
|
||||
import inst::T;
|
||||
|
||||
// Define T as f64
|
||||
#[path = "inst_f64.rs"]
|
||||
mod inst;
|
||||
|
||||
// Use the implementation for the same source file!
|
||||
#[path = "template.rs"]
|
||||
mod template;
|
||||
|
||||
}
|
||||
|
||||
#[path = "module-polymorphism-files"]
|
||||
mod f32 {
|
||||
import inst::T;
|
||||
|
||||
#[path = "inst_f32.rs"]
|
||||
mod inst;
|
||||
|
||||
#[path = "template.rs"]
|
||||
mod template;
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
// This isn't really xfailed; it's used by the
|
||||
// module-polymorphism.rc test
|
||||
// xfail-test
|
||||
|
||||
fn main() {
|
||||
// All of these functions are defined by a single module
|
||||
// source file but instantiated for different types
|
||||
assert float::template::plus(1.0f, 2.0f) == 3.0f;
|
||||
assert f64::template::plus(1.0f64, 2.0f64) == 3.0f64;
|
||||
assert f32::template::plus(1.0f32, 2.0f32) == 3.0f32;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
type T = f32;
|
|
@ -0,0 +1 @@
|
|||
type T = f64;
|
|
@ -0,0 +1 @@
|
|||
type T = float;
|
|
@ -0,0 +1,3 @@
|
|||
fn plus(x: T, y: T) -> T {
|
||||
x + y
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
#[no_core];
|
||||
|
||||
|
||||
#[path = "module-polymorphism2-files"]
|
||||
mod mystd {
|
||||
|
||||
#[path = "float-template"]
|
||||
mod float {
|
||||
// The type of the float
|
||||
import inst::T;
|
||||
|
||||
// Unfortunate
|
||||
import template::*;
|
||||
export plus;
|
||||
|
||||
// Define T as float
|
||||
#[path = "inst_float.rs"]
|
||||
mod inst;
|
||||
|
||||
// Add in the implementation from a single source file
|
||||
#[path = "template.rs"]
|
||||
mod template;
|
||||
}
|
||||
|
||||
|
||||
#[path = "float-template"]
|
||||
mod f64 {
|
||||
|
||||
import inst::T;
|
||||
|
||||
// Unfortunate
|
||||
import template::*;
|
||||
export plus;
|
||||
|
||||
// Define T as f64
|
||||
#[path = "inst_f64.rs"]
|
||||
mod inst;
|
||||
|
||||
// Use the implementation for the same source file!
|
||||
#[path = "template.rs"]
|
||||
mod template;
|
||||
|
||||
}
|
||||
|
||||
#[path = "float-template"]
|
||||
mod f32 {
|
||||
import inst::T;
|
||||
|
||||
// Unfortunate
|
||||
import template::*;
|
||||
export plus;
|
||||
|
||||
#[path = "inst_f32.rs"]
|
||||
mod inst;
|
||||
|
||||
#[path = "template.rs"]
|
||||
mod template;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
// This isn't really xfailed; it's used by the
|
||||
// module-polymorphism.rc test
|
||||
// xfail-test
|
||||
|
||||
fn main() {
|
||||
// All of these functions are defined by a single module
|
||||
// source file but instantiated for different types
|
||||
assert mystd::float::plus(1.0f, 2.0f) == 3.0f;
|
||||
assert mystd::f64::plus(1.0f64, 2.0f64) == 3.0f64;
|
||||
assert mystd::f32::plus(1.0f32, 2.0f32) == 3.0f32;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fn plus(x: T, y: T) -> T {
|
||||
x + y
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
type T = f32;
|
|
@ -0,0 +1 @@
|
|||
type T = f64;
|
|
@ -0,0 +1 @@
|
|||
type T = float;
|
|
@ -0,0 +1,39 @@
|
|||
#[no_core];
|
||||
|
||||
// Use one template module to specify in a single file the implementation
|
||||
// of functions for multiple types
|
||||
|
||||
#[path = "module-polymorphism3-files"]
|
||||
mod mystd {
|
||||
|
||||
// The template is specified in float-template.rs
|
||||
#[path = "float-template"]
|
||||
mod float {
|
||||
// The type of the float
|
||||
import inst::T;
|
||||
|
||||
// Define T as appropriate for platform
|
||||
#[path = "inst_float.rs"]
|
||||
mod inst;
|
||||
}
|
||||
|
||||
// Use the same template
|
||||
#[path = "float-template"]
|
||||
mod f64 {
|
||||
|
||||
import inst::T;
|
||||
|
||||
// Define T as f64
|
||||
#[path = "inst_f64.rs"]
|
||||
mod inst;
|
||||
}
|
||||
|
||||
#[path = "float-template"]
|
||||
mod f32 {
|
||||
import inst::T;
|
||||
|
||||
#[path = "inst_f32.rs"]
|
||||
mod inst;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
// This isn't really xfailed; it's used by the
|
||||
// module-polymorphism.rc test
|
||||
// xfail-test
|
||||
|
||||
fn main() {
|
||||
// All of these functions are defined by a single module
|
||||
// source file but instantiated for different types
|
||||
assert mystd::float::plus(1.0f, 2.0f) == 3.0f;
|
||||
assert mystd::f64::plus(1.0f64, 2.0f64) == 3.0f64;
|
||||
assert mystd::f32::plus(1.0f32, 2.0f32) == 3.0f32;
|
||||
}
|
Loading…
Reference in New Issue