aboutsummaryrefslogtreecommitdiff
path: root/lib/test/string.c
blob: 725d5479574626c0902b69faa6b0a4d4670b71ec (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
#include "../string.h"
#include <assert.h>

static const char *dec = "12341234";
static const char *neg_dec = "-12341234";
static const char *u32_hex = "decafade";
static const char *i32_hex = "7fffffff";
static char buffer[64];

int
main()
{
  { // utoa
    char *r;

    r = utoa(buffer, 12341234u, 10);
    for (unsigned i = 0; dec[i] != '\0'; ++i) assert(r[i] == dec[i]);

    r = utoa(buffer, 0xdecafade, 16);
    for (unsigned i = 0; u32_hex[i] != '\0'; ++i) assert(r[i] == u32_hex[i]);
  }
  { // itoa
    char *r;

    r = itoa(buffer, 12341234, 10);
    for (unsigned i = 0; dec[i] != '\0'; ++i) assert(r[i] == dec[i]);

    r = itoa(buffer, -12341234, 10);
    for (unsigned i = 0; neg_dec[i] != '\0'; ++i) assert(r[i] == neg_dec[i]);

    r = itoa(buffer, 0x7fffffff, 16);
    for (unsigned i = 0; i32_hex[i] != '\0'; ++i) assert(r[i] == i32_hex[i]);
  }
}