@@ -353,6 +353,35 @@ public void testValidCharacterReferenceDecimal()
353
353
*
354
354
* @throws java.lang.Exception if any.
355
355
*/
356
+ @ Test
357
+ public void testParserPosition ()
358
+ throws Exception
359
+ {
360
+ String input = "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?><!-- A --> \n <!-- B --><test>\t nnn</test>\n <!-- C\n C -->" ;
361
+
362
+ MXParser parser = new MXParser ();
363
+ parser .setInput ( new StringReader ( input ) );
364
+
365
+ assertEquals ( XmlPullParser .PROCESSING_INSTRUCTION , parser .nextToken () );
366
+ assertPosition ( 1 , 39 , parser );
367
+ assertEquals ( XmlPullParser .COMMENT , parser .nextToken () );
368
+ assertPosition ( 1 , 49 , parser );
369
+ assertEquals ( XmlPullParser .IGNORABLE_WHITESPACE , parser .nextToken () );
370
+ assertPosition ( 2 , 3 , parser ); // end when next token starts
371
+ assertEquals ( XmlPullParser .COMMENT , parser .nextToken () );
372
+ assertPosition ( 2 , 12 , parser );
373
+ assertEquals ( XmlPullParser .START_TAG , parser .nextToken () );
374
+ assertPosition ( 2 , 18 , parser );
375
+ assertEquals ( XmlPullParser .TEXT , parser .nextToken () );
376
+ assertPosition ( 2 , 23 , parser ); // end when next token starts
377
+ assertEquals ( XmlPullParser .END_TAG , parser .nextToken () );
378
+ assertPosition ( 2 , 29 , parser );
379
+ assertEquals ( XmlPullParser .IGNORABLE_WHITESPACE , parser .nextToken () );
380
+ assertPosition ( 3 , 2 , parser ); // end when next token starts
381
+ assertEquals ( XmlPullParser .COMMENT , parser .nextToken () );
382
+ assertPosition ( 4 , 6 , parser );
383
+ }
384
+
356
385
@ Test
357
386
public void testProcessingInstruction ()
358
387
throws Exception
@@ -624,7 +653,7 @@ public void testMalformedProcessingInstructionNoClosingQuestionMark()
624
653
}
625
654
catch ( XmlPullParserException ex )
626
655
{
627
- assertTrue ( ex .getMessage ().contains ( "processing instruction started on line 1 and column 2 was not closed" ) );
656
+ assertTrue ( ex .getMessage ().contains ( "processing instruction started on line 1 and column 1 was not closed" ) );
628
657
}
629
658
}
630
659
@@ -657,7 +686,7 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark()
657
686
}
658
687
catch ( XmlPullParserException ex )
659
688
{
660
- assertTrue ( ex .getMessage ().contains ( "processing instruction started on line 1 and column 13 was not closed" ) );
689
+ assertTrue ( ex .getMessage ().contains ( "processing instruction started on line 1 and column 12 was not closed" ) );
661
690
}
662
691
}
663
692
@@ -900,6 +929,12 @@ public void testEncodingISO_8859_1_setInputStream()
900
929
}
901
930
}
902
931
932
+ private static void assertPosition ( int row , int col , MXParser parser )
933
+ {
934
+ assertEquals ( "Current line" , row , parser .getLineNumber () );
935
+ assertEquals ( "Current column" , col , parser .getColumnNumber () );
936
+ }
937
+
903
938
/**
904
939
* Issue 163: https://github.com/codehaus-plexus/plexus-utils/issues/163
905
940
*
@@ -958,7 +993,7 @@ public void testCustomEntityNotFoundInText()
958
993
}
959
994
catch ( XmlPullParserException e )
960
995
{
961
- assertTrue ( e .getMessage ().contains ( "could not resolve entity named 'otherentity' (position: START_TAG seen <root>&otherentity;... @1:19 )" ) );
996
+ assertTrue ( e .getMessage ().contains ( "could not resolve entity named 'otherentity' (position: START_TAG seen <root>&otherentity;... @1:20 )" ) );
962
997
assertEquals ( XmlPullParser .START_TAG , parser .getEventType () ); // not an ENTITY_REF
963
998
assertEquals ( "otherentity" , parser .getText () );
964
999
}
@@ -1025,7 +1060,7 @@ public void testCustomEntityNotFoundInAttr()
1025
1060
}
1026
1061
catch ( XmlPullParserException e )
1027
1062
{
1028
- assertTrue ( e .getMessage ().contains ( "could not resolve entity named 'otherentity' (position: START_DOCUMENT seen <root name=\" &otherentity;... @1:25 )" ) );
1063
+ assertTrue ( e .getMessage ().contains ( "could not resolve entity named 'otherentity' (position: START_DOCUMENT seen <root name=\" &otherentity;... @1:26 )" ) );
1029
1064
assertEquals ( XmlPullParser .START_DOCUMENT , parser .getEventType () ); // not an ENTITY_REF
1030
1065
assertNull ( parser .getText () );
1031
1066
}
@@ -1060,7 +1095,7 @@ public void testCustomEntityNotFoundInAttrTokenize() throws Exception
1060
1095
}
1061
1096
catch ( XmlPullParserException e )
1062
1097
{
1063
- assertTrue ( e .getMessage ().contains ( "could not resolve entity named 'otherentity' (position: START_DOCUMENT seen <root name=\" &otherentity;... @1:25 )" ) );
1098
+ assertTrue ( e .getMessage ().contains ( "could not resolve entity named 'otherentity' (position: START_DOCUMENT seen <root name=\" &otherentity;... @1:26 )" ) );
1064
1099
assertEquals ( XmlPullParser .START_DOCUMENT , parser .getEventType () ); // not an ENTITY_REF
1065
1100
assertNull ( parser .getText () );
1066
1101
}
0 commit comments