Skip to content

Commit 4ea7313

Browse files
committed
Expand short type test coverage
Add comprehensive test cases for short data type operations across multiple categories in the test suite. - Add short variable assignment and arithmetic tests - Include short pointer operations and dereferencing - Add short array operations and compound assignments - Expand compound literal tests with short type support - Add short function parameters and return values Test suite now validates short type functionality across all major language features and both target architectures.
1 parent 6f72fb8 commit 4ea7313

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

tests/driver.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ declare -a variable_tests=(
476476
"10 int var; var = 10; return var;"
477477
"42 int va; int vb; va = 11; vb = 31; int vc; vc = va + vb; return vc;"
478478
"50 int v; v = 30; v = 50; return v;"
479+
"25 short s; s = 25; return s;"
480+
"50 short sa = 20; short sb = 30; short sc = sa + sb; return sc;"
479481
)
480482

481483
run_items_tests variable_tests
@@ -493,6 +495,14 @@ int main() {
493495
}
494496
EOF
495497

498+
try_ 42 << EOF
499+
typedef struct { short x; short y; } point_t;
500+
int main() {
501+
point_t p = {42, 100};
502+
return p.x;
503+
}
504+
EOF
505+
496506
try_ 100 << EOF
497507
typedef struct { int x; int y; } point_t;
498508
int main() {
@@ -620,6 +630,15 @@ int main() {
620630
}
621631
EOF
622632

633+
# Test: Array compound literal assigned to scalar short (non-standard)
634+
try_ 100 << EOF
635+
int main() {
636+
/* Non-standard: Assigns first element of array to scalar short */
637+
short x = (short[]){100, 200, 300};
638+
return x;
639+
}
640+
EOF
641+
623642
# Test: Array compound literal in arithmetic expression
624643
try_ 150 << EOF
625644
int main() {
@@ -630,6 +649,16 @@ int main() {
630649
}
631650
EOF
632651

652+
# Test: Array compound literal in arithmetic expression
653+
try_ 150 << EOF
654+
int main() {
655+
short a = 50;
656+
/* Non-standard: Uses first element (100) in addition */
657+
short b = a + (short[]){100, 200};
658+
return b;
659+
}
660+
EOF
661+
633662
# Test: Mixed scalar and array compound literals
634663
try_ 35 << EOF
635664
int main() {
@@ -905,6 +934,17 @@ int test_function() {
905934
}
906935
EOF
907936

937+
# Test function with short parameters and return type
938+
try_ 35 << EOF
939+
short add_shorts(short a, short b) {
940+
return a + b;
941+
}
942+
943+
int main() {
944+
return add_shorts(15, 20);
945+
}
946+
EOF
947+
908948
# Test other large values
909949
try_large 1000 << EOF
910950
int test_function() {
@@ -998,6 +1038,7 @@ items 3 "int x; int *y; x = 3; y = &x; return y[0];"
9981038
items 5 "int b; int *a; b = 10; a = &b; a[0] = 5; return b;"
9991039
items 2 "int x[2]; int y; x[1] = 2; y = *(x + 1); return y;"
10001040
items 2 "int x; int *y; int z; z = 2; y = &z; x = *y; return x;"
1041+
items 2 "short x; short *y; short z; z = 2; y = &z; x = *y; return x;"
10011042

10021043
# pointer dereference immediately after declaration
10031044
items 42 "int x; x = 10; int *p; p = &x; p[0] = 42; exit(x);"
@@ -1464,6 +1505,35 @@ int main() {
14641505
}
14651506
EOF
14661507

1508+
# Test short pointer
1509+
try_ 150 << EOF
1510+
int main() {
1511+
short value = 150;
1512+
short *ptr = &value;
1513+
return *ptr;
1514+
}
1515+
EOF
1516+
1517+
# Test short pointer arithmetic
1518+
try_ 20 << EOF
1519+
int main() {
1520+
short arr[3] = {10, 20, 30};
1521+
short *p = arr;
1522+
p++;
1523+
return *p;
1524+
}
1525+
EOF
1526+
1527+
# Test short pointer difference
1528+
try_ 2 << EOF
1529+
int main() {
1530+
short data[5] = {1, 2, 3, 4, 5};
1531+
short *start = data + 1;
1532+
short *end = data + 3;
1533+
return end - start;
1534+
}
1535+
EOF
1536+
14671537
# Category: Function Pointers
14681538
begin_category "Function Pointers" "Testing function pointer declarations and calls"
14691539

@@ -1525,6 +1595,14 @@ int main() {
15251595
}
15261596
EOF
15271597

1598+
# Test short array
1599+
try_ 25 << EOF
1600+
int main() {
1601+
short arr[4] = {10, 15, 20, 25};
1602+
return arr[3];
1603+
}
1604+
EOF
1605+
15281606
# 2D Array Tests
15291607
# with proper row-major indexing for multi-dimensional arrays
15301608
try_ 78 << EOF
@@ -1986,6 +2064,9 @@ items 4 "int a; a = 2; a <<= 1; return a;"
19862064
items 2 "int a; a = 4; a >>= 1; return a;"
19872065
items 1 "int a; a = 1; a ^= 0; return a;"
19882066
items 20 "int *p; int a[3]; a[0] = 10; a[1] = 20; a[2] = 30; p = a; p+=1; return p[0];"
2067+
items 8 "short s; s = 5; s += 3; return s;"
2068+
items 15 "short s; s = 20; s -= 5; return s;"
2069+
items 24 "short s; s = 6; s *= 4; return s;"
19892070

19902071
# Category: Sizeof Operator
19912072
begin_category "Sizeof Operator" "Testing sizeof operator on various types"
@@ -1994,16 +2075,19 @@ begin_category "Sizeof Operator" "Testing sizeof operator on various types"
19942075
expr 0 "sizeof(void)";
19952076
expr 1 "sizeof(_Bool)";
19962077
expr 1 "sizeof(char)";
2078+
expr 2 "sizeof(short)";
19972079
expr 4 "sizeof(int)";
19982080
# sizeof pointers
19992081
expr 4 "sizeof(void*)";
20002082
expr 4 "sizeof(_Bool*)";
20012083
expr 4 "sizeof(char*)";
2084+
expr 4 "sizeof(short*)";
20022085
expr 4 "sizeof(int*)";
20032086
# sizeof multi-level pointer
20042087
expr 4 "sizeof(void**)";
20052088
expr 4 "sizeof(_Bool**)";
20062089
expr 4 "sizeof(char**)";
2090+
expr 4 "sizeof(short**)";
20072091
expr 4 "sizeof(int**)";
20082092
# sizeof struct
20092093
try_ 4 << EOF
@@ -4974,6 +5058,15 @@ EOF
49745058
# Type Casting Tests
49755059
echo "Testing type casting functionality..."
49765060

5061+
declare -a cast_tests=(
5062+
"42 int var; var = (int)42; return var;"
5063+
"10 int var; var = (short)10; return var;"
5064+
"5 short s; s = (short)5; return s;"
5065+
"20 short s; s = (int)20; return s;"
5066+
"15 short sa = 10; short sb = (short)5; return sa + sb;"
5067+
"30 int ia = 10; int ib = (int)20; return ia + ib;"
5068+
)
5069+
49775070
# Basic int to char cast
49785071
try_ 65 << EOF
49795072
int main() {

0 commit comments

Comments
 (0)