1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license.
3
3
4
+ using System . Collections . Generic ;
4
5
using System . Globalization ;
5
6
using System . IO ;
7
+ using System . Linq ;
6
8
using FluentAssertions ;
7
9
using Microsoft . OpenApi . Writers ;
8
10
using Xunit ;
@@ -20,20 +22,35 @@ public OpenApiWriterSpecialCharacterTests(ITestOutputHelper output)
20
22
_output = output ;
21
23
}
22
24
25
+ static bool [ ] shouldProduceTerseOutputValues = new [ ] { true , false } ;
26
+
27
+ public static IEnumerable < object [ ] > StringWithSpecialCharacters
28
+ {
29
+ get
30
+ {
31
+ return
32
+ from inputExpected in new [ ] {
33
+ new [ ] { "Test\b Test" , "\" Test\\ bTest\" " } ,
34
+ new [ ] { "Test\f Test" , "\" Test\\ fTest\" " } ,
35
+ new [ ] { "Test\n Test" , "\" Test\\ nTest\" " } ,
36
+ new [ ] { "Test\r Test" , "\" Test\\ rTest\" " } ,
37
+ new [ ] { "Test\t Test" , "\" Test\\ tTest\" " } ,
38
+ new [ ] { "Test\\ Test" , "\" Test\\ \\ Test\" " } ,
39
+ new [ ] { "Test\" Test" , "\" Test\\ \" Test\" " } ,
40
+ new [ ] { "StringsWith\" Quotes\" " , "\" StringsWith\\ \" Quotes\\ \" \" " } ,
41
+ }
42
+ from shouldBeTerse in shouldProduceTerseOutputValues
43
+ select new object [ ] { inputExpected [ 0 ] , inputExpected [ 1 ] , shouldBeTerse } ;
44
+ }
45
+ }
46
+
23
47
[ Theory ]
24
- [ InlineData ( "Test\b Test" , "\" Test\\ bTest\" " ) ]
25
- [ InlineData ( "Test\f Test" , "\" Test\\ fTest\" " ) ]
26
- [ InlineData ( "Test\n Test" , "\" Test\\ nTest\" " ) ]
27
- [ InlineData ( "Test\r Test" , "\" Test\\ rTest\" " ) ]
28
- [ InlineData ( "Test\t Test" , "\" Test\\ tTest\" " ) ]
29
- [ InlineData ( "Test\\ Test" , "\" Test\\ \\ Test\" " ) ]
30
- [ InlineData ( "Test\" Test" , "\" Test\\ \" Test\" " ) ]
31
- [ InlineData ( "StringsWith\" Quotes\" " , "\" StringsWith\\ \" Quotes\\ \" \" " ) ]
32
- public void WriteStringWithSpecialCharactersAsJsonWorks ( string input , string expected )
48
+ [ MemberData ( nameof ( StringWithSpecialCharacters ) ) ]
49
+ public void WriteStringWithSpecialCharactersAsJsonWorks ( string input , string expected , bool produceTerseOutput )
33
50
{
34
51
// Arrange
35
52
var outputStringWriter = new StringWriter ( CultureInfo . InvariantCulture ) ;
36
- var writer = new OpenApiJsonWriter ( outputStringWriter ) ;
53
+ var writer = new OpenApiJsonWriter ( outputStringWriter , new OpenApiJsonWriterSettings { Terse = produceTerseOutput } ) ;
37
54
38
55
// Act
39
56
writer . WriteValue ( input ) ;
@@ -75,7 +92,7 @@ public void WriteStringWithSpecialCharactersAsYamlWorks(string input, string exp
75
92
// Assert
76
93
actual . Should ( ) . Be ( expected ) ;
77
94
}
78
-
95
+
79
96
[ Theory ]
80
97
[ InlineData ( "multiline\r \n string" , "test: |-\n multiline\n string" ) ]
81
98
[ InlineData ( "ends with\r \n line break\r \n " , "test: |\n ends with\n line break" ) ]
@@ -103,7 +120,7 @@ public void WriteStringWithNewlineCharactersInObjectAsYamlWorks(string input, st
103
120
// Assert
104
121
actual . Should ( ) . Be ( expected ) ;
105
122
}
106
-
123
+
107
124
[ Theory ]
108
125
[ InlineData ( "multiline\r \n string" , "- |-\n multiline\n string" ) ]
109
126
[ InlineData ( "ends with\r \n line break\r \n " , "- |\n ends with\n line break" ) ]
0 commit comments