@@ -36,12 +36,13 @@ public class JavaPropertyReaderTest : KajabityToolsTest
36
36
private string CommentsTestFile ;
37
37
private string DuplicateTestFile ;
38
38
private string LineBreaksTestFile ;
39
- private string MixedTestFile ;
39
+ private string UrlsTestFile ;
40
40
private string SeparatorsTestFile ;
41
41
private string SpecialCharactersTestFile ;
42
42
private string NonAciiSymbolsUtf8TestFile ;
43
43
private string NonAsciiSymbolsNativeToAsciiTestFile ;
44
44
private string Utf8WithBomFile ;
45
+ private string LineBreakWithUnicodeFile ;
45
46
46
47
/// <summary>
47
48
/// The directory where a copy of the Java test data input files are placed.
@@ -75,12 +76,13 @@ public void SetUp()
75
76
CommentsTestFile = Path . Combine ( JavaTestDataDirectory , "comments.properties" ) ;
76
77
DuplicateTestFile = Path . Combine ( JavaTestDataDirectory , "duplicate.properties" ) ;
77
78
LineBreaksTestFile = Path . Combine ( JavaTestDataDirectory , "line-breaks.properties" ) ;
78
- MixedTestFile = Path . Combine ( JavaTestDataDirectory , "mixed .properties" ) ;
79
+ UrlsTestFile = Path . Combine ( JavaTestDataDirectory , "urls .properties" ) ;
79
80
SeparatorsTestFile = Path . Combine ( JavaTestDataDirectory , "separators.properties" ) ;
80
81
SpecialCharactersTestFile = Path . Combine ( JavaTestDataDirectory , "special-characters.properties" ) ;
81
82
NonAciiSymbolsUtf8TestFile = Path . Combine ( JavaTestDataDirectory , "non-ascii-symbols-utf8.properties" ) ;
82
83
NonAsciiSymbolsNativeToAsciiTestFile = Path . Combine ( JavaTestDataDirectory , "non-ascii-symbols-native2ascii.properties" ) ;
83
84
Utf8WithBomFile = Path . Combine ( JavaTestDataDirectory , "utf8-with-BOM.properties" ) ;
85
+ LineBreakWithUnicodeFile = Path . Combine ( JavaTestDataDirectory , "line-break-unicode.properties" ) ;
84
86
}
85
87
86
88
[ Test ]
@@ -155,7 +157,10 @@ public void TestComments()
155
157
properties . Load ( fileStream ) ;
156
158
fileStream . Close ( ) ;
157
159
158
- //Assert.Equals( properties.Count, 3 );
160
+ Assert . AreEqual ( properties . Count , 3 ) ;
161
+ Assert . AreEqual ( properties [ "name" ] , "value" ) ;
162
+ Assert . AreEqual ( properties [ "key\n with\n newlines" ] , "value" ) ;
163
+ Assert . AreEqual ( properties [ "key-no-newlines" ] , "Value\n with\n newlines." ) ;
159
164
}
160
165
catch ( Exception ex )
161
166
{
@@ -184,7 +189,7 @@ public void TestDuplicates()
184
189
fileStream . Close ( ) ;
185
190
186
191
Assert . AreEqual ( properties . Count , 1 ) ;
187
- Assert . IsTrue ( "c" . Equals ( properties . GetProperty ( "a" ) ) ) ;
192
+ Assert . AreEqual ( properties [ "a" ] , "c" ) ;
188
193
}
189
194
catch ( Exception ex )
190
195
{
@@ -212,7 +217,13 @@ public void TestLineBreaks()
212
217
properties . Load ( fileStream ) ;
213
218
fileStream . Close ( ) ;
214
219
215
- //Assert.Equals( properties.Count, 3 );
220
+ Assert . AreEqual ( properties . Count , 5 ) ;
221
+ Assert . AreEqual ( properties [ "key\n with\n newlines" ] , "value" ) ;
222
+ Assert . AreEqual ( properties [ "key-no-newlines" ] , "Value\n with\n newlines." ) ;
223
+
224
+ Assert . AreEqual ( properties [ "fruits" ] , "apple, banana, pear, cantaloupe, watermelon, kiwi, mango" ) ;
225
+ Assert . AreEqual ( properties [ "fruits2" ] , "apple, banana, pear, cantaloupe, watermelon, " ) ;
226
+ Assert . AreEqual ( properties [ "kiwi," ] , "mango" ) ;
216
227
}
217
228
catch ( Exception ex )
218
229
{
@@ -240,7 +251,19 @@ public void TestSeparators()
240
251
properties . Load ( fileStream ) ;
241
252
fileStream . Close ( ) ;
242
253
243
- //Assert.IsEmpty(properties);
254
+ Assert . AreEqual ( properties . Count , 8 ) ;
255
+
256
+ Assert . AreEqual ( properties [ "a" ] , "b" ) ;
257
+ Assert . AreEqual ( properties [ "c" ] , "d" ) ;
258
+
259
+ Assert . AreEqual ( properties [ "e" ] , "f" ) ;
260
+ Assert . AreEqual ( properties [ "gh" ] , "ij klm" ) ;
261
+
262
+ Assert . AreEqual ( properties [ "Truth1" ] , "Beauty 1" ) ;
263
+ Assert . AreEqual ( properties [ "Truth3" ] , "Beauty 3" ) ;
264
+ Assert . AreEqual ( properties [ "Truth2" ] , "Beauty 2" ) ;
265
+
266
+ Assert . AreEqual ( properties [ "cheeses" ] , "" ) ;
244
267
}
245
268
catch ( Exception ex )
246
269
{
@@ -268,7 +291,17 @@ public void TestSpecialCharacters()
268
291
properties . Load ( fileStream ) ;
269
292
fileStream . Close ( ) ;
270
293
271
- //Assert.IsEmpty(properties);
294
+ Assert . AreEqual ( properties . Count , 7 ) ;
295
+ Assert . AreEqual ( properties [ "key with spaces" ] , "value with spaces" ) ;
296
+
297
+ Assert . AreEqual ( properties [ "anotherKey" ] , "unicode \\ u0041='A'" ) ;
298
+ Assert . AreEqual ( properties [ "\u0000 \u001F Unicode-Key" ] , "\u0000 \t \n \u001F \u4567 Unicode Value" ) ;
299
+
300
+ Assert . AreEqual ( properties [ "# key-not-comment" ] , " value begins with\t space." ) ;
301
+
302
+ Assert . AreEqual ( properties [ "One" ] , "Two = Three Four" ) ;
303
+ Assert . AreEqual ( properties [ "Five Six" ] , "Seven Eight" ) ;
304
+ Assert . AreEqual ( properties [ "Nine" ] , "Ten " ) ;
272
305
}
273
306
catch ( Exception ex )
274
307
{
@@ -312,7 +345,7 @@ public void TestUtf8NonAsciiSymbols()
312
345
// this is to ensure that setting the encoding makes a difference
313
346
utf8PropertiesIncorrect . Load ( utf8FileStream ) ;
314
347
315
-
348
+
316
349
JavaProperties isoProperties = new JavaProperties ( ) ;
317
350
isoProperties . Load ( isoFileStream ) ;
318
351
@@ -333,7 +366,7 @@ public void TestUtf8NonAsciiSymbols()
333
366
Assert . AreNotEqual ( utf8PropertiesIncorrect [ key ] , utf8PropertiesCorrect [ key ] ) ;
334
367
Assert . AreNotEqual ( utf8PropertiesIncorrect [ key ] , isoProperties [ key ] ) ;
335
368
}
336
-
369
+
337
370
}
338
371
isoFileStream . Close ( ) ;
339
372
@@ -357,19 +390,23 @@ public void TestUtf8NonAsciiSymbols()
357
390
}
358
391
359
392
[ Test ]
360
- public void TestMixed ( )
393
+ public void TestUrls ( )
361
394
{
362
395
FileStream fileStream = null ;
363
396
try
364
397
{
365
- Console . WriteLine ( "Loading " + MixedTestFile ) ;
398
+ Console . WriteLine ( "Loading " + UrlsTestFile ) ;
366
399
367
- fileStream = new FileStream ( MixedTestFile , FileMode . Open ) ;
400
+ fileStream = new FileStream ( UrlsTestFile , FileMode . Open ) ;
368
401
JavaProperties properties = new JavaProperties ( ) ;
369
402
properties . Load ( fileStream ) ;
370
403
fileStream . Close ( ) ;
371
404
372
- //Assert.IsEmpty(properties);
405
+ Assert . AreEqual ( properties . Count , 3 ) ;
406
+
407
+ Assert . AreEqual ( properties [ "http://www.kajabity.com" ] , "my lovely web site." ) ;
408
+ Assert . AreEqual ( properties [ "my-blog" ] , "http://www.kajabity.com" ) ;
409
+ Assert . AreEqual ( properties [ "my-blog-2" ] , "{my-blog}" ) ;
373
410
}
374
411
catch ( Exception ex )
375
412
{
@@ -413,5 +450,32 @@ public void TestUtf8WithBom()
413
450
}
414
451
}
415
452
}
453
+
454
+ [ Test ]
455
+ public void TestLineBreakInUnicodeSequence ( )
456
+ {
457
+ FileStream fileStream = null ;
458
+ try
459
+ {
460
+ // Read the test properties file.
461
+ Console . WriteLine ( "Loading " + LineBreakWithUnicodeFile ) ;
462
+ fileStream = new FileStream ( LineBreakWithUnicodeFile , FileMode . Open ) ;
463
+ JavaProperties properties = new JavaProperties ( ) ;
464
+ properties . Load ( fileStream ) ;
465
+
466
+ Assert . AreEqual ( properties [ "AAAP" ] , "B" ) ;
467
+ }
468
+ catch ( Exception ex )
469
+ {
470
+ Assert . Fail ( ex . Message ) ;
471
+ }
472
+ finally
473
+ {
474
+ if ( fileStream != null )
475
+ {
476
+ fileStream . Close ( ) ;
477
+ }
478
+ }
479
+ }
416
480
}
417
481
}
0 commit comments