/// 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{ int field }" ).for_struct("Integer", |s| { s .assert_num_monomorphs(0); }); Tester::new_single_source_expect_ok( "single polymorph", " struct Number{ T number } int instantiator() { auto a = Number{ number: 0 }; auto b = Number{ number: 1 }; auto c = Number{ number: 2 }; auto d = Number{ number: 3 }; auto e = Number>{ number: Number{ number: 4 }}; return 0; } " ).for_struct("Number", |s| { s .assert_has_monomorph("byte") .assert_has_monomorph("short") .assert_has_monomorph("int") .assert_has_monomorph("long") .assert_has_monomorph("Number") .assert_num_monomorphs(5); }).for_function("instantiator", |f| { f .for_variable("a", |v| {v.assert_concrete_type("Number");} ) .for_variable("e", |v| {v.assert_concrete_type("Number>");} ); }); } #[test] fn test_enum_monomorphs() { Tester::new_single_source_expect_ok( "no polymorph", " enum Answer{ Yes, No } int do_it() { auto a = Answer::Yes; return 0; } " ).for_enum("Answer", |e| { e .assert_num_monomorphs(0); }); Tester::new_single_source_expect_ok( "single polymorph", " enum Answer { Yes, No } int instantiator() { auto a = Answer::Yes; auto b = Answer::No; auto c = Answer::Yes; auto d = Answer>>::No; return 0; } " ).for_enum("Answer", |e| { e .assert_num_monomorphs(3) .assert_has_monomorph("byte") .assert_has_monomorph("int") .assert_has_monomorph("Answer>"); }); } #[test] fn test_union_monomorphs() { Tester::new_single_source_expect_ok( "no polymorph", " union Trinary { Undefined, Value(boolean) } int do_it() { auto a = Trinary::Value(true); return 0; } " ).for_union("Trinary", |e| { e .assert_num_monomorphs(0); }); // TODO: Does this do what we want? Or do we expect the embedded monomorph // Result to be instantiated as well? I don't think so. Tester::new_single_source_expect_ok( "polymorphs", " union Result{ Ok(T), Err(E) } int instantiator() { short a_short = 5; auto a = Result::Ok(0); auto b = Result::Ok(true); auto c = Result, Result>::Err(Result::Ok(5)); auto d = Result, auto>::Err(Result::Ok(a_short)); return 0; } " ).for_union("Result", |e| { e .assert_num_monomorphs(4) .assert_has_monomorph("byte;bool") .assert_has_monomorph("bool;byte") .assert_has_monomorph("Result;Result") .assert_has_monomorph("short;long"); }).for_function("instantiator", |f| { f .for_variable("d", |v| { v .assert_parser_type("auto") .assert_concrete_type("Result,Result>"); }); }); }