harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

24-imports.ha (2195B)


      1 use rt;
      2 use testmod;
      3 
      4 fn _enum() void = {
      5 	assert(testmod::other::EIGHT == 8);
      6 	assert(testmod::char_enum::ONE == 1);
      7 };
      8 
      9 fn accept() void = {
     10 	assert(rt::compile("
     11 		use testmod;
     12 		export fn main() void = static assert(testmod::val == 42);
     13 	") == rt::EXIT_SUCCESS);
     14 	assert(rt::compile("
     15 		use testmod;
     16 		use alias = testmod;
     17 		export fn main() void = static assert(testmod::val == alias::val);
     18 	") == rt::EXIT_SUCCESS);
     19 	assert(rt::compile("
     20 		use testmod;
     21 		use testmod::{val, val2};
     22 		export fn main() void = static assert(
     23 			testmod::val == val && testmod::val2 == val2
     24 		);
     25 	") == rt::EXIT_SUCCESS);
     26 	assert(rt::compile("
     27 		use testmod;
     28 		use testmod::*;
     29 		export fn main() void = static assert(
     30 			testmod::val == val && testmod::val2 == val2
     31 		);
     32 	") == rt::EXIT_SUCCESS);
     33 	assert(rt::compile("
     34 		use testmod;
     35 		use testmod::{alias = val, val2};
     36 		export fn main() void = static assert(
     37 			testmod::val == alias && testmod::val2 == val2
     38 		);
     39 	") == rt::EXIT_SUCCESS);
     40 	assert(rt::compile("
     41 		use testmod;
     42 		use modalias = testmod::{valalias = val, val2};
     43 		export fn main() void = static assert(
     44 			testmod::val == modalias::valalias && testmod::val2 == modalias::val2
     45 		);
     46 	") == rt::EXIT_SUCCESS);
     47 };
     48 
     49 fn reject() void = {
     50 	assert(rt::compile("
     51 		use wrong;
     52 		export fn main() void = { testmod::val };
     53 	") == rt::EXIT_FAILURE);
     54 	assert(rt::compile("
     55 		use testmod::{val};
     56 		export fn main() void = static assert(
     57 			testmod::val == 42
     58 		);
     59 	") == rt::EXIT_FAILURE);
     60 	assert(rt::compile("
     61 		use testmod::{val};
     62 		export fn main() void = static assert(
     63 			val2 == 90
     64 		);
     65 	") == rt::EXIT_FAILURE);
     66 	assert(rt::compile("
     67 		use testmod;
     68 		use test = testmod::*;
     69 		export fn main() void = void;
     70 	") == rt::EXIT_FAILURE);
     71 	assert(rt::compile("
     72 		use testmod;
     73 		use testmod*;
     74 		export fn main() void = void;
     75 	") == rt::EXIT_FAILURE);
     76 	assert(rt::compile("
     77 		use testmod::{alias = val, val2};
     78 		export fn main() void = static assert(val == 42);
     79 	") == rt::EXIT_FAILURE);
     80 	assert(rt::compile("
     81 		use modalias = testmod::{valalias = val, val2};
     82 		export fn main() void = static assert(valalias == 42);
     83 	") == rt::EXIT_FAILURE);
     84 };
     85 
     86 
     87 export fn main() void = {
     88 	_enum();
     89 	accept();
     90 	reject();
     91 };