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
|
libtoml.so.$(LIB_VERSION): toml.o
|
||||||
$(CC) -shared -o $@ $^
|
$(CC) -shared -o $@ $^
|
||||||
|
|
||||||
toml_json: toml_json.c $(LIB)
|
$(EXEC): $(LIB)
|
||||||
|
|
||||||
toml_cat: toml_cat.c $(LIB)
|
|
||||||
|
|
||||||
toml_sample: toml_sample.c $(LIB)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
install -d ${prefix}/include ${prefix}/lib
|
install -d ${prefix}/include ${prefix}/lib
|
||||||
|
@ -50,4 +44,7 @@ clean:
|
||||||
rm -f *.o $(EXEC) $(LIB) $(LIB_SHARED)
|
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 <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.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];
|
char xxbuf[6], buf[6];
|
||||||
int64_t xxcode, code;
|
int64_t xxcode, code;
|
||||||
int xxsize;
|
int xxsize;
|
||||||
|
|
||||||
|
xxsize = 2, xxcode = 0x80;
|
||||||
xxsize = 2, xxcode = 0x80; memcpy(xxbuf, "\xc2\x80", xxsize);
|
memcpy(xxbuf, "\xc2\x80", xxsize);
|
||||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, 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);
|
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||||
|
|
||||||
xxsize = 2, xxcode = 0x7ff; memcpy(xxbuf, "\xdf\xbf", xxsize);
|
xxsize = 2, xxcode = 0x7ff;
|
||||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
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);
|
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||||
|
|
||||||
xxsize = 3, xxcode = 0x800; memcpy(xxbuf, "\xe0\xa0\x80", xxsize);
|
xxsize = 3, xxcode = 0x800;
|
||||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
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);
|
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||||
|
|
||||||
xxsize = 3, xxcode = 0xfffd; memcpy(xxbuf, "\xef\xbf\xbd", xxsize);
|
xxsize = 3, xxcode = 0xfffd;
|
||||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
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);
|
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||||
|
|
||||||
xxsize = 4, xxcode = 0x10000; memcpy(xxbuf, "\xf0\x90\x80\x80", xxsize);
|
xxsize = 4, xxcode = 0x10000;
|
||||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
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);
|
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||||
|
|
||||||
xxsize = 4, xxcode = 0x1fffff; memcpy(xxbuf, "\xf7\xbf\xbf\xbf", xxsize);
|
xxsize = 4, xxcode = 0x1fffff;
|
||||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
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);
|
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||||
|
|
||||||
xxsize = 5, xxcode = 0x200000; memcpy(xxbuf, "\xf8\x88\x80\x80\x80", xxsize);
|
xxsize = 5, xxcode = 0x200000;
|
||||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
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);
|
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||||
|
|
||||||
xxsize = 5, xxcode = 0x3ffffff; memcpy(xxbuf, "\xfb\xbf\xbf\xbf\xbf", xxsize);
|
xxsize = 5, xxcode = 0x3ffffff;
|
||||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
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);
|
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||||
|
|
||||||
xxsize = 6, xxcode = 0x4000000; memcpy(xxbuf, "\xfc\x84\x80\x80\x80\x80", xxsize);
|
xxsize = 6, xxcode = 0x4000000;
|
||||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
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);
|
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||||
|
|
||||||
xxsize = 6, xxcode = 0x7fffffff; memcpy(xxbuf, "\xfd\xbf\xbf\xbf\xbf\xbf", xxsize);
|
xxsize = 6, xxcode = 0x7fffffff;
|
||||||
assert(toml_ucs_to_utf8(xxcode, buf) == xxsize && 0 == memcmp(buf, xxbuf, xxsize));
|
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);
|
assert(toml_utf8_to_ucs(buf, xxsize, &code) == xxsize && code == xxcode);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue