mkrf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +2 -0
  2. data/MIT-LICENSE +7 -0
  3. data/README +54 -0
  4. data/Rakefile +107 -0
  5. data/lib/mkrf.rb +4 -0
  6. data/lib/mkrf/availability.rb +219 -0
  7. data/lib/mkrf/generator.rb +146 -0
  8. data/test/abstract_unit.rb +4 -0
  9. data/test/fixtures/down_a_directory/header_down_a_directory.h +1 -0
  10. data/test/fixtures/stdmkrf.h +1 -0
  11. data/test/sample_files/libtrivial/Rakefile +31 -0
  12. data/test/sample_files/libtrivial/extconf.rb +3 -0
  13. data/test/sample_files/libtrivial/lib/libtrivial.c +5 -0
  14. data/test/sample_files/libtrivial/lib/libtrivial.o +0 -0
  15. data/test/sample_files/libtrivial/libtrivial_so.bundle +0 -0
  16. data/test/sample_files/libtrivial/mkrf.log +1 -0
  17. data/test/sample_files/libxml-ruby-0.3.8/CHANGELOG +74 -0
  18. data/test/sample_files/libxml-ruby-0.3.8/LICENSE +22 -0
  19. data/test/sample_files/libxml-ruby-0.3.8/README +144 -0
  20. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/cbg.c +76 -0
  21. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/extconf.rb +49 -0
  22. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.c +86 -0
  23. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.h +82 -0
  24. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.rb +107 -0
  25. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log +1 -0
  26. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/old_extconf.rb +95 -0
  27. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.c +372 -0
  28. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.h +21 -0
  29. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.c +224 -0
  30. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.h +21 -0
  31. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.c +1159 -0
  32. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.h +27 -0
  33. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.c +168 -0
  34. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.h +17 -0
  35. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.c +167 -0
  36. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.h +21 -0
  37. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.c +2139 -0
  38. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.h +28 -0
  39. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.c +248 -0
  40. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.h +26 -0
  41. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.c +153 -0
  42. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.h +21 -0
  43. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.c +1417 -0
  44. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.h +31 -0
  45. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.c +715 -0
  46. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.h +22 -0
  47. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.c +426 -0
  48. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.h +52 -0
  49. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.c +142 -0
  50. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.h +16 -0
  51. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.c +43 -0
  52. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.h +12 -0
  53. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.c +20 -0
  54. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.h +13 -0
  55. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.c +363 -0
  56. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.h +24 -0
  57. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.c +125 -0
  58. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.h +24 -0
  59. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.c +100 -0
  60. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.h +27 -0
  61. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.c +21 -0
  62. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.h +18 -0
  63. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/sax_parser_callbacks.inc +202 -0
  64. data/test/sample_files/syck-0.55/CHANGELOG +186 -0
  65. data/test/sample_files/syck-0.55/COPYING +54 -0
  66. data/test/sample_files/syck-0.55/Makefile +582 -0
  67. data/test/sample_files/syck-0.55/Makefile.am +5 -0
  68. data/test/sample_files/syck-0.55/Makefile.in +582 -0
  69. data/test/sample_files/syck-0.55/README +105 -0
  70. data/test/sample_files/syck-0.55/README.BYTECODE +484 -0
  71. data/test/sample_files/syck-0.55/README.EXT +444 -0
  72. data/test/sample_files/syck-0.55/RELEASE +123 -0
  73. data/test/sample_files/syck-0.55/TODO +25 -0
  74. data/test/sample_files/syck-0.55/aclocal.m4 +883 -0
  75. data/test/sample_files/syck-0.55/bootstrap +7 -0
  76. data/test/sample_files/syck-0.55/config.h +79 -0
  77. data/test/sample_files/syck-0.55/config.h.in +78 -0
  78. data/test/sample_files/syck-0.55/config.status +1197 -0
  79. data/test/sample_files/syck-0.55/config/README +14 -0
  80. data/test/sample_files/syck-0.55/config/depcomp +529 -0
  81. data/test/sample_files/syck-0.55/config/install-sh +323 -0
  82. data/test/sample_files/syck-0.55/config/missing +357 -0
  83. data/test/sample_files/syck-0.55/configure +6728 -0
  84. data/test/sample_files/syck-0.55/configure.in +36 -0
  85. data/test/sample_files/syck-0.55/ext/ruby/CHANGELOG +303 -0
  86. data/test/sample_files/syck-0.55/ext/ruby/README +400 -0
  87. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/MANIFEST +1 -0
  88. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/bytecode.c +1170 -0
  89. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/emitter.c +1224 -0
  90. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/extconf.rb +10 -0
  91. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.c +1894 -0
  92. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.h +79 -0
  93. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/handler.c +174 -0
  94. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/implicit.c +2989 -0
  95. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log +1 -0
  96. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/node.c +407 -0
  97. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/rubyext.c +2385 -0
  98. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.c +504 -0
  99. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.h +458 -0
  100. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/token.c +2707 -0
  101. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yaml2byte.c +250 -0
  102. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yamlbyte.h +170 -0
  103. data/test/sample_files/syck-0.55/ext/ruby/install.rb +1022 -0
  104. data/test/sample_files/syck-0.55/ext/ruby/lib/okay.rb +161 -0
  105. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/news.rb +69 -0
  106. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/rpc.rb +434 -0
  107. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml.rb +436 -0
  108. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/baseemitter.rb +247 -0
  109. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/basenode.rb +216 -0
  110. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/compat.rb +26 -0
  111. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/constants.rb +45 -0
  112. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/dbm.rb +111 -0
  113. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/emitter.rb +107 -0
  114. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/encoding.rb +33 -0
  115. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/error.rb +34 -0
  116. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/rubytypes.rb +438 -0
  117. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/store.rb +29 -0
  118. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stream.rb +40 -0
  119. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb +83 -0
  120. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/syck.rb +19 -0
  121. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/tag.rb +86 -0
  122. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/types.rb +188 -0
  123. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/yamlnode.rb +54 -0
  124. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/ypath.rb +52 -0
  125. data/test/sample_files/syck-0.55/ext/ruby/lib/yod.rb +1168 -0
  126. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-modules.rb +27 -0
  127. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-sample.rb +336 -0
  128. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-validate.rb +341 -0
  129. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-client.rb +51 -0
  130. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-server.rb +85 -0
  131. data/test/sample_files/syck-0.55/ext/ruby/samples/yaml-sortHashKeys.rb +128 -0
  132. data/test/sample_files/syck-0.55/ext/ruby/tests/basic.rb +1653 -0
  133. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsAnchorAlias.yml +51 -0
  134. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBasicTests.yml +282 -0
  135. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockMapping.yml +78 -0
  136. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockSequence.yml +0 -0
  137. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsDocumentSeparator.yml +102 -0
  138. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsErrorTests.yml +23 -0
  139. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFlowCollections.yml +73 -0
  140. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFoldedScalars.yml +215 -0
  141. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsMapInSeq.yml +0 -0
  142. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsNullsAndEmpties.yml +66 -0
  143. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsRubyTests.yml +182 -0
  144. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsSpecificationExamples.yml +2699 -0
  145. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsTypeTransfers.yml +265 -0
  146. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsYpath.yml +221 -0
  147. data/test/sample_files/syck-0.55/ext/ruby/yts/cookbook.rb +159 -0
  148. data/test/sample_files/syck-0.55/ext/ruby/yts/index.yml +10 -0
  149. data/test/sample_files/syck-0.55/ext/ruby/yts/yts.rb +193 -0
  150. data/test/sample_files/syck-0.55/lib/Makefile +497 -0
  151. data/test/sample_files/syck-0.55/lib/Makefile.am +27 -0
  152. data/test/sample_files/syck-0.55/lib/Makefile.in +497 -0
  153. data/test/sample_files/syck-0.55/lib/bytecode.c +1170 -0
  154. data/test/sample_files/syck-0.55/lib/bytecode.re +525 -0
  155. data/test/sample_files/syck-0.55/lib/emitter.c +1224 -0
  156. data/test/sample_files/syck-0.55/lib/gram.c +1894 -0
  157. data/test/sample_files/syck-0.55/lib/gram.h +79 -0
  158. data/test/sample_files/syck-0.55/lib/gram.output +2005 -0
  159. data/test/sample_files/syck-0.55/lib/gram.y +481 -0
  160. data/test/sample_files/syck-0.55/lib/handler.c +174 -0
  161. data/test/sample_files/syck-0.55/lib/implicit.c +2989 -0
  162. data/test/sample_files/syck-0.55/lib/implicit.re +206 -0
  163. data/test/sample_files/syck-0.55/lib/node.c +407 -0
  164. data/test/sample_files/syck-0.55/lib/syck.c +504 -0
  165. data/test/sample_files/syck-0.55/lib/syck.h +458 -0
  166. data/test/sample_files/syck-0.55/lib/syck_st.c +577 -0
  167. data/test/sample_files/syck-0.55/lib/syck_st.h +46 -0
  168. data/test/sample_files/syck-0.55/lib/token.c +2707 -0
  169. data/test/sample_files/syck-0.55/lib/token.re +1139 -0
  170. data/test/sample_files/syck-0.55/lib/yaml2byte.c +250 -0
  171. data/test/sample_files/syck-0.55/lib/yamlbyte.h +170 -0
  172. data/test/sample_files/syck-0.55/stamp-h1 +1 -0
  173. data/test/sample_files/syck-0.55/tests/Basic.c +141 -0
  174. data/test/sample_files/syck-0.55/tests/CuTest.c +294 -0
  175. data/test/sample_files/syck-0.55/tests/CuTest.h +84 -0
  176. data/test/sample_files/syck-0.55/tests/Emit.c +87 -0
  177. data/test/sample_files/syck-0.55/tests/Makefile +480 -0
  178. data/test/sample_files/syck-0.55/tests/Makefile.am +13 -0
  179. data/test/sample_files/syck-0.55/tests/Makefile.in +480 -0
  180. data/test/sample_files/syck-0.55/tests/Parse.c +208 -0
  181. data/test/sample_files/syck-0.55/tests/YTS.c +2310 -0
  182. data/test/sample_files/syck-0.55/tests/YTS.c.erb +326 -0
  183. data/test/sample_files/syck-0.55/tests/YTS.c.rb +44 -0
  184. data/test/test_availability.rb +68 -0
  185. data/test/test_generator.rb +74 -0
  186. metadata +252 -0
@@ -0,0 +1,208 @@
1
+ //
2
+ // Parse.c
3
+ //
4
+ // $Author: whythluckystiff $
5
+ // $Date: 2003/07/29 16:54:35 $
6
+ //
7
+ // Copyright (C) 2003 why the lucky stiff
8
+ //
9
+
10
+ #include <string.h>
11
+ #include "syck.h"
12
+ #include "CuTest.h"
13
+
14
+ //
15
+ // 1. Test the buffering -- read 4 bytes at a time
16
+ //
17
+ void
18
+ TestSyckReadString( CuTest *tc )
19
+ {
20
+ SyckParser *parser;
21
+ char *tmp;
22
+ int len = 0;
23
+
24
+ parser = syck_new_parser();
25
+ syck_parser_str_auto( parser, "test: 1\nand: 2\nalso: 3", syck_io_str_read );
26
+
27
+ len = syck_parser_readlen( parser, 4 );
28
+ CuAssert( tc, "Wrong length, line 1.", 4 == len );
29
+ parser->token = parser->buffer + 4;
30
+ tmp = syck_strndup( parser->buffer, len );
31
+ CuAssertStrEquals( tc, "test", tmp );
32
+ free( tmp );
33
+
34
+ len = syck_parser_readlen( parser, 4 );
35
+ CuAssert( tc, "Wrong length, line 2.", 4 == len );
36
+ parser->token = parser->buffer + 4;
37
+ tmp = syck_strndup( parser->buffer, len );
38
+ CuAssertStrEquals( tc, ": 1\n", tmp );
39
+ free( tmp );
40
+
41
+ len = syck_parser_readlen( parser, 4 );
42
+ CuAssert( tc, "Wrong length, line 3.", 4 == len );
43
+ parser->token = parser->buffer + 4;
44
+ tmp = syck_strndup( parser->buffer, len );
45
+ CuAssertStrEquals( tc, "and:", tmp );
46
+ free( tmp );
47
+
48
+ len = syck_parser_readlen( parser, 4 );
49
+ CuAssert( tc, "Wrong length, line 4.", 4 == len );
50
+ parser->token = parser->buffer + 4;
51
+ tmp = syck_strndup( parser->buffer, len );
52
+ CuAssertStrEquals( tc, " 2\na", tmp );
53
+ free( tmp );
54
+
55
+ len = syck_parser_readlen( parser, 4 );
56
+ CuAssert( tc, "Wrong length, line 5.", 4 == len );
57
+ parser->token = parser->buffer + 4;
58
+ tmp = syck_strndup( parser->buffer, len );
59
+ CuAssertStrEquals( tc, "lso:", tmp );
60
+ free( tmp );
61
+
62
+ len = syck_parser_readlen( parser, 4 );
63
+ CuAssert( tc, "Wrong length, line 6.", 2 == len );
64
+ parser->token = parser->buffer + 4;
65
+ tmp = syck_strndup( parser->buffer, len );
66
+ CuAssertStrEquals( tc, " 3", tmp );
67
+ free( tmp );
68
+
69
+ free_any_io( parser );
70
+ syck_free_parser( parser );
71
+ }
72
+
73
+ //
74
+ // 2. Test parsing a simple string and handler
75
+ //
76
+ SYMID
77
+ SyckParseStringHandler( SyckParser *p, SyckNode *n )
78
+ {
79
+ if ( n->kind != syck_str_kind )
80
+ return 100;
81
+
82
+ if ( strcmp( syck_str_read( n ), "a_test_string" ) != 0 )
83
+ return 200;
84
+
85
+ return 1112;
86
+ }
87
+
88
+ void
89
+ TestSyckParseString( CuTest *tc )
90
+ {
91
+ SyckParser *parser;
92
+ SYMID id;
93
+
94
+ parser = syck_new_parser();
95
+ syck_parser_handler( parser, SyckParseStringHandler );
96
+ syck_parser_str_auto( parser, "--- a_test_string", NULL );
97
+
98
+ id = syck_parse( parser );
99
+ CuAssert( tc, "Handler returned incorrect value.", 1112 == id );
100
+
101
+ syck_free_parser( parser );
102
+ }
103
+
104
+ //
105
+ // 3.
106
+ //
107
+ SYMID
108
+ SyckParseString2Handler( SyckParser *p, SyckNode *n )
109
+ {
110
+ if ( n->kind != syck_str_kind )
111
+ return 100;
112
+
113
+ if ( strcmp( syck_str_read( n ), "a_test_string" ) != 0 )
114
+ return 200;
115
+
116
+ return 1112;
117
+ }
118
+
119
+ enum st_retval
120
+ ListAnchors( char *key, SyckNode *n, CuTest *tc )
121
+ {
122
+ char *sd = syck_strndup( n->data.str->ptr, n->data.str->len );
123
+ CuAssertStrEquals( tc, "test", key );
124
+ CuAssertStrEquals( tc, "13", sd );
125
+ free( sd );
126
+ return ST_CONTINUE;
127
+ }
128
+
129
+ void
130
+ TestSyckParseString2( CuTest *tc )
131
+ {
132
+ SyckParser *parser;
133
+ parser = syck_new_parser();
134
+ syck_parser_handler( parser, SyckParseStringHandler );
135
+ syck_parser_str_auto( parser, "--- {test: 1, and: 2, or: &test 13}", NULL );
136
+ syckparse( parser );
137
+ st_foreach( parser->anchors, ListAnchors, tc );
138
+ syck_free_parser( parser );
139
+ }
140
+
141
+ void
142
+ TestSyckParseMap( CuTest *tc )
143
+ {
144
+ SYMID id;
145
+ SyckParser *parser;
146
+ parser = syck_new_parser();
147
+ syck_parser_handler( parser, SyckParseStringHandler );
148
+ syck_parser_str_auto( parser, "\ntest: 1\nand: 2\nor:\n test: 1\n and: 2\n fourdepth:\n deep: 1\nlast: end", NULL );
149
+ syck_parse( parser );
150
+ syck_free_parser( parser );
151
+ }
152
+
153
+ void
154
+ TestSyckParseFold( CuTest *tc )
155
+ {
156
+ SYMID id;
157
+ SyckParser *parser;
158
+ parser = syck_new_parser();
159
+ syck_parser_handler( parser, SyckParseStringHandler );
160
+ syck_parser_str_auto( parser, "\ntest: |\n deep: 1\nlast: end\n \n", NULL );
161
+ syck_parse( parser );
162
+ syck_free_parser( parser );
163
+ }
164
+
165
+ void
166
+ TestSyckParseMultidoc( CuTest *tc )
167
+ {
168
+ SYMID id;
169
+ SyckParser *parser;
170
+ parser = syck_new_parser();
171
+ syck_parser_handler( parser, SyckParseStringHandler );
172
+ syck_parser_str_auto( parser, "---\ntest: |\n deep: 1\n---\nlast: end\n \n", NULL );
173
+ syck_parse( parser );
174
+ syck_parse( parser );
175
+ syck_free_parser( parser );
176
+ }
177
+
178
+ CuSuite *
179
+ SyckGetSuite()
180
+ {
181
+ CuSuite *suite = CuSuiteNew();
182
+ SUITE_ADD_TEST( suite, TestSyckReadString );
183
+ SUITE_ADD_TEST( suite, TestSyckParseString );
184
+ SUITE_ADD_TEST( suite, TestSyckParseString2 );
185
+ SUITE_ADD_TEST( suite, TestSyckParseMap );
186
+ SUITE_ADD_TEST( suite, TestSyckParseFold );
187
+ SUITE_ADD_TEST( suite, TestSyckParseMultidoc );
188
+ return suite;
189
+ }
190
+
191
+ int main(void)
192
+ {
193
+ CuString *output = CuStringNew();
194
+ CuSuite* suite = SyckGetSuite();
195
+ int count;
196
+
197
+ CuSuiteRun(suite);
198
+ CuSuiteSummary(suite, output);
199
+ CuSuiteDetails(suite, output);
200
+
201
+ printf("%s\n", output->buffer);
202
+ count = suite->failCount;
203
+
204
+ CuStringFree( output );
205
+ CuSuiteFree( suite );
206
+
207
+ return count;
208
+ }
@@ -0,0 +1,2310 @@
1
+ //
2
+ // YTS.c
3
+ //
4
+ // $Author: why $
5
+ // $Date: 2005/04/13 06:27:54 $
6
+ //
7
+ // Copyright (C) 2004 why the lucky stiff
8
+ //
9
+ // Well, this is the Yaml Testing Suite in the form of a plain C
10
+ // API. Basically, this is as good as C integration gets for Syck.
11
+ // You've got to have a symbol table around. From there, you can
12
+ // query your data.
13
+ //
14
+
15
+ #include <string.h>
16
+ #include "syck.h"
17
+ #include "CuTest.h"
18
+
19
+ /* YAML test node structures */
20
+ #define T_STR 10
21
+ #define T_SEQ 20
22
+ #define T_MAP 30
23
+ #define T_END 40
24
+ #define ILEN 2
25
+
26
+ struct test_node {
27
+ int type;
28
+ char *tag;
29
+ char *key;
30
+ struct test_node *value;
31
+ };
32
+ struct test_node end_node = { T_END };
33
+
34
+ /*
35
+ * Assertion which compares a YAML document with an
36
+ * equivalent set of test_node structs.
37
+ */
38
+ SYMID
39
+ syck_copy_handler(p, n)
40
+ SyckParser *p;
41
+ SyckNode *n;
42
+ {
43
+ int i = 0;
44
+ struct test_node *tn = S_ALLOC_N( struct test_node, 1 );
45
+
46
+ switch ( n->kind )
47
+ {
48
+ case syck_str_kind:
49
+ tn->type = T_STR;
50
+ tn->key = syck_strndup( n->data.str->ptr, n->data.str->len );
51
+ tn->value = 0;
52
+ break;
53
+
54
+ case syck_seq_kind:
55
+ {
56
+ struct test_node *val;
57
+ struct test_node *seq = S_ALLOC_N( struct test_node, n->data.list->idx + 1 );
58
+ tn->type = T_SEQ;
59
+ tn->key = 0;
60
+ for ( i = 0; i < n->data.list->idx; i++ )
61
+ {
62
+ SYMID oid = syck_seq_read( n, i );
63
+ syck_lookup_sym( p, oid, (char **)&val );
64
+ seq[i] = val[0];
65
+ }
66
+ seq[n->data.list->idx] = end_node;
67
+ tn->value = seq;
68
+ }
69
+ break;
70
+
71
+ case syck_map_kind:
72
+ {
73
+ struct test_node *val;
74
+ struct test_node *map = S_ALLOC_N( struct test_node, ( n->data.pairs->idx * 2 ) + 1 );
75
+ tn->type = T_MAP;
76
+ tn->key = 0;
77
+ for ( i = 0; i < n->data.pairs->idx; i++ )
78
+ {
79
+ SYMID oid = syck_map_read( n, map_key, i );
80
+ syck_lookup_sym( p, oid, (char **)&val );
81
+ map[i * 2] = val[0];
82
+
83
+ oid = syck_map_read( n, map_value, i );
84
+ syck_lookup_sym( p, oid, (char **)&val );
85
+ map[(i * 2) + 1] = val[0];
86
+ }
87
+ map[n->data.pairs->idx * 2] = end_node;
88
+ tn->value = map;
89
+ }
90
+ break;
91
+ }
92
+
93
+ tn->tag = 0;
94
+ if ( n->type_id != NULL ) {
95
+ tn->tag = syck_strndup( n->type_id, strlen( n->type_id ) );
96
+ }
97
+
98
+ return syck_add_sym( p, (char *) tn );
99
+ }
100
+
101
+ int
102
+ syck_free_copies( char *key, struct test_node *tn, char *arg )
103
+ {
104
+ if ( tn != NULL ) {
105
+ switch ( tn->type ) {
106
+ case T_STR:
107
+ S_FREE( tn->key );
108
+ break;
109
+
110
+ case T_SEQ:
111
+ case T_MAP:
112
+ S_FREE( tn->value );
113
+ break;
114
+ }
115
+ if ( tn->tag != NULL ) S_FREE( tn->tag );
116
+ S_FREE( tn );
117
+ }
118
+ tn = NULL;
119
+ return ST_CONTINUE;
120
+ }
121
+
122
+ void CuStreamCompareX( CuTest* tc, struct test_node *s1, struct test_node *s2 ) {
123
+ int i = 0;
124
+ while ( 1 ) {
125
+ CuAssertIntEquals( tc, s1[i].type, s2[i].type );
126
+ if ( s1[i].type == T_END ) return;
127
+ if ( s1[i].tag != 0 && s2[i].tag != 0 ) CuAssertStrEquals( tc, s1[i].tag, s2[i].tag );
128
+ switch ( s1[i].type ) {
129
+ case T_STR:
130
+ CuAssertStrEquals( tc, s1[i].key, s2[i].key );
131
+ break;
132
+ case T_SEQ:
133
+ case T_MAP:
134
+ CuStreamCompareX( tc, s1[i].value, s2[i].value );
135
+ break;
136
+ }
137
+ i++;
138
+ }
139
+ }
140
+
141
+ void CuStreamCompare( CuTest* tc, char *yaml, struct test_node *stream ) {
142
+ int doc_ct = 0;
143
+ struct test_node *ystream = S_ALLOC_N( struct test_node, doc_ct + 1 );
144
+ CuString *msg;
145
+
146
+ /* Set up parser */
147
+ SyckParser *parser = syck_new_parser();
148
+ syck_parser_str_auto( parser, yaml, NULL );
149
+ syck_parser_handler( parser, syck_copy_handler );
150
+ syck_parser_error_handler( parser, NULL );
151
+ syck_parser_implicit_typing( parser, 1 );
152
+ syck_parser_taguri_expansion( parser, 1 );
153
+
154
+ /* Parse all streams */
155
+ while ( 1 )
156
+ {
157
+ struct test_node *ydoc;
158
+ SYMID oid = syck_parse( parser );
159
+ if ( parser->eof == 1 ) break;
160
+
161
+ /* Add document to stream */
162
+ syck_lookup_sym( parser, oid, (char **)&ydoc );
163
+ ystream[doc_ct] = ydoc[0];
164
+ doc_ct++;
165
+ S_REALLOC_N( ystream, struct test_node, doc_ct + 1 );
166
+ }
167
+ ystream[doc_ct] = end_node;
168
+
169
+ /* Traverse the struct and the symbol table side-by-side */
170
+ /* DEBUG: y( stream, 0 ); y( ystream, 0 ); */
171
+ CuStreamCompareX( tc, stream, ystream );
172
+
173
+ /* Free the node tables and the parser */
174
+ S_FREE( ystream );
175
+ if ( parser->syms != NULL )
176
+ st_foreach( parser->syms, syck_free_copies, 0 );
177
+ syck_free_parser( parser );
178
+ }
179
+
180
+ /*
181
+ * Setup for testing N->Y->N.
182
+ */
183
+ void
184
+ test_output_handler( emitter, str, len )
185
+ SyckEmitter *emitter;
186
+ char *str;
187
+ long len;
188
+ {
189
+ CuString *dest = (CuString *)emitter->bonus;
190
+ CuStringAppendLen( dest, str, len );
191
+ }
192
+
193
+ SYMID
194
+ build_symbol_table( SyckEmitter *emitter, struct test_node *node ) {
195
+ switch ( node->type ) {
196
+ case T_SEQ:
197
+ case T_MAP:
198
+ {
199
+ int i = 0;
200
+ while ( node->value[i].type != T_END ) {
201
+ SYMID id = build_symbol_table( emitter, &node->value[i] );
202
+ i++;
203
+ }
204
+ }
205
+ return syck_emitter_mark_node( emitter, (st_data_t)node );
206
+
207
+ case T_STR:
208
+ return 0;
209
+ }
210
+ }
211
+
212
+ void
213
+ test_emitter_handler( SyckEmitter *emitter, st_data_t data ) {
214
+ struct test_node *node = (struct test_node *)data;
215
+ switch ( node->type ) {
216
+ case T_STR:
217
+ syck_emit_scalar( emitter, node->tag, scalar_none, 0, 0, 0, node->key, strlen( node->key ) );
218
+ break;
219
+ case T_SEQ:
220
+ {
221
+ int i = 0;
222
+ syck_emit_seq( emitter, node->tag, 1 );
223
+ while ( node->value[i].type != T_END ) {
224
+ syck_emit_item( emitter, (st_data_t)&node->value[i] );
225
+ i++;
226
+ }
227
+ syck_emit_end( emitter );
228
+ }
229
+ break;
230
+ case T_MAP:
231
+ {
232
+ int i = 0;
233
+ syck_emit_map( emitter, node->tag, 1 );
234
+ while ( node->value[i].type != T_END ) {
235
+ syck_emit_item( emitter, (st_data_t)&node->value[i] );
236
+ i++;
237
+ }
238
+ syck_emit_end( emitter );
239
+ }
240
+ break;
241
+ }
242
+ }
243
+
244
+ void CuRoundTrip( CuTest* tc, struct test_node *stream ) {
245
+ int i = 0;
246
+ CuString *cs = CuStringNew();
247
+ SyckEmitter *emitter = syck_new_emitter();
248
+
249
+ /* Calculate anchors and tags */
250
+ build_symbol_table( emitter, stream );
251
+
252
+ /* Build the stream */
253
+ syck_output_handler( emitter, test_output_handler );
254
+ syck_emitter_handler( emitter, test_emitter_handler );
255
+ emitter->bonus = cs;
256
+ while ( stream[i].type != T_END )
257
+ {
258
+ syck_emit( emitter, (st_data_t)&stream[i] );
259
+ syck_emitter_flush( emitter, 0 );
260
+ i++;
261
+ }
262
+
263
+ /* Reload the stream and compare */
264
+ /* printf( "-- output for %s --\n%s\n--- end of output --\n", tc->name, cs->buffer ); */
265
+ CuStreamCompare( tc, cs->buffer, stream );
266
+ CuStringFree( cs );
267
+
268
+ syck_free_emitter( emitter );
269
+ }
270
+
271
+ /*
272
+ * ACTUAL TESTS FOR THE YAML TESTING SUITE BEGIN HERE
273
+ * (EVERYTHING PREVIOUS WAS SET UP FOR THE TESTS)
274
+ */
275
+
276
+ /*
277
+ * Example 2.1: Sequence of scalars
278
+ */
279
+ void
280
+ YtsSpecificationExamples_0( CuTest *tc )
281
+ {
282
+ struct test_node seq[] = {
283
+ { T_STR, 0, "Mark McGwire" },
284
+ { T_STR, 0, "Sammy Sosa" },
285
+ { T_STR, 0, "Ken Griffey" },
286
+ end_node
287
+ };
288
+ struct test_node stream[] = {
289
+ { T_SEQ, 0, 0, seq },
290
+ end_node
291
+ };
292
+
293
+ CuStreamCompare( tc,
294
+
295
+ /* YAML document */
296
+ "- Mark McGwire \n"
297
+ "- Sammy Sosa \n"
298
+ "- Ken Griffey \n"
299
+ ,
300
+
301
+ /* C structure of validations */
302
+ stream
303
+ );
304
+
305
+ CuRoundTrip( tc, stream );
306
+ }
307
+ /*
308
+ * Example 2.2: Mapping of scalars to scalars
309
+ */
310
+ void
311
+ YtsSpecificationExamples_1( CuTest *tc )
312
+ {
313
+ struct test_node map[] = {
314
+ { T_STR, 0, "hr" },
315
+ { T_STR, 0, "65" },
316
+ { T_STR, 0, "avg" },
317
+ { T_STR, 0, "0.278" },
318
+ { T_STR, 0, "rbi" },
319
+ { T_STR, 0, "147" },
320
+ end_node
321
+ };
322
+ struct test_node stream[] = {
323
+ { T_MAP, 0, 0, map },
324
+ end_node
325
+ };
326
+
327
+ CuStreamCompare( tc,
328
+
329
+ /* YAML document */
330
+ "hr: 65 \n"
331
+ "avg: 0.278 \n"
332
+ "rbi: 147 \n"
333
+ ,
334
+
335
+ /* C structure of validations */
336
+ stream
337
+ );
338
+
339
+ CuRoundTrip( tc, stream );
340
+ }
341
+ /*
342
+ * Example 2.3: Mapping of scalars to sequences
343
+ */
344
+ void
345
+ YtsSpecificationExamples_2( CuTest *tc )
346
+ {
347
+ struct test_node seq1[] = {
348
+ { T_STR, 0, "Boston Red Sox" },
349
+ { T_STR, 0, "Detroit Tigers" },
350
+ { T_STR, 0, "New York Yankees" },
351
+ end_node
352
+ };
353
+ struct test_node seq2[] = {
354
+ { T_STR, 0, "New York Mets" },
355
+ { T_STR, 0, "Chicago Cubs" },
356
+ { T_STR, 0, "Atlanta Braves" },
357
+ end_node
358
+ };
359
+ struct test_node map[] = {
360
+ { T_STR, 0, "american" },
361
+ { T_SEQ, 0, 0, seq1 },
362
+ { T_STR, 0, "national" },
363
+ { T_SEQ, 0, 0, seq2 },
364
+ end_node
365
+ };
366
+ struct test_node stream[] = {
367
+ { T_MAP, 0, 0, map },
368
+ end_node
369
+ };
370
+
371
+ CuStreamCompare( tc,
372
+
373
+ /* YAML document */
374
+ "american: \n"
375
+ " - Boston Red Sox \n"
376
+ " - Detroit Tigers \n"
377
+ " - New York Yankees \n"
378
+ "national: \n"
379
+ " - New York Mets \n"
380
+ " - Chicago Cubs \n"
381
+ " - Atlanta Braves \n"
382
+ ,
383
+
384
+ /* C structure of validations */
385
+ stream
386
+ );
387
+
388
+ CuRoundTrip( tc, stream );
389
+ }
390
+ /*
391
+ * Example 2.4: Sequence of mappings
392
+ */
393
+ void
394
+ YtsSpecificationExamples_3( CuTest *tc )
395
+ {
396
+ struct test_node map1[] = {
397
+ { T_STR, 0, "name" },
398
+ { T_STR, 0, "Mark McGwire" },
399
+ { T_STR, 0, "hr" },
400
+ { T_STR, 0, "65" },
401
+ { T_STR, 0, "avg" },
402
+ { T_STR, 0, "0.278" },
403
+ end_node
404
+ };
405
+ struct test_node map2[] = {
406
+ { T_STR, 0, "name" },
407
+ { T_STR, 0, "Sammy Sosa" },
408
+ { T_STR, 0, "hr" },
409
+ { T_STR, 0, "63" },
410
+ { T_STR, 0, "avg" },
411
+ { T_STR, 0, "0.288" },
412
+ end_node
413
+ };
414
+ struct test_node seq[] = {
415
+ { T_MAP, 0, 0, map1 },
416
+ { T_MAP, 0, 0, map2 },
417
+ end_node
418
+ };
419
+ struct test_node stream[] = {
420
+ { T_SEQ, 0, 0, seq },
421
+ end_node
422
+ };
423
+
424
+ CuStreamCompare( tc,
425
+
426
+ /* YAML document */
427
+ "- \n"
428
+ " name: Mark McGwire \n"
429
+ " hr: 65 \n"
430
+ " avg: 0.278 \n"
431
+ "- \n"
432
+ " name: Sammy Sosa \n"
433
+ " hr: 63 \n"
434
+ " avg: 0.288 \n"
435
+ ,
436
+
437
+ /* C structure of validations */
438
+ stream
439
+ );
440
+
441
+ CuRoundTrip( tc, stream );
442
+ }
443
+ /*
444
+ * Example legacy_A5: Legacy A5
445
+ */
446
+ void
447
+ YtsSpecificationExamples_4( CuTest *tc )
448
+ {
449
+ struct test_node seq1[] = {
450
+ { T_STR, 0, "New York Yankees" },
451
+ { T_STR, 0, "Atlanta Braves" },
452
+ end_node
453
+ };
454
+ struct test_node seq2[] = {
455
+ { T_STR, 0, "2001-07-02" },
456
+ { T_STR, 0, "2001-08-12" },
457
+ { T_STR, 0, "2001-08-14" },
458
+ end_node
459
+ };
460
+ struct test_node seq3[] = {
461
+ { T_STR, 0, "Detroit Tigers" },
462
+ { T_STR, 0, "Chicago Cubs" },
463
+ end_node
464
+ };
465
+ struct test_node seq4[] = {
466
+ { T_STR, 0, "2001-07-23" },
467
+ end_node
468
+ };
469
+ struct test_node map[] = {
470
+ { T_SEQ, 0, 0, seq1 },
471
+ { T_SEQ, 0, 0, seq2 },
472
+ { T_SEQ, 0, 0, seq3 },
473
+ { T_SEQ, 0, 0, seq4 },
474
+ end_node
475
+ };
476
+ struct test_node stream[] = {
477
+ { T_MAP, 0, 0, map },
478
+ end_node
479
+ };
480
+
481
+ CuStreamCompare( tc,
482
+
483
+ /* YAML document */
484
+ "? \n"
485
+ " - New York Yankees \n"
486
+ " - Atlanta Braves \n"
487
+ ": \n"
488
+ " - 2001-07-02 \n"
489
+ " - 2001-08-12 \n"
490
+ " - 2001-08-14 \n"
491
+ "? \n"
492
+ " - Detroit Tigers \n"
493
+ " - Chicago Cubs \n"
494
+ ": \n"
495
+ " - 2001-07-23 \n"
496
+ ,
497
+
498
+ /* C structure of validations */
499
+ stream
500
+ );
501
+
502
+ CuRoundTrip( tc, stream );
503
+ }
504
+ /*
505
+ * Example 2.5: Sequence of sequences
506
+ */
507
+ void
508
+ YtsSpecificationExamples_5( CuTest *tc )
509
+ {
510
+ struct test_node seq1[] = {
511
+ { T_STR, 0, "name" },
512
+ { T_STR, 0, "hr" },
513
+ { T_STR, 0, "avg" },
514
+ end_node
515
+ };
516
+ struct test_node seq2[] = {
517
+ { T_STR, 0, "Mark McGwire" },
518
+ { T_STR, 0, "65" },
519
+ { T_STR, 0, "0.278" },
520
+ end_node
521
+ };
522
+ struct test_node seq3[] = {
523
+ { T_STR, 0, "Sammy Sosa" },
524
+ { T_STR, 0, "63" },
525
+ { T_STR, 0, "0.288" },
526
+ end_node
527
+ };
528
+ struct test_node seq[] = {
529
+ { T_SEQ, 0, 0, seq1 },
530
+ { T_SEQ, 0, 0, seq2 },
531
+ { T_SEQ, 0, 0, seq3 },
532
+ end_node
533
+ };
534
+ struct test_node stream[] = {
535
+ { T_SEQ, 0, 0, seq },
536
+ end_node
537
+ };
538
+
539
+ CuStreamCompare( tc,
540
+
541
+ /* YAML document */
542
+ "- [ name , hr , avg ] \n"
543
+ "- [ Mark McGwire , 65 , 0.278 ] \n"
544
+ "- [ Sammy Sosa , 63 , 0.288 ] \n"
545
+ ,
546
+
547
+ /* C structure of validations */
548
+ stream
549
+ );
550
+
551
+ CuRoundTrip( tc, stream );
552
+ }
553
+ /*
554
+ * Example 2.6: Mapping of mappings
555
+ */
556
+ void
557
+ YtsSpecificationExamples_6( CuTest *tc )
558
+ {
559
+ struct test_node map1[] = {
560
+ { T_STR, 0, "hr" },
561
+ { T_STR, 0, "65" },
562
+ { T_STR, 0, "avg" },
563
+ { T_STR, 0, "0.278" },
564
+ end_node
565
+ };
566
+ struct test_node map2[] = {
567
+ { T_STR, 0, "hr" },
568
+ { T_STR, 0, "63" },
569
+ { T_STR, 0, "avg" },
570
+ { T_STR, 0, "0.288" },
571
+ end_node
572
+ };
573
+ struct test_node map[] = {
574
+ { T_STR, 0, "Mark McGwire" },
575
+ { T_MAP, 0, 0, map1 },
576
+ { T_STR, 0, "Sammy Sosa" },
577
+ { T_MAP, 0, 0, map2 },
578
+ end_node
579
+ };
580
+ struct test_node stream[] = {
581
+ { T_MAP, 0, 0, map },
582
+ end_node
583
+ };
584
+
585
+ CuStreamCompare( tc,
586
+
587
+ /* YAML document */
588
+ "Mark McGwire: {hr: 65, avg: 0.278}\n"
589
+ "Sammy Sosa: {\n"
590
+ " hr: 63,\n"
591
+ " avg: 0.288\n"
592
+ " }\n"
593
+ ,
594
+
595
+ /* C structure of validations */
596
+ stream
597
+ );
598
+
599
+ CuRoundTrip( tc, stream );
600
+ }
601
+ /*
602
+ * Example 2.7: Two documents in a stream each with a leading comment
603
+ */
604
+ void
605
+ YtsSpecificationExamples_7( CuTest *tc )
606
+ {
607
+ struct test_node seq1[] = {
608
+ { T_STR, 0, "Mark McGwire" },
609
+ { T_STR, 0, "Sammy Sosa" },
610
+ { T_STR, 0, "Ken Griffey" },
611
+ end_node
612
+ };
613
+ struct test_node seq2[] = {
614
+ { T_STR, 0, "Chicago Cubs" },
615
+ { T_STR, 0, "St Louis Cardinals" },
616
+ end_node
617
+ };
618
+ struct test_node stream[] = {
619
+ { T_SEQ, 0, 0, seq1 },
620
+ { T_SEQ, 0, 0, seq2 },
621
+ end_node
622
+ };
623
+
624
+ CuStreamCompare( tc,
625
+
626
+ /* YAML document */
627
+ "# Ranking of 1998 home runs\n"
628
+ "---\n"
629
+ "- Mark McGwire\n"
630
+ "- Sammy Sosa\n"
631
+ "- Ken Griffey\n"
632
+ "\n"
633
+ "# Team ranking\n"
634
+ "---\n"
635
+ "- Chicago Cubs\n"
636
+ "- St Louis Cardinals\n"
637
+ ,
638
+
639
+ /* C structure of validations */
640
+ stream
641
+ );
642
+
643
+ CuRoundTrip( tc, stream );
644
+ }
645
+ /*
646
+ * Example 2.8: Play by play feed from a game
647
+ */
648
+ void
649
+ YtsSpecificationExamples_8( CuTest *tc )
650
+ {
651
+ struct test_node map1[] = {
652
+ { T_STR, 0, "time" },
653
+ { T_STR, 0, "20:03:20" },
654
+ { T_STR, 0, "player" },
655
+ { T_STR, 0, "Sammy Sosa" },
656
+ { T_STR, 0, "action" },
657
+ { T_STR, 0, "strike (miss)" },
658
+ end_node
659
+ };
660
+ struct test_node map2[] = {
661
+ { T_STR, 0, "time" },
662
+ { T_STR, 0, "20:03:47" },
663
+ { T_STR, 0, "player" },
664
+ { T_STR, 0, "Sammy Sosa" },
665
+ { T_STR, 0, "action" },
666
+ { T_STR, 0, "grand slam" },
667
+ end_node
668
+ };
669
+ struct test_node stream[] = {
670
+ { T_MAP, 0, 0, map1 },
671
+ { T_MAP, 0, 0, map2 },
672
+ end_node
673
+ };
674
+
675
+ CuStreamCompare( tc,
676
+
677
+ /* YAML document */
678
+ "---\n"
679
+ "time: 20:03:20\n"
680
+ "player: Sammy Sosa\n"
681
+ "action: strike (miss)\n"
682
+ "...\n"
683
+ "---\n"
684
+ "time: 20:03:47\n"
685
+ "player: Sammy Sosa\n"
686
+ "action: grand slam\n"
687
+ "...\n"
688
+ ,
689
+
690
+ /* C structure of validations */
691
+ stream
692
+ );
693
+
694
+ CuRoundTrip( tc, stream );
695
+ }
696
+ /*
697
+ * Example 2.9: Single document with two comments
698
+ */
699
+ void
700
+ YtsSpecificationExamples_9( CuTest *tc )
701
+ {
702
+ struct test_node seq1[] = {
703
+ { T_STR, 0, "Mark McGwire" },
704
+ { T_STR, 0, "Sammy Sosa" },
705
+ end_node
706
+ };
707
+ struct test_node seq2[] = {
708
+ { T_STR, 0, "Sammy Sosa" },
709
+ { T_STR, 0, "Ken Griffey" },
710
+ end_node
711
+ };
712
+ struct test_node map[] = {
713
+ { T_STR, 0, "hr" },
714
+ { T_SEQ, 0, 0, seq1 },
715
+ { T_STR, 0, "rbi" },
716
+ { T_SEQ, 0, 0, seq2 },
717
+ end_node
718
+ };
719
+ struct test_node stream[] = {
720
+ { T_MAP, 0, 0, map },
721
+ end_node
722
+ };
723
+
724
+ CuStreamCompare( tc,
725
+
726
+ /* YAML document */
727
+ "hr: # 1998 hr ranking \n"
728
+ " - Mark McGwire \n"
729
+ " - Sammy Sosa \n"
730
+ "rbi: \n"
731
+ " # 1998 rbi ranking \n"
732
+ " - Sammy Sosa \n"
733
+ " - Ken Griffey \n"
734
+ ,
735
+
736
+ /* C structure of validations */
737
+ stream
738
+ );
739
+
740
+ CuRoundTrip( tc, stream );
741
+ }
742
+ /*
743
+ * Example 2.1: Node for Sammy Sosa appears twice in this document
744
+ */
745
+ void
746
+ YtsSpecificationExamples_10( CuTest *tc )
747
+ {
748
+ struct test_node seq1[] = {
749
+ { T_STR, 0, "Mark McGwire" },
750
+ { T_STR, 0, "Sammy Sosa" },
751
+ end_node
752
+ };
753
+ struct test_node seq2[] = {
754
+ { T_STR, 0, "Sammy Sosa" },
755
+ { T_STR, 0, "Ken Griffey" },
756
+ end_node
757
+ };
758
+ struct test_node map[] = {
759
+ { T_STR, 0, "hr" },
760
+ { T_SEQ, 0, 0, seq1 },
761
+ { T_STR, 0, "rbi" },
762
+ { T_SEQ, 0, 0, seq2 },
763
+ end_node
764
+ };
765
+ struct test_node stream[] = {
766
+ { T_MAP, 0, 0, map },
767
+ end_node
768
+ };
769
+
770
+ CuStreamCompare( tc,
771
+
772
+ /* YAML document */
773
+ "---\n"
774
+ "hr: \n"
775
+ " - Mark McGwire \n"
776
+ " # Following node labeled SS \n"
777
+ " - &SS Sammy Sosa \n"
778
+ "rbi: \n"
779
+ " - *SS # Subsequent occurance \n"
780
+ " - Ken Griffey \n"
781
+ ,
782
+
783
+ /* C structure of validations */
784
+ stream
785
+ );
786
+
787
+ CuRoundTrip( tc, stream );
788
+ }
789
+ /*
790
+ * Example 2.11: Mapping between sequences
791
+ */
792
+ void
793
+ YtsSpecificationExamples_11( CuTest *tc )
794
+ {
795
+ struct test_node seq1[] = {
796
+ { T_STR, 0, "New York Yankees" },
797
+ { T_STR, 0, "Atlanta Braves" },
798
+ end_node
799
+ };
800
+ struct test_node seq2[] = {
801
+ { T_STR, 0, "2001-07-02" },
802
+ { T_STR, 0, "2001-08-12" },
803
+ { T_STR, 0, "2001-08-14" },
804
+ end_node
805
+ };
806
+ struct test_node seq3[] = {
807
+ { T_STR, 0, "Detroit Tigers" },
808
+ { T_STR, 0, "Chicago Cubs" },
809
+ end_node
810
+ };
811
+ struct test_node seq4[] = {
812
+ { T_STR, 0, "2001-07-23" },
813
+ end_node
814
+ };
815
+ struct test_node map[] = {
816
+ { T_SEQ, 0, 0, seq3 },
817
+ { T_SEQ, 0, 0, seq4 },
818
+ { T_SEQ, 0, 0, seq1 },
819
+ { T_SEQ, 0, 0, seq2 },
820
+ end_node
821
+ };
822
+ struct test_node stream[] = {
823
+ { T_MAP, 0, 0, map },
824
+ end_node
825
+ };
826
+
827
+ CuStreamCompare( tc,
828
+
829
+ /* YAML document */
830
+ "? # PLAY SCHEDULE \n"
831
+ " - Detroit Tigers \n"
832
+ " - Chicago Cubs \n"
833
+ ": \n"
834
+ " - 2001-07-23 \n"
835
+ "\n"
836
+ "? [ New York Yankees, \n"
837
+ " Atlanta Braves ] \n"
838
+ ": [ 2001-07-02, 2001-08-12, \n"
839
+ " 2001-08-14 ] \n"
840
+ ,
841
+
842
+ /* C structure of validations */
843
+ stream
844
+ );
845
+
846
+ CuRoundTrip( tc, stream );
847
+ }
848
+ /*
849
+ * Example 2.12: Sequence key shortcut
850
+ */
851
+ void
852
+ YtsSpecificationExamples_12( CuTest *tc )
853
+ {
854
+ struct test_node map1[] = {
855
+ { T_STR, 0, "item" },
856
+ { T_STR, 0, "Super Hoop" },
857
+ { T_STR, 0, "quantity" },
858
+ { T_STR, 0, "1" },
859
+ end_node
860
+ };
861
+ struct test_node map2[] = {
862
+ { T_STR, 0, "item" },
863
+ { T_STR, 0, "Basketball" },
864
+ { T_STR, 0, "quantity" },
865
+ { T_STR, 0, "4" },
866
+ end_node
867
+ };
868
+ struct test_node map3[] = {
869
+ { T_STR, 0, "item" },
870
+ { T_STR, 0, "Big Shoes" },
871
+ { T_STR, 0, "quantity" },
872
+ { T_STR, 0, "1" },
873
+ end_node
874
+ };
875
+ struct test_node seq[] = {
876
+ { T_MAP, 0, 0, map1 },
877
+ { T_MAP, 0, 0, map2 },
878
+ { T_MAP, 0, 0, map3 },
879
+ end_node
880
+ };
881
+ struct test_node stream[] = {
882
+ { T_SEQ, 0, 0, seq },
883
+ end_node
884
+ };
885
+
886
+ CuStreamCompare( tc,
887
+
888
+ /* YAML document */
889
+ "---\n"
890
+ "# products purchased\n"
891
+ "- item : Super Hoop\n"
892
+ " quantity: 1\n"
893
+ "- item : Basketball\n"
894
+ " quantity: 4\n"
895
+ "- item : Big Shoes\n"
896
+ " quantity: 1\n"
897
+ ,
898
+
899
+ /* C structure of validations */
900
+ stream
901
+ );
902
+
903
+ CuRoundTrip( tc, stream );
904
+ }
905
+ /*
906
+ * Example 2.13: Literal perserves newlines
907
+ */
908
+ void
909
+ YtsSpecificationExamples_13( CuTest *tc )
910
+ {
911
+ struct test_node stream[] = {
912
+ { T_STR, 0, "\\//||\\/||\n// || ||_\n" },
913
+ end_node
914
+ };
915
+
916
+ CuStreamCompare( tc,
917
+
918
+ /* YAML document */
919
+ "# ASCII Art\n"
920
+ "--- | \n"
921
+ " \\//||\\/||\n"
922
+ " // || ||_\n"
923
+ ,
924
+
925
+ /* C structure of validations */
926
+ stream
927
+ );
928
+
929
+ CuRoundTrip( tc, stream );
930
+ }
931
+ /*
932
+ * Example 2.14: Folded treats newlines as a space
933
+ */
934
+ void
935
+ YtsSpecificationExamples_14( CuTest *tc )
936
+ {
937
+ struct test_node stream[] = {
938
+ { T_STR, 0, "Mark McGwire's year was crippled by a knee injury." },
939
+ end_node
940
+ };
941
+
942
+ CuStreamCompare( tc,
943
+
944
+ /* YAML document */
945
+ "---\n"
946
+ " Mark McGwire's\n"
947
+ " year was crippled\n"
948
+ " by a knee injury.\n"
949
+ ,
950
+
951
+ /* C structure of validations */
952
+ stream
953
+ );
954
+
955
+ CuRoundTrip( tc, stream );
956
+ }
957
+ /*
958
+ * Example 2.15: Newlines preserved for indented and blank lines
959
+ */
960
+ void
961
+ YtsSpecificationExamples_15( CuTest *tc )
962
+ {
963
+ struct test_node stream[] = {
964
+ { T_STR, 0, "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n" },
965
+ end_node
966
+ };
967
+
968
+ CuStreamCompare( tc,
969
+
970
+ /* YAML document */
971
+ "--- > \n"
972
+ " Sammy Sosa completed another\n"
973
+ " fine season with great stats.\n"
974
+ "\n"
975
+ " 63 Home Runs\n"
976
+ " 0.288 Batting Average\n"
977
+ "\n"
978
+ " What a year!\n"
979
+ ,
980
+
981
+ /* C structure of validations */
982
+ stream
983
+ );
984
+
985
+ CuRoundTrip( tc, stream );
986
+ }
987
+ /*
988
+ * Example 2.16: Indentation determines scope
989
+ */
990
+ void
991
+ YtsSpecificationExamples_16( CuTest *tc )
992
+ {
993
+ struct test_node map[] = {
994
+ { T_STR, 0, "name" },
995
+ { T_STR, 0, "Mark McGwire" },
996
+ { T_STR, 0, "accomplishment" },
997
+ { T_STR, 0, "Mark set a major league home run record in 1998.\n" },
998
+ { T_STR, 0, "stats" },
999
+ { T_STR, 0, "65 Home Runs\n0.278 Batting Average\n" },
1000
+ end_node
1001
+ };
1002
+ struct test_node stream[] = {
1003
+ { T_MAP, 0, 0, map },
1004
+ end_node
1005
+ };
1006
+
1007
+ CuStreamCompare( tc,
1008
+
1009
+ /* YAML document */
1010
+ "name: Mark McGwire \n"
1011
+ "accomplishment: > \n"
1012
+ " Mark set a major league\n"
1013
+ " home run record in 1998.\n"
1014
+ "stats: | \n"
1015
+ " 65 Home Runs\n"
1016
+ " 0.278 Batting Average\n"
1017
+ ,
1018
+
1019
+ /* C structure of validations */
1020
+ stream
1021
+ );
1022
+
1023
+ CuRoundTrip( tc, stream );
1024
+ }
1025
+ /*
1026
+ * Example 2.18: Multiline flow scalars
1027
+ */
1028
+ void
1029
+ YtsSpecificationExamples_18( CuTest *tc )
1030
+ {
1031
+ struct test_node map[] = {
1032
+ { T_STR, 0, "plain" },
1033
+ { T_STR, 0, "This unquoted scalar spans many lines." },
1034
+ { T_STR, 0, "quoted" },
1035
+ { T_STR, 0, "So does this quoted scalar.\n" },
1036
+ end_node
1037
+ };
1038
+ struct test_node stream[] = {
1039
+ { T_MAP, 0, 0, map },
1040
+ end_node
1041
+ };
1042
+
1043
+ CuStreamCompare( tc,
1044
+
1045
+ /* YAML document */
1046
+ "plain:\n"
1047
+ " This unquoted scalar\n"
1048
+ " spans many lines.\n"
1049
+ "\n"
1050
+ "quoted: \"So does this\n"
1051
+ " quoted scalar.\\n\"\n"
1052
+ ,
1053
+
1054
+ /* C structure of validations */
1055
+ stream
1056
+ );
1057
+
1058
+ CuRoundTrip( tc, stream );
1059
+ }
1060
+ /*
1061
+ * Example 2.19: Integers
1062
+ */
1063
+ void
1064
+ YtsSpecificationExamples_19( CuTest *tc )
1065
+ {
1066
+ struct test_node map[] = {
1067
+ { T_STR, 0, "canonical" },
1068
+ { T_STR, 0, "12345" },
1069
+ { T_STR, 0, "decimal" },
1070
+ { T_STR, 0, "+12,345" },
1071
+ { T_STR, 0, "sexagecimal" },
1072
+ { T_STR, 0, "3:25:45" },
1073
+ { T_STR, 0, "octal" },
1074
+ { T_STR, 0, "014" },
1075
+ { T_STR, 0, "hexadecimal" },
1076
+ { T_STR, 0, "0xC" },
1077
+ end_node
1078
+ };
1079
+ struct test_node stream[] = {
1080
+ { T_MAP, 0, 0, map },
1081
+ end_node
1082
+ };
1083
+
1084
+ CuStreamCompare( tc,
1085
+
1086
+ /* YAML document */
1087
+ "canonical: 12345 \n"
1088
+ "decimal: +12,345 \n"
1089
+ "sexagecimal: 3:25:45\n"
1090
+ "octal: 014 \n"
1091
+ "hexadecimal: 0xC \n"
1092
+ ,
1093
+
1094
+ /* C structure of validations */
1095
+ stream
1096
+ );
1097
+
1098
+ CuRoundTrip( tc, stream );
1099
+ }
1100
+ /*
1101
+ * Example 2.2: Floating point
1102
+ */
1103
+ void
1104
+ YtsSpecificationExamples_20( CuTest *tc )
1105
+ {
1106
+ struct test_node map[] = {
1107
+ { T_STR, 0, "canonical" },
1108
+ { T_STR, 0, "1.23015e+3" },
1109
+ { T_STR, 0, "exponential" },
1110
+ { T_STR, 0, "12.3015e+02" },
1111
+ { T_STR, 0, "sexagecimal" },
1112
+ { T_STR, 0, "20:30.15" },
1113
+ { T_STR, 0, "fixed" },
1114
+ { T_STR, 0, "1,230.15" },
1115
+ { T_STR, 0, "negative infinity" },
1116
+ { T_STR, 0, "-.inf" },
1117
+ { T_STR, 0, "not a number" },
1118
+ { T_STR, 0, ".NaN" },
1119
+ end_node
1120
+ };
1121
+ struct test_node stream[] = {
1122
+ { T_MAP, 0, 0, map },
1123
+ end_node
1124
+ };
1125
+
1126
+ CuStreamCompare( tc,
1127
+
1128
+ /* YAML document */
1129
+ "canonical: 1.23015e+3 \n"
1130
+ "exponential: 12.3015e+02 \n"
1131
+ "sexagecimal: 20:30.15\n"
1132
+ "fixed: 1,230.15 \n"
1133
+ "negative infinity: -.inf\n"
1134
+ "not a number: .NaN \n"
1135
+ ,
1136
+
1137
+ /* C structure of validations */
1138
+ stream
1139
+ );
1140
+
1141
+ CuRoundTrip( tc, stream );
1142
+ }
1143
+ /*
1144
+ * Example 2.21: Miscellaneous
1145
+ */
1146
+ void
1147
+ YtsSpecificationExamples_21( CuTest *tc )
1148
+ {
1149
+ struct test_node map[] = {
1150
+ { T_STR, 0, "null" },
1151
+ { T_STR, 0, "~" },
1152
+ { T_STR, 0, "true" },
1153
+ { T_STR, 0, "y" },
1154
+ { T_STR, 0, "false" },
1155
+ { T_STR, 0, "n" },
1156
+ { T_STR, 0, "string" },
1157
+ { T_STR, 0, "12345" },
1158
+ end_node
1159
+ };
1160
+ struct test_node stream[] = {
1161
+ { T_MAP, 0, 0, map },
1162
+ end_node
1163
+ };
1164
+
1165
+ CuStreamCompare( tc,
1166
+
1167
+ /* YAML document */
1168
+ "null: ~ \n"
1169
+ "true: y\n"
1170
+ "false: n \n"
1171
+ "string: '12345' \n"
1172
+ ,
1173
+
1174
+ /* C structure of validations */
1175
+ stream
1176
+ );
1177
+
1178
+ CuRoundTrip( tc, stream );
1179
+ }
1180
+ /*
1181
+ * Example 2.22: Timestamps
1182
+ */
1183
+ void
1184
+ YtsSpecificationExamples_22( CuTest *tc )
1185
+ {
1186
+ struct test_node map[] = {
1187
+ { T_STR, 0, "canonical" },
1188
+ { T_STR, 0, "2001-12-15T02:59:43.1Z" },
1189
+ { T_STR, 0, "iso8601" },
1190
+ { T_STR, 0, "2001-12-14t21:59:43.10-05:00" },
1191
+ { T_STR, 0, "spaced" },
1192
+ { T_STR, 0, "2001-12-14 21:59:43.10 -05:00" },
1193
+ { T_STR, 0, "date" },
1194
+ { T_STR, 0, "2002-12-14" },
1195
+ end_node
1196
+ };
1197
+ struct test_node stream[] = {
1198
+ { T_MAP, 0, 0, map },
1199
+ end_node
1200
+ };
1201
+
1202
+ CuStreamCompare( tc,
1203
+
1204
+ /* YAML document */
1205
+ "canonical: 2001-12-15T02:59:43.1Z\n"
1206
+ "iso8601: 2001-12-14t21:59:43.10-05:00\n"
1207
+ "spaced: 2001-12-14 21:59:43.10 -05:00\n"
1208
+ "date: 2002-12-14 # Time is noon UTC\n"
1209
+ ,
1210
+
1211
+ /* C structure of validations */
1212
+ stream
1213
+ );
1214
+
1215
+ CuRoundTrip( tc, stream );
1216
+ }
1217
+ /*
1218
+ * Example legacy D4: legacy Timestamps test
1219
+ */
1220
+ void
1221
+ YtsSpecificationExamples_23( CuTest *tc )
1222
+ {
1223
+ struct test_node map[] = {
1224
+ { T_STR, 0, "canonical" },
1225
+ { T_STR, 0, "2001-12-15T02:59:43.00Z" },
1226
+ { T_STR, 0, "iso8601" },
1227
+ { T_STR, 0, "2001-02-28t21:59:43.00-05:00" },
1228
+ { T_STR, 0, "spaced" },
1229
+ { T_STR, 0, "2001-12-14 21:59:43.00 -05:00" },
1230
+ { T_STR, 0, "date" },
1231
+ { T_STR, 0, "2002-12-14" },
1232
+ end_node
1233
+ };
1234
+ struct test_node stream[] = {
1235
+ { T_MAP, 0, 0, map },
1236
+ end_node
1237
+ };
1238
+
1239
+ CuStreamCompare( tc,
1240
+
1241
+ /* YAML document */
1242
+ "canonical: 2001-12-15T02:59:43.00Z\n"
1243
+ "iso8601: 2001-02-28t21:59:43.00-05:00\n"
1244
+ "spaced: 2001-12-14 21:59:43.00 -05:00\n"
1245
+ "date: 2002-12-14\n"
1246
+ ,
1247
+
1248
+ /* C structure of validations */
1249
+ stream
1250
+ );
1251
+
1252
+ CuRoundTrip( tc, stream );
1253
+ }
1254
+ /*
1255
+ * Example 2.23: Various explicit families
1256
+ */
1257
+ void
1258
+ YtsSpecificationExamples_24( CuTest *tc )
1259
+ {
1260
+ struct test_node map[] = {
1261
+ { T_STR, 0, "not-date" },
1262
+ { T_STR, "tag:yaml.org,2002:str", "2002-04-28" },
1263
+ { T_STR, 0, "picture" },
1264
+ { T_STR, "tag:yaml.org,2002:binary", "R0lGODlhDAAMAIQAAP//9/X\n17unp5WZmZgAAAOfn515eXv\nPz7Y6OjuDg4J+fn5OTk6enp\n56enmleECcgggoBADs=\n" },
1265
+ { T_STR, 0, "application specific tag" },
1266
+ { T_STR, "x-private:something", "The semantics of the tag\nabove may be different for\ndifferent documents.\n" },
1267
+ end_node
1268
+ };
1269
+ struct test_node stream[] = {
1270
+ { T_MAP, 0, 0, map },
1271
+ end_node
1272
+ };
1273
+
1274
+ CuStreamCompare( tc,
1275
+
1276
+ /* YAML document */
1277
+ "not-date: !str 2002-04-28\n"
1278
+ "picture: !binary |\n"
1279
+ " R0lGODlhDAAMAIQAAP//9/X\n"
1280
+ " 17unp5WZmZgAAAOfn515eXv\n"
1281
+ " Pz7Y6OjuDg4J+fn5OTk6enp\n"
1282
+ " 56enmleECcgggoBADs=\n"
1283
+ "\n"
1284
+ "application specific tag: !!something |\n"
1285
+ " The semantics of the tag\n"
1286
+ " above may be different for\n"
1287
+ " different documents.\n"
1288
+ ,
1289
+
1290
+ /* C structure of validations */
1291
+ stream
1292
+ );
1293
+
1294
+ CuRoundTrip( tc, stream );
1295
+ }
1296
+ /*
1297
+ * Example 2.24: Application specific family
1298
+ */
1299
+ void
1300
+ YtsSpecificationExamples_25( CuTest *tc )
1301
+ {
1302
+ struct test_node point1[] = {
1303
+ { T_STR, 0, "x" },
1304
+ { T_STR, 0, "73" },
1305
+ { T_STR, 0, "y" },
1306
+ { T_STR, 0, "129" },
1307
+ end_node
1308
+ };
1309
+ struct test_node point2[] = {
1310
+ { T_STR, 0, "x" },
1311
+ { T_STR, 0, "89" },
1312
+ { T_STR, 0, "y" },
1313
+ { T_STR, 0, "102" },
1314
+ end_node
1315
+ };
1316
+ struct test_node map1[] = {
1317
+ { T_STR, 0, "center" },
1318
+ { T_MAP, 0, 0, point1 },
1319
+ { T_STR, 0, "radius" },
1320
+ { T_STR, 0, "7" },
1321
+ end_node
1322
+ };
1323
+ struct test_node map2[] = {
1324
+ { T_STR, 0, "start" },
1325
+ { T_MAP, 0, 0, point1 },
1326
+ { T_STR, 0, "finish" },
1327
+ { T_MAP, 0, 0, point2 },
1328
+ end_node
1329
+ };
1330
+ struct test_node map3[] = {
1331
+ { T_STR, 0, "start" },
1332
+ { T_MAP, 0, 0, point1 },
1333
+ { T_STR, 0, "color" },
1334
+ { T_STR, 0, "0xFFEEBB" },
1335
+ { T_STR, 0, "value" },
1336
+ { T_STR, 0, "Pretty vector drawing." },
1337
+ end_node
1338
+ };
1339
+ struct test_node seq[] = {
1340
+ { T_MAP, "tag:clarkevans.com,2002:graph/circle", 0, map1 },
1341
+ { T_MAP, "tag:clarkevans.com,2002:graph/line", 0, map2 },
1342
+ { T_MAP, "tag:clarkevans.com,2002:graph/label", 0, map3 },
1343
+ end_node
1344
+ };
1345
+ struct test_node stream[] = {
1346
+ { T_SEQ, "tag:clarkevans.com,2002:graph/shape", 0, seq },
1347
+ end_node
1348
+ };
1349
+
1350
+ CuStreamCompare( tc,
1351
+
1352
+ /* YAML document */
1353
+ "# Establish a tag prefix\n"
1354
+ "--- !clarkevans.com,2002/graph/^shape\n"
1355
+ " # Use the prefix: shorthand for\n"
1356
+ " # !clarkevans.com,2002/graph/circle\n"
1357
+ "- !^circle\n"
1358
+ " center: &ORIGIN {x: 73, 'y': 129}\n"
1359
+ " radius: 7\n"
1360
+ "- !^line # !clarkevans.com,2002/graph/line\n"
1361
+ " start: *ORIGIN\n"
1362
+ " finish: { x: 89, 'y': 102 }\n"
1363
+ "- !^label\n"
1364
+ " start: *ORIGIN\n"
1365
+ " color: 0xFFEEBB\n"
1366
+ " value: Pretty vector drawing.\n"
1367
+ ,
1368
+
1369
+ /* C structure of validations */
1370
+ stream
1371
+ );
1372
+
1373
+ CuRoundTrip( tc, stream );
1374
+ }
1375
+ /*
1376
+ * Example 2.26: Ordered mappings
1377
+ */
1378
+ void
1379
+ YtsSpecificationExamples_26( CuTest *tc )
1380
+ {
1381
+ struct test_node map1[] = {
1382
+ { T_STR, 0, "Mark McGwire" },
1383
+ { T_STR, 0, "65" },
1384
+ end_node
1385
+ };
1386
+ struct test_node map2[] = {
1387
+ { T_STR, 0, "Sammy Sosa" },
1388
+ { T_STR, 0, "63" },
1389
+ end_node
1390
+ };
1391
+ struct test_node map3[] = {
1392
+ { T_STR, 0, "Ken Griffy" },
1393
+ { T_STR, 0, "58" },
1394
+ end_node
1395
+ };
1396
+ struct test_node seq[] = {
1397
+ { T_MAP, 0, 0, map1 },
1398
+ { T_MAP, 0, 0, map2 },
1399
+ { T_MAP, 0, 0, map3 },
1400
+ end_node
1401
+ };
1402
+ struct test_node stream[] = {
1403
+ { T_SEQ, "tag:yaml.org,2002:omap", 0, seq },
1404
+ end_node
1405
+ };
1406
+
1407
+ CuStreamCompare( tc,
1408
+
1409
+ /* YAML document */
1410
+ "# ordered maps are represented as\n"
1411
+ "# a sequence of mappings, with\n"
1412
+ "# each mapping having one key\n"
1413
+ "--- !omap\n"
1414
+ "- Mark McGwire: 65\n"
1415
+ "- Sammy Sosa: 63\n"
1416
+ "- Ken Griffy: 58\n"
1417
+ ,
1418
+
1419
+ /* C structure of validations */
1420
+ stream
1421
+ );
1422
+
1423
+ CuRoundTrip( tc, stream );
1424
+ }
1425
+ /*
1426
+ * Example 2.27: Invoice
1427
+ */
1428
+ void
1429
+ YtsSpecificationExamples_27( CuTest *tc )
1430
+ {
1431
+ struct test_node prod1[] = {
1432
+ { T_STR, 0, "sku" },
1433
+ { T_STR, 0, "BL394D" },
1434
+ { T_STR, 0, "quantity" },
1435
+ { T_STR, 0, "4" },
1436
+ { T_STR, 0, "description" },
1437
+ { T_STR, 0, "Basketball" },
1438
+ { T_STR, 0, "price" },
1439
+ { T_STR, 0, "450.00" },
1440
+ end_node
1441
+ };
1442
+ struct test_node prod2[] = {
1443
+ { T_STR, 0, "sku" },
1444
+ { T_STR, 0, "BL4438H" },
1445
+ { T_STR, 0, "quantity" },
1446
+ { T_STR, 0, "1" },
1447
+ { T_STR, 0, "description" },
1448
+ { T_STR, 0, "Super Hoop" },
1449
+ { T_STR, 0, "price" },
1450
+ { T_STR, 0, "2392.00" },
1451
+ end_node
1452
+ };
1453
+ struct test_node products[] = {
1454
+ { T_MAP, 0, 0, prod1 },
1455
+ { T_MAP, 0, 0, prod2 },
1456
+ end_node
1457
+ };
1458
+ struct test_node address[] = {
1459
+ { T_STR, 0, "lines" },
1460
+ { T_STR, 0, "458 Walkman Dr.\nSuite #292\n" },
1461
+ { T_STR, 0, "city" },
1462
+ { T_STR, 0, "Royal Oak" },
1463
+ { T_STR, 0, "state" },
1464
+ { T_STR, 0, "MI" },
1465
+ { T_STR, 0, "postal" },
1466
+ { T_STR, 0, "48046" },
1467
+ end_node
1468
+ };
1469
+ struct test_node id001[] = {
1470
+ { T_STR, 0, "given" },
1471
+ { T_STR, 0, "Chris" },
1472
+ { T_STR, 0, "family" },
1473
+ { T_STR, 0, "Dumars" },
1474
+ { T_STR, 0, "address" },
1475
+ { T_MAP, 0, 0, address },
1476
+ end_node
1477
+ };
1478
+ struct test_node map[] = {
1479
+ { T_STR, 0, "invoice" },
1480
+ { T_STR, 0, "34843" },
1481
+ { T_STR, 0, "date" },
1482
+ { T_STR, 0, "2001-01-23" },
1483
+ { T_STR, 0, "bill-to" },
1484
+ { T_MAP, 0, 0, id001 },
1485
+ { T_STR, 0, "ship-to" },
1486
+ { T_MAP, 0, 0, id001 },
1487
+ { T_STR, 0, "product" },
1488
+ { T_SEQ, 0, 0, products },
1489
+ { T_STR, 0, "tax" },
1490
+ { T_STR, 0, "251.42" },
1491
+ { T_STR, 0, "total" },
1492
+ { T_STR, 0, "4443.52" },
1493
+ { T_STR, 0, "comments" },
1494
+ { T_STR, 0, "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n" },
1495
+ end_node
1496
+ };
1497
+ struct test_node stream[] = {
1498
+ { T_MAP, "tag:clarkevans.com,2002:invoice", 0, map },
1499
+ end_node
1500
+ };
1501
+
1502
+ CuStreamCompare( tc,
1503
+
1504
+ /* YAML document */
1505
+ "--- !clarkevans.com,2002/^invoice\n"
1506
+ "invoice: 34843\n"
1507
+ "date : 2001-01-23\n"
1508
+ "bill-to: &id001\n"
1509
+ " given : Chris\n"
1510
+ " family : Dumars\n"
1511
+ " address:\n"
1512
+ " lines: |\n"
1513
+ " 458 Walkman Dr.\n"
1514
+ " Suite #292\n"
1515
+ " city : Royal Oak\n"
1516
+ " state : MI\n"
1517
+ " postal : 48046\n"
1518
+ "ship-to: *id001\n"
1519
+ "product:\n"
1520
+ " - sku : BL394D\n"
1521
+ " quantity : 4\n"
1522
+ " description : Basketball\n"
1523
+ " price : 450.00\n"
1524
+ " - sku : BL4438H\n"
1525
+ " quantity : 1\n"
1526
+ " description : Super Hoop\n"
1527
+ " price : 2392.00\n"
1528
+ "tax : 251.42\n"
1529
+ "total: 4443.52\n"
1530
+ "comments: >\n"
1531
+ " Late afternoon is best.\n"
1532
+ " Backup contact is Nancy\n"
1533
+ " Billsmer @ 338-4338.\n"
1534
+ ,
1535
+
1536
+ /* C structure of validations */
1537
+ stream
1538
+ );
1539
+
1540
+ CuRoundTrip( tc, stream );
1541
+ }
1542
+ /*
1543
+ * Example 2.28: Log file
1544
+ */
1545
+ void
1546
+ YtsSpecificationExamples_28( CuTest *tc )
1547
+ {
1548
+ struct test_node map1[] = {
1549
+ { T_STR, 0, "Time" },
1550
+ { T_STR, 0, "2001-11-23 15:01:42 -05:00" },
1551
+ { T_STR, 0, "User" },
1552
+ { T_STR, 0, "ed" },
1553
+ { T_STR, 0, "Warning" },
1554
+ { T_STR, 0, "This is an error message for the log file\n" },
1555
+ end_node
1556
+ };
1557
+ struct test_node map2[] = {
1558
+ { T_STR, 0, "Time" },
1559
+ { T_STR, 0, "2001-11-23 15:02:31 -05:00" },
1560
+ { T_STR, 0, "User" },
1561
+ { T_STR, 0, "ed" },
1562
+ { T_STR, 0, "Warning" },
1563
+ { T_STR, 0, "A slightly different error message.\n" },
1564
+ end_node
1565
+ };
1566
+ struct test_node file1[] = {
1567
+ { T_STR, 0, "file" },
1568
+ { T_STR, 0, "TopClass.py" },
1569
+ { T_STR, 0, "line" },
1570
+ { T_STR, 0, "23" },
1571
+ { T_STR, 0, "code" },
1572
+ { T_STR, 0, "x = MoreObject(\"345\\n\")\n" },
1573
+ end_node
1574
+ };
1575
+ struct test_node file2[] = {
1576
+ { T_STR, 0, "file" },
1577
+ { T_STR, 0, "MoreClass.py" },
1578
+ { T_STR, 0, "line" },
1579
+ { T_STR, 0, "58" },
1580
+ { T_STR, 0, "code" },
1581
+ { T_STR, 0, "foo = bar" },
1582
+ end_node
1583
+ };
1584
+ struct test_node stack[] = {
1585
+ { T_MAP, 0, 0, file1 },
1586
+ { T_MAP, 0, 0, file2 },
1587
+ end_node
1588
+ };
1589
+ struct test_node map3[] = {
1590
+ { T_STR, 0, "Date" },
1591
+ { T_STR, 0, "2001-11-23 15:03:17 -05:00" },
1592
+ { T_STR, 0, "User" },
1593
+ { T_STR, 0, "ed" },
1594
+ { T_STR, 0, "Fatal" },
1595
+ { T_STR, 0, "Unknown variable \"bar\"\n" },
1596
+ { T_STR, 0, "Stack" },
1597
+ { T_SEQ, 0, 0, stack },
1598
+ end_node
1599
+ };
1600
+ struct test_node stream[] = {
1601
+ { T_MAP, 0, 0, map1 },
1602
+ { T_MAP, 0, 0, map2 },
1603
+ { T_MAP, 0, 0, map3 },
1604
+ end_node
1605
+ };
1606
+
1607
+ CuStreamCompare( tc,
1608
+
1609
+ /* YAML document */
1610
+ "---\n"
1611
+ "Time: 2001-11-23 15:01:42 -05:00\n"
1612
+ "User: ed\n"
1613
+ "Warning: >\n"
1614
+ " This is an error message\n"
1615
+ " for the log file\n"
1616
+ "---\n"
1617
+ "Time: 2001-11-23 15:02:31 -05:00\n"
1618
+ "User: ed\n"
1619
+ "Warning: >\n"
1620
+ " A slightly different error\n"
1621
+ " message.\n"
1622
+ "---\n"
1623
+ "Date: 2001-11-23 15:03:17 -05:00\n"
1624
+ "User: ed\n"
1625
+ "Fatal: >\n"
1626
+ " Unknown variable \"bar\"\n"
1627
+ "Stack:\n"
1628
+ " - file: TopClass.py\n"
1629
+ " line: 23\n"
1630
+ " code: |\n"
1631
+ " x = MoreObject(\"345\\n\")\n"
1632
+ " - file: MoreClass.py\n"
1633
+ " line: 58\n"
1634
+ " code: |-\n"
1635
+ " foo = bar\n"
1636
+ ,
1637
+
1638
+ /* C structure of validations */
1639
+ stream
1640
+ );
1641
+
1642
+ CuRoundTrip( tc, stream );
1643
+ }
1644
+ /*
1645
+ * Example : Throwaway comments
1646
+ */
1647
+ void
1648
+ YtsSpecificationExamples_29( CuTest *tc )
1649
+ {
1650
+ struct test_node map[] = {
1651
+ { T_STR, 0, "this" },
1652
+ { T_STR, 0, "contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n" },
1653
+ end_node
1654
+ };
1655
+ struct test_node stream[] = {
1656
+ { T_MAP, 0, 0, map },
1657
+ end_node
1658
+ };
1659
+
1660
+ CuStreamCompare( tc,
1661
+
1662
+ /* YAML document */
1663
+ "### These are four throwaway comment ### \n"
1664
+ "\n"
1665
+ "### lines (the second line is empty). ### \n"
1666
+ "this: | # Comments may trail lines.\n"
1667
+ " contains three lines of text.\n"
1668
+ " The third one starts with a\n"
1669
+ " # character. This isn't a comment.\n"
1670
+ "\n"
1671
+ "# These are three throwaway comment\n"
1672
+ "# lines (the first line is empty).\n"
1673
+ ,
1674
+
1675
+ /* C structure of validations */
1676
+ stream
1677
+ );
1678
+
1679
+ CuRoundTrip( tc, stream );
1680
+ }
1681
+ /*
1682
+ * Example : Document with a single value
1683
+ */
1684
+ void
1685
+ YtsSpecificationExamples_30( CuTest *tc )
1686
+ {
1687
+ struct test_node stream[] = {
1688
+ { T_STR, 0, "This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end.\n" },
1689
+ end_node
1690
+ };
1691
+
1692
+ CuStreamCompare( tc,
1693
+
1694
+ /* YAML document */
1695
+ "--- > \n"
1696
+ "This YAML stream contains a single text value.\n"
1697
+ "The next stream is a log file - a sequence of\n"
1698
+ "log entries. Adding an entry to the log is a\n"
1699
+ "simple matter of appending it at the end.\n"
1700
+ ,
1701
+
1702
+ /* C structure of validations */
1703
+ stream
1704
+ );
1705
+
1706
+ CuRoundTrip( tc, stream );
1707
+ }
1708
+ /*
1709
+ * Example : Document stream
1710
+ */
1711
+ void
1712
+ YtsSpecificationExamples_31( CuTest *tc )
1713
+ {
1714
+ struct test_node map1[] = {
1715
+ { T_STR, 0, "at" },
1716
+ { T_STR, 0, "2001-08-12 09:25:00.00 Z" },
1717
+ { T_STR, 0, "type" },
1718
+ { T_STR, 0, "GET" },
1719
+ { T_STR, 0, "HTTP" },
1720
+ { T_STR, 0, "1.0" },
1721
+ { T_STR, 0, "url" },
1722
+ { T_STR, 0, "/index.html" },
1723
+ end_node
1724
+ };
1725
+ struct test_node map2[] = {
1726
+ { T_STR, 0, "at" },
1727
+ { T_STR, 0, "2001-08-12 09:25:10.00 Z" },
1728
+ { T_STR, 0, "type" },
1729
+ { T_STR, 0, "GET" },
1730
+ { T_STR, 0, "HTTP" },
1731
+ { T_STR, 0, "1.0" },
1732
+ { T_STR, 0, "url" },
1733
+ { T_STR, 0, "/toc.html" },
1734
+ end_node
1735
+ };
1736
+ struct test_node stream[] = {
1737
+ { T_MAP, 0, 0, map1 },
1738
+ { T_MAP, 0, 0, map2 },
1739
+ end_node
1740
+ };
1741
+
1742
+ CuStreamCompare( tc,
1743
+
1744
+ /* YAML document */
1745
+ "--- \n"
1746
+ "at: 2001-08-12 09:25:00.00 Z \n"
1747
+ "type: GET \n"
1748
+ "HTTP: '1.0' \n"
1749
+ "url: '/index.html' \n"
1750
+ "--- \n"
1751
+ "at: 2001-08-12 09:25:10.00 Z \n"
1752
+ "type: GET \n"
1753
+ "HTTP: '1.0' \n"
1754
+ "url: '/toc.html' \n"
1755
+ ,
1756
+
1757
+ /* C structure of validations */
1758
+ stream
1759
+ );
1760
+
1761
+ CuRoundTrip( tc, stream );
1762
+ }
1763
+ /*
1764
+ * Example : Top level mapping
1765
+ */
1766
+ void
1767
+ YtsSpecificationExamples_32( CuTest *tc )
1768
+ {
1769
+ struct test_node map[] = {
1770
+ { T_STR, 0, "invoice" },
1771
+ { T_STR, 0, "34843" },
1772
+ { T_STR, 0, "date" },
1773
+ { T_STR, 0, "2001-01-23" },
1774
+ { T_STR, 0, "total" },
1775
+ { T_STR, 0, "4443.52" },
1776
+ end_node
1777
+ };
1778
+ struct test_node stream[] = {
1779
+ { T_MAP, 0, 0, map },
1780
+ end_node
1781
+ };
1782
+
1783
+ CuStreamCompare( tc,
1784
+
1785
+ /* YAML document */
1786
+ "# This stream is an example of a top-level mapping. \n"
1787
+ "invoice : 34843 \n"
1788
+ "date : 2001-01-23 \n"
1789
+ "total : 4443.52 \n"
1790
+ ,
1791
+
1792
+ /* C structure of validations */
1793
+ stream
1794
+ );
1795
+
1796
+ CuRoundTrip( tc, stream );
1797
+ }
1798
+ /*
1799
+ * Example : Single-line documents
1800
+ */
1801
+ void
1802
+ YtsSpecificationExamples_33( CuTest *tc )
1803
+ {
1804
+ struct test_node map[] = {
1805
+ end_node
1806
+ };
1807
+ struct test_node seq[] = {
1808
+ end_node
1809
+ };
1810
+ struct test_node stream[] = {
1811
+ { T_MAP, 0, 0, map },
1812
+ { T_SEQ, 0, 0, seq },
1813
+ { T_STR, 0, "" },
1814
+ end_node
1815
+ };
1816
+
1817
+ CuStreamCompare( tc,
1818
+
1819
+ /* YAML document */
1820
+ "# The following is a sequence of three documents. \n"
1821
+ "# The first contains an empty mapping, the second \n"
1822
+ "# an empty sequence, and the last an empty string. \n"
1823
+ "--- {} \n"
1824
+ "--- [ ] \n"
1825
+ "--- '' \n"
1826
+ ,
1827
+
1828
+ /* C structure of validations */
1829
+ stream
1830
+ );
1831
+
1832
+ CuRoundTrip( tc, stream );
1833
+ }
1834
+ /*
1835
+ * Example : Document with pause
1836
+ */
1837
+ void
1838
+ YtsSpecificationExamples_34( CuTest *tc )
1839
+ {
1840
+ struct test_node map1[] = {
1841
+ { T_STR, 0, "sent at" },
1842
+ { T_STR, 0, "2002-06-06 11:46:25.10 Z" },
1843
+ { T_STR, 0, "payload" },
1844
+ { T_STR, 0, "Whatever" },
1845
+ end_node
1846
+ };
1847
+ struct test_node map2[] = {
1848
+ { T_STR, 0, "sent at" },
1849
+ { T_STR, 0, "2002-06-06 12:05:53.47 Z" },
1850
+ { T_STR, 0, "payload" },
1851
+ { T_STR, 0, "Whatever" },
1852
+ end_node
1853
+ };
1854
+ struct test_node stream[] = {
1855
+ { T_MAP, 0, 0, map1 },
1856
+ { T_MAP, 0, 0, map2 },
1857
+ end_node
1858
+ };
1859
+
1860
+ CuStreamCompare( tc,
1861
+
1862
+ /* YAML document */
1863
+ "# A communication channel based on a YAML stream. \n"
1864
+ "--- \n"
1865
+ "sent at: 2002-06-06 11:46:25.10 Z \n"
1866
+ "payload: Whatever \n"
1867
+ "# Receiver can process this as soon as the following is sent: \n"
1868
+ "... \n"
1869
+ "# Even if the next message is sent long after: \n"
1870
+ "--- \n"
1871
+ "sent at: 2002-06-06 12:05:53.47 Z \n"
1872
+ "payload: Whatever \n"
1873
+ "... \n"
1874
+ ,
1875
+
1876
+ /* C structure of validations */
1877
+ stream
1878
+ );
1879
+
1880
+ CuRoundTrip( tc, stream );
1881
+ }
1882
+ /*
1883
+ * Example : Explicit typing
1884
+ */
1885
+ void
1886
+ YtsSpecificationExamples_35( CuTest *tc )
1887
+ {
1888
+ struct test_node map[] = {
1889
+ { T_STR, 0, "integer" },
1890
+ { T_STR, "tag:yaml.org,2002:int", "12" },
1891
+ { T_STR, 0, "also int" },
1892
+ { T_STR, "tag:yaml.org,2002:int", "12" },
1893
+ { T_STR, 0, "string" },
1894
+ { T_STR, "tag:yaml.org,2002:str", "12" },
1895
+ end_node
1896
+ };
1897
+ struct test_node stream[] = {
1898
+ { T_MAP, 0, 0, map },
1899
+ end_node
1900
+ };
1901
+
1902
+ CuStreamCompare( tc,
1903
+
1904
+ /* YAML document */
1905
+ "integer: 12 \n"
1906
+ "also int: ! \"12\" \n"
1907
+ "string: !str 12 \n"
1908
+ ,
1909
+
1910
+ /* C structure of validations */
1911
+ stream
1912
+ );
1913
+
1914
+ CuRoundTrip( tc, stream );
1915
+ }
1916
+ /*
1917
+ * Example : Private types
1918
+ */
1919
+ void
1920
+ YtsSpecificationExamples_36( CuTest *tc )
1921
+ {
1922
+ struct test_node pool[] = {
1923
+ { T_STR, 0, "number" },
1924
+ { T_STR, 0, "8" },
1925
+ { T_STR, 0, "color" },
1926
+ { T_STR, 0, "black" },
1927
+ end_node
1928
+ };
1929
+ struct test_node map1[] = {
1930
+ { T_STR, 0, "pool" },
1931
+ { T_MAP, "x-private:ball", 0, pool },
1932
+ end_node
1933
+ };
1934
+ struct test_node bearing[] = {
1935
+ { T_STR, 0, "material" },
1936
+ { T_STR, 0, "steel" },
1937
+ end_node
1938
+ };
1939
+ struct test_node map2[] = {
1940
+ { T_STR, 0, "bearing" },
1941
+ { T_MAP, "x-private:ball", 0, bearing },
1942
+ end_node
1943
+ };
1944
+ struct test_node stream[] = {
1945
+ { T_MAP, 0, 0, map1 },
1946
+ { T_MAP, 0, 0, map2 },
1947
+ end_node
1948
+ };
1949
+
1950
+ CuStreamCompare( tc,
1951
+
1952
+ /* YAML document */
1953
+ "# Both examples below make use of the 'x-private:ball' \n"
1954
+ "# type family URI, but with different semantics. \n"
1955
+ "--- \n"
1956
+ "pool: !!ball \n"
1957
+ " number: 8 \n"
1958
+ " color: black \n"
1959
+ "--- \n"
1960
+ "bearing: !!ball \n"
1961
+ " material: steel \n"
1962
+ ,
1963
+
1964
+ /* C structure of validations */
1965
+ stream
1966
+ );
1967
+
1968
+ CuRoundTrip( tc, stream );
1969
+ }
1970
+ /*
1971
+ * Example : Type family under yaml.org
1972
+ */
1973
+ void
1974
+ YtsSpecificationExamples_37( CuTest *tc )
1975
+ {
1976
+ struct test_node seq[] = {
1977
+ { T_STR, "tag:yaml.org,2002:str", "a Unicode string" },
1978
+ end_node
1979
+ };
1980
+ struct test_node stream[] = {
1981
+ { T_SEQ, 0, 0, seq },
1982
+ end_node
1983
+ };
1984
+
1985
+ CuStreamCompare( tc,
1986
+
1987
+ /* YAML document */
1988
+ "# The URI is 'tag:yaml.org,2002:str' \n"
1989
+ "- !str a Unicode string \n"
1990
+ ,
1991
+
1992
+ /* C structure of validations */
1993
+ stream
1994
+ );
1995
+
1996
+ CuRoundTrip( tc, stream );
1997
+ }
1998
+ /*
1999
+ * Example : Type family under perl.yaml.org
2000
+ */
2001
+ void
2002
+ YtsSpecificationExamples_38( CuTest *tc )
2003
+ {
2004
+ struct test_node map[] = {
2005
+ end_node
2006
+ };
2007
+ struct test_node seq[] = {
2008
+ { T_MAP, "tag:perl.yaml.org,2002:Text::Tabs", 0, map },
2009
+ end_node
2010
+ };
2011
+ struct test_node stream[] = {
2012
+ { T_SEQ, 0, 0, seq },
2013
+ end_node
2014
+ };
2015
+
2016
+ CuStreamCompare( tc,
2017
+
2018
+ /* YAML document */
2019
+ "# The URI is 'tag:perl.yaml.org,2002:Text::Tabs' \n"
2020
+ "- !perl/Text::Tabs {} \n"
2021
+ ,
2022
+
2023
+ /* C structure of validations */
2024
+ stream
2025
+ );
2026
+
2027
+ CuRoundTrip( tc, stream );
2028
+ }
2029
+ /*
2030
+ * Example : Type family under clarkevans.com
2031
+ */
2032
+ void
2033
+ YtsSpecificationExamples_39( CuTest *tc )
2034
+ {
2035
+ struct test_node map[] = {
2036
+ end_node
2037
+ };
2038
+ struct test_node seq[] = {
2039
+ { T_MAP, "tag:clarkevans.com,2003-02:timesheet", 0, map },
2040
+ end_node
2041
+ };
2042
+ struct test_node stream[] = {
2043
+ { T_SEQ, 0, 0, seq },
2044
+ end_node
2045
+ };
2046
+
2047
+ CuStreamCompare( tc,
2048
+
2049
+ /* YAML document */
2050
+ "# The URI is 'tag:clarkevans.com,2003-02:timesheet' \n"
2051
+ "- !clarkevans.com,2003-02/timesheet {}\n"
2052
+ ,
2053
+
2054
+ /* C structure of validations */
2055
+ stream
2056
+ );
2057
+
2058
+ CuRoundTrip( tc, stream );
2059
+ }
2060
+ /*
2061
+ * Example : URI Escaping
2062
+ */
2063
+ void
2064
+ YtsSpecificationExamples_40( CuTest *tc )
2065
+ {
2066
+ struct test_node same[] = {
2067
+ { T_STR, "tag:domain.tld,2002:type0", "value" },
2068
+ { T_STR, "tag:domain.tld,2002:type0", "value" },
2069
+ end_node
2070
+ };
2071
+ struct test_node diff[] = {
2072
+ { T_STR, "tag:domain.tld,2002:type%30", "value" },
2073
+ { T_STR, "tag:domain.tld,2002:type0", "value" },
2074
+ end_node
2075
+ };
2076
+ struct test_node map[] = {
2077
+ { T_STR, 0, "same" },
2078
+ { T_SEQ, 0, 0, same },
2079
+ { T_STR, 0, "different" },
2080
+ { T_SEQ, 0, 0, diff },
2081
+ end_node
2082
+ };
2083
+ struct test_node stream[] = {
2084
+ { T_MAP, 0, 0, map },
2085
+ end_node
2086
+ };
2087
+
2088
+ CuStreamCompare( tc,
2089
+
2090
+ /* YAML document */
2091
+ "same: \n"
2092
+ " - !domain.tld,2002/type\\x30 value\n"
2093
+ " - !domain.tld,2002/type0 value\n"
2094
+ "different: # As far as the YAML parser is concerned \n"
2095
+ " - !domain.tld,2002/type%30 value\n"
2096
+ " - !domain.tld,2002/type0 value\n"
2097
+ ,
2098
+
2099
+ /* C structure of validations */
2100
+ stream
2101
+ );
2102
+
2103
+ CuRoundTrip( tc, stream );
2104
+ }
2105
+ /*
2106
+ * Example : Overriding anchors
2107
+ */
2108
+ void
2109
+ YtsSpecificationExamples_42( CuTest *tc )
2110
+ {
2111
+ struct test_node map[] = {
2112
+ { T_STR, 0, "anchor" },
2113
+ { T_STR, 0, "This scalar has an anchor." },
2114
+ { T_STR, 0, "override" },
2115
+ { T_STR, 0, "The alias node below is a repeated use of this value.\n" },
2116
+ { T_STR, 0, "alias" },
2117
+ { T_STR, 0, "The alias node below is a repeated use of this value.\n" },
2118
+ end_node
2119
+ };
2120
+ struct test_node stream[] = {
2121
+ { T_MAP, 0, 0, map },
2122
+ end_node
2123
+ };
2124
+
2125
+ CuStreamCompare( tc,
2126
+
2127
+ /* YAML document */
2128
+ "anchor : &A001 This scalar has an anchor. \n"
2129
+ "override : &A001 >\n"
2130
+ " The alias node below is a\n"
2131
+ " repeated use of this value.\n"
2132
+ "alias : *A001\n"
2133
+ ,
2134
+
2135
+ /* C structure of validations */
2136
+ stream
2137
+ );
2138
+
2139
+ CuRoundTrip( tc, stream );
2140
+ }
2141
+ /*
2142
+ * Example : Flow and block formatting
2143
+ */
2144
+ void
2145
+ YtsSpecificationExamples_43( CuTest *tc )
2146
+ {
2147
+ struct test_node empty[] = {
2148
+ end_node
2149
+ };
2150
+ struct test_node flow[] = {
2151
+ { T_STR, 0, "one" },
2152
+ { T_STR, 0, "two" },
2153
+ { T_STR, 0, "three" },
2154
+ { T_STR, 0, "four" },
2155
+ { T_STR, 0, "five" },
2156
+ end_node
2157
+ };
2158
+ struct test_node inblock[] = {
2159
+ { T_STR, 0, "Subordinate sequence entry" },
2160
+ end_node
2161
+ };
2162
+ struct test_node block[] = {
2163
+ { T_STR, 0, "First item in top sequence" },
2164
+ { T_SEQ, 0, 0, inblock },
2165
+ { T_STR, 0, "A folded sequence entry\n" },
2166
+ { T_STR, 0, "Sixth item in top sequence" },
2167
+ end_node
2168
+ };
2169
+ struct test_node map[] = {
2170
+ { T_STR, 0, "empty" },
2171
+ { T_SEQ, 0, 0, empty },
2172
+ { T_STR, 0, "flow" },
2173
+ { T_SEQ, 0, 0, flow },
2174
+ { T_STR, 0, "block" },
2175
+ { T_SEQ, 0, 0, block },
2176
+ end_node
2177
+ };
2178
+ struct test_node stream[] = {
2179
+ { T_MAP, 0, 0, map },
2180
+ end_node
2181
+ };
2182
+
2183
+ CuStreamCompare( tc,
2184
+
2185
+ /* YAML document */
2186
+ "empty: [] \n"
2187
+ "flow: [ one, two, three # May span lines, \n"
2188
+ " , four, # indentation is \n"
2189
+ " five ] # mostly ignored. \n"
2190
+ "block: \n"
2191
+ " - First item in top sequence \n"
2192
+ " - \n"
2193
+ " - Subordinate sequence entry \n"
2194
+ " - > \n"
2195
+ " A folded sequence entry\n"
2196
+ " - Sixth item in top sequence \n"
2197
+ ,
2198
+
2199
+ /* C structure of validations */
2200
+ stream
2201
+ );
2202
+
2203
+ CuRoundTrip( tc, stream );
2204
+ }
2205
+ /*
2206
+ * Example : Timestamp
2207
+ */
2208
+ void
2209
+ YtsSpecificationExamples_62( CuTest *tc )
2210
+ {
2211
+ struct test_node map[] = {
2212
+ { T_STR, 0, "canonical" },
2213
+ { T_STR, 0, "2001-12-15T02:59:43.1Z" },
2214
+ { T_STR, 0, "valid iso8601" },
2215
+ { T_STR, 0, "2001-12-14t21:59:43.10-05:00" },
2216
+ { T_STR, 0, "space separated" },
2217
+ { T_STR, 0, "2001-12-14 21:59:43.10 -05:00" },
2218
+ { T_STR, 0, "date (noon UTC)" },
2219
+ { T_STR, 0, "2002-12-14" },
2220
+ end_node
2221
+ };
2222
+ struct test_node stream[] = {
2223
+ { T_MAP, 0, 0, map },
2224
+ end_node
2225
+ };
2226
+
2227
+ CuStreamCompare( tc,
2228
+
2229
+ /* YAML document */
2230
+ "canonical: 2001-12-15T02:59:43.1Z \n"
2231
+ "valid iso8601: 2001-12-14t21:59:43.10-05:00 \n"
2232
+ "space separated: 2001-12-14 21:59:43.10 -05:00 \n"
2233
+ "date (noon UTC): 2002-12-14 \n"
2234
+ ,
2235
+
2236
+ /* C structure of validations */
2237
+ stream
2238
+ );
2239
+
2240
+ CuRoundTrip( tc, stream );
2241
+ }
2242
+
2243
+ CuSuite *
2244
+ SyckGetSuite()
2245
+ {
2246
+ CuSuite *suite = CuSuiteNew();
2247
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_0 );
2248
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_1 );
2249
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_2 );
2250
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_3 );
2251
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_4 );
2252
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_5 );
2253
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_6 );
2254
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_7 );
2255
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_8 );
2256
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_9 );
2257
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_10 );
2258
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_11 );
2259
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_12 );
2260
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_13 );
2261
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_14 );
2262
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_15 );
2263
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_16 );
2264
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_18 );
2265
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_19 );
2266
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_20 );
2267
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_21 );
2268
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_22 );
2269
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_23 );
2270
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_24 );
2271
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_25 );
2272
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_26 );
2273
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_27 );
2274
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_28 );
2275
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_29 );
2276
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_30 );
2277
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_31 );
2278
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_32 );
2279
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_33 );
2280
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_34 );
2281
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_35 );
2282
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_36 );
2283
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_37 );
2284
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_38 );
2285
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_39 );
2286
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_40 );
2287
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_42 );
2288
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_43 );
2289
+ SUITE_ADD_TEST( suite, YtsSpecificationExamples_62 );
2290
+ return suite;
2291
+ }
2292
+
2293
+ int main(void)
2294
+ {
2295
+ CuString *output = CuStringNew();
2296
+ CuSuite* suite = SyckGetSuite();
2297
+ int count;
2298
+
2299
+ CuSuiteRun(suite);
2300
+ CuSuiteSummary(suite, output);
2301
+ CuSuiteDetails(suite, output);
2302
+
2303
+ printf("%s\n", output->buffer);
2304
+ count = suite->failCount;
2305
+
2306
+ CuStringFree( output );
2307
+ CuSuiteFree( suite );
2308
+
2309
+ return count;
2310
+ }