The problem with this line
Assert.AreEqual(formatted, $"{{countdown|{date:o}}}");
is that you have 3 curly quotes after the format string
of the variable to be escaped and it starts escaping from left to right, therefore it treats the first 2 curly quotes as part of the format string and the third curly quote as the closing one.
So it transforms o
in o}
and the it's unable to interpolate it.
This should work
Assert.AreEqual(formatted, $"{{countdown|{date:o}"+"}");
Notice that the simpler $"{date}}}"
(i.e. 3 curls after the variable without a format string
) does work because it recognizes that the first curly quote is the closing one, while the interpretation of the format specifier after the :
breaks the correct closing parenthesis identification.
To prove that the format string is escaped like a string, consider that the following
$"{date:x6f}"
is treated as
$"{date:o}"
Finally, it is perfectly possible that the double escaped curly quotes are part of a custom date format, so it is absolutely reasonable the behaviour of the compiler. Again, a concrete example
$"{date:MMM}}dd}}yyy}" // it's a valid feb}09}2017
Parsing is a formal process based on expression grammar rules, can't be done by just glancing at it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…