Skip to content

Commit df5e054

Browse files
ArkatufusAaronontheweb
authored andcommitted
Specific test for dot and comma in key (#84)
* Add specific test for #79 * Add comma case
1 parent 4b4f6ae commit df5e054

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

src/Hocon.Tests/PathTests.cs

+45-13
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ public PathTests(ITestOutputHelper output)
1818
}
1919

2020
[Theory]
21-
[InlineData(new string[] { "foo", "bar" }, "foo.bar")]
22-
[InlineData(new string[] { "foo", "bar.baz" }, "foo.\"bar.baz\"")]
23-
[InlineData(new string[] { "shoot", "a \"laser\" beam" }, "shoot.\"a \\\"laser\\\" beam\"")]
24-
[InlineData(new string[] { "foo", "bar\nbaz" }, "foo.\"bar\\nbaz\"")]
25-
[InlineData(new string[] { "foo", "bar baz", " wis " }, "foo.bar baz. wis ")]
26-
[InlineData(new string[] { "foo", "bar\tbaz"}, "foo.bar\tbaz")]
27-
[InlineData(new string[] { "foo", "bar\r\nbaz", "x\r" }, "foo.\"bar\r\\nbaz\".x\r")]
28-
[InlineData(new string[] { "foo", "" }, "foo.\"\"")]
29-
[InlineData(new string[] { "foo", "\\" }, "foo.\"\\\\\"")]
30-
[InlineData(new string[] { "$\"{}[]:=,#`^?!@*&\\" }, "\"" + "$\\\"{}[]:=,#`^?!@*&\\\\" + "\"")]
21+
[InlineData(new [] { "foo", "bar" }, "foo.bar")]
22+
[InlineData(new [] { "foo", "bar.baz" }, "foo.\"bar.baz\"")]
23+
[InlineData(new [] { "shoot", "a \"laser\" beam" }, "shoot.\"a \\\"laser\\\" beam\"")]
24+
[InlineData(new [] { "foo", "bar\nbaz" }, "foo.\"bar\\nbaz\"")]
25+
[InlineData(new [] { "foo", "bar baz", " wis " }, "foo.bar baz. wis ")]
26+
[InlineData(new [] { "foo", "bar\tbaz"}, "foo.bar\tbaz")]
27+
[InlineData(new [] { "foo", "bar\r\nbaz", "x\r" }, "foo.\"bar\r\\nbaz\".x\r")]
28+
[InlineData(new [] { "foo", "" }, "foo.\"\"")]
29+
[InlineData(new [] { "foo", "\\" }, "foo.\"\\\\\"")]
30+
[InlineData(new [] { "$\"{}[]:=,#`^?!@*&\\" }, "\"" + "$\\\"{}[]:=,#`^?!@*&\\\\" + "\"")]
3131
public void CanParseAndSerialize(string[] pathKeys, string path)
3232
{
3333
HoconPath hoconPath = new HoconPath(pathKeys);
@@ -47,19 +47,51 @@ public void CanParseAndSerialize(string[] pathKeys, string path)
4747
Assert.Equal(pathKeys[i], hoconPath2[i]);
4848
}
4949

50-
_output.WriteLine(string.Format("Path [{0}] serialized from: {1}", path, string.Join(", ", pathKeys)));
50+
_output.WriteLine($"Path [{path}] serialized from: {string.Join(", ", pathKeys)}");
51+
}
52+
53+
// Test that #79 invalid token exception does not happen.
54+
[Fact]
55+
public void DotAndCommaInQuotedKeyShouldBePreserved_79()
56+
{
57+
const string hocon = @"
58+
akka {
59+
persistence {
60+
journal {
61+
plugin = ""akka.persistence.journal.sql - server""
62+
sql-server {
63+
class = ""Akka.Persistence.SqlServer.Journal.BatchingSqlServerJournal, Akka.Persistence.SqlServer""
64+
schema-name = dbo
65+
table-name = EventJournal
66+
auto-initialize = off
67+
event-adapters
68+
{
69+
json-adapter = ""Demo.EventAdapter, Demo""
70+
}
71+
event-adapter-bindings
72+
{
73+
""Demo.IMyEvent, MyDemoAssembly"" = json-adapter #this line makes a invalid token exception
74+
}
75+
}
76+
}
77+
}
78+
}";
79+
var config = Parser.Parse(hocon);
80+
var path = HoconPath.Parse("akka.persistence.journal.sql-server.event-adapter-bindings.\"Demo.IMyEvent, MyDemoAssembly\"");
81+
Assert.Equal("Demo.IMyEvent, MyDemoAssembly", path.Last());
82+
Assert.Equal("json-adapter", config.GetString(path));
5183
}
5284

5385
[Fact]
5486
public void PathToStringQuoteKeysContainingDot()
5587
{
56-
var path1 = new HoconPath(new string[] {
88+
var path1 = new HoconPath(new [] {
5789
"i am",
5890
"kong.fu",
5991
"panda"
6092
});
6193

62-
var path2 = new HoconPath(new string[]
94+
var path2 = new HoconPath(new []
6395
{
6496
"i am",
6597
"kong",

0 commit comments

Comments
 (0)