Skip to content

Commit

Permalink
test: Add a test for interesting module template polymorphism
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Apr 14, 2012
1 parent 979a225 commit 611061b
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/test/run-pass/module-polymorphism-files/inst_f32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type T = f32;
1 change: 1 addition & 0 deletions src/test/run-pass/module-polymorphism-files/inst_f64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type T = f64;
1 change: 1 addition & 0 deletions src/test/run-pass/module-polymorphism-files/inst_float.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type T = float;
3 changes: 3 additions & 0 deletions src/test/run-pass/module-polymorphism-files/template.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn plus(x: T, y: T) -> T {
x + y
}
45 changes: 45 additions & 0 deletions src/test/run-pass/module-polymorphism.rc
Original file line number Diff line number Diff line change
@@ -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;

}
11 changes: 11 additions & 0 deletions src/test/run-pass/module-polymorphism.rs
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type T = f32;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type T = f64;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type T = float;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn plus(x: T, y: T) -> T {
x + y
}
61 changes: 61 additions & 0 deletions src/test/run-pass/module-polymorphism2.rc
Original file line number Diff line number Diff line change
@@ -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;

}

}
11 changes: 11 additions & 0 deletions src/test/run-pass/module-polymorphism2.rs
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn plus(x: T, y: T) -> T {
x + y
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type T = f32;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type T = f64;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type T = float;
39 changes: 39 additions & 0 deletions src/test/run-pass/module-polymorphism3.rc
Original file line number Diff line number Diff line change
@@ -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;
}

}
11 changes: 11 additions & 0 deletions src/test/run-pass/module-polymorphism3.rs
Original file line number Diff line number Diff line change
@@ -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 comments on commit 611061b

Please sign in to comment.