aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/test_cast_expressions.sh
blob: f6824ada59fb4bbf4d70e3b05209325c260133d1 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
cat <<'EOF' > expected
65
65
127
1
42
99
10
EOF
test_diff <<'EOF'
int printf(const char*, ...);

int main() {
    char c = 65;
    int i = (int)c;
    printf("%d\n", i);

    int i2 = 321;
    char c2 = (char)i2;
    printf("%d\n", c2);

    short s = 127;
    int i3 = (int)s;
    printf("%d\n", i3);

    int i4 = 65537;
    short s2 = (short)i4;
    printf("%d\n", s2);

    long l = 42;
    int i5 = (int)l;
    printf("%d\n", i5);

    int i6 = 99;
    long l2 = (long)i6;
    printf("%d\n", (int)l2);

    char c3 = 10;
    short s3 = (short)c3;
    int i7 = (int)s3;
    long l3 = (long)i7;
    printf("%d\n", (int)l3);

    return 0;
}
EOF

cat <<'EOF' > expected
Result: 130
EOF
test_diff <<'EOF'
int printf(const char*, ...);

int main() {
    char c = 65;
    int result = (int)c + (int)c;
    printf("Result: %d\n", result);
    return 0;
}
EOF

cat <<'EOF' > expected
10
20
30
EOF
test_diff <<'EOF'
int printf(const char*, ...);

int main() {
    char a = 5;
    char b = 5;
    int sum = (int)a + (int)b;
    printf("%d\n", sum);

    short s1 = 10;
    short s2 = 10;
    int sum2 = (int)s1 + (int)s2;
    printf("%d\n", sum2);

    long l1 = 15;
    long l2 = 15;
    int sum3 = (int)(l1 + l2);
    printf("%d\n", sum3);

    return 0;
}
EOF

cat <<'EOF' > expected
10
EOF
test_diff <<'EOF'
int printf(const char*, ...);

int main() {
    char c = -10;
    int i = (int)c;
    printf("%d\n", -i);
    return 0;
}
EOF

cat <<'EOF' > expected
Char: 65
Int: 65
EOF
test_diff <<'EOF'
int printf(const char*, ...);

char get_char() {
    return 65;
}

int main() {
    char c = get_char();
    int i = (int)get_char();
    printf("Char: %d\n", c);
    printf("Int: %d\n", i);
    return 0;
}
EOF

cat <<'EOF' > expected
Equal
EOF
test_diff <<'EOF'
int printf(const char*, ...);

int main() {
    char c = 42;
    int i = 42;
    if ((int)c == i) {
        printf("Equal\n");
    } else {
        printf("Not equal\n");
    }
    return 0;
}
EOF

cat <<'EOF' > expected
55
EOF
test_diff <<'EOF'
int printf(const char*, ...);

int main() {
    long l = 55;
    char c = (char)(short)(int)l;
    printf("%d\n", c);
    return 0;
}
EOF