github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/tests/while.c (about) 1 #include "tests.h" 2 #include <assert.h> 3 #include <ctype.h> 4 #include <stdio.h> 5 6 typedef float* triangle; 7 8 int getNumberToken(char a[], int* cursor) 9 { 10 int value = 0; 11 assert((*cursor) >= 0 && (*cursor) < strlen(a)); 12 do { 13 value = value * 10 + (int)(a[*cursor]) - (int)('0'); 14 (*cursor)++; 15 } while (isdigit(a[*cursor])); 16 return value; 17 } 18 19 int main() 20 { 21 plan(10); 22 23 int value = 1; 24 25 while (value <= 3) { 26 pass("value is %d", value); 27 value++; 28 } 29 30 // continue 31 value = 0; 32 while (value < 3) { 33 value++; 34 if (value < 3) 35 continue; 36 pass("%d", value); 37 } 38 39 diag("while without body"); 40 while (0) 41 ; 42 pass("%s", "while without body"); 43 44 value = 1; 45 while ((value--, value)) 46 ; 47 is_eq(value, 0); 48 49 diag("while with star"); 50 { 51 int* ok; 52 int value2; 53 ok = &value2; 54 *ok = 1; 55 int counter = 0; 56 do { 57 counter++; 58 if (counter > 10) { 59 break; 60 } 61 if (counter < 10) { 62 break; 63 } 64 *ok = *ok - 1; 65 } while (*ok); 66 is_eq(*ok, 1); 67 } 68 69 diag("while with --"); 70 { 71 int T = 2; 72 int counter = 0; 73 while (T--) { 74 if (counter > 50) { 75 break; 76 } 77 }; 78 is_eq(T, -1); 79 } 80 diag("while in triangle"); 81 { 82 float f = 87.76; 83 triangle* newtriangle; 84 triangle value[50]; 85 for (int y; y < 50; y++) { 86 value[y] = (triangle)(&f); 87 } 88 newtriangle = &value; 89 int counter = 0; 90 do { 91 counter++; 92 if (counter > 10) { 93 break; 94 } 95 if (counter < 10) { 96 break; 97 } 98 } while ((newtriangle)[counter] == (triangle)NULL); 99 is_eq(counter, 1); 100 } 101 102 int v = 3; 103 int res = getNumberToken("my test string", &v); 104 is_eq(res, 68); 105 106 done_testing(); 107 }