scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 7fd464216a0a7b9b257ac939e5e3368b0708f6c2
parent 63e5f14bd7ab8c139c9d7ba6c27e47fd56ef4286
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Thu, 30 Apr 2026 21:57:28 +0200

tests/libc: Add 0080-atoi

Diffstat:
Mtests/libc/execute/.gitignore | 1+
Atests/libc/execute/0080-atoi.c | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/libc/execute/libc-tests.lst | 1+
3 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore @@ -78,3 +78,4 @@ test.log 0077-setlocale 0078-time 0079-atof +0080-atoi diff --git a/tests/libc/execute/0080-atoi.c b/tests/libc/execute/0080-atoi.c @@ -0,0 +1,63 @@ +#include <assert.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> + +/* +output: +testing +done +end: +*/ + +void +test(void) +{ + int n; + char buf[64]; + + n = atoi("abc"); + assert(n == 0); + + n = atoi(" abc"); + assert(n == 0); + + n = atoi("1234 "); + assert(n == 1234); + + n = atoi(" 1234 0"); + assert(n == 1234); + + n = atoi("+"); + assert(n == 0); + + n = atoi(" +1"); + assert(n == 1); + + n = atoi("+ 1"); + assert(n == 0); + + n = atoi(" -1"); + assert(n == -1); + + n = atoi("- 1"); + assert(n == 0); + + sprintf(buf, "%d", INT_MAX); + n = atoi(buf); + assert(n == INT_MAX); + + sprintf(buf, "%d", INT_MIN); + n = atoi(buf); + assert(n == INT_MIN); +} + +int +main() +{ + puts("testing"); + test(); + puts("done"); + + return 0; +} diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst @@ -76,3 +76,4 @@ 0077-setlocale 0078-time 0079-atof [TODO] +0080-atoi