ndtypes 0.2.0dev4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +50 -0
  3. data/Gemfile +2 -0
  4. data/History.md +0 -0
  5. data/README.md +19 -0
  6. data/Rakefile +125 -0
  7. data/ext/ruby_ndtypes/extconf.rb +55 -0
  8. data/ext/ruby_ndtypes/gc_guard.c +36 -0
  9. data/ext/ruby_ndtypes/gc_guard.h +12 -0
  10. data/ext/ruby_ndtypes/ndtypes/AUTHORS.txt +5 -0
  11. data/ext/ruby_ndtypes/ndtypes/INSTALL.txt +101 -0
  12. data/ext/ruby_ndtypes/ndtypes/LICENSE.txt +29 -0
  13. data/ext/ruby_ndtypes/ndtypes/MANIFEST.in +3 -0
  14. data/ext/ruby_ndtypes/ndtypes/Makefile.in +87 -0
  15. data/ext/ruby_ndtypes/ndtypes/README.rst +47 -0
  16. data/ext/ruby_ndtypes/ndtypes/config.guess +1530 -0
  17. data/ext/ruby_ndtypes/ndtypes/config.h.in +67 -0
  18. data/ext/ruby_ndtypes/ndtypes/config.sub +1782 -0
  19. data/ext/ruby_ndtypes/ndtypes/configure +5260 -0
  20. data/ext/ruby_ndtypes/ndtypes/configure.ac +161 -0
  21. data/ext/ruby_ndtypes/ndtypes/doc/Makefile +14 -0
  22. data/ext/ruby_ndtypes/ndtypes/doc/_static/copybutton.js +66 -0
  23. data/ext/ruby_ndtypes/ndtypes/doc/conf.py +26 -0
  24. data/ext/ruby_ndtypes/ndtypes/doc/grammar/grammar.rst +27 -0
  25. data/ext/ruby_ndtypes/ndtypes/doc/index.rst +56 -0
  26. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/context.rst +131 -0
  27. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/encodings.rst +68 -0
  28. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/fields-values.rst +175 -0
  29. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/functions.rst +72 -0
  30. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/index.rst +43 -0
  31. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/init.rst +48 -0
  32. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/io.rst +100 -0
  33. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/memory.rst +124 -0
  34. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/predicates.rst +110 -0
  35. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/typedef.rst +31 -0
  36. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/types.rst +594 -0
  37. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/util.rst +166 -0
  38. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/buffer-protocol.rst +27 -0
  39. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/index.rst +21 -0
  40. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/pattern-matching.rst +330 -0
  41. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/quickstart.rst +144 -0
  42. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/types.rst +544 -0
  43. data/ext/ruby_ndtypes/ndtypes/doc/releases/index.rst +35 -0
  44. data/ext/ruby_ndtypes/ndtypes/install-sh +527 -0
  45. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.in +271 -0
  46. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.vc +269 -0
  47. data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.c +230 -0
  48. data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.c +268 -0
  49. data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.h +109 -0
  50. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.in +73 -0
  51. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.vc +70 -0
  52. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/README.txt +16 -0
  53. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.c +2179 -0
  54. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.h +134 -0
  55. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.y +428 -0
  56. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.c +2543 -0
  57. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.h +735 -0
  58. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.l +176 -0
  59. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.c +543 -0
  60. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.c +110 -0
  61. data/ext/ruby_ndtypes/ndtypes/libndtypes/context.c +228 -0
  62. data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.c +634 -0
  63. data/ext/ruby_ndtypes/ndtypes/libndtypes/encodings.c +116 -0
  64. data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.c +288 -0
  65. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.c +3067 -0
  66. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.h +180 -0
  67. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.y +417 -0
  68. data/ext/ruby_ndtypes/ndtypes/libndtypes/io.c +1658 -0
  69. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.c +2773 -0
  70. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.h +734 -0
  71. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.l +222 -0
  72. data/ext/ruby_ndtypes/ndtypes/libndtypes/match.c +1132 -0
  73. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.c +2323 -0
  74. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h.in +893 -0
  75. data/ext/ruby_ndtypes/ndtypes/libndtypes/overflow.h +161 -0
  76. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.c +473 -0
  77. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.h +92 -0
  78. data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.c +246 -0
  79. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.c +269 -0
  80. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.h +197 -0
  81. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.in +48 -0
  82. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.vc +46 -0
  83. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.c +1007 -0
  84. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.c +442 -0
  85. data/ext/ruby_ndtypes/ndtypes/libndtypes/slice.h +42 -0
  86. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.c +238 -0
  87. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.h +50 -0
  88. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.c +371 -0
  89. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.h +100 -0
  90. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.in +55 -0
  91. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.vc +45 -0
  92. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.c +82 -0
  93. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.h +49 -0
  94. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/runtest.c +1657 -0
  95. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test.h +85 -0
  96. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_array.c +115 -0
  97. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_buffer.c +137 -0
  98. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_indent.c +201 -0
  99. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_match.c +2397 -0
  100. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_numba.c +57 -0
  101. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse.c +349 -0
  102. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_error.c +27839 -0
  103. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_roundtrip.c +350 -0
  104. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_record.c +231 -0
  105. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typecheck.c +375 -0
  106. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typedef.c +65 -0
  107. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/valgrind.supp +30 -0
  108. data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/bench.c +79 -0
  109. data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/indent.c +94 -0
  110. data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/print_ast.c +96 -0
  111. data/ext/ruby_ndtypes/ndtypes/libndtypes/util.c +474 -0
  112. data/ext/ruby_ndtypes/ndtypes/libndtypes/values.c +228 -0
  113. data/ext/ruby_ndtypes/ndtypes/python/bench.py +49 -0
  114. data/ext/ruby_ndtypes/ndtypes/python/ndt_randtype.py +409 -0
  115. data/ext/ruby_ndtypes/ndtypes/python/ndt_support.py +14 -0
  116. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/__init__.py +70 -0
  117. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/_ndtypes.c +1332 -0
  118. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/docstrings.h +319 -0
  119. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/pyndtypes.h +154 -0
  120. data/ext/ruby_ndtypes/ndtypes/python/test_ndtypes.py +1977 -0
  121. data/ext/ruby_ndtypes/ndtypes/setup.py +288 -0
  122. data/ext/ruby_ndtypes/ndtypes/vcbuild/INSTALL.txt +41 -0
  123. data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest32.bat +15 -0
  124. data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest64.bat +13 -0
  125. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild32.bat +38 -0
  126. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild64.bat +38 -0
  127. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcclean.bat +13 -0
  128. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcdistclean.bat +14 -0
  129. data/ext/ruby_ndtypes/ruby_ndtypes.c +1003 -0
  130. data/ext/ruby_ndtypes/ruby_ndtypes.h +37 -0
  131. data/ext/ruby_ndtypes/ruby_ndtypes_internal.h +28 -0
  132. data/lib/ndtypes.rb +45 -0
  133. data/lib/ndtypes/errors.rb +2 -0
  134. data/lib/ndtypes/version.rb +6 -0
  135. data/ndtypes.gemspec +47 -0
  136. data/spec/gc_table_spec.rb +10 -0
  137. data/spec/ndtypes_spec.rb +289 -0
  138. data/spec/spec_helper.rb +241 -0
  139. metadata +242 -0
@@ -0,0 +1,85 @@
1
+ /*
2
+ * BSD 3-Clause License
3
+ *
4
+ * Copyright (c) 2017-2018, plures
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
14
+ * this list of conditions and the following disclaimer in the documentation
15
+ * and/or other materials provided with the distribution.
16
+ *
17
+ * 3. Neither the name of the copyright holder nor the names of its
18
+ * contributors may be used to endorse or promote products derived from
19
+ * this software without specific prior written permission.
20
+ *
21
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+
34
+ #ifndef TEST_H
35
+ #define TEST_H
36
+
37
+
38
+ #include "ndtypes.h"
39
+
40
+
41
+ typedef struct {
42
+ const char *input;
43
+ const char *indented;
44
+ } indent_testcase_t;
45
+
46
+ typedef struct {
47
+ const char *pattern;
48
+ const char *candidate;
49
+ int expected;
50
+ } match_testcase_t;
51
+
52
+ typedef struct {
53
+ const char *signature;
54
+ const char *in[128];
55
+ const char *out[128];
56
+ const char *broadcast[128];
57
+ int outer_dims;
58
+ bool success;
59
+ } typecheck_testcase_t;
60
+
61
+ typedef struct {
62
+ const char *signature;
63
+ const char *sig;
64
+ const char *core;
65
+ } numba_testcase_t;
66
+
67
+ extern const char *parse_tests[];
68
+ extern const char *parse_tests[];
69
+ extern const char *parse_roundtrip_tests[];
70
+ extern const char *parse_error_tests[];
71
+ extern const indent_testcase_t indent_tests[];
72
+ extern const char *typedef_tests[];
73
+ extern const char *typedef_error_tests[];
74
+ extern const match_testcase_t match_tests[];
75
+ extern const typecheck_testcase_t typecheck_tests[];
76
+ extern const numba_testcase_t numba_tests[];
77
+ extern const char *buffer_tests[];
78
+ extern const char *buffer_roundtrip_tests[];
79
+ extern const char *buffer_error_tests[];
80
+
81
+ int test_struct_align_pack(void);
82
+ int test_array(void);
83
+
84
+
85
+ #endif /* TEST_H */
@@ -0,0 +1,115 @@
1
+ /*
2
+ * BSD 3-Clause License
3
+ *
4
+ * Copyright (c) 2017-2018, plures
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
14
+ * this list of conditions and the following disclaimer in the documentation
15
+ * and/or other materials provided with the distribution.
16
+ *
17
+ * 3. Neither the name of the copyright holder nor the names of its
18
+ * contributors may be used to endorse or promote products derived from
19
+ * this software without specific prior written permission.
20
+ *
21
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+
34
+ #include <stdio.h>
35
+ #include <stdlib.h>
36
+ #include <stdint.h>
37
+ #include <inttypes.h>
38
+ #include <stdalign.h>
39
+ #include <stddef.h>
40
+ #include <string.h>
41
+ #include <assert.h>
42
+ #include "ndtypes.h"
43
+ #include "test.h"
44
+
45
+
46
+ #ifdef __clang__
47
+ #pragma clang diagnostic ignored "-Wgnu-alignof-expression"
48
+ #endif
49
+
50
+
51
+ /*********************************************************************/
52
+ /* nested arrays */
53
+ /*********************************************************************/
54
+
55
+ #ifdef __GNUC__
56
+ typedef struct {
57
+ uint8_t data[2][3][10];
58
+ } nested_1;
59
+
60
+ typedef struct {
61
+ ndt_complex64_t data[3][7];
62
+ } nested_2;
63
+
64
+ typedef struct {
65
+ nested_1 a;
66
+ nested_2 b;
67
+ } struct_1;
68
+
69
+ static struct_1 array_1[10][3];
70
+
71
+ static const char *type_array_1 =
72
+ "10 * 3 * { a: 2 * 3 * 10 * ?uint8, b: 3 * 7 * ?complex64 }";
73
+
74
+ int
75
+ test_array(void)
76
+ {
77
+ ndt_context_t *ctx;
78
+ ndt_t *t;
79
+
80
+ ctx = ndt_context_new();
81
+ if (ctx == NULL) {
82
+ fprintf(stderr, "error: out of memory");
83
+ return -1;
84
+ }
85
+
86
+ t = ndt_from_string(type_array_1, ctx);
87
+ if (t == NULL) {
88
+ fprintf(stderr, "test_struct_align_pack: parse: FAIL: %s\n",
89
+ ndt_context_msg(ctx));
90
+ ndt_context_del(ctx);
91
+ return -1;
92
+ }
93
+ if (ndt_is_abstract(t)) {
94
+ fprintf(stderr,
95
+ "test_struct_align_pack: parse: FAIL: unexpected abstract type\n");
96
+ ndt_context_del(ctx);
97
+ return -1;
98
+ }
99
+
100
+ (void)array_1;
101
+ if (t->datasize != sizeof(array_1)) {
102
+ fprintf(stderr, "test_array: array_1: FAIL: %" PRIi64 " %zu", t->datasize, sizeof(array_1));
103
+ }
104
+ else {
105
+ fprintf(stderr, "test_array (1 test case)\n");
106
+ }
107
+
108
+ ndt_del(t);
109
+ ndt_context_del(ctx);
110
+
111
+ return 0;
112
+ }
113
+ #endif
114
+
115
+
@@ -0,0 +1,137 @@
1
+ /*
2
+ * BSD 3-Clause License
3
+ *
4
+ * Copyright (c) 2017-2018, plures
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
14
+ * this list of conditions and the following disclaimer in the documentation
15
+ * and/or other materials provided with the distribution.
16
+ *
17
+ * 3. Neither the name of the copyright holder nor the names of its
18
+ * contributors may be used to endorse or promote products derived from
19
+ * this software without specific prior written permission.
20
+ *
21
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+
34
+ #include <stdio.h>
35
+ #include "test.h"
36
+
37
+
38
+ const char *buffer_tests[] = {
39
+ "?",
40
+ "c", "b", "B",
41
+ "h", "i", "l", "q",
42
+ "H", "I", "L", "Q",
43
+ "n", "N",
44
+ "e", "f", "d",
45
+ "E", "F", "D",
46
+ "s", "100s",
47
+ "T{b:a:100s:b:}",
48
+
49
+
50
+ "(10,2)?",
51
+ "(10)c",
52
+ "(2,3)b",
53
+ "(0,2,0)B",
54
+ "(1,2,3,4)h",
55
+ "(2,3,10)F",
56
+ "(20,2,100)D",
57
+ "(10,2)s",
58
+ "(10,2)100s",
59
+ "(10,2)T{b:a:100s:b:}",
60
+ "(10,2)T{b:a:100s:b:}",
61
+
62
+ "T{T{F:foo:(2,3)L:bar:}:a:100s:b:}",
63
+
64
+ "f -> f",
65
+ "ff -> f",
66
+ "fc -> f",
67
+ "F -> Q",
68
+
69
+ "T{b:a:100s:b:} -> T{T{F:foo:(2,3)L:bar:}:a:100s:b:}",
70
+
71
+ NULL
72
+ };
73
+
74
+ const char *buffer_roundtrip_tests[] = {
75
+ "=b", "<b", ">b",
76
+ "=B", "<B", ">B",
77
+ "=h", "<H", ">B",
78
+ "=i", "<I", ">I",
79
+ "=q", "<q", ">q",
80
+ "=H", "<H", ">H",
81
+ "=I", "<I", ">I",
82
+ "=Q", "<Q", ">Q",
83
+ "=e", "<e", ">e",
84
+ "=f", "<f", ">f",
85
+ "=d", "<d", ">d",
86
+ "=E", "<E", ">E",
87
+ "=F", "<F", ">F",
88
+ "=D", "<D", ">D",
89
+
90
+ "(2)=Q",
91
+ "(2)<Q",
92
+ "(2)>Q",
93
+ "(2,3)=Q",
94
+ "(2,3)<Q",
95
+ "(2,3)>Q",
96
+ "(2,3,4)=Q",
97
+ "(2,3,4)<Q",
98
+ "(2,3,4)>Q",
99
+
100
+ "T{=b:a:100s:b:}",
101
+ "T{T{=F:foo:(2,3)=I:bar:}:a:100s:b:}",
102
+
103
+ NULL
104
+ };
105
+
106
+ const char *buffer_error_tests[] = {
107
+ "&",
108
+ "Ze",
109
+ "Zf",
110
+ "Zd",
111
+ "O", "O",
112
+ "T{O:a:100O:b:}",
113
+
114
+ "(2,3)T{f:a:=0s:b:}",
115
+
116
+ "{10,2)f",
117
+ "({,2)f",
118
+ "(10{2)f",
119
+ "(10,{)f",
120
+ "(10,2}f",
121
+ "(10,2}}",
122
+
123
+ "(10,2)T{{:a:100s:b:}",
124
+ "(10,2)T{b{a:100s:b:}",
125
+ "(10,2)T{b:{:100s:b:}",
126
+ "(10,2)T{b:a:{:b:}",
127
+ "(10,2)T{b:a:100{:b:}",
128
+ "(10,2)T{b:a:100s{b:}",
129
+ "(10,2)T{b:a:100s:{:}",
130
+ "(10,2)T{b:a:100s:b{}",
131
+ "(10,2)T{b:a:100s:b:{",
132
+ "(10,2)T{b:a:100s:b:}}",
133
+
134
+ "T{T{F:foo:(2,3)%:bar:}:a:100s:b:}",
135
+
136
+ NULL
137
+ };
@@ -0,0 +1,201 @@
1
+ /*
2
+ * BSD 3-Clause License
3
+ *
4
+ * Copyright (c) 2017-2018, plures
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
14
+ * this list of conditions and the following disclaimer in the documentation
15
+ * and/or other materials provided with the distribution.
16
+ *
17
+ * 3. Neither the name of the copyright holder nor the names of its
18
+ * contributors may be used to endorse or promote products derived from
19
+ * this software without specific prior written permission.
20
+ *
21
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+
34
+ #include <stdio.h>
35
+ #include "test.h"
36
+
37
+
38
+ const indent_testcase_t indent_tests[] = {
39
+ {
40
+ "\
41
+ {battingpost: 100 * {yearID: ?int32, round: ?string, playerID: ?string, teamID: ?string, lgID: (?string, int64, 5 * 10 * {a: complex128, b: ?int32}), G: ?int32, AB: ?int32, R: ?int32, H: (int32, 10 * int32), HR: {a: 10 * float64, b: 10 * int32}, RBI: ?int32, SB: ?int32, CS: ?int32, BB: ?int32, SO: ?int32, IBB: ?int32, HBP: ?int32, SH: ?int32, SF: ?int32, GIDP: ?int32, AString: fixed_string(100,'utf32'), BString: fixed_string(100), CBytes: bytes(align=16), DBytes: fixed_bytes(size=1600, align=16)}, awardsmanagers: 10 * {managerID: ?string, awardID: ?string, yearID: ?int32, lgID: ?string, tie: ?string, notes: ?string}, hofold: 10 * {hofID: ?string, yearid: ?int32, votedBy: ?string, ballots: ?int32, votes: ?int32, inducted: ?string, category: ?string}, salaries: 10 * {yearID: ?int32, teamID: ?string, lgID: ?string, playerID: ?string, salary: ?float64}, pitchingpost: 10 * {playerID: ?string, yearID: ?int32, round: ?string, teamID: ?string, lgID: ?string, W: ?int32, L: ?int32, G: ?int32, GS: ?int32, CG: ?int32, SHO: ?int32, SV: ?int32, IPouts: ?int32, H: ?int32, ER: ?int32, HR: ?int32, BB: ?int32, SO: ?int32, BAOpp: ?float64, ERA: ?float64, IBB: ?int32, WP: ?int32, HBP: ?int32, BK: ?int32, BFP: ?int32, GF: ?int32, R: ?int32, SH: ?int32, SF: ?int32, GIDP: ?int32}, managers: 10 * {managerID: ?string, yearID: ?int32, teamID: ?string, lgID: ?string, inseason: ?int32, G: ?int32, W: ?int32, L: ?int32, rank: ?int32, plyrMgr: ?string}, teams: 10 * {yearID: ?int32, lgID: ?string, teamID: ?string, franchID: ?string, divID: ?string, Rank: ?int32, G: ?int32, Ghome: ?int32, W: ?int32, L: ?int32, DivWin: ?string, WCWin: ?string, LgWin: ?string, WSWin: ?string, R: ?int32, AB: ?int32, H: ?int32, B: ?int32, B: ?int32, HR: ?int32, BB: ?int32, SO: ?int32, SB: ?int32, CS: ?int32, HBP: ?int32, SF: ?int32, RA: ?int32, ER: ?int32, ERA: ?float64, CG: ?int32, SHO: ?int32, SV: ?int32, IPouts: ?int32, HA: ?int32, HRA: ?int32, BBA: ?int32, SOA: ?int32, E: ?int32, DP: ?int32, FP: ?float64, name: ?string, park: ?string, attendance: ?int32, BPF: ?int32, PPF: ?int32, teamIDBR: ?string, teamIDlahman45: ?string, teamIDretro: ?string}}\
42
+ ",
43
+
44
+ "\
45
+ {\n\
46
+ battingpost : 100 * {\n\
47
+ yearID : ?int32,\n\
48
+ round : ?string,\n\
49
+ playerID : ?string,\n\
50
+ teamID : ?string,\n\
51
+ lgID : (?string, int64, 5 * 10 * {\n\
52
+ a : complex128,\n\
53
+ b : ?int32\n\
54
+ }),\n\
55
+ G : ?int32,\n\
56
+ AB : ?int32,\n\
57
+ R : ?int32,\n\
58
+ H : (int32, 10 * int32),\n\
59
+ HR : {\n\
60
+ a : 10 * float64,\n\
61
+ b : 10 * int32\n\
62
+ },\n\
63
+ RBI : ?int32,\n\
64
+ SB : ?int32,\n\
65
+ CS : ?int32,\n\
66
+ BB : ?int32,\n\
67
+ SO : ?int32,\n\
68
+ IBB : ?int32,\n\
69
+ HBP : ?int32,\n\
70
+ SH : ?int32,\n\
71
+ SF : ?int32,\n\
72
+ GIDP : ?int32,\n\
73
+ AString : fixed_string(100, 'utf32'),\n\
74
+ BString : fixed_string(100),\n\
75
+ CBytes : bytes(align=16),\n\
76
+ DBytes : fixed_bytes(size=1600, align=16)\n\
77
+ },\n\
78
+ awardsmanagers : 10 * {\n\
79
+ managerID : ?string,\n\
80
+ awardID : ?string,\n\
81
+ yearID : ?int32,\n\
82
+ lgID : ?string,\n\
83
+ tie : ?string,\n\
84
+ notes : ?string\n\
85
+ },\n\
86
+ hofold : 10 * {\n\
87
+ hofID : ?string,\n\
88
+ yearid : ?int32,\n\
89
+ votedBy : ?string,\n\
90
+ ballots : ?int32,\n\
91
+ votes : ?int32,\n\
92
+ inducted : ?string,\n\
93
+ category : ?string\n\
94
+ },\n\
95
+ salaries : 10 * {\n\
96
+ yearID : ?int32,\n\
97
+ teamID : ?string,\n\
98
+ lgID : ?string,\n\
99
+ playerID : ?string,\n\
100
+ salary : ?float64\n\
101
+ },\n\
102
+ pitchingpost : 10 * {\n\
103
+ playerID : ?string,\n\
104
+ yearID : ?int32,\n\
105
+ round : ?string,\n\
106
+ teamID : ?string,\n\
107
+ lgID : ?string,\n\
108
+ W : ?int32,\n\
109
+ L : ?int32,\n\
110
+ G : ?int32,\n\
111
+ GS : ?int32,\n\
112
+ CG : ?int32,\n\
113
+ SHO : ?int32,\n\
114
+ SV : ?int32,\n\
115
+ IPouts : ?int32,\n\
116
+ H : ?int32,\n\
117
+ ER : ?int32,\n\
118
+ HR : ?int32,\n\
119
+ BB : ?int32,\n\
120
+ SO : ?int32,\n\
121
+ BAOpp : ?float64,\n\
122
+ ERA : ?float64,\n\
123
+ IBB : ?int32,\n\
124
+ WP : ?int32,\n\
125
+ HBP : ?int32,\n\
126
+ BK : ?int32,\n\
127
+ BFP : ?int32,\n\
128
+ GF : ?int32,\n\
129
+ R : ?int32,\n\
130
+ SH : ?int32,\n\
131
+ SF : ?int32,\n\
132
+ GIDP : ?int32\n\
133
+ },\n\
134
+ managers : 10 * {\n\
135
+ managerID : ?string,\n\
136
+ yearID : ?int32,\n\
137
+ teamID : ?string,\n\
138
+ lgID : ?string,\n\
139
+ inseason : ?int32,\n\
140
+ G : ?int32,\n\
141
+ W : ?int32,\n\
142
+ L : ?int32,\n\
143
+ rank : ?int32,\n\
144
+ plyrMgr : ?string\n\
145
+ },\n\
146
+ teams : 10 * {\n\
147
+ yearID : ?int32,\n\
148
+ lgID : ?string,\n\
149
+ teamID : ?string,\n\
150
+ franchID : ?string,\n\
151
+ divID : ?string,\n\
152
+ Rank : ?int32,\n\
153
+ G : ?int32,\n\
154
+ Ghome : ?int32,\n\
155
+ W : ?int32,\n\
156
+ L : ?int32,\n\
157
+ DivWin : ?string,\n\
158
+ WCWin : ?string,\n\
159
+ LgWin : ?string,\n\
160
+ WSWin : ?string,\n\
161
+ R : ?int32,\n\
162
+ AB : ?int32,\n\
163
+ H : ?int32,\n\
164
+ B : ?int32,\n\
165
+ B : ?int32,\n\
166
+ HR : ?int32,\n\
167
+ BB : ?int32,\n\
168
+ SO : ?int32,\n\
169
+ SB : ?int32,\n\
170
+ CS : ?int32,\n\
171
+ HBP : ?int32,\n\
172
+ SF : ?int32,\n\
173
+ RA : ?int32,\n\
174
+ ER : ?int32,\n\
175
+ ERA : ?float64,\n\
176
+ CG : ?int32,\n\
177
+ SHO : ?int32,\n\
178
+ SV : ?int32,\n\
179
+ IPouts : ?int32,\n\
180
+ HA : ?int32,\n\
181
+ HRA : ?int32,\n\
182
+ BBA : ?int32,\n\
183
+ SOA : ?int32,\n\
184
+ E : ?int32,\n\
185
+ DP : ?int32,\n\
186
+ FP : ?float64,\n\
187
+ name : ?string,\n\
188
+ park : ?string,\n\
189
+ attendance : ?int32,\n\
190
+ BPF : ?int32,\n\
191
+ PPF : ?int32,\n\
192
+ teamIDBR : ?string,\n\
193
+ teamIDlahman45 : ?string,\n\
194
+ teamIDretro : ?string\n\
195
+ }\n\
196
+ }\
197
+ " },
198
+
199
+ { NULL, NULL }
200
+ };
201
+