Skip to content

Commit 2cae1dc

Browse files
committed
ISSUE-7 Fixed handling of line wrapping inside unicode escape.
Added specific reader tests and completed all of the reader tests. Added detailed set of Writer tests - and compared with Java equivalents.
1 parent e1093f1 commit 2cae1dc

9 files changed

+587
-250
lines changed

Kajabity.Tools.Java.Test/Java/JavaPropertyReaderTest.cs

+77-13
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ public class JavaPropertyReaderTest : KajabityToolsTest
3636
private string CommentsTestFile;
3737
private string DuplicateTestFile;
3838
private string LineBreaksTestFile;
39-
private string MixedTestFile;
39+
private string UrlsTestFile;
4040
private string SeparatorsTestFile;
4141
private string SpecialCharactersTestFile;
4242
private string NonAciiSymbolsUtf8TestFile;
4343
private string NonAsciiSymbolsNativeToAsciiTestFile;
4444
private string Utf8WithBomFile;
45+
private string LineBreakWithUnicodeFile;
4546

4647
/// <summary>
4748
/// The directory where a copy of the Java test data input files are placed.
@@ -75,12 +76,13 @@ public void SetUp()
7576
CommentsTestFile = Path.Combine(JavaTestDataDirectory, "comments.properties");
7677
DuplicateTestFile = Path.Combine(JavaTestDataDirectory, "duplicate.properties");
7778
LineBreaksTestFile = Path.Combine(JavaTestDataDirectory, "line-breaks.properties");
78-
MixedTestFile = Path.Combine(JavaTestDataDirectory, "mixed.properties");
79+
UrlsTestFile = Path.Combine(JavaTestDataDirectory, "urls.properties");
7980
SeparatorsTestFile = Path.Combine(JavaTestDataDirectory, "separators.properties");
8081
SpecialCharactersTestFile = Path.Combine(JavaTestDataDirectory, "special-characters.properties");
8182
NonAciiSymbolsUtf8TestFile = Path.Combine(JavaTestDataDirectory, "non-ascii-symbols-utf8.properties");
8283
NonAsciiSymbolsNativeToAsciiTestFile = Path.Combine(JavaTestDataDirectory, "non-ascii-symbols-native2ascii.properties");
8384
Utf8WithBomFile = Path.Combine(JavaTestDataDirectory, "utf8-with-BOM.properties");
85+
LineBreakWithUnicodeFile = Path.Combine(JavaTestDataDirectory, "line-break-unicode.properties");
8486
}
8587

8688
[Test]
@@ -155,7 +157,10 @@ public void TestComments()
155157
properties.Load(fileStream);
156158
fileStream.Close();
157159

158-
//Assert.Equals( properties.Count, 3 );
160+
Assert.AreEqual(properties.Count, 3);
161+
Assert.AreEqual(properties["name"], "value");
162+
Assert.AreEqual(properties["key\nwith\nnewlines"], "value");
163+
Assert.AreEqual(properties["key-no-newlines"], "Value\nwith\nnewlines.");
159164
}
160165
catch (Exception ex)
161166
{
@@ -184,7 +189,7 @@ public void TestDuplicates()
184189
fileStream.Close();
185190

186191
Assert.AreEqual(properties.Count, 1);
187-
Assert.IsTrue("c".Equals(properties.GetProperty("a")));
192+
Assert.AreEqual(properties["a"], "c");
188193
}
189194
catch (Exception ex)
190195
{
@@ -212,7 +217,13 @@ public void TestLineBreaks()
212217
properties.Load(fileStream);
213218
fileStream.Close();
214219

215-
//Assert.Equals( properties.Count, 3 );
220+
Assert.AreEqual(properties.Count, 5);
221+
Assert.AreEqual(properties["key\nwith\nnewlines"], "value");
222+
Assert.AreEqual(properties["key-no-newlines"], "Value\nwith\nnewlines.");
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");
216227
}
217228
catch (Exception ex)
218229
{
@@ -240,7 +251,19 @@ public void TestSeparators()
240251
properties.Load(fileStream);
241252
fileStream.Close();
242253

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"], "");
244267
}
245268
catch (Exception ex)
246269
{
@@ -268,7 +291,17 @@ public void TestSpecialCharacters()
268291
properties.Load(fileStream);
269292
fileStream.Close();
270293

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\u001FUnicode-Key"], "\u0000\t\n\u001F\u4567Unicode Value");
299+
300+
Assert.AreEqual(properties["# key-not-comment"], " value begins with\tspace.");
301+
302+
Assert.AreEqual(properties["One"], "Two = Three Four");
303+
Assert.AreEqual(properties["Five Six"], "Seven Eight");
304+
Assert.AreEqual(properties["Nine"], "Ten ");
272305
}
273306
catch (Exception ex)
274307
{
@@ -312,7 +345,7 @@ public void TestUtf8NonAsciiSymbols()
312345
// this is to ensure that setting the encoding makes a difference
313346
utf8PropertiesIncorrect.Load(utf8FileStream);
314347

315-
348+
316349
JavaProperties isoProperties = new JavaProperties();
317350
isoProperties.Load(isoFileStream);
318351

@@ -333,7 +366,7 @@ public void TestUtf8NonAsciiSymbols()
333366
Assert.AreNotEqual(utf8PropertiesIncorrect[key], utf8PropertiesCorrect[key]);
334367
Assert.AreNotEqual(utf8PropertiesIncorrect[key], isoProperties[key]);
335368
}
336-
369+
337370
}
338371
isoFileStream.Close();
339372

@@ -357,19 +390,23 @@ public void TestUtf8NonAsciiSymbols()
357390
}
358391

359392
[Test]
360-
public void TestMixed()
393+
public void TestUrls()
361394
{
362395
FileStream fileStream = null;
363396
try
364397
{
365-
Console.WriteLine("Loading " + MixedTestFile);
398+
Console.WriteLine("Loading " + UrlsTestFile);
366399

367-
fileStream = new FileStream(MixedTestFile, FileMode.Open);
400+
fileStream = new FileStream(UrlsTestFile, FileMode.Open);
368401
JavaProperties properties = new JavaProperties();
369402
properties.Load(fileStream);
370403
fileStream.Close();
371404

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}");
373410
}
374411
catch (Exception ex)
375412
{
@@ -413,5 +450,32 @@ public void TestUtf8WithBom()
413450
}
414451
}
415452
}
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+
}
416480
}
417481
}

0 commit comments

Comments
 (0)