@@ -75,5 +75,63 @@ public void WriteStringWithSpecialCharactersAsYamlWorks(string input, string exp
75
75
// Assert
76
76
actual . Should ( ) . Be ( expected ) ;
77
77
}
78
+
79
+ [ Theory ]
80
+ [ InlineData ( "multiline\r \n string" , "test: |\n multiline\r \n string" ) ]
81
+ [ InlineData ( "multiline\n string" , "test: |\n multiline\n string" ) ]
82
+ [ InlineData ( "multiline\r string" , "test: |\n multiline\r string" ) ]
83
+ [ InlineData ( "multiline\n \r string" , "test: |\n multiline\n \r string" ) ]
84
+ [ InlineData ( "ends with\r \n line break\r \n " , "test: |+\n ends with\r \n line break\r \n " ) ]
85
+ [ InlineData ( "ends with\n line break\n " , "test: |+\n ends with\n line break\n " ) ]
86
+ [ InlineData ( "ends with\r line break\r " , "test: |+\n ends with\r line break\r " ) ]
87
+ [ InlineData ( "ends with\n \r line break\n \r " , "test: |+\n ends with\n \r line break\n \r " ) ]
88
+ [ InlineData ( " starts with\n spaces" , "test: |2\n starts with\n spaces" ) ]
89
+ [ InlineData ( " starts with\n spaces, and ends with line break\n " , "test: |+2\n starts with\n spaces, and ends with line break\n " ) ]
90
+ [ InlineData ( "contains\n \n \n empty lines" , "test: |\n contains\n \n \n empty lines" ) ]
91
+ [ InlineData ( "no line breaks fallback " , "test: 'no line breaks fallback '" ) ]
92
+ public void WriteStringWithNewlineCharactersInObjectAsYamlWorks ( string input , string expected )
93
+ {
94
+ // Arrange
95
+ var outputStringWriter = new StringWriter ( CultureInfo . InvariantCulture ) ;
96
+ var writer = new OpenApiYamlWriter ( outputStringWriter ) { UseLiteralStyle = true , } ;
97
+
98
+ // Act
99
+ writer . WriteStartObject ( ) ;
100
+ writer . WritePropertyName ( "test" ) ;
101
+ writer . WriteValue ( input ) ;
102
+ writer . WriteEndObject ( ) ;
103
+ var actual = outputStringWriter . GetStringBuilder ( ) . ToString ( ) ;
104
+
105
+ // Assert
106
+ actual . Should ( ) . Be ( expected ) ;
107
+ }
108
+
109
+ [ Theory ]
110
+ [ InlineData ( "multiline\r \n string" , "- |\n multiline\r \n string" ) ]
111
+ [ InlineData ( "multiline\n string" , "- |\n multiline\n string" ) ]
112
+ [ InlineData ( "multiline\r string" , "- |\n multiline\r string" ) ]
113
+ [ InlineData ( "multiline\n \r string" , "- |\n multiline\n \r string" ) ]
114
+ [ InlineData ( "ends with\r \n line break\r \n " , "- |+\n ends with\r \n line break\r \n " ) ]
115
+ [ InlineData ( "ends with\n line break\n " , "- |+\n ends with\n line break\n " ) ]
116
+ [ InlineData ( "ends with\r line break\r " , "- |+\n ends with\r line break\r " ) ]
117
+ [ InlineData ( "ends with\n \r line break\n \r " , "- |+\n ends with\n \r line break\n \r " ) ]
118
+ [ InlineData ( " starts with\n spaces" , "- |2\n starts with\n spaces" ) ]
119
+ [ InlineData ( " starts with\n spaces, and ends with line break\n " , "- |+2\n starts with\n spaces, and ends with line break\n " ) ]
120
+ [ InlineData ( "contains\n \n \n empty lines" , "- |\n contains\n \n \n empty lines" ) ]
121
+ [ InlineData ( "no line breaks fallback " , "- 'no line breaks fallback '" ) ]
122
+ public void WriteStringWithNewlineCharactersInArrayAsYamlWorks ( string input , string expected )
123
+ {
124
+ // Arrange
125
+ var outputStringWriter = new StringWriter ( CultureInfo . InvariantCulture ) ;
126
+ var writer = new OpenApiYamlWriter ( outputStringWriter ) { UseLiteralStyle = true , } ;
127
+
128
+ // Act
129
+ writer . WriteStartArray ( ) ;
130
+ writer . WriteValue ( input ) ;
131
+ var actual = outputStringWriter . GetStringBuilder ( ) . ToString ( ) ;
132
+
133
+ // Assert
134
+ actual . Should ( ) . Be ( expected ) ;
135
+ }
78
136
}
79
137
}
0 commit comments