aboutsummaryrefslogtreecommitdiffstats
path: root/tests/variables.bad
diff options
context:
space:
mode:
Diffstat (limited to 'tests/variables.bad')
-rw-r--r--tests/variables.bad53
1 files changed, 27 insertions, 26 deletions
diff --git a/tests/variables.bad b/tests/variables.bad
index 88e04d1..34293dc 100644
--- a/tests/variables.bad
+++ b/tests/variables.bad
@@ -11,10 +11,11 @@ set c = (1 + 2 - 3)
11 11
12; Struct definitions. 12; Struct definitions.
13struct vec { 13struct vec {
14 x: f32 14 x: f64
15 y: f32 15 y: f64
16 z: f32 16 z: f64
17} 17}
18let v = vec : { x = 2.0 y = 3.0 }
18 19
19; Default values are allowed, including const expressions. 20; Default values are allowed, including const expressions.
20struct person { 21struct person {
@@ -28,41 +29,41 @@ set player_a.name = "alex"
28set player_a.age = 32 29set player_a.age = 32
29let player_b = player_a 30let player_b = player_a
30 31
31; Anonymous structs can also be declared inline.
32let user: { id: u64 name: str }
33set user.id = 10
34set user.name = "haxor"
35
36; We can have anonymous struct fields. 32; We can have anonymous struct fields.
37struct entity { 33struct entity {
38 pos: vec 34 pos: vec
39 vel: vec 35 vel: vec
40 attr: { 36 ; TODO: ...
41 id: u64 37 ; attr: {
42 name: str 38 ; id: u64
43 } 39 ; name: str
40 ; }
44} 41}
45 42
46; Symbols followed by curly braces output struct literals. 43; Symbols followed by curly braces output struct literals.
47let particle = entity : { 44let particle = entity : {
48 ; Two ways of initializing inner fields. 45 ; Two ways of initializing inner fields.
49 pos = vec : { x = 1 y = 2 } 46 pos = vec : { x = 1.0 y = 2.0 }
50 attr.id = 1 47 ; TODO: Get rid of this, unnecessary complexity on the implementation, let's
51 attr.name = "particle" 48 ; just do the top option.
49 ; attr.id = 1
50 ; attr.name = "particle"
52 51
53 ; Missing initialization fields default to zero. 52 ; Missing initialization fields default to zero.
54 vel = vec : { y = -3 } 53 vel = vec : { y = -3.0 }
55} 54}
55; let particle = entity : {}
56; TODO: Now we can get rid of parenthesis on if/while statements
56 57
57; We can have static arrays and have indexed access. 58; ; We can have static arrays and have indexed access.
58let numbers: u32[0xff] 59; let numbers: u32[0xff]
59set numbers[0] = 32 60; set numbers[0] = 32
60set numbers[1] = 42 61; set numbers[1] = 42
61 62
62; Arrays are syntactic sugar for pointers (@). 63; ; Arrays are syntactic sugar for pointers (@).
63let ptr:@u32 = numbers 64; let ptr:@u32 = numbers
64set ptr[10] = 33 65; set ptr[10] = 33
65 66
66; Strings hold a .mem and .size fields with the number of bytes it holds. 67; ; Strings hold a .mem and .size fields with the number of bytes it holds.
67let hello: str = "hello world" 68; let hello: str = "hello world"
68set c[1] = 'a' ; "hallo world" 69; set c[1] = 'a' ; "hallo world"