public
Description: JvYAMLb is a YAML processing library for Java, used by JRuby
Homepage: http://code.google.com/p/jvyamlb
Clone URL: git://github.com/olabini/jvyamlb.git
Several test for how comments behave, and also a fix for the positioning 
of empty scalar inserted by parser.
olabini (author)
Sun Jul 13 09:50:36 -0700 2008
commit  32c6be3d141a9fc4799325b6280367d04f58f6bb
tree    8ce03a3123989bd6822f46fb38db952d5ef54e23
parent  927ee0f4a1613bef34e5209502d3357d1f4fe821
...
231
232
233
 
 
 
 
 
 
 
234
235
236
...
476
477
478
479
 
480
481
482
...
485
486
487
 
488
489
490
...
677
678
679
680
 
681
682
683
...
231
232
233
234
235
236
237
238
239
240
241
242
243
...
483
484
485
 
486
487
488
489
...
492
493
494
495
496
497
498
...
685
686
687
 
688
689
690
691
0
@@ -231,6 +231,13 @@ public class ParserImpl implements Parser {
0
             return new AliasEvent(value);
0
         }
0
 
0
+ protected void setEmptyToken(Token t) {
0
+ }
0
+
0
+ protected Token getEmptyToken(Scanner scanner) {
0
+ return scanner.peekToken();
0
+ }
0
+
0
         protected void parserException(final String when, final String what, final String note, final Token t) {
0
             throw new ParserException(when, what, note);
0
         }
0
@@ -476,7 +483,7 @@ public class ParserImpl implements Parser {
0
             case P_BLOCK_MAPPING_ENTRY_VALUE: {
0
                 if(scanner.peekToken() instanceof KeyToken || scanner.peekToken() instanceof ValueToken) {
0
                     if(scanner.peekToken() instanceof ValueToken) {
0
- scanner.getToken();
0
+ final Token value = scanner.getToken();
0
                         final Token curr = scanner.peekToken();
0
                         if(!(curr instanceof KeyToken || curr instanceof ValueToken || curr instanceof BlockEndToken)) {
0
                             if(curr instanceof ScalarToken && scanner.peekToken(1) instanceof BlockEntryToken) {
0
@@ -485,6 +492,7 @@ public class ParserImpl implements Parser {
0
                             }
0
                             parseStack.push(P_BLOCK_NODE_OR_INDENTLESS_SEQUENCE);
0
                         } else {
0
+ setEmptyToken(value);
0
                             parseStack.push(P_EMPTY_SCALAR);
0
                         }
0
                     } else {
0
@@ -677,7 +685,7 @@ public class ParserImpl implements Parser {
0
                 return getAlias(tok.getValue(), tok);
0
             }
0
             case P_EMPTY_SCALAR: {
0
- return getScalar(null,null,new boolean[]{true,false},new ByteList(ByteList.NULL_ARRAY),(char)0, scanner.peekToken(), null, null);
0
+ return getScalar(null,null,new boolean[]{true,false},new ByteList(ByteList.NULL_ARRAY),(char)0, getEmptyToken(scanner), null, null);
0
             }
0
             }
0
 
...
107
108
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
111
112
...
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
0
@@ -107,6 +107,21 @@ public class PositioningParserImpl extends ParserImpl implements PositioningPars
0
         protected void parserException(final String when, final String what, final String note, final Token t) {
0
             throw new PositionedParserException(when, what, note, ((Positionable)t).getRange());
0
         }
0
+
0
+ private Token emptyToken = null;
0
+
0
+ protected void setEmptyToken(Token t) {
0
+ this.emptyToken = t;
0
+ }
0
+
0
+ protected Token getEmptyToken(Scanner scanner) {
0
+ if(emptyToken != null) {
0
+ Token ret = emptyToken;
0
+ emptyToken = null;
0
+ return ret;
0
+ }
0
+ return scanner.peekToken();
0
+ }
0
     }
0
     
0
     public PositioningParserImpl(final PositioningScanner scanner) {
...
400
401
402
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
...
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
0
@@ -400,4 +400,21 @@ public class PositioningParserImplTest extends YAMLTestCase {
0
             assertEquals("Position should be correct for exception", new Position.Range(new Position(0,8,8),new Position(0,11,11)), ((PositionedParserException)e).getRange());
0
         }
0
     }
0
+
0
+ public void testCommentBeforeSecondKeyWithBlankFirst() throws Exception {
0
+ List expected = new ArrayList();
0
+ expected.add(new PositionedStreamStartEvent(new Position.Range(new Position(0,0,0))));
0
+ expected.add(new PositionedDocumentStartEvent(false, new int[]{1,1}, null, new Position.Range(new Position(0,0,0))));
0
+ expected.add(new PositionedMappingStartEvent(null, null, true, false, new Position.Range(new Position(0,0,0))));
0
+ expected.add(new PositionedScalarEvent(null, null, new boolean[]{true,false}, s("a"), (char)0, new Position.Range(new Position(0,0,0), new Position(0,1,1))));
0
+ expected.add(new PositionedScalarEvent(null, null, new boolean[]{true,false}, s(""), (char)0, new Position.Range(new Position(0,2,2), new Position(0,2,2))));
0
+ expected.add(new PositionedScalarEvent(null, null, new boolean[]{true,false}, s("c"), (char)0, new Position.Range(new Position(2,0,9), new Position(2,1,10))));
0
+ expected.add(new PositionedScalarEvent(null, null, new boolean[]{true,false}, s("d"), (char)0, new Position.Range(new Position(2,3,12), new Position(2,4,13))));
0
+ expected.add(new PositionedMappingEndEvent(new Position.Range(new Position(2,4,13))));
0
+ expected.add(new PositionedDocumentEndEvent(false, new Position.Range(new Position(2,4,13))));
0
+ expected.add(new PositionedStreamEndEvent(new Position.Range(new Position(2,4,13))));
0
+
0
+ List events = getParse("a: \n#foo\nc: d");
0
+ assertEquals(expected, events);
0
+ }
0
 }
...
346
347
348
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
...
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
0
@@ -346,4 +346,66 @@ public class PositioningScannerImplTest extends YAMLTestCase {
0
             assertEquals("Position should be correct for exception", new Position.Range(new Position(0,5,5)), ((PositionedScannerException)e).getRange());
0
         }
0
     }
0
+
0
+ public void testSimpleObjectWithCommentBefore() throws Exception {
0
+ List expected = new ArrayList();
0
+ expected.add(new PositionedStreamStartToken(new Position.Range(new Position(0,0,0))));
0
+ expected.add(new PositionedScalarToken(s("abc"), true, (char)0, new Position.Range(new Position(1,0,9), new Position(1,3,12))));
0
+ expected.add(new PositionedStreamEndToken(new Position.Range(new Position(1,3,12))));
0
+
0
+ List tokens = getScan("#comment\nabc");
0
+ assertEquals(expected, tokens);
0
+ }
0
+
0
+ public void testCommentBeforeFirstKey() throws Exception {
0
+ List expected = new ArrayList();
0
+ expected.add(new PositionedStreamStartToken( new Position.Range(new Position(0,0,0))));
0
+ expected.add(new PositionedBlockMappingStartToken( new Position.Range(new Position(1,0,5))));
0
+ expected.add(new PositionedKeyToken( new Position.Range(new Position(1,0,5))));
0
+ expected.add(new PositionedScalarToken(s("a"), true, (char)0, new Position.Range(new Position(1,0,5), new Position(1,1,6))));
0
+ expected.add(new PositionedValueToken( new Position.Range(new Position(1,2,7))));
0
+ expected.add(new PositionedScalarToken(s("b"), true, (char)0, new Position.Range(new Position(1,3,8), new Position(1,4,9))));
0
+ expected.add(new PositionedBlockEndToken( new Position.Range(new Position(1,4,9))));
0
+ expected.add(new PositionedStreamEndToken( new Position.Range(new Position(1,4,9))));
0
+
0
+ List tokens = getScan("#foo\na: b");
0
+ assertEquals(expected, tokens);
0
+ }
0
+
0
+ public void testCommentBeforeSecondKey() throws Exception {
0
+ List expected = new ArrayList();
0
+ expected.add(new PositionedStreamStartToken( new Position.Range(new Position(0,0,0))));
0
+ expected.add(new PositionedBlockMappingStartToken( new Position.Range(new Position(0,0,0))));
0
+ expected.add(new PositionedKeyToken( new Position.Range(new Position(0,0,0))));
0
+ expected.add(new PositionedScalarToken(s("a"), true, (char)0, new Position.Range(new Position(0,0,0), new Position(0,1,1))));
0
+ expected.add(new PositionedValueToken( new Position.Range(new Position(0,2,2))));
0
+ expected.add(new PositionedScalarToken(s("b"), true, (char)0, new Position.Range(new Position(0,3,3), new Position(0,4,4))));
0
+ expected.add(new PositionedKeyToken( new Position.Range(new Position(2,0,10))));
0
+ expected.add(new PositionedScalarToken(s("c"), true, (char)0, new Position.Range(new Position(2,0,10), new Position(2,1,11))));
0
+ expected.add(new PositionedValueToken( new Position.Range(new Position(2,2,12))));
0
+ expected.add(new PositionedScalarToken(s("d"), true, (char)0, new Position.Range(new Position(2,3,13), new Position(2,4,14))));
0
+ expected.add(new PositionedBlockEndToken( new Position.Range(new Position(2,4,14))));
0
+ expected.add(new PositionedStreamEndToken( new Position.Range(new Position(2,4,14))));
0
+
0
+ List tokens = getScan("a: b\n#foo\nc: d");
0
+ assertEquals(expected, tokens);
0
+ }
0
+
0
+ public void testCommentBeforeSecondKeyWithBlankFirst() throws Exception {
0
+ List expected = new ArrayList();
0
+ expected.add(new PositionedStreamStartToken( new Position.Range(new Position(0,0,0))));
0
+ expected.add(new PositionedBlockMappingStartToken( new Position.Range(new Position(0,0,0))));
0
+ expected.add(new PositionedKeyToken( new Position.Range(new Position(0,0,0))));
0
+ expected.add(new PositionedScalarToken(s("a"), true, (char)0, new Position.Range(new Position(0,0,0), new Position(0,1,1))));
0
+ expected.add(new PositionedValueToken( new Position.Range(new Position(0,2,2))));
0
+ expected.add(new PositionedKeyToken( new Position.Range(new Position(2,0,9))));
0
+ expected.add(new PositionedScalarToken(s("c"), true, (char)0, new Position.Range(new Position(2,0,9), new Position(2,1,10))));
0
+ expected.add(new PositionedValueToken( new Position.Range(new Position(2,2,11))));
0
+ expected.add(new PositionedScalarToken(s("d"), true, (char)0, new Position.Range(new Position(2,3,12), new Position(2,4,13))));
0
+ expected.add(new PositionedBlockEndToken( new Position.Range(new Position(2,4,13))));
0
+ expected.add(new PositionedStreamEndToken( new Position.Range(new Position(2,4,13))));
0
+
0
+ List tokens = getScan("a: \n#foo\nc: d");
0
+ assertEquals(expected, tokens);
0
+ }
0
 }// PositioningScannerImplTest

Comments

    No one has commented yet.