-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add a test for interesting module template polymorphism
- Loading branch information
Showing
18 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type T = f32; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type T = f64; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type T = float; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn plus(x: T, y: T) -> T { | ||
x + y | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/run-pass/module-polymorphism2-files/float-template/inst_f32.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type T = f32; |
1 change: 1 addition & 0 deletions
1
src/test/run-pass/module-polymorphism2-files/float-template/inst_f64.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type T = f64; |
1 change: 1 addition & 0 deletions
1
src/test/run-pass/module-polymorphism2-files/float-template/inst_float.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type T = float; |
3 changes: 3 additions & 0 deletions
3
src/test/run-pass/module-polymorphism2-files/float-template/template.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn plus(x: T, y: T) -> T { | ||
x + y | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
3 changes: 3 additions & 0 deletions
3
src/test/run-pass/module-polymorphism3-files/float-template.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn plus(x: T, y: T) -> T { | ||
x + y | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/run-pass/module-polymorphism3-files/float-template/inst_f32.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type T = f32; |
1 change: 1 addition & 0 deletions
1
src/test/run-pass/module-polymorphism3-files/float-template/inst_f64.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type T = f64; |
1 change: 1 addition & 0 deletions
1
src/test/run-pass/module-polymorphism3-files/float-template/inst_float.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type T = float; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |