summary refs log tree commit diff
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2020-09-28 14:35:07 +0200
committersternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2020-09-28 14:35:07 +0200
commite40c0e7d75df7922dd24fd5d756cd7f907035545 (patch)
treeaf3a766afbcf92bf58a397541ae620d80ff2f71a
parentf07be4b0307934cd69500fa5eeb412c20e6cb697 (diff)
feat(emitjson): support more int types
-rw-r--r--warteraum/emitjson.c16
-rw-r--r--warteraum/emitjson.h16
-rw-r--r--warteraum/test/test_emitjson.c57
3 files changed, 79 insertions, 10 deletions
diff --git a/warteraum/emitjson.c b/warteraum/emitjson.c
index 70b61b9..bfbd323 100644
--- a/warteraum/emitjson.c
+++ b/warteraum/emitjson.c
@@ -167,5 +167,19 @@ void ej_bool(struct ej_context *ctx, bool b) {
   }
 
 EJ_INT_FUN(ej_uint, unsigned int, false)
-
 EJ_INT_FUN(ej_int, int, true)
+
+EJ_INT_FUN(ej_long_long, long long int, true)
+EJ_INT_FUN(ej_long, long int, true)
+EJ_INT_FUN(ej_ulong, unsigned long int, false)
+EJ_INT_FUN(ej_ulong_long, unsigned long long int, false)
+
+EJ_INT_FUN(ej_int8, int8_t, true)
+EJ_INT_FUN(ej_int16, int16_t, true)
+EJ_INT_FUN(ej_int32, int32_t, true)
+EJ_INT_FUN(ej_int64, int64_t, true)
+
+EJ_INT_FUN(ej_uint8, uint8_t, false)
+EJ_INT_FUN(ej_uint16, uint16_t, false)
+EJ_INT_FUN(ej_uint32, uint32_t, false)
+EJ_INT_FUN(ej_uint64, uint64_t, false)
diff --git a/warteraum/emitjson.h b/warteraum/emitjson.h
index 0e6f673..1f59bf3 100644
--- a/warteraum/emitjson.h
+++ b/warteraum/emitjson.h
@@ -2,6 +2,7 @@
 #define WARTERAUM_EMITJSON_H
 
 #include <stdbool.h>
+#include <stdint.h>
 
 struct ej_context {
   FILE *out;
@@ -33,4 +34,19 @@ void ej_bool(struct ej_context *, bool);
 void ej_int(struct ej_context *, int);
 void ej_uint(struct ej_context *, unsigned int);
 
+void ej_long(struct ej_context *, long int);
+void ej_ulong(struct ej_context *, unsigned long int);
+void ej_long_long(struct ej_context *, long long int);
+void ej_ulong_long(struct ej_context *, unsigned long long int);
+
+void ej_uint8(struct ej_context *, uint8_t);
+void ej_uint16(struct ej_context *, uint16_t);
+void ej_uint32(struct ej_context *, uint32_t);
+void ej_uint64(struct ej_context *, uint64_t);
+
+void ej_int8(struct ej_context *, int8_t);
+void ej_int16(struct ej_context *, int16_t);
+void ej_int32(struct ej_context *, int32_t);
+void ej_int64(struct ej_context *, int64_t);
+
 #endif
diff --git a/warteraum/test/test_emitjson.c b/warteraum/test/test_emitjson.c
index 1f51adc..d12bd75 100644
--- a/warteraum/test/test_emitjson.c
+++ b/warteraum/test/test_emitjson.c
@@ -18,24 +18,63 @@ int main(int argc, char **argv) {
   ej_init(&ctx, out);
 
   ej_object(&ctx);
-  EJ_STATIC_BIND(&ctx, "array");
+
+  EJ_STATIC_BIND(&ctx, "bools and stuff");
   ej_array(&ctx);
-  ej_uint(&ctx, 25500001);
-  ej_int(&ctx, -12000);
-  ej_int(&ctx, 10000);
-  ej_string(&ctx, "foo\tbar\nbaz\\", 12);
+  ej_bool(&ctx, true);
+  ej_bool(&ctx, false);
   ej_null(&ctx);
+  ej_array_end(&ctx);
+
+  EJ_STATIC_BIND(&ctx, "strings");
+  ej_array(&ctx);
+  ej_string(&ctx, "foo\tbar\nbaz", 11);
+  ej_string(&ctx, "form\ffeed", 9);
+  ej_string(&ctx, "🤭 unicode 😳", 17);
+  ej_array_end(&ctx);
+
+  EJ_STATIC_BIND(&ctx, "objects");
+  ej_array(&ctx);
   ej_object(&ctx);
   ej_bind(&ctx, "hello", 5);
   ej_string(&ctx, "world", 5);
-  ej_bind(&ctx, "foo\\", 4);
+  ej_bind(&ctx, "foo\r\nbar", 7);
   ej_uint(&ctx, 42);
   ej_object_end(&ctx);
-  ej_bool(&ctx, true);
-  ej_bool(&ctx, false);
+  ej_object(&ctx);
+  ej_object_end(&ctx);
   ej_array_end(&ctx);
-  EJ_STATIC_BIND(&ctx, "number");
+
+  EJ_STATIC_BIND(&ctx, "numbers");
+  ej_array(&ctx);
   ej_uint(&ctx, 1312);
+  ej_uint(&ctx, 25500001);
+  ej_int(&ctx, -12000);
+  ej_int(&ctx, 10000);
+  ej_long(&ctx, -50000);
+  ej_ulong(&ctx, 18340983094);
+  ej_long_long(&ctx, 129302193092);
+  ej_ulong_long(&ctx, 129302193092);
+
+  ej_int8(&ctx, INT8_MAX);
+  ej_int8(&ctx, INT8_MIN);
+  ej_int16(&ctx, INT16_MAX);
+  ej_int16(&ctx, INT16_MIN);
+  ej_int32(&ctx, INT32_MAX);
+  ej_int32(&ctx, INT32_MIN);
+  ej_int64(&ctx, INT64_MAX);
+  ej_int64(&ctx, INT64_MIN);
+
+  ej_uint8(&ctx, UINT8_MAX);
+  ej_uint8(&ctx, 0);
+  ej_uint16(&ctx, UINT16_MAX);
+  ej_uint16(&ctx, 0);
+  ej_uint32(&ctx, UINT32_MAX);
+  ej_uint32(&ctx, 0);
+  ej_uint64(&ctx, UINT64_MAX);
+  ej_uint64(&ctx, 0);
+
+  ej_array_end(&ctx);
   ej_object_end(&ctx);
 
   fclose(out);