Files
@ 2451a3ca7e4d
Branch filter:
Location: CSY/reowolf/src/protocol/tests/parser_monomorphs.rs - annotation
2451a3ca7e4d
3.7 KiB
application/rls-services+xml
WIP: Refactored most of type table, pending one bugfix
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 fc2d65a1b906 9774ef9fe888 ba57649f36e2 ba57649f36e2 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 d7baa792c2c2 fc2d65a1b906 fc2d65a1b906 fc2d65a1b906 fc2d65a1b906 fc2d65a1b906 9774ef9fe888 9774ef9fe888 9774ef9fe888 9774ef9fe888 ba57649f36e2 fc2d65a1b906 ba57649f36e2 ba57649f36e2 ba57649f36e2 9774ef9fe888 e406c61b1158 fc2d65a1b906 fc2d65a1b906 9774ef9fe888 f7c20c8ac012 f7c20c8ac012 f7c20c8ac012 f7c20c8ac012 f7c20c8ac012 f7c20c8ac012 f7c20c8ac012 f7c20c8ac012 d7baa792c2c2 f7c20c8ac012 f7c20c8ac012 ba57649f36e2 d23aebafc979 d23aebafc979 f7c20c8ac012 f7c20c8ac012 ef37386d0c6f ba57649f36e2 ef37386d0c6f f7c20c8ac012 f7c20c8ac012 f7c20c8ac012 f7c20c8ac012 d7baa792c2c2 fc2d65a1b906 fc2d65a1b906 fc2d65a1b906 fc2d65a1b906 f7c20c8ac012 f7c20c8ac012 f7c20c8ac012 f7c20c8ac012 2451a3ca7e4d 2451a3ca7e4d f7c20c8ac012 5051cf740055 5051cf740055 5051cf740055 5051cf740055 5051cf740055 5051cf740055 5051cf740055 d7baa792c2c2 d7baa792c2c2 5051cf740055 5051cf740055 ba57649f36e2 ba57649f36e2 5051cf740055 5051cf740055 5051cf740055 5051cf740055 5051cf740055 5051cf740055 d7baa792c2c2 fc2d65a1b906 d7baa792c2c2 d7baa792c2c2 fc2d65a1b906 fc2d65a1b906 5051cf740055 5051cf740055 5051cf740055 5051cf740055 ba57649f36e2 ba57649f36e2 ba57649f36e2 ba57649f36e2 ba57649f36e2 ba57649f36e2 6929a6091ed6 6929a6091ed6 6929a6091ed6 fc2d65a1b906 6929a6091ed6 5051cf740055 9774ef9fe888 | /// parser_monomorphs.rs
///
/// Simple tests to make sure that all of the appropriate monomorphs are
/// instantiated
use super::*;
#[test]
fn test_struct_monomorphs() {
Tester::new_single_source_expect_ok(
"no polymorph",
"struct Integer{ s32 field }"
).for_struct("Integer", |s| { s
.assert_num_monomorphs(1)
.assert_has_monomorph("Integer");
});
Tester::new_single_source_expect_ok(
"single polymorph",
"
struct Number<T>{ T number }
func instantiator() -> s32 {
auto a = Number<s8>{ number: 0 };
auto b = Number<s8>{ number: 1 };
auto c = Number<s32>{ number: 2 };
auto d = Number<s64>{ number: 3 };
auto e = Number<Number<s16>>{ number: Number{ number: 4 }};
return 0;
}
"
).for_struct("Number", |s| { s
.assert_has_monomorph("Number<s8>")
.assert_has_monomorph("Number<s16>")
.assert_has_monomorph("Number<s32>")
.assert_has_monomorph("Number<s64>")
.assert_has_monomorph("Number<Number<s16>>")
.assert_num_monomorphs(5);
}).for_function("instantiator", |f| { f
.for_variable("a", |v| {v.assert_concrete_type("Number<s8>");} )
.for_variable("e", |v| {v.assert_concrete_type("Number<Number<s16>>");} );
});
}
#[test]
fn test_enum_monomorphs() {
Tester::new_single_source_expect_ok(
"no polymorph",
"
enum Answer{ Yes, No }
func do_it() -> s32 { auto a = Answer::Yes; return 0; }
"
).for_enum("Answer", |e| { e
.assert_num_monomorphs(1)
.assert_has_monomorph("Answer")
.assert_size_alignment("Answer", 1, 1);
});
// Note for reader: because the enum doesn't actually use the polymorphic
// variable, we expect to have 1 monomorph: the type only has to be laid
// out once.
Tester::new_single_source_expect_ok(
"single polymorph",
"
enum Answer<T> { Yes, No }
func instantiator() -> s32 {
auto a = Answer<s8>::Yes;
auto b = Answer<s8>::No;
auto c = Answer<s32>::Yes;
auto d = Answer<Answer<Answer<s64>>>::No;
return 0;
}
"
).for_enum("Answer", |e| { e
.assert_has_monomorph("2Answer<s8>")
.assert_num_monomorphs(1);
});
}
#[test]
fn test_union_monomorphs() {
Tester::new_single_source_expect_ok(
"no polymorph",
"
union Trinary { Undefined, Value(bool) }
func do_it() -> s32 { auto a = Trinary::Value(true); return 0; }
"
).for_union("Trinary", |e| { e
.assert_num_monomorphs(1)
.assert_has_monomorph("Trinary");
});
Tester::new_single_source_expect_ok(
"polymorphs",
"
union Result<T, E>{ Ok(T), Err(E) }
func instantiator() -> s32 {
s16 a_s16 = 5;
auto a = Result<s8, bool>::Ok(0);
auto b = Result<bool, s8>::Ok(true);
auto c = Result<Result<s8, s32>, Result<s16, s64>>::Err(Result::Ok(5));
auto d = Result<Result<s8, s32>, auto>::Err(Result<auto, s64>::Ok(a_s16));
return 0;
}
"
).for_union("Result", |e| { e
.assert_num_monomorphs(5)
.assert_has_monomorph("Result<s8,bool>")
.assert_has_monomorph("Result<bool,s8>")
.assert_has_monomorph("Result<Result<s8,s32>,Result<s16,s64>>")
.assert_has_monomorph("Result<s8,s32>")
.assert_has_monomorph("Result<s16,s64>");
}).for_function("instantiator", |f| { f
.for_variable("d", |v| { v
.assert_parser_type("auto")
.assert_concrete_type("Result<Result<s8,s32>,Result<s16,s64>>");
});
});
}
|