@@ -1931,4 +1931,189 @@ public void InvalidArrayIndex_ExceptionIncludesFullPath_ForJsonElement()
19311931 }
19321932
19331933 #endregion
1934+
1935+ #region Path Escape Syntax Tests
1936+
1937+ public class BracketStringLiteralTests
1938+ {
1939+ [ Fact ]
1940+ public void GetValue_DoubleQuoteBracket_AccessesKeyWithDot ( )
1941+ {
1942+ // Arrange
1943+ var dict = new Dictionary < string , object >
1944+ {
1945+ [ "my.key" ] = "value with dot"
1946+ } ;
1947+
1948+ // Act
1949+ var result = ObjectPath . GetValue ( dict , "[\" my.key\" ]" ) ;
1950+
1951+ // Assert
1952+ Assert . Equal ( "value with dot" , result ) ;
1953+ }
1954+
1955+ [ Fact ]
1956+ public void GetValue_SingleQuoteBracket_AccessesKeyWithDot ( )
1957+ {
1958+ // Arrange
1959+ var dict = new Dictionary < string , object >
1960+ {
1961+ [ "my.key" ] = "value with dot"
1962+ } ;
1963+
1964+ // Act
1965+ var result = ObjectPath . GetValue ( dict , "['my.key']" ) ;
1966+
1967+ // Assert
1968+ Assert . Equal ( "value with dot" , result ) ;
1969+ }
1970+
1971+ [ Fact ]
1972+ public void GetValue_BracketKey_AccessesKeyWithBrackets ( )
1973+ {
1974+ // Arrange
1975+ var dict = new Dictionary < string , object >
1976+ {
1977+ [ "key[0]" ] = "value with brackets"
1978+ } ;
1979+
1980+ // Act
1981+ var result = ObjectPath . GetValue ( dict , "[\" key[0]\" ]" ) ;
1982+
1983+ // Assert
1984+ Assert . Equal ( "value with brackets" , result ) ;
1985+ }
1986+
1987+ [ Fact ]
1988+ public void GetValue_MixedSyntax_WorksCorrectly ( )
1989+ {
1990+ // Arrange
1991+ var data = new Dictionary < string , object >
1992+ {
1993+ [ "config.settings" ] = new Dictionary < string , object >
1994+ {
1995+ [ "value" ] = 42
1996+ }
1997+ } ;
1998+
1999+ // Act - Access "config.settings" key, then "value" property
2000+ var result = ObjectPath . GetValue ( data , "[\" config.settings\" ].value" ) ;
2001+
2002+ // Assert
2003+ Assert . Equal ( 42 , result ) ;
2004+ }
2005+
2006+ [ Fact ]
2007+ public void GetValue_NestedBracketKeys_WorksCorrectly ( )
2008+ {
2009+ // Arrange
2010+ var data = new Dictionary < string , object >
2011+ {
2012+ [ "level.one" ] = new Dictionary < string , object >
2013+ {
2014+ [ "level.two" ] = "nested value"
2015+ }
2016+ } ;
2017+
2018+ // Act
2019+ var result = ObjectPath . GetValue ( data , "[\" level.one\" ][\" level.two\" ]" ) ;
2020+
2021+ // Assert
2022+ Assert . Equal ( "nested value" , result ) ;
2023+ }
2024+
2025+ [ Fact ]
2026+ public void GetValue_EscapedQuotes_WorksCorrectly ( )
2027+ {
2028+ // Arrange
2029+ var dict = new Dictionary < string , object >
2030+ {
2031+ [ "key\" quote" ] = "escaped quote value"
2032+ } ;
2033+
2034+ // Act - Use backslash to escape the quote
2035+ var result = ObjectPath . GetValue ( dict , "[\" key\\ \" quote\" ]" ) ;
2036+
2037+ // Assert
2038+ Assert . Equal ( "escaped quote value" , result ) ;
2039+ }
2040+
2041+ [ Fact ]
2042+ public void GetValue_CombinedWithArrayIndex_WorksCorrectly ( )
2043+ {
2044+ // Arrange
2045+ var data = new Dictionary < string , object >
2046+ {
2047+ [ "items.list" ] = new List < object > { "first" , "second" , "third" }
2048+ } ;
2049+
2050+ // Act
2051+ var result = ObjectPath . GetValue ( data , "[\" items.list\" ][1]" ) ;
2052+
2053+ // Assert
2054+ Assert . Equal ( "second" , result ) ;
2055+ }
2056+
2057+ [ Fact ]
2058+ public void GetValue_JsonElement_WithBracketSyntax ( )
2059+ {
2060+ // Arrange
2061+ var json = """{"data.key": {"nested.prop": "json value"}}""" ;
2062+ var doc = JsonDocument . Parse ( json ) ;
2063+
2064+ // Act
2065+ var result = ObjectPath . GetValue ( doc . RootElement , "[\" data.key\" ][\" nested.prop\" ]" ) ;
2066+
2067+ // Assert
2068+ Assert . Equal ( "json value" , result ) ;
2069+ }
2070+
2071+ [ Fact ]
2072+ public void GetValue_RegularObjectAfterBracketKey_WorksCorrectly ( )
2073+ {
2074+ // Arrange
2075+ var dict = new Dictionary < string , object >
2076+ {
2077+ [ "my.config" ] = new { Name = "Test" , Value = 123 }
2078+ } ;
2079+
2080+ // Act
2081+ var name = ObjectPath . GetValue ( dict , "[\" my.config\" ].Name" ) ;
2082+ var value = ObjectPath . GetValue ( dict , "[\" my.config\" ].Value" ) ;
2083+
2084+ // Assert
2085+ Assert . Equal ( "Test" , name ) ;
2086+ Assert . Equal ( 123 , value ) ;
2087+ }
2088+
2089+ [ Fact ]
2090+ public void TryGetValue_WithBracketSyntax_ReturnsTrue ( )
2091+ {
2092+ // Arrange
2093+ var dict = new Dictionary < string , object > { [ "a.b" ] = "value" } ;
2094+
2095+ // Act
2096+ var result = ObjectPath . TryGetValue ( dict , "[\" a.b\" ]" , out var value ) ;
2097+
2098+ // Assert
2099+ Assert . True ( result ) ;
2100+ Assert . Equal ( "value" , value ) ;
2101+ }
2102+
2103+ [ Fact ]
2104+ public void TryGetValue_WithInvalidBracketKey_ReturnsFalse ( )
2105+ {
2106+ // Arrange
2107+ var dict = new Dictionary < string , object > { [ "key" ] = "value" } ;
2108+
2109+ // Act
2110+ var result = ObjectPath . TryGetValue ( dict , "[\" nonexistent.key\" ]" , out var value ) ;
2111+
2112+ // Assert
2113+ Assert . False ( result ) ;
2114+ Assert . Null ( value ) ;
2115+ }
2116+ }
2117+
2118+ #endregion
19342119}
0 commit comments