aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/do_while.sh
blob: dbb4815db17b768871742c627763796be2a67f01 (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
cat <<'EOF' > expected
body 0
foo 1
body 1
foo 2
body 2
foo 3
body 3
foo 4
body 4
foo 5
EOF
test_diff <<'EOF'
int printf();

int foo(int i) {
    printf("foo %d\n", i);
    return i;
}

int main() {
    int i = 0;
    do {
        printf("body %d\n", i);
        ++i;
    } while (foo(i) < 5);

    return 0;
}
EOF

cat <<'EOF' > expected
body 0
foo 1
body 1
foo 2
body 2
EOF
test_diff <<'EOF'
int printf();

int foo(int i) {
    printf("foo %d\n", i);
    return i;
}

int main() {
    int i = 0;
    do {
        printf("body %d\n", i);
        ++i;
        if (i == 3) {
            break;
        }
    } while (foo(i) < 5);

    return 0;
}
EOF

cat <<'EOF' > expected
body 1
foo 1
foo 2
body 3
foo 3
foo 4
body 5
foo 5
EOF
test_diff <<'EOF'
int printf();

int foo(int i) {
    printf("foo %d\n", i);
    return i;
}

int main() {
    int i = 0;
    do {
        ++i;
        if (i % 2 == 0) {
            continue;
        }
        printf("body %d\n", i);
    } while (foo(i) < 5);

    return 0;
}
EOF