| 1 | // |
|---|
| 2 | // YTS.c |
|---|
| 3 | // |
|---|
| 4 | // $Author$ |
|---|
| 5 | // $Date$ |
|---|
| 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 | |
|---|
| 145 | /* Set up parser */ |
|---|
| 146 | SyckParser *parser = syck_new_parser(); |
|---|
| 147 | syck_parser_str_auto( parser, yaml, NULL ); |
|---|
| 148 | syck_parser_handler( parser, syck_copy_handler ); |
|---|
| 149 | syck_parser_error_handler( parser, NULL ); |
|---|
| 150 | syck_parser_implicit_typing( parser, 1 ); |
|---|
| 151 | syck_parser_taguri_expansion( parser, 1 ); |
|---|
| 152 | |
|---|
| 153 | /* Parse all streams */ |
|---|
| 154 | while ( 1 ) |
|---|
| 155 | { |
|---|
| 156 | struct test_node *ydoc; |
|---|
| 157 | SYMID oid = syck_parse( parser ); |
|---|
| 158 | if ( parser->eof == 1 ) break; |
|---|
| 159 | |
|---|
| 160 | /* Add document to stream */ |
|---|
| 161 | int res = syck_lookup_sym( parser, oid, (char **)&ydoc ); |
|---|
| 162 | if (0 == res) |
|---|
| 163 | break; |
|---|
| 164 | |
|---|
| 165 | ystream[doc_ct] = ydoc[0]; |
|---|
| 166 | doc_ct++; |
|---|
| 167 | S_REALLOC_N( ystream, struct test_node, doc_ct + 1 ); |
|---|
| 168 | } |
|---|
| 169 | ystream[doc_ct] = end_node; |
|---|
| 170 | |
|---|
| 171 | /* Traverse the struct and the symbol table side-by-side */ |
|---|
| 172 | /* DEBUG: y( stream, 0 ); y( ystream, 0 ); */ |
|---|
| 173 | CuStreamCompareX( tc, stream, ystream ); |
|---|
| 174 | |
|---|
| 175 | /* Free the node tables and the parser */ |
|---|
| 176 | S_FREE( ystream ); |
|---|
| 177 | if ( parser->syms != NULL ) |
|---|
| 178 | st_foreach( parser->syms, syck_free_copies, 0 ); |
|---|
| 179 | syck_free_parser( parser ); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | /* |
|---|
| 183 | * Setup for testing N->Y->N. |
|---|
| 184 | */ |
|---|
| 185 | void |
|---|
| 186 | test_output_handler( emitter, str, len ) |
|---|
| 187 | SyckEmitter *emitter; |
|---|
| 188 | char *str; |
|---|
| 189 | long len; |
|---|
| 190 | { |
|---|
| 191 | CuString *dest = (CuString *)emitter->bonus; |
|---|
| 192 | CuStringAppendLen( dest, str, len ); |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | SYMID |
|---|
| 196 | build_symbol_table( SyckEmitter *emitter, struct test_node *node ) { |
|---|
| 197 | switch ( node->type ) { |
|---|
| 198 | case T_SEQ: |
|---|
| 199 | case T_MAP: |
|---|
| 200 | { |
|---|
| 201 | int i = 0; |
|---|
| 202 | while ( node->value[i].type != T_END ) { |
|---|
| 203 | build_symbol_table( emitter, &node->value[i] ); |
|---|
| 204 | i++; |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | return syck_emitter_mark_node( emitter, (st_data_t)node ); |
|---|
| 208 | |
|---|
| 209 | default: break; |
|---|
| 210 | } |
|---|
| 211 | return 0; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | void |
|---|
| 215 | test_emitter_handler( SyckEmitter *emitter, st_data_t data ) { |
|---|
| 216 | struct test_node *node = (struct test_node *)data; |
|---|
| 217 | switch ( node->type ) { |
|---|
| 218 | case T_STR: |
|---|
| 219 | syck_emit_scalar( emitter, node->tag, scalar_none, 0, 0, 0, node->key, strlen( node->key ) ); |
|---|
| 220 | break; |
|---|
| 221 | case T_SEQ: |
|---|
| 222 | { |
|---|
| 223 | int i = 0; |
|---|
| 224 | syck_emit_seq( emitter, node->tag, seq_none ); |
|---|
| 225 | while ( node->value[i].type != T_END ) { |
|---|
| 226 | syck_emit_item( emitter, (st_data_t)&node->value[i] ); |
|---|
| 227 | i++; |
|---|
| 228 | } |
|---|
| 229 | syck_emit_end( emitter ); |
|---|
| 230 | } |
|---|
| 231 | break; |
|---|
| 232 | case T_MAP: |
|---|
| 233 | { |
|---|
| 234 | int i = 0; |
|---|
| 235 | syck_emit_map( emitter, node->tag, map_none ); |
|---|
| 236 | while ( node->value[i].type != T_END ) { |
|---|
| 237 | syck_emit_item( emitter, (st_data_t)&node->value[i] ); |
|---|
| 238 | i++; |
|---|
| 239 | } |
|---|
| 240 | syck_emit_end( emitter ); |
|---|
| 241 | } |
|---|
| 242 | break; |
|---|
| 243 | } |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | void CuRoundTrip( CuTest* tc, struct test_node *stream ) { |
|---|
| 247 | int i = 0; |
|---|
| 248 | CuString *cs = CuStringNew(); |
|---|
| 249 | SyckEmitter *emitter = syck_new_emitter(); |
|---|
| 250 | |
|---|
| 251 | /* Calculate anchors and tags */ |
|---|
| 252 | build_symbol_table( emitter, stream ); |
|---|
| 253 | |
|---|
| 254 | /* Build the stream */ |
|---|
| 255 | syck_output_handler( emitter, test_output_handler ); |
|---|
| 256 | syck_emitter_handler( emitter, test_emitter_handler ); |
|---|
| 257 | emitter->bonus = cs; |
|---|
| 258 | while ( stream[i].type != T_END ) |
|---|
| 259 | { |
|---|
| 260 | syck_emit( emitter, (st_data_t)&stream[i] ); |
|---|
| 261 | syck_emitter_flush( emitter, 0 ); |
|---|
| 262 | i++; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | /* Reload the stream and compare */ |
|---|
| 266 | /* printf( "-- output for %s --\n%s\n--- end of output --\n", tc->name, cs->buffer ); */ |
|---|
| 267 | CuStreamCompare( tc, cs->buffer, stream ); |
|---|
| 268 | CuStringFree( cs ); |
|---|
| 269 | |
|---|
| 270 | syck_free_emitter( emitter ); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | /* |
|---|
| 274 | * ACTUAL TESTS FOR THE YAML TESTING SUITE BEGIN HERE |
|---|
| 275 | * (EVERYTHING PREVIOUS WAS SET UP FOR THE TESTS) |
|---|
| 276 | */ |
|---|
| 277 | |
|---|
| 278 | /* |
|---|
| 279 | * Example : Trailing tab in plains |
|---|
| 280 | */ |
|---|
| 281 | void |
|---|
| 282 | YtsFoldedScalars_7( CuTest *tc ) |
|---|
| 283 | { |
|---|
| 284 | struct test_node map[] = { |
|---|
| 285 | { T_STR, 0, "a" }, |
|---|
| 286 | { T_STR, 0, "b" }, |
|---|
| 287 | end_node |
|---|
| 288 | }; |
|---|
| 289 | struct test_node stream[] = { |
|---|
| 290 | { T_MAP, 0, 0, map }, |
|---|
| 291 | end_node |
|---|
| 292 | }; |
|---|
| 293 | |
|---|
| 294 | CuStreamCompare( tc, |
|---|
| 295 | |
|---|
| 296 | /* YAML document */ |
|---|
| 297 | "a: b\t \n" |
|---|
| 298 | , |
|---|
| 299 | |
|---|
| 300 | /* C structure of validations */ |
|---|
| 301 | stream |
|---|
| 302 | ); |
|---|
| 303 | |
|---|
| 304 | CuRoundTrip( tc, stream ); |
|---|
| 305 | } |
|---|
| 306 | /* |
|---|
| 307 | * Example : Empty Sequence |
|---|
| 308 | */ |
|---|
| 309 | void |
|---|
| 310 | YtsNullsAndEmpties_0( CuTest *tc ) |
|---|
| 311 | { |
|---|
| 312 | struct test_node seq[] = { |
|---|
| 313 | end_node |
|---|
| 314 | }; |
|---|
| 315 | struct test_node map[] = { |
|---|
| 316 | { T_STR, 0, "empty" }, |
|---|
| 317 | { T_SEQ, 0, 0, seq }, |
|---|
| 318 | end_node |
|---|
| 319 | }; |
|---|
| 320 | struct test_node stream[] = { |
|---|
| 321 | { T_MAP, 0, 0, map }, |
|---|
| 322 | end_node |
|---|
| 323 | }; |
|---|
| 324 | |
|---|
| 325 | CuStreamCompare( tc, |
|---|
| 326 | |
|---|
| 327 | /* YAML document */ |
|---|
| 328 | "empty: [] \n" |
|---|
| 329 | , |
|---|
| 330 | |
|---|
| 331 | /* C structure of validations */ |
|---|
| 332 | stream |
|---|
| 333 | ); |
|---|
| 334 | |
|---|
| 335 | CuRoundTrip( tc, stream ); |
|---|
| 336 | } |
|---|
| 337 | /* |
|---|
| 338 | * Example : Empty Mapping |
|---|
| 339 | */ |
|---|
| 340 | void |
|---|
| 341 | YtsNullsAndEmpties_1( CuTest *tc ) |
|---|
| 342 | { |
|---|
| 343 | struct test_node map2[] = { |
|---|
| 344 | end_node |
|---|
| 345 | }; |
|---|
| 346 | struct test_node map1[] = { |
|---|
| 347 | { T_STR, 0, "empty" }, |
|---|
| 348 | { T_MAP, 0, 0, map2 }, |
|---|
| 349 | end_node |
|---|
| 350 | }; |
|---|
| 351 | struct test_node stream[] = { |
|---|
| 352 | { T_MAP, 0, 0, map1 }, |
|---|
| 353 | end_node |
|---|
| 354 | }; |
|---|
| 355 | |
|---|
| 356 | CuStreamCompare( tc, |
|---|
| 357 | |
|---|
| 358 | /* YAML document */ |
|---|
| 359 | "empty: {} \n" |
|---|
| 360 | , |
|---|
| 361 | |
|---|
| 362 | /* C structure of validations */ |
|---|
| 363 | stream |
|---|
| 364 | ); |
|---|
| 365 | |
|---|
| 366 | CuRoundTrip( tc, stream ); |
|---|
| 367 | } |
|---|
| 368 | /* |
|---|
| 369 | * Example : Empty Sequence as Entire Document |
|---|
| 370 | */ |
|---|
| 371 | void |
|---|
| 372 | YtsNullsAndEmpties_2( CuTest *tc ) |
|---|
| 373 | { |
|---|
| 374 | struct test_node seq[] = { |
|---|
| 375 | end_node |
|---|
| 376 | }; |
|---|
| 377 | struct test_node stream[] = { |
|---|
| 378 | { T_SEQ, 0, 0, seq }, |
|---|
| 379 | end_node |
|---|
| 380 | }; |
|---|
| 381 | |
|---|
| 382 | CuStreamCompare( tc, |
|---|
| 383 | |
|---|
| 384 | /* YAML document */ |
|---|
| 385 | "--- [] \n" |
|---|
| 386 | , |
|---|
| 387 | |
|---|
| 388 | /* C structure of validations */ |
|---|
| 389 | stream |
|---|
| 390 | ); |
|---|
| 391 | |
|---|
| 392 | CuRoundTrip( tc, stream ); |
|---|
| 393 | } |
|---|
| 394 | /* |
|---|
| 395 | * Example : Empty Mapping as Entire Document |
|---|
| 396 | */ |
|---|
| 397 | void |
|---|
| 398 | YtsNullsAndEmpties_3( CuTest *tc ) |
|---|
| 399 | { |
|---|
| 400 | struct test_node map[] = { |
|---|
| 401 | end_node |
|---|
| 402 | }; |
|---|
| 403 | struct test_node stream[] = { |
|---|
| 404 | { T_MAP, 0, 0, map }, |
|---|
| 405 | end_node |
|---|
| 406 | }; |
|---|
| 407 | |
|---|
| 408 | CuStreamCompare( tc, |
|---|
| 409 | |
|---|
| 410 | /* YAML document */ |
|---|
| 411 | "--- {} \n" |
|---|
| 412 | , |
|---|
| 413 | |
|---|
| 414 | /* C structure of validations */ |
|---|
| 415 | stream |
|---|
| 416 | ); |
|---|
| 417 | |
|---|
| 418 | CuRoundTrip( tc, stream ); |
|---|
| 419 | } |
|---|
| 420 | /* |
|---|
| 421 | * Example : Null as Document |
|---|
| 422 | */ |
|---|
| 423 | void |
|---|
| 424 | YtsNullsAndEmpties_4( CuTest *tc ) |
|---|
| 425 | { |
|---|
| 426 | struct test_node stream[] = { |
|---|
| 427 | { T_STR, 0, "~" }, |
|---|
| 428 | end_node |
|---|
| 429 | }; |
|---|
| 430 | |
|---|
| 431 | CuStreamCompare( tc, |
|---|
| 432 | |
|---|
| 433 | /* YAML document */ |
|---|
| 434 | "--- ~ \n" |
|---|
| 435 | , |
|---|
| 436 | |
|---|
| 437 | /* C structure of validations */ |
|---|
| 438 | stream |
|---|
| 439 | ); |
|---|
| 440 | |
|---|
| 441 | CuRoundTrip( tc, stream ); |
|---|
| 442 | } |
|---|
| 443 | /* |
|---|
| 444 | * Example : Empty String |
|---|
| 445 | */ |
|---|
| 446 | void |
|---|
| 447 | YtsNullsAndEmpties_5( CuTest *tc ) |
|---|
| 448 | { |
|---|
| 449 | struct test_node stream[] = { |
|---|
| 450 | { T_STR, 0, "" }, |
|---|
| 451 | end_node |
|---|
| 452 | }; |
|---|
| 453 | |
|---|
| 454 | CuStreamCompare( tc, |
|---|
| 455 | |
|---|
| 456 | /* YAML document */ |
|---|
| 457 | "--- '' \n" |
|---|
| 458 | , |
|---|
| 459 | |
|---|
| 460 | /* C structure of validations */ |
|---|
| 461 | stream |
|---|
| 462 | ); |
|---|
| 463 | |
|---|
| 464 | CuRoundTrip( tc, stream ); |
|---|
| 465 | } |
|---|
| 466 | /* |
|---|
| 467 | * Example 2.1: Sequence of scalars |
|---|
| 468 | */ |
|---|
| 469 | void |
|---|
| 470 | YtsSpecificationExamples_0( CuTest *tc ) |
|---|
| 471 | { |
|---|
| 472 | struct test_node seq[] = { |
|---|
| 473 | { T_STR, 0, "Mark McGwire" }, |
|---|
| 474 | { T_STR, 0, "Sammy Sosa" }, |
|---|
| 475 | { T_STR, 0, "Ken Griffey" }, |
|---|
| 476 | end_node |
|---|
| 477 | }; |
|---|
| 478 | struct test_node stream[] = { |
|---|
| 479 | { T_SEQ, 0, 0, seq }, |
|---|
| 480 | end_node |
|---|
| 481 | }; |
|---|
| 482 | |
|---|
| 483 | CuStreamCompare( tc, |
|---|
| 484 | |
|---|
| 485 | /* YAML document */ |
|---|
| 486 | "- Mark McGwire \n" |
|---|
| 487 | "- Sammy Sosa \n" |
|---|
| 488 | "- Ken Griffey \n" |
|---|
| 489 | , |
|---|
| 490 | |
|---|
| 491 | /* C structure of validations */ |
|---|
| 492 | stream |
|---|
| 493 | ); |
|---|
| 494 | |
|---|
| 495 | CuRoundTrip( tc, stream ); |
|---|
| 496 | } |
|---|
| 497 | /* |
|---|
| 498 | * Example 2.2: Mapping of scalars to scalars |
|---|
| 499 | */ |
|---|
| 500 | void |
|---|
| 501 | YtsSpecificationExamples_1( CuTest *tc ) |
|---|
| 502 | { |
|---|
| 503 | struct test_node map[] = { |
|---|
| 504 | { T_STR, 0, "hr" }, |
|---|
| 505 | { T_STR, 0, "65" }, |
|---|
| 506 | { T_STR, 0, "avg" }, |
|---|
| 507 | { T_STR, 0, "0.278" }, |
|---|
| 508 | { T_STR, 0, "rbi" }, |
|---|
| 509 | { T_STR, 0, "147" }, |
|---|
| 510 | end_node |
|---|
| 511 | }; |
|---|
| 512 | struct test_node stream[] = { |
|---|
| 513 | { T_MAP, 0, 0, map }, |
|---|
| 514 | end_node |
|---|
| 515 | }; |
|---|
| 516 | |
|---|
| 517 | CuStreamCompare( tc, |
|---|
| 518 | |
|---|
| 519 | /* YAML document */ |
|---|
| 520 | "hr: 65 \n" |
|---|
| 521 | "avg: 0.278 \n" |
|---|
| 522 | "rbi: 147 \n" |
|---|
| 523 | , |
|---|
| 524 | |
|---|
| 525 | /* C structure of validations */ |
|---|
| 526 | stream |
|---|
| 527 | ); |
|---|
| 528 | |
|---|
| 529 | CuRoundTrip( tc, stream ); |
|---|
| 530 | } |
|---|
| 531 | /* |
|---|
| 532 | * Example 2.3: Mapping of scalars to sequences |
|---|
| 533 | */ |
|---|
| 534 | void |
|---|
| 535 | YtsSpecificationExamples_2( CuTest *tc ) |
|---|
| 536 | { |
|---|
| 537 | struct test_node seq1[] = { |
|---|
| 538 | { T_STR, 0, "Boston Red Sox" }, |
|---|
| 539 | { T_STR, 0, "Detroit Tigers" }, |
|---|
| 540 | { T_STR, 0, "New York Yankees" }, |
|---|
| 541 | end_node |
|---|
| 542 | }; |
|---|
| 543 | struct test_node seq2[] = { |
|---|
| 544 | { T_STR, 0, "New York Mets" }, |
|---|
| 545 | { T_STR, 0, "Chicago Cubs" }, |
|---|
| 546 | { T_STR, 0, "Atlanta Braves" }, |
|---|
| 547 | end_node |
|---|
| 548 | }; |
|---|
| 549 | struct test_node map[] = { |
|---|
| 550 | { T_STR, 0, "american" }, |
|---|
| 551 | { T_SEQ, 0, 0, seq1 }, |
|---|
| 552 | { T_STR, 0, "national" }, |
|---|
| 553 | { T_SEQ, 0, 0, seq2 }, |
|---|
| 554 | end_node |
|---|
| 555 | }; |
|---|
| 556 | struct test_node stream[] = { |
|---|
| 557 | { T_MAP, 0, 0, map }, |
|---|
| 558 | end_node |
|---|
| 559 | }; |
|---|
| 560 | |
|---|
| 561 | CuStreamCompare( tc, |
|---|
| 562 | |
|---|
| 563 | /* YAML document */ |
|---|
| 564 | "american: \n" |
|---|
| 565 | " - Boston Red Sox \n" |
|---|
| 566 | " - Detroit Tigers \n" |
|---|
| 567 | " - New York Yankees \n" |
|---|
| 568 | "national: \n" |
|---|
| 569 | " - New York Mets \n" |
|---|
| 570 | " - Chicago Cubs \n" |
|---|
| 571 | " - Atlanta Braves \n" |
|---|
| 572 | , |
|---|
| 573 | |
|---|
| 574 | /* C structure of validations */ |
|---|
| 575 | stream |
|---|
| 576 | ); |
|---|
| 577 | |
|---|
| 578 | CuRoundTrip( tc, stream ); |
|---|
| 579 | } |
|---|
| 580 | /* |
|---|
| 581 | * Example 2.4: Sequence of mappings |
|---|
| 582 | */ |
|---|
| 583 | void |
|---|
| 584 | YtsSpecificationExamples_3( CuTest *tc ) |
|---|
| 585 | { |
|---|
| 586 | struct test_node map1[] = { |
|---|
| 587 | { T_STR, 0, "name" }, |
|---|
| 588 | { T_STR, 0, "Mark McGwire" }, |
|---|
| 589 | { T_STR, 0, "hr" }, |
|---|
| 590 | { T_STR, 0, "65" }, |
|---|
| 591 | { T_STR, 0, "avg" }, |
|---|
| 592 | { T_STR, 0, "0.278" }, |
|---|
| 593 | end_node |
|---|
| 594 | }; |
|---|
| 595 | struct test_node map2[] = { |
|---|
| 596 | { T_STR, 0, "name" }, |
|---|
| 597 | { T_STR, 0, "Sammy Sosa" }, |
|---|
| 598 | { T_STR, 0, "hr" }, |
|---|
| 599 | { T_STR, 0, "63" }, |
|---|
| 600 | { T_STR, 0, "avg" }, |
|---|
| 601 | { T_STR, 0, "0.288" }, |
|---|
| 602 | end_node |
|---|
| 603 | }; |
|---|
| 604 | struct test_node seq[] = { |
|---|
| 605 | { T_MAP, 0, 0, map1 }, |
|---|
| 606 | { T_MAP, 0, 0, map2 }, |
|---|
| 607 | end_node |
|---|
| 608 | }; |
|---|
| 609 | struct test_node stream[] = { |
|---|
| 610 | { T_SEQ, 0, 0, seq }, |
|---|
| 611 | end_node |
|---|
| 612 | }; |
|---|
| 613 | |
|---|
| 614 | CuStreamCompare( tc, |
|---|
| 615 | |
|---|
| 616 | /* YAML document */ |
|---|
| 617 | "- \n" |
|---|
| 618 | " name: Mark McGwire \n" |
|---|
| 619 | " hr: 65 \n" |
|---|
| 620 | " avg: 0.278 \n" |
|---|
| 621 | "- \n" |
|---|
| 622 | " name: Sammy Sosa \n" |
|---|
| 623 | " hr: 63 \n" |
|---|
| 624 | " avg: 0.288 \n" |
|---|
| 625 | , |
|---|
| 626 | |
|---|
| 627 | /* C structure of validations */ |
|---|
| 628 | stream |
|---|
| 629 | ); |
|---|
| 630 | |
|---|
| 631 | CuRoundTrip( tc, stream ); |
|---|
| 632 | } |
|---|
| 633 | /* |
|---|
| 634 | * Example legacy_A5: Legacy A5 |
|---|
| 635 | */ |
|---|
| 636 | void |
|---|
| 637 | YtsSpecificationExamples_4( CuTest *tc ) |
|---|
| 638 | { |
|---|
| 639 | struct test_node seq1[] = { |
|---|
| 640 | { T_STR, 0, "New York Yankees" }, |
|---|
| 641 | { T_STR, 0, "Atlanta Braves" }, |
|---|
| 642 | end_node |
|---|
| 643 | }; |
|---|
| 644 | struct test_node seq2[] = { |
|---|
| 645 | { T_STR, 0, "2001-07-02" }, |
|---|
| 646 | { T_STR, 0, "2001-08-12" }, |
|---|
| 647 | { T_STR, 0, "2001-08-14" }, |
|---|
| 648 | end_node |
|---|
| 649 | }; |
|---|
| 650 | struct test_node seq3[] = { |
|---|
| 651 | { T_STR, 0, "Detroit Tigers" }, |
|---|
| 652 | { T_STR, 0, "Chicago Cubs" }, |
|---|
| 653 | end_node |
|---|
| 654 | }; |
|---|
| 655 | struct test_node seq4[] = { |
|---|
| 656 | { T_STR, 0, "2001-07-23" }, |
|---|
| 657 | end_node |
|---|
| 658 | }; |
|---|
| 659 | struct test_node map[] = { |
|---|
| 660 | { T_SEQ, 0, 0, seq1 }, |
|---|
| 661 | { T_SEQ, 0, 0, seq2 }, |
|---|
| 662 | { T_SEQ, 0, 0, seq3 }, |
|---|
| 663 | { T_SEQ, 0, 0, seq4 }, |
|---|
| 664 | end_node |
|---|
| 665 | }; |
|---|
| 666 | struct test_node stream[] = { |
|---|
| 667 | { T_MAP, 0, 0, map }, |
|---|
| 668 | end_node |
|---|
| 669 | }; |
|---|
| 670 | |
|---|
| 671 | CuStreamCompare( tc, |
|---|
| 672 | |
|---|
| 673 | /* YAML document */ |
|---|
| 674 | "? \n" |
|---|
| 675 | " - New York Yankees \n" |
|---|
| 676 | " - Atlanta Braves \n" |
|---|
| 677 | ": \n" |
|---|
| 678 | " - 2001-07-02 \n" |
|---|
| 679 | " - 2001-08-12 \n" |
|---|
| 680 | " - 2001-08-14 \n" |
|---|
| 681 | "? \n" |
|---|
| 682 | " - Detroit Tigers \n" |
|---|
| 683 | " - Chicago Cubs \n" |
|---|
| 684 | ": \n" |
|---|
| 685 | " - 2001-07-23 \n" |
|---|
| 686 | , |
|---|
| 687 | |
|---|
| 688 | /* C structure of validations */ |
|---|
| 689 | stream |
|---|
| 690 | ); |
|---|
| 691 | |
|---|
| 692 | CuRoundTrip( tc, stream ); |
|---|
| 693 | } |
|---|
| 694 | /* |
|---|
| 695 | * Example 2.5: Sequence of sequences |
|---|
| 696 | */ |
|---|
| 697 | void |
|---|
| 698 | YtsSpecificationExamples_5( CuTest *tc ) |
|---|
| 699 | { |
|---|
| 700 | struct test_node seq1[] = { |
|---|
| 701 | { T_STR, 0, "name" }, |
|---|
| 702 | { T_STR, 0, "hr" }, |
|---|
| 703 | { T_STR, 0, "avg" }, |
|---|
| 704 | end_node |
|---|
| 705 | }; |
|---|
| 706 | struct test_node seq2[] = { |
|---|
| 707 | { T_STR, 0, "Mark McGwire" }, |
|---|
| 708 | { T_STR, 0, "65" }, |
|---|
| 709 | { T_STR, 0, "0.278" }, |
|---|
| 710 | end_node |
|---|
| 711 | }; |
|---|
| 712 | struct test_node seq3[] = { |
|---|
| 713 | { T_STR, 0, "Sammy Sosa" }, |
|---|
| 714 | { T_STR, 0, "63" }, |
|---|
| 715 | { T_STR, 0, "0.288" }, |
|---|
| 716 | end_node |
|---|
| 717 | }; |
|---|
| 718 | struct test_node seq[] = { |
|---|
| 719 | { T_SEQ, 0, 0, seq1 }, |
|---|
| 720 | { T_SEQ, 0, 0, seq2 }, |
|---|
| 721 | { T_SEQ, 0, 0, seq3 }, |
|---|
| 722 | end_node |
|---|
| 723 | }; |
|---|
| 724 | struct test_node stream[] = { |
|---|
| 725 | { T_SEQ, 0, 0, seq }, |
|---|
| 726 | end_node |
|---|
| 727 | }; |
|---|
| 728 | |
|---|
| 729 | CuStreamCompare( tc, |
|---|
| 730 | |
|---|
| 731 | /* YAML document */ |
|---|
| 732 | "- [ name , hr , avg ] \n" |
|---|
| 733 | "- [ Mark McGwire , 65 , 0.278 ] \n" |
|---|
| 734 | "- [ Sammy Sosa , 63 , 0.288 ] \n" |
|---|
| 735 | , |
|---|
| 736 | |
|---|
| 737 | /* C structure of validations */ |
|---|
| 738 | stream |
|---|
| 739 | ); |
|---|
| 740 | |
|---|
| 741 | CuRoundTrip( tc, stream ); |
|---|
| 742 | } |
|---|
| 743 | /* |
|---|
| 744 | * Example 2.6: Mapping of mappings |
|---|
| 745 | */ |
|---|
| 746 | void |
|---|
| 747 | YtsSpecificationExamples_6( CuTest *tc ) |
|---|
| 748 | { |
|---|
| 749 | struct test_node map1[] = { |
|---|
| 750 | { T_STR, 0, "hr" }, |
|---|
| 751 | { T_STR, 0, "65" }, |
|---|
| 752 | { T_STR, 0, "avg" }, |
|---|
| 753 | { T_STR, 0, "0.278" }, |
|---|
| 754 | end_node |
|---|
| 755 | }; |
|---|
| 756 | struct test_node map2[] = { |
|---|
| 757 | { T_STR, 0, "hr" }, |
|---|
| 758 | { T_STR, 0, "63" }, |
|---|
| 759 | { T_STR, 0, "avg" }, |
|---|
| 760 | { T_STR, 0, "0.288" }, |
|---|
| 761 | end_node |
|---|
| 762 | }; |
|---|
| 763 | struct test_node map[] = { |
|---|
| 764 | { T_STR, 0, "Mark McGwire" }, |
|---|
| 765 | { T_MAP, 0, 0, map1 }, |
|---|
| 766 | { T_STR, 0, "Sammy Sosa" }, |
|---|
| 767 | { T_MAP, 0, 0, map2 }, |
|---|
| 768 | end_node |
|---|
| 769 | }; |
|---|
| 770 | struct test_node stream[] = { |
|---|
| 771 | { T_MAP, 0, 0, map }, |
|---|
| 772 | end_node |
|---|
| 773 | }; |
|---|
| 774 | |
|---|
| 775 | CuStreamCompare( tc, |
|---|
| 776 | |
|---|
| 777 | /* YAML document */ |
|---|
| 778 | "Mark McGwire: {hr: 65, avg: 0.278}\n" |
|---|
| 779 | "Sammy Sosa: {\n" |
|---|
| 780 | " hr: 63,\n" |
|---|
| 781 | " avg: 0.288\n" |
|---|
| 782 | " }\n" |
|---|
| 783 | , |
|---|
| 784 | |
|---|
| 785 | /* C structure of validations */ |
|---|
| 786 | stream |
|---|
| 787 | ); |
|---|
| 788 | |
|---|
| 789 | CuRoundTrip( tc, stream ); |
|---|
| 790 | } |
|---|
| 791 | /* |
|---|
| 792 | * Example 2.7: Two documents in a stream each with a leading comment |
|---|
| 793 | */ |
|---|
| 794 | void |
|---|
| 795 | YtsSpecificationExamples_7( CuTest *tc ) |
|---|
| 796 | { |
|---|
| 797 | struct test_node seq1[] = { |
|---|
| 798 | { T_STR, 0, "Mark McGwire" }, |
|---|
| 799 | { T_STR, 0, "Sammy Sosa" }, |
|---|
| 800 | { T_STR, 0, "Ken Griffey" }, |
|---|
| 801 | end_node |
|---|
| 802 | }; |
|---|
| 803 | struct test_node seq2[] = { |
|---|
| 804 | { T_STR, 0, "Chicago Cubs" }, |
|---|
| 805 | { T_STR, 0, "St Louis Cardinals" }, |
|---|
| 806 | end_node |
|---|
| 807 | }; |
|---|
| 808 | struct test_node stream[] = { |
|---|
| 809 | { T_SEQ, 0, 0, seq1 }, |
|---|
| 810 | { T_SEQ, 0, 0, seq2 }, |
|---|
| 811 | end_node |
|---|
| 812 | }; |
|---|
| 813 | |
|---|
| 814 | CuStreamCompare( tc, |
|---|
| 815 | |
|---|
| 816 | /* YAML document */ |
|---|
| 817 | "# Ranking of 1998 home runs\n" |
|---|
| 818 | "---\n" |
|---|
| 819 | "- Mark McGwire\n" |
|---|
| 820 | "- Sammy Sosa\n" |
|---|
| 821 | "- Ken Griffey\n" |
|---|
| 822 | "\n" |
|---|
| 823 | "# Team ranking\n" |
|---|
| 824 | "---\n" |
|---|
| 825 | "- Chicago Cubs\n" |
|---|
| 826 | "- St Louis Cardinals\n" |
|---|
| 827 | , |
|---|
| 828 | |
|---|
| 829 | /* C structure of validations */ |
|---|
| 830 | stream |
|---|
| 831 | ); |
|---|
| 832 | |
|---|
| 833 | CuRoundTrip( tc, stream ); |
|---|
| 834 | } |
|---|
| 835 | /* |
|---|
| 836 | * Example 2.8: Play by play feed from a game |
|---|
| 837 | */ |
|---|
| 838 | void |
|---|
| 839 | YtsSpecificationExamples_8( CuTest *tc ) |
|---|
| 840 | { |
|---|
| 841 | struct test_node map1[] = { |
|---|
| 842 | { T_STR, 0, "time" }, |
|---|
| 843 | { T_STR, 0, "20:03:20" }, |
|---|
| 844 | { T_STR, 0, "player" }, |
|---|
| 845 | { T_STR, 0, "Sammy Sosa" }, |
|---|
| 846 | { T_STR, 0, "action" }, |
|---|
| 847 | { T_STR, 0, "strike (miss)" }, |
|---|
| 848 | end_node |
|---|
| 849 | }; |
|---|
| 850 | struct test_node map2[] = { |
|---|
| 851 | { T_STR, 0, "time" }, |
|---|
| 852 | { T_STR, 0, "20:03:47" }, |
|---|
| 853 | { T_STR, 0, "player" }, |
|---|
| 854 | { T_STR, 0, "Sammy Sosa" }, |
|---|
| 855 | { T_STR, 0, "action" }, |
|---|
| 856 | { T_STR, 0, "grand slam" }, |
|---|
| 857 | end_node |
|---|
| 858 | }; |
|---|
| 859 | struct test_node stream[] = { |
|---|
| 860 | { T_MAP, 0, 0, map1 }, |
|---|
| 861 | { T_MAP, 0, 0, map2 }, |
|---|
| 862 | end_node |
|---|
| 863 | }; |
|---|
| 864 | |
|---|
| 865 | CuStreamCompare( tc, |
|---|
| 866 | |
|---|
| 867 | /* YAML document */ |
|---|
| 868 | "---\n" |
|---|
| 869 | "time: 20:03:20\n" |
|---|
| 870 | "player: Sammy Sosa\n" |
|---|
| 871 | "action: strike (miss)\n" |
|---|
| 872 | "...\n" |
|---|
| 873 | "---\n" |
|---|
| 874 | "time: 20:03:47\n" |
|---|
| 875 | "player: Sammy Sosa\n" |
|---|
| 876 | "action: grand slam\n" |
|---|
| 877 | "...\n" |
|---|
| 878 | , |
|---|
| 879 | |
|---|
| 880 | /* C structure of validations */ |
|---|
| 881 | stream |
|---|
| 882 | ); |
|---|
| 883 | |
|---|
| 884 | CuRoundTrip( tc, stream ); |
|---|
| 885 | } |
|---|
| 886 | /* |
|---|
| 887 | * Example 2.9: Single document with two comments |
|---|
| 888 | */ |
|---|
| 889 | void |
|---|
| 890 | YtsSpecificationExamples_9( CuTest *tc ) |
|---|
| 891 | { |
|---|
| 892 | struct test_node seq1[] = { |
|---|
| 893 | { T_STR, 0, "Mark McGwire" }, |
|---|
| 894 | { T_STR, 0, "Sammy Sosa" }, |
|---|
| 895 | end_node |
|---|
| 896 | }; |
|---|
| 897 | struct test_node seq2[] = { |
|---|
| 898 | { T_STR, 0, "Sammy Sosa" }, |
|---|
| 899 | { T_STR, 0, "Ken Griffey" }, |
|---|
| 900 | end_node |
|---|
| 901 | }; |
|---|
| 902 | struct test_node map[] = { |
|---|
| 903 | { T_STR, 0, "hr" }, |
|---|
| 904 | { T_SEQ, 0, 0, seq1 }, |
|---|
| 905 | { T_STR, 0, "rbi" }, |
|---|
| 906 | { T_SEQ, 0, 0, seq2 }, |
|---|
| 907 | end_node |
|---|
| 908 | }; |
|---|
| 909 | struct test_node stream[] = { |
|---|
| 910 | { T_MAP, 0, 0, map }, |
|---|
| 911 | end_node |
|---|
| 912 | }; |
|---|
| 913 | |
|---|
| 914 | CuStreamCompare( tc, |
|---|
| 915 | |
|---|
| 916 | /* YAML document */ |
|---|
| 917 | "hr: # 1998 hr ranking \n" |
|---|
| 918 | " - Mark McGwire \n" |
|---|
| 919 | " - Sammy Sosa \n" |
|---|
| 920 | "rbi: \n" |
|---|
| 921 | " # 1998 rbi ranking \n" |
|---|
| 922 | " - Sammy Sosa \n" |
|---|
| 923 | " - Ken Griffey \n" |
|---|
| 924 | , |
|---|
| 925 | |
|---|
| 926 | /* C structure of validations */ |
|---|
| 927 | stream |
|---|
| 928 | ); |
|---|
| 929 | |
|---|
| 930 | CuRoundTrip( tc, stream ); |
|---|
| 931 | } |
|---|
| 932 | /* |
|---|
| 933 | * Example 2.1: Node for Sammy Sosa appears twice in this document |
|---|
| 934 | */ |
|---|
| 935 | void |
|---|
| 936 | YtsSpecificationExamples_10( CuTest *tc ) |
|---|
| 937 | { |
|---|
| 938 | struct test_node seq1[] = { |
|---|
| 939 | { T_STR, 0, "Mark McGwire" }, |
|---|
| 940 | { T_STR, 0, "Sammy Sosa" }, |
|---|
| 941 | end_node |
|---|
| 942 | }; |
|---|
| 943 | struct test_node seq2[] = { |
|---|
| 944 | { T_STR, 0, "Sammy Sosa" }, |
|---|
| 945 | { T_STR, 0, "Ken Griffey" }, |
|---|
| 946 | end_node |
|---|
| 947 | }; |
|---|
| 948 | struct test_node map[] = { |
|---|
| 949 | { T_STR, 0, "hr" }, |
|---|
| 950 | { T_SEQ, 0, 0, seq1 }, |
|---|
| 951 | { T_STR, 0, "rbi" }, |
|---|
| 952 | { T_SEQ, 0, 0, seq2 }, |
|---|
| 953 | end_node |
|---|
| 954 | }; |
|---|
| 955 | struct test_node stream[] = { |
|---|
| 956 | { T_MAP, 0, 0, map }, |
|---|
| 957 | end_node |
|---|
| 958 | }; |
|---|
| 959 | |
|---|
| 960 | CuStreamCompare( tc, |
|---|
| 961 | |
|---|
| 962 | /* YAML document */ |
|---|
| 963 | "---\n" |
|---|
| 964 | "hr: \n" |
|---|
| 965 | " - Mark McGwire \n" |
|---|
| 966 | " # Following node labeled SS \n" |
|---|
| 967 | " - &SS Sammy Sosa \n" |
|---|
| 968 | "rbi: \n" |
|---|
| 969 | " - *SS # Subsequent occurance \n" |
|---|
| 970 | " - Ken Griffey \n" |
|---|
| 971 | , |
|---|
| 972 | |
|---|
| 973 | /* C structure of validations */ |
|---|
| 974 | stream |
|---|
| 975 | ); |
|---|
| 976 | |
|---|
| 977 | CuRoundTrip( tc, stream ); |
|---|
| 978 | } |
|---|
| 979 | /* |
|---|
| 980 | * Example 2.11: Mapping between sequences |
|---|
| 981 | */ |
|---|
| 982 | void |
|---|
| 983 | YtsSpecificationExamples_11( CuTest *tc ) |
|---|
| 984 | { |
|---|
| 985 | struct test_node seq1[] = { |
|---|
| 986 | { T_STR, 0, "New York Yankees" }, |
|---|
| 987 | { T_STR, 0, "Atlanta Braves" }, |
|---|
| 988 | end_node |
|---|
| 989 | }; |
|---|
| 990 | struct test_node seq2[] = { |
|---|
| 991 | { T_STR, 0, "2001-07-02" }, |
|---|
| 992 | { T_STR, 0, "2001-08-12" }, |
|---|
| 993 | { T_STR, 0, "2001-08-14" }, |
|---|
| 994 | end_node |
|---|
| 995 | }; |
|---|
| 996 | struct test_node seq3[] = { |
|---|
| 997 | { T_STR, 0, "Detroit Tigers" }, |
|---|
| 998 | { T_STR, 0, "Chicago Cubs" }, |
|---|
| 999 | end_node |
|---|
| 1000 | }; |
|---|
| 1001 | struct test_node seq4[] = { |
|---|
| 1002 | { T_STR, 0, "2001-07-23" }, |
|---|
| 1003 | end_node |
|---|
| 1004 | }; |
|---|
| 1005 | struct test_node map[] = { |
|---|
| 1006 | { T_SEQ, 0, 0, seq3 }, |
|---|
| 1007 | { T_SEQ, 0, 0, seq4 }, |
|---|
| 1008 | { T_SEQ, 0, 0, seq1 }, |
|---|
| 1009 | { T_SEQ, 0, 0, seq2 }, |
|---|
| 1010 | end_node |
|---|
| 1011 | }; |
|---|
| 1012 | struct test_node stream[] = { |
|---|
| 1013 | { T_MAP, 0, 0, map }, |
|---|
| 1014 | end_node |
|---|
| 1015 | }; |
|---|
| 1016 | |
|---|
| 1017 | CuStreamCompare( tc, |
|---|
| 1018 | |
|---|
| 1019 | /* YAML document */ |
|---|
| 1020 | "? # PLAY SCHEDULE \n" |
|---|
| 1021 | " - Detroit Tigers \n" |
|---|
| 1022 | " - Chicago Cubs \n" |
|---|
| 1023 | ": \n" |
|---|
| 1024 | " - 2001-07-23 \n" |
|---|
| 1025 | "\n" |
|---|
| 1026 | "? [ New York Yankees, \n" |
|---|
| 1027 | " Atlanta Braves ] \n" |
|---|
| 1028 | ": [ 2001-07-02, 2001-08-12, \n" |
|---|
| 1029 | " 2001-08-14 ] \n" |
|---|
| 1030 | , |
|---|
| 1031 | |
|---|
| 1032 | /* C structure of validations */ |
|---|
| 1033 | stream |
|---|
| 1034 | ); |
|---|
| 1035 | |
|---|
| 1036 | CuRoundTrip( tc, stream ); |
|---|
| 1037 | } |
|---|
| 1038 | /* |
|---|
| 1039 | * Example 2.12: Sequence key shortcut |
|---|
| 1040 | */ |
|---|
| 1041 | void |
|---|
| 1042 | YtsSpecificationExamples_12( CuTest *tc ) |
|---|
| 1043 | { |
|---|
| 1044 | struct test_node map1[] = { |
|---|
| 1045 | { T_STR, 0, "item" }, |
|---|
| 1046 | { T_STR, 0, "Super Hoop" }, |
|---|
| 1047 | { T_STR, 0, "quantity" }, |
|---|
| 1048 | { T_STR, 0, "1" }, |
|---|
| 1049 | end_node |
|---|
| 1050 | }; |
|---|
| 1051 | struct test_node map2[] = { |
|---|
| 1052 | { T_STR, 0, "item" }, |
|---|
| 1053 | { T_STR, 0, "Basketball" }, |
|---|
| 1054 | { T_STR, 0, "quantity" }, |
|---|
| 1055 | { T_STR, 0, "4" }, |
|---|
| 1056 | end_node |
|---|
| 1057 | }; |
|---|
| 1058 | struct test_node map3[] = { |
|---|
| 1059 | { T_STR, 0, "item" }, |
|---|
| 1060 | { T_STR, 0, "Big Shoes" }, |
|---|
| 1061 | { T_STR, 0, "quantity" }, |
|---|
| 1062 | { T_STR, 0, "1" }, |
|---|
| 1063 | end_node |
|---|
| 1064 | }; |
|---|
| 1065 | struct test_node seq[] = { |
|---|
| 1066 | { T_MAP, 0, 0, map1 }, |
|---|
| 1067 | { T_MAP, 0, 0, map2 }, |
|---|
| 1068 | { T_MAP, 0, 0, map3 }, |
|---|
| 1069 | end_node |
|---|
| 1070 | }; |
|---|
| 1071 | struct test_node stream[] = { |
|---|
| 1072 | { T_SEQ, 0, 0, seq }, |
|---|
| 1073 | end_node |
|---|
| 1074 | }; |
|---|
| 1075 | |
|---|
| 1076 | CuStreamCompare( tc, |
|---|
| 1077 | |
|---|
| 1078 | /* YAML document */ |
|---|
| 1079 | "---\n" |
|---|
| 1080 | "# products purchased\n" |
|---|
| 1081 | "- item : Super Hoop\n" |
|---|
| 1082 | " quantity: 1\n" |
|---|
| 1083 | "- item : Basketball\n" |
|---|
| 1084 | " quantity: 4\n" |
|---|
| 1085 | "- item : Big Shoes\n" |
|---|
| 1086 | " quantity: 1\n" |
|---|
| 1087 | , |
|---|
| 1088 | |
|---|
| 1089 | /* C structure of validations */ |
|---|
| 1090 | stream |
|---|
| 1091 | ); |
|---|
| 1092 | |
|---|
| 1093 | CuRoundTrip( tc, stream ); |
|---|
| 1094 | } |
|---|
| 1095 | /* |
|---|
| 1096 | * Example 2.13: Literal perserves newlines |
|---|
| 1097 | */ |
|---|
| 1098 | void |
|---|
| 1099 | YtsSpecificationExamples_13( CuTest *tc ) |
|---|
| 1100 | { |
|---|
| 1101 | struct test_node stream[] = { |
|---|
| 1102 | { T_STR, 0, "\\//||\\/||\n// || ||_\n" }, |
|---|
| 1103 | end_node |
|---|
| 1104 | }; |
|---|
| 1105 | |
|---|
| 1106 | CuStreamCompare( tc, |
|---|
| 1107 | |
|---|
| 1108 | /* YAML document */ |
|---|
| 1109 | "# ASCII Art\n" |
|---|
| 1110 | "--- | \n" |
|---|
| 1111 | " \\//||\\/||\n" |
|---|
| 1112 | " // || ||_\n" |
|---|
| 1113 | , |
|---|
| 1114 | |
|---|
| 1115 | /* C structure of validations */ |
|---|
| 1116 | stream |
|---|
| 1117 | ); |
|---|
| 1118 | |
|---|
| 1119 | CuRoundTrip( tc, stream ); |
|---|
| 1120 | } |
|---|
| 1121 | /* |
|---|
| 1122 | * Example 2.14: Folded treats newlines as a space |
|---|
| 1123 | */ |
|---|
| 1124 | void |
|---|
| 1125 | YtsSpecificationExamples_14( CuTest *tc ) |
|---|
| 1126 | { |
|---|
| 1127 | struct test_node stream[] = { |
|---|
| 1128 | { T_STR, 0, "Mark McGwire's year was crippled by a knee injury." }, |
|---|
| 1129 | end_node |
|---|
| 1130 | }; |
|---|
| 1131 | |
|---|
| 1132 | CuStreamCompare( tc, |
|---|
| 1133 | |
|---|
| 1134 | /* YAML document */ |
|---|
| 1135 | "---\n" |
|---|
| 1136 | " Mark McGwire's\n" |
|---|
| 1137 | " year was crippled\n" |
|---|
| 1138 | " by a knee injury.\n" |
|---|
| 1139 | , |
|---|
| 1140 | |
|---|
| 1141 | /* C structure of validations */ |
|---|
| 1142 | stream |
|---|
| 1143 | ); |
|---|
| 1144 | |
|---|
| 1145 | CuRoundTrip( tc, stream ); |
|---|
| 1146 | } |
|---|
| 1147 | /* |
|---|
| 1148 | * Example 2.15: Newlines preserved for indented and blank lines |
|---|
| 1149 | */ |
|---|
| 1150 | void |
|---|
| 1151 | YtsSpecificationExamples_15( CuTest *tc ) |
|---|
| 1152 | { |
|---|
| 1153 | struct test_node stream[] = { |
|---|
| 1154 | { 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" }, |
|---|
| 1155 | end_node |
|---|
| 1156 | }; |
|---|
| 1157 | |
|---|
| 1158 | CuStreamCompare( tc, |
|---|
| 1159 | |
|---|
| 1160 | /* YAML document */ |
|---|
| 1161 | "--- > \n" |
|---|
| 1162 | " Sammy Sosa completed another\n" |
|---|
| 1163 | " fine season with great stats.\n" |
|---|
| 1164 | "\n" |
|---|
| 1165 | " 63 Home Runs\n" |
|---|
| 1166 | " 0.288 Batting Average\n" |
|---|
| 1167 | "\n" |
|---|
| 1168 | " What a year!\n" |
|---|
| 1169 | , |
|---|
| 1170 | |
|---|
| 1171 | /* C structure of validations */ |
|---|
| 1172 | stream |
|---|
| 1173 | ); |
|---|
| 1174 | |
|---|
| 1175 | CuRoundTrip( tc, stream ); |
|---|
| 1176 | } |
|---|
| 1177 | /* |
|---|
| 1178 | * Example 2.16: Indentation determines scope |
|---|
| 1179 | */ |
|---|
| 1180 | void |
|---|
| 1181 | YtsSpecificationExamples_16( CuTest *tc ) |
|---|
| 1182 | { |
|---|
| 1183 | struct test_node map[] = { |
|---|
| 1184 | { T_STR, 0, "name" }, |
|---|
| 1185 | { T_STR, 0, "Mark McGwire" }, |
|---|
| 1186 | { T_STR, 0, "accomplishment" }, |
|---|
| 1187 | { T_STR, 0, "Mark set a major league home run record in 1998.\n" }, |
|---|
| 1188 | { T_STR, 0, "stats" }, |
|---|
| 1189 | { T_STR, 0, "65 Home Runs\n0.278 Batting Average\n" }, |
|---|
| 1190 | end_node |
|---|
| 1191 | }; |
|---|
| 1192 | struct test_node stream[] = { |
|---|
| 1193 | { T_MAP, 0, 0, map }, |
|---|
| 1194 | end_node |
|---|
| 1195 | }; |
|---|
| 1196 | |
|---|
| 1197 | CuStreamCompare( tc, |
|---|
| 1198 | |
|---|
| 1199 | /* YAML document */ |
|---|
| 1200 | "name: Mark McGwire \n" |
|---|
| 1201 | "accomplishment: > \n" |
|---|
| 1202 | " Mark set a major league\n" |
|---|
| 1203 | " home run record in 1998.\n" |
|---|
| 1204 | "stats: | \n" |
|---|
| 1205 | " 65 Home Runs\n" |
|---|
| 1206 | " 0.278 Batting Average\n" |
|---|
| 1207 | , |
|---|
| 1208 | |
|---|
| 1209 | /* C structure of validations */ |
|---|
| 1210 | stream |
|---|
| 1211 | ); |
|---|
| 1212 | |
|---|
| 1213 | CuRoundTrip( tc, stream ); |
|---|
| 1214 | } |
|---|
| 1215 | /* |
|---|
| 1216 | * Example 2.18: Multiline flow scalars |
|---|
| 1217 | */ |
|---|
| 1218 | void |
|---|
| 1219 | YtsSpecificationExamples_18( CuTest *tc ) |
|---|
| 1220 | { |
|---|
| 1221 | struct test_node map[] = { |
|---|
| 1222 | { T_STR, 0, "plain" }, |
|---|
| 1223 | { T_STR, 0, "This unquoted scalar spans many lines." }, |
|---|
| 1224 | { T_STR, 0, "quoted" }, |
|---|
| 1225 | { T_STR, 0, "So does this quoted scalar.\n" }, |
|---|
| 1226 | end_node |
|---|
| 1227 | }; |
|---|
| 1228 | struct test_node stream[] = { |
|---|
| 1229 | { T_MAP, 0, 0, map }, |
|---|
| 1230 | end_node |
|---|
| 1231 | }; |
|---|
| 1232 | |
|---|
| 1233 | CuStreamCompare( tc, |
|---|
| 1234 | |
|---|
| 1235 | /* YAML document */ |
|---|
| 1236 | "plain:\n" |
|---|
| 1237 | " This unquoted scalar\n" |
|---|
| 1238 | " spans many lines.\n" |
|---|
| 1239 | "\n" |
|---|
| 1240 | "quoted: \"So does this\n" |
|---|
| 1241 | " quoted scalar.\\n\"\n" |
|---|
| 1242 | , |
|---|
| 1243 | |
|---|
| 1244 | /* C structure of validations */ |
|---|
| 1245 | stream |
|---|
| 1246 | ); |
|---|
| 1247 | |
|---|
| 1248 | CuRoundTrip( tc, stream ); |
|---|
| 1249 | } |
|---|
| 1250 | /* |
|---|
| 1251 | * Example 2.19: Integers |
|---|
| 1252 | */ |
|---|
| 1253 | void |
|---|
| 1254 | YtsSpecificationExamples_19( CuTest *tc ) |
|---|
| 1255 | { |
|---|
| 1256 | struct test_node map[] = { |
|---|
| 1257 | { T_STR, 0, "canonical" }, |
|---|
| 1258 | { T_STR, 0, "12345" }, |
|---|
| 1259 | { T_STR, 0, "decimal" }, |
|---|
| 1260 | { T_STR, 0, "+12,345" }, |
|---|
| 1261 | { T_STR, 0, "sexagecimal" }, |
|---|
| 1262 | { T_STR, 0, "3:25:45" }, |
|---|
| 1263 | { T_STR, 0, "octal" }, |
|---|
| 1264 | { T_STR, 0, "014" }, |
|---|
| 1265 | { T_STR, 0, "hexadecimal" }, |
|---|
| 1266 | { T_STR, 0, "0xC" }, |
|---|
| 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 | "canonical: 12345 \n" |
|---|
| 1278 | "decimal: +12,345 \n" |
|---|
| 1279 | "sexagecimal: 3:25:45\n" |
|---|
| 1280 | "octal: 014 \n" |
|---|
| 1281 | "hexadecimal: 0xC \n" |
|---|
| 1282 | , |
|---|
| 1283 | |
|---|
| 1284 | /* C structure of validations */ |
|---|
| 1285 | stream |
|---|
| 1286 | ); |
|---|
| 1287 | |
|---|
| 1288 | CuRoundTrip( tc, stream ); |
|---|
| 1289 | } |
|---|
| 1290 | /* |
|---|
| 1291 | * Example 2.2: Floating point |
|---|
| 1292 | */ |
|---|
| 1293 | void |
|---|
| 1294 | YtsSpecificationExamples_20( CuTest *tc ) |
|---|
| 1295 | { |
|---|
| 1296 | struct test_node map[] = { |
|---|
| 1297 | { T_STR, 0, "canonical" }, |
|---|
| 1298 | { T_STR, 0, "1.23015e+3" }, |
|---|
| 1299 | { T_STR, 0, "exponential" }, |
|---|
| 1300 | { T_STR, 0, "12.3015e+02" }, |
|---|
| 1301 | { T_STR, 0, "sexagecimal" }, |
|---|
| 1302 | { T_STR, 0, "20:30.15" }, |
|---|
| 1303 | { T_STR, 0, "fixed" }, |
|---|
| 1304 | { T_STR, 0, "1,230.15" }, |
|---|
| 1305 | { T_STR, 0, "negative infinity" }, |
|---|
| 1306 | { T_STR, 0, "-.inf" }, |
|---|
| 1307 | { T_STR, 0, "not a number" }, |
|---|
| 1308 | { T_STR, 0, ".NaN" }, |
|---|
| 1309 | end_node |
|---|
| 1310 | }; |
|---|
| 1311 | struct test_node stream[] = { |
|---|
| 1312 | { T_MAP, 0, 0, map }, |
|---|
| 1313 | end_node |
|---|
| 1314 | }; |
|---|
| 1315 | |
|---|
| 1316 | CuStreamCompare( tc, |
|---|
| 1317 | |
|---|
| 1318 | /* YAML document */ |
|---|
| 1319 | "canonical: 1.23015e+3 \n" |
|---|
| 1320 | "exponential: 12.3015e+02 \n" |
|---|
| 1321 | "sexagecimal: 20:30.15\n" |
|---|
| 1322 | "fixed: 1,230.15 \n" |
|---|
| 1323 | "negative infinity: -.inf\n" |
|---|
| 1324 | "not a number: .NaN \n" |
|---|
| 1325 | , |
|---|
| 1326 | |
|---|
| 1327 | /* C structure of validations */ |
|---|
| 1328 | stream |
|---|
| 1329 | ); |
|---|
| 1330 | |
|---|
| 1331 | CuRoundTrip( tc, stream ); |
|---|
| 1332 | } |
|---|
| 1333 | /* |
|---|
| 1334 | * Example 2.21: Miscellaneous |
|---|
| 1335 | */ |
|---|
| 1336 | void |
|---|
| 1337 | YtsSpecificationExamples_21( CuTest *tc ) |
|---|
| 1338 | { |
|---|
| 1339 | struct test_node map[] = { |
|---|
| 1340 | { T_STR, 0, "null" }, |
|---|
| 1341 | { T_STR, 0, "~" }, |
|---|
| 1342 | { T_STR, 0, "true" }, |
|---|
| 1343 | { T_STR, 0, "y" }, |
|---|
| 1344 | { T_STR, 0, "false" }, |
|---|
| 1345 | { T_STR, 0, "n" }, |
|---|
| 1346 | { T_STR, 0, "string" }, |
|---|
| 1347 | { T_STR, 0, "12345" }, |
|---|
| 1348 | end_node |
|---|
| 1349 | }; |
|---|
| 1350 | struct test_node stream[] = { |
|---|
| 1351 | { T_MAP, 0, 0, map }, |
|---|
| 1352 | end_node |
|---|
| 1353 | }; |
|---|
| 1354 | |
|---|
| 1355 | CuStreamCompare( tc, |
|---|
| 1356 | |
|---|
| 1357 | /* YAML document */ |
|---|
| 1358 | "null: ~ \n" |
|---|
| 1359 | "true: y\n" |
|---|
| 1360 | "false: n \n" |
|---|
| 1361 | "string: '12345' \n" |
|---|
| 1362 | , |
|---|
| 1363 | |
|---|
| 1364 | /* C structure of validations */ |
|---|
| 1365 | stream |
|---|
| 1366 | ); |
|---|
| 1367 | |
|---|
| 1368 | CuRoundTrip( tc, stream ); |
|---|
| 1369 | } |
|---|
| 1370 | /* |
|---|
| 1371 | * Example 2.22: Timestamps |
|---|
| 1372 | */ |
|---|
| 1373 | void |
|---|
| 1374 | YtsSpecificationExamples_22( CuTest *tc ) |
|---|
| 1375 | { |
|---|
| 1376 | struct test_node map[] = { |
|---|
| 1377 | { T_STR, 0, "canonical" }, |
|---|
| 1378 | { T_STR, 0, "2001-12-15T02:59:43.1Z" }, |
|---|
| 1379 | { T_STR, 0, "iso8601" }, |
|---|
| 1380 | { T_STR, 0, "2001-12-14t21:59:43.10-05:00" }, |
|---|
| 1381 | { T_STR, 0, "spaced" }, |
|---|
| 1382 | { T_STR, 0, "2001-12-14 21:59:43.10 -05:00" }, |
|---|
| 1383 | { T_STR, 0, "date" }, |
|---|
| 1384 | { T_STR, 0, "2002-12-14" }, |
|---|
| 1385 | end_node |
|---|
| 1386 | }; |
|---|
| 1387 | struct test_node stream[] = { |
|---|
| 1388 | { T_MAP, 0, 0, map }, |
|---|
| 1389 | end_node |
|---|
| 1390 | }; |
|---|
| 1391 | |
|---|
| 1392 | CuStreamCompare( tc, |
|---|
| 1393 | |
|---|
| 1394 | /* YAML document */ |
|---|
| 1395 | "canonical: 2001-12-15T02:59:43.1Z\n" |
|---|
| 1396 | "iso8601: 2001-12-14t21:59:43.10-05:00\n" |
|---|
| 1397 | "spaced: 2001-12-14 21:59:43.10 -05:00\n" |
|---|
| 1398 | "date: 2002-12-14 # Time is noon UTC\n" |
|---|
| 1399 | , |
|---|
| 1400 | |
|---|
| 1401 | /* C structure of validations */ |
|---|
| 1402 | stream |
|---|
| 1403 | ); |
|---|
| 1404 | |
|---|
| 1405 | CuRoundTrip( tc, stream ); |
|---|
| 1406 | } |
|---|
| 1407 | /* |
|---|
| 1408 | * Example legacy D4: legacy Timestamps test |
|---|
| 1409 | */ |
|---|
| 1410 | void |
|---|
| 1411 | YtsSpecificationExamples_23( CuTest *tc ) |
|---|
| 1412 | { |
|---|
| 1413 | struct test_node map[] = { |
|---|
| 1414 | { T_STR, 0, "canonical" }, |
|---|
| 1415 | { T_STR, 0, "2001-12-15T02:59:43.00Z" }, |
|---|
| 1416 | { T_STR, 0, "iso8601" }, |
|---|
| 1417 | { T_STR, 0, "2001-02-28t21:59:43.00-05:00" }, |
|---|
| 1418 | { T_STR, 0, "spaced" }, |
|---|
| 1419 | { T_STR, 0, "2001-12-14 21:59:43.00 -05:00" }, |
|---|
| 1420 | { T_STR, 0, "date" }, |
|---|
| 1421 | { T_STR, 0, "2002-12-14" }, |
|---|
| 1422 | end_node |
|---|
| 1423 | }; |
|---|
| 1424 | struct test_node stream[] = { |
|---|
| 1425 | { T_MAP, 0, 0, map }, |
|---|
| 1426 | end_node |
|---|
| 1427 | }; |
|---|
| 1428 | |
|---|
| 1429 | CuStreamCompare( tc, |
|---|
| 1430 | |
|---|
| 1431 | /* YAML document */ |
|---|
| 1432 | "canonical: 2001-12-15T02:59:43.00Z\n" |
|---|
| 1433 | "iso8601: 2001-02-28t21:59:43.00-05:00\n" |
|---|
| 1434 | "spaced: 2001-12-14 21:59:43.00 -05:00\n" |
|---|
| 1435 | "date: 2002-12-14\n" |
|---|
| 1436 | , |
|---|
| 1437 | |
|---|
| 1438 | /* C structure of validations */ |
|---|
| 1439 | stream |
|---|
| 1440 | ); |
|---|
| 1441 | |
|---|
| 1442 | CuRoundTrip( tc, stream ); |
|---|
| 1443 | } |
|---|
| 1444 | /* |
|---|
| 1445 | * Example 2.23: Various explicit families |
|---|
| 1446 | */ |
|---|
| 1447 | void |
|---|
| 1448 | YtsSpecificationExamples_24( CuTest *tc ) |
|---|
| 1449 | { |
|---|
| 1450 | struct test_node map[] = { |
|---|
| 1451 | { T_STR, 0, "not-date" }, |
|---|
| 1452 | { T_STR, "tag:yaml.org,2002:str", "2002-04-28" }, |
|---|
| 1453 | { T_STR, 0, "picture" }, |
|---|
| 1454 | { T_STR, "tag:yaml.org,2002:binary", "R0lGODlhDAAMAIQAAP//9/X\n17unp5WZmZgAAAOfn515eXv\nPz7Y6OjuDg4J+fn5OTk6enp\n56enmleECcgggoBADs=\n" }, |
|---|
| 1455 | { T_STR, 0, "application specific tag" }, |
|---|
| 1456 | { T_STR, "x-private:something", "The semantics of the tag\nabove may be different for\ndifferent documents.\n" }, |
|---|
| 1457 | end_node |
|---|
| 1458 | }; |
|---|
| 1459 | struct test_node stream[] = { |
|---|
| 1460 | { T_MAP, 0, 0, map }, |
|---|
| 1461 | end_node |
|---|
| 1462 | }; |
|---|
| 1463 | |
|---|
| 1464 | CuStreamCompare( tc, |
|---|
| 1465 | |
|---|
| 1466 | /* YAML document */ |
|---|
| 1467 | "not-date: !str 2002-04-28\n" |
|---|
| 1468 | "picture: !binary |\n" |
|---|
| 1469 | " R0lGODlhDAAMAIQAAP//9/X\n" |
|---|
| 1470 | " 17unp5WZmZgAAAOfn515eXv\n" |
|---|
| 1471 | " Pz7Y6OjuDg4J+fn5OTk6enp\n" |
|---|
| 1472 | " 56enmleECcgggoBADs=\n" |
|---|
| 1473 | "\n" |
|---|
| 1474 | "application specific tag: !!something |\n" |
|---|
| 1475 | " The semantics of the tag\n" |
|---|
| 1476 | " above may be different for\n" |
|---|
| 1477 | " different docu |
|---|