File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
tests/MongoDB.Bson.Tests/IO Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -1218,6 +1218,7 @@ private BsonType ParseExtendedJson()
1218
1218
case "$maxkey" : case "$maxKey" : _currentValue = ParseMaxKeyExtendedJson ( ) ; return BsonType . MaxKey ;
1219
1219
case "$minkey" : case "$minKey" : _currentValue = ParseMinKeyExtendedJson ( ) ; return BsonType . MinKey ;
1220
1220
case "$numberDecimal" : _currentValue = ParseNumberDecimalExtendedJson ( ) ; return BsonType . Decimal128 ;
1221
+ case "$numberInt" : _currentValue = ParseNumberIntExtendedJson ( ) ; return BsonType . Int32 ;
1221
1222
case "$numberLong" : _currentValue = ParseNumberLongExtendedJson ( ) ; return BsonType . Int64 ;
1222
1223
case "$oid" : _currentValue = ParseObjectIdExtendedJson ( ) ; return BsonType . ObjectId ;
1223
1224
case "$regex" : _currentValue = ParseRegularExpressionExtendedJson ( ) ; return BsonType . RegularExpression ;
@@ -1548,6 +1549,26 @@ private BsonValue ParseNumberDecimalExtendedJson()
1548
1549
return ( BsonDecimal128 ) value ;
1549
1550
}
1550
1551
1552
+ private BsonValue ParseNumberIntExtendedJson ( )
1553
+ {
1554
+ VerifyToken ( ":" ) ;
1555
+
1556
+ int value ;
1557
+ var valueToken = PopToken ( ) ;
1558
+ if ( valueToken . Type == JsonTokenType . Int32 )
1559
+ {
1560
+ value = valueToken . Int32Value ;
1561
+ }
1562
+ else
1563
+ {
1564
+ var message = string . Format ( "JSON reader expected an integer but found '{0}'." , valueToken . Lexeme ) ;
1565
+ throw new FormatException ( message ) ;
1566
+ }
1567
+
1568
+ VerifyToken ( "}" ) ;
1569
+ return ( BsonInt32 ) value ;
1570
+ }
1571
+
1551
1572
private BsonValue ParseNumberLongExtendedJson ( )
1552
1573
{
1553
1574
VerifyToken ( ":" ) ;
Original file line number Diff line number Diff line change @@ -525,6 +525,21 @@ public void TestInt32()
525
525
Assert . Equal ( json , BsonSerializer . Deserialize < int > ( json ) . ToJson ( ) ) ;
526
526
}
527
527
528
+ [ Theory ]
529
+ [ InlineData ( "{ $numberInt: 1 }" , 1 ) ]
530
+ [ InlineData ( "{ $numberInt: -2147483648 }" , - 2147483648 ) ]
531
+ [ InlineData ( "{ $numberInt: 2147483647 }" , 2147483647 ) ]
532
+ public void TestInt32ExtendedJson ( string json , int expectedResult )
533
+ {
534
+ using ( var reader = new JsonReader ( json ) )
535
+ {
536
+ var result = reader . ReadInt32 ( ) ;
537
+
538
+ result . Should ( ) . Be ( expectedResult ) ;
539
+ reader . IsAtEndOfFile ( ) . Should ( ) . BeTrue ( ) ;
540
+ }
541
+ }
542
+
528
543
[ Theory ]
529
544
[ InlineData ( "Number(123)" ) ]
530
545
[ InlineData ( "NumberInt(123)" ) ]
You can’t perform that action at this time.
0 commit comments