hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

types.ha (1254B)


      1 // License: MPL-2.0
      2 // (c) 2021 Drew DeVault <sir@cmpwn.com>
      3 
      4 @test fn struct_union() void = {
      5 	roundtrip("export type foo = struct {
      6 	@offset(void) x: int,
      7 	y: int,
      8 };
      9 
     10 export type bar = union {
     11 	x: int,
     12 	// docs docs docs
     13 	y: int,
     14 };
     15 
     16 export type baz = struct {
     17 	embedded,
     18 	struct {
     19 		x: int,
     20 		y: int,
     21 	},
     22 };
     23 ");
     24 };
     25 
     26 @test fn array_slice() void = {
     27 	roundtrip("export type foo = []int;
     28 
     29 export type bar = [*]int;
     30 
     31 export type baz = [_]int;
     32 
     33 export type bat = [void]int;
     34 ");
     35 };
     36 
     37 @test fn enum_type() void = {
     38 	roundtrip("export type foo = enum {
     39 	X = void,
     40 	// foo
     41 	// bar
     42 	Y = void,
     43 	Z, // foo
     44 	Q, // bar
     45 };
     46 
     47 export type bar = enum uint {
     48 	X = void,
     49 	Y = void,
     50 	Z,
     51 	Q,
     52 };
     53 
     54 export type baz = enum rune {
     55 	X = void,
     56 	Y = void,
     57 	Z,
     58 	Q,
     59 };
     60 ");
     61 };
     62 
     63 @test fn tuple() void = {
     64 	roundtrip("export type foo = (int, str);
     65 
     66 export type bar = (a, b::c, d);
     67 
     68 export type baz = (bat, foo::bar::baz, long_type_name, yet_another_very_long_type_name,
     69 	this_spans_multiple_lines, for_readability);
     70 ");
     71 };
     72 
     73 @test fn tagged_union() void = {
     74 	roundtrip("export type foo = (size | void);
     75 
     76 export type bar = (a | b::c | ...d);
     77 
     78 export type baz = (bat | foo::bar::baz | long_type_name | yet_another_very_long_type_name |
     79 	this_spans_multiple_lines | for_readability);
     80 ");
     81 };