@@ -287,27 +287,30 @@ public static void TryParseValueInvalidDataFail(string json)
287
287
Assert . Equal ( 0 , reader . BytesConsumed ) ;
288
288
}
289
289
290
- [ Theory ]
291
- [ InlineData ( "null" ) ]
292
- [ InlineData ( "\r \n null " ) ]
293
- [ InlineData ( "false" ) ]
294
- [ InlineData ( "true " ) ]
295
- [ InlineData ( " 42.0 " ) ]
296
- [ InlineData ( " \" str\" \r \n " ) ]
297
- [ InlineData ( " \" string with escaping: \\ u0041\\ u0042\\ u0043\" \r \n " ) ]
298
- [ InlineData ( " [ ]" ) ]
299
- [ InlineData ( " [null, true, 42.0, \" str\" , [], {}, ]" ) ]
300
- [ InlineData ( " { } " ) ]
301
- [ InlineData ( """
302
-
303
- {
304
- /* I am a comment */
305
- "key1" : 1,
306
- "key2" : null,
307
- "key3" : true,
308
- }
290
+ public static IEnumerable < object [ ] > JsonMarshal_GetRawUtf8Value_TestData ( )
291
+ {
292
+ yield return new object [ ] { "null" } ;
293
+ yield return new object [ ] { "\r \n null " } ;
294
+ yield return new object [ ] { "false" } ;
295
+ yield return new object [ ] { "true " } ;
296
+ yield return new object [ ] { " 42.0 " } ;
297
+ yield return new object [ ] { " \" str\" \r \n " } ;
298
+ yield return new object [ ] { " \" string with escaping: \\ u0041\\ u0042\\ u0043\" \r \n " } ;
299
+ yield return new object [ ] { " [ ]" } ;
300
+ yield return new object [ ] { " [null, true, 42.0, \" str\" , [], {}, ]" } ;
301
+ yield return new object [ ] { " { } " } ;
302
+ yield return new object [ ] { """
303
+ {
304
+ /* I am a comment */
305
+ "key1" : 1,
306
+ "key2" : null,
307
+ "key3" : true,
308
+ }
309
+ """ } ;
310
+ }
309
311
310
- """ ) ]
312
+ [ Theory ]
313
+ [ MemberData ( nameof ( JsonMarshal_GetRawUtf8Value_TestData ) ) ]
311
314
public static void JsonMarshal_GetRawUtf8Value_RootValue_ReturnsFullValue ( string json )
312
315
{
313
316
JsonDocumentOptions options = new JsonDocumentOptions { AllowTrailingCommas = true , CommentHandling = JsonCommentHandling . Skip } ;
@@ -318,6 +321,18 @@ public static void JsonMarshal_GetRawUtf8Value_RootValue_ReturnsFullValue(string
318
321
Assert . Equal ( json . Trim ( ) , Encoding . UTF8 . GetString ( rawValue . ToArray ( ) ) ) ;
319
322
}
320
323
324
+ [ Theory ]
325
+ [ MemberData ( nameof ( JsonMarshal_GetRawUtf8Value_TestData ) ) ]
326
+ public static void JsonMarshal_GetRawUtf8Value_JsonElement_ParseValue_ReturnsFullValue ( string json )
327
+ {
328
+ JsonReaderOptions options = new ( ) { CommentHandling = JsonCommentHandling . Skip , AllowTrailingCommas = true } ;
329
+ Utf8JsonReader reader = new ( Encoding . UTF8 . GetBytes ( json ) , isFinalBlock : true , new JsonReaderState ( options ) ) ;
330
+ JsonElement element = JsonElement . ParseValue ( ref reader ) ;
331
+
332
+ ReadOnlySpan < byte > rawValue = JsonMarshal . GetRawUtf8Value ( element ) ;
333
+ Assert . Equal ( json . Trim ( ) , Encoding . UTF8 . GetString ( rawValue . ToArray ( ) ) ) ;
334
+ }
335
+
321
336
[ Fact ]
322
337
public static void JsonMarshal_GetRawUtf8Value_NestedValues_ReturnsExpectedValue ( )
323
338
{
0 commit comments