diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-01-08 23:10:30 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-01-09 01:29:43 +0900 |
| commit | 1e89f9ff938ed458e8be8904bb29b7ced406f9d5 (patch) | |
| tree | e92a832c6b409542017985ad9b423037fcfb721c /tests | |
| parent | dbbaf84db126bc9b72c50987aa724b923f6f52f3 (diff) | |
| download | ducc-1e89f9ff938ed458e8be8904bb29b7ced406f9d5.tar.gz ducc-1e89f9ff938ed458e8be8904bb29b7ced406f9d5.tar.zst ducc-1e89f9ff938ed458e8be8904bb29b7ced406f9d5.zip | |
feat: support seven or more parameters/arguments
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/function_basics.c | 43 | ||||
| -rw-r--r-- | tests/helpers.h | 2 | ||||
| -rw-r--r-- | tests/run.sh | 2 |
3 files changed, 45 insertions, 2 deletions
diff --git a/tests/function_basics.c b/tests/function_basics.c index f02384c..1d79ad7 100644 --- a/tests/function_basics.c +++ b/tests/function_basics.c @@ -1,5 +1,8 @@ #include <helpers.h> +int sprintf(char*, const char*, ...); +int strcmp(const char*, const char*); + int foo() { int i; int ret; @@ -38,6 +41,36 @@ int f6(int a, int b, int c, int d, int e, int f) { return f; } +int f7(int select, int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) { + switch (select) { + case 0: + return a; + case 1: + return b; + case 2: + return c; + case 3: + return d; + case 4: + return e; + case 5: + return f; + case 6: + return g; + case 7: + return h; + case 8: + return i; + case 9: + return j; + } +} + +char* f8(char* buf, int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) { + sprintf(buf, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", a, b, c, d, e, f, g, h, i, j); + return buf; +} + int main() { ASSERT_EQ(66, foo()); ASSERT_EQ(10, 10 * f(1, 2, 3, 4, 5, 6)); @@ -46,4 +79,14 @@ int main() { ASSERT_EQ(40, 10 * f4(1, 2, 3, 4, 5, 6)); ASSERT_EQ(50, 10 * f5(1, 2, 3, 4, 5, 6)); ASSERT_EQ(60, 10 * f6(1, 2, 3, 4, 5, 6)); + + ASSERT_EQ(1, f7(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + ASSERT_EQ(2, f7(1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + ASSERT_EQ(6, f7(5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + ASSERT_EQ(7, f7(6, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + ASSERT_EQ(8, f7(7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + ASSERT_EQ(10, f7(9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + + char buf[100]; + ASSERT_EQ(0, strcmp("1,2,3,4,5,6,7,8,9,10", f8(buf, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10))); } diff --git a/tests/helpers.h b/tests/helpers.h index f8affe7..39274e4 100644 --- a/tests/helpers.h +++ b/tests/helpers.h @@ -10,7 +10,7 @@ extern FILE* stderr; #define ASSERT(a, file, line) \ do { \ if (!(a)) { \ - fprintf(stderr, "%s:%d: assert failed", file, line); \ + fprintf(stderr, "%s:%d: assert failed\n", file, line); \ exit(1); \ } \ } while (0) diff --git a/tests/run.sh b/tests/run.sh index 0835d9a..6b3bb00 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -14,7 +14,7 @@ if [[ -f "$c_test_file" ]]; then echo "$c_test_file" mkdir -p "$tmp_dir" cd "$tmp_dir" - test_exit_code < "../../../$c_test_file" + test_exit_code 0 < "../../../$c_test_file" cd "../../.." elif [[ -f "$sh_test_file" ]]; then source tests/helpers.sh |
