aboutsummaryrefslogtreecommitdiff
path: root/tests/variables.sh
blob: 0c88784ea1b84a9a9f6964404efaa2ddc9a584f2 (plain) (blame)
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
#!/bin/bash

. tests/common.sh

set -e

echo -n "- One variable: "
assert_exit_status 'fn main() { let x: int; x = 45; return x; }' 45
assert_exit_status 'fn main() { let x: int = 45; return x; }' 45
assert_exit_status 'fn main() { let x: int = 45; return x+x; }' 90

assert_exit_status_stdin 5 <<EOF
fn main() { 
    let x: int;
    x = 3;
    x = 5;
    return x;  
}
EOF

assert_exit_status_stdin 5 <<EOF
fn main() { 
    let x: int = 3;
    x = x + x - 1;
    return x;  
}
EOF

echo " OK"

echo -n "- Multiple variable: "

assert_exit_status_stdin 2 <<EOF
fn main() { 
    let x: int = 1;
    let y: int = x + x;
    return y;  
}
EOF

assert_exit_status_stdin 23 <<EOF
fn main() { 
    let x: int = 1;
    let y: int = x + x;
    let z: int = y + y;
    let w: int = z + z;
    let r: int = w + w;
    return r + x + y + z;  
}
EOF

assert_exit_status_stdin 2 <<EOF
fn main() { 
    let x: int = 1;
    let y: int = x + x;
    y = y + x;
    x = (x + x) * y;
    return x / y;  
}
EOF

echo " OK"