format
This commit is contained in:
parent
32c38751b9
commit
d3a4391ae9
2 changed files with 66 additions and 53 deletions
13
Makefile
13
Makefile
|
@ -29,13 +29,7 @@ libtoml.a: toml.o
|
|||
libtoml.so.$(LIB_VERSION): toml.o
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
toml_json: toml_json.c $(LIB)
|
||||
|
||||
toml_cat: toml_cat.c $(LIB)
|
||||
|
||||
toml_sample: toml_sample.c $(LIB)
|
||||
|
||||
|
||||
$(EXEC): $(LIB)
|
||||
|
||||
install: all
|
||||
install -d ${prefix}/include ${prefix}/lib
|
||||
|
@ -50,4 +44,7 @@ clean:
|
|||
rm -f *.o $(EXEC) $(LIB) $(LIB_SHARED)
|
||||
|
||||
|
||||
.PHONY: all clean install
|
||||
format:
|
||||
clang-format -i $(shell find . -name '*.[ch]')
|
||||
|
||||
.PHONY: all clean install format
|
||||
|
|
|
@ -1,56 +1,72 @@
|
|||
#include <stdio.h>
|
||||
#include "../toml.h"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "../toml.h"
|
||||
|
||||
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
int main(int argc, const char *argv[]) {
|
||||
char xxbuf[6], buf[6];
|
||||
int64_t xxcode, code;
|
||||
int xxsize;
|
||||
|
||||
|
||||
xxsize = 2, xxcode = 0x80; memcpy(xxbuf, "\xc2\x80", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
||||
xxsize = 2, xxcode = 0x80;
|
||||
memcpy(xxbuf, "\xc2\x80", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&
|
||||
0 == memcmp(buf, xxbuf, xxsize));
|
||||
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||
|
||||
xxsize = 2, xxcode = 0x7ff; memcpy(xxbuf, "\xdf\xbf", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
||||
xxsize = 2, xxcode = 0x7ff;
|
||||
memcpy(xxbuf, "\xdf\xbf", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&
|
||||
0 == memcmp(buf, xxbuf, xxsize));
|
||||
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||
|
||||
xxsize = 3, xxcode = 0x800; memcpy(xxbuf, "\xe0\xa0\x80", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
||||
xxsize = 3, xxcode = 0x800;
|
||||
memcpy(xxbuf, "\xe0\xa0\x80", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&
|
||||
0 == memcmp(buf, xxbuf, xxsize));
|
||||
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||
|
||||
xxsize = 3, xxcode = 0xfffd; memcpy(xxbuf, "\xef\xbf\xbd", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
||||
xxsize = 3, xxcode = 0xfffd;
|
||||
memcpy(xxbuf, "\xef\xbf\xbd", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&
|
||||
0 == memcmp(buf, xxbuf, xxsize));
|
||||
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||
|
||||
xxsize = 4, xxcode = 0x10000; memcpy(xxbuf, "\xf0\x90\x80\x80", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
||||
xxsize = 4, xxcode = 0x10000;
|
||||
memcpy(xxbuf, "\xf0\x90\x80\x80", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&
|
||||
0 == memcmp(buf, xxbuf, xxsize));
|
||||
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||
|
||||
xxsize = 4, xxcode = 0x1fffff; memcpy(xxbuf, "\xf7\xbf\xbf\xbf", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
||||
xxsize = 4, xxcode = 0x1fffff;
|
||||
memcpy(xxbuf, "\xf7\xbf\xbf\xbf", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&
|
||||
0 == memcmp(buf, xxbuf, xxsize));
|
||||
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||
|
||||
xxsize = 5, xxcode = 0x200000; memcpy(xxbuf, "\xf8\x88\x80\x80\x80", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
||||
xxsize = 5, xxcode = 0x200000;
|
||||
memcpy(xxbuf, "\xf8\x88\x80\x80\x80", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&
|
||||
0 == memcmp(buf, xxbuf, xxsize));
|
||||
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||
|
||||
xxsize = 5, xxcode = 0x3ffffff; memcpy(xxbuf, "\xfb\xbf\xbf\xbf\xbf", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
||||
xxsize = 5, xxcode = 0x3ffffff;
|
||||
memcpy(xxbuf, "\xfb\xbf\xbf\xbf\xbf", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&
|
||||
0 == memcmp(buf, xxbuf, xxsize));
|
||||
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||
|
||||
xxsize = 6, xxcode = 0x4000000; memcpy(xxbuf, "\xfc\x84\x80\x80\x80\x80", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
||||
xxsize = 6, xxcode = 0x4000000;
|
||||
memcpy(xxbuf, "\xfc\x84\x80\x80\x80\x80", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&
|
||||
0 == memcmp(buf, xxbuf, xxsize));
|
||||
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||
|
||||
xxsize = 6, xxcode = 0x7fffffff; memcpy(xxbuf, "\xfd\xbf\xbf\xbf\xbf\xbf", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
||||
xxsize = 6, xxcode = 0x7fffffff;
|
||||
memcpy(xxbuf, "\xfd\xbf\xbf\xbf\xbf\xbf", xxsize);
|
||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize &&
|
||||
0 == memcmp(buf, xxbuf, xxsize));
|
||||
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue