public void TestNestedChunks() { // Any character that appears after a '\' will always be added. This only has an effect for the '{', '}' and '\' characters, all others do not need to be escaped FormatChunk[] chunks = FormatChunk.Parse(@"This: {Tag:Is a very {complicated: {nested} format string with \{{escaped}\} tags and other \\ \'\characters\}}} and some trailing text").ToArray(); // ReSharper disable PossibleNullReferenceException Assert.AreEqual(3, chunks.Length); Assert.AreEqual("This: ", chunks[0].Value); Assert.AreEqual("Tag", chunks[1].Tag); Assert.AreEqual(" and some trailing text", chunks[2].Value); chunks = chunks[1].Children.ToArray(); Assert.AreEqual(2, chunks.Length); Assert.AreEqual("Is a very ", chunks[0].Value); Assert.AreEqual("complicated", chunks[1].Tag); chunks = chunks[1].Children.ToArray(); Assert.AreEqual(5, chunks.Length); Assert.AreEqual(" ", chunks[0].Value); Assert.AreEqual("nested", chunks[1].Tag); Assert.AreEqual(@" format string with {", chunks[2].Value); Assert.AreEqual("escaped", chunks[3].Tag); Assert.AreEqual(@"} tags and other \ 'characters}", chunks[4].Value); // ReSharper restore PossibleNullReferenceException }
public void TestInvalidAlignedFillPoint() { FormatChunk[] chunks = FormatChunk.Parse("{0,}").ToArray(); Assert.AreEqual(1, chunks.Length); FormatChunk chunk = chunks[0]; Assert.IsNotNull(chunk); Assert.AreEqual("0", chunk.Tag); Assert.IsNull(chunk.Value); }
public void TestAlignedFillPoint() { FormatChunk[] chunks = FormatChunk.Parse("{0,-1}").ToArray(); Assert.AreEqual(1, chunks.Length); FormatChunk chunk = chunks[0]; Assert.IsNotNull(chunk); Assert.AreEqual("{0,-1}", chunk.ToString("F", null)); Assert.IsNull(chunk.Value); Assert.IsNotNull(chunk.Tag); Assert.AreEqual("0", chunk.Tag); Assert.AreEqual(-1, chunk.Alignment); Assert.IsNull(chunk.Format); }
public void TestTrailingSpace() { FormatChunk[] chunks = FormatChunk.Parse("{0,-1:G} ").ToArray(); Assert.AreEqual(2, chunks.Length); FormatChunk chunk = chunks[0]; Assert.IsNotNull(chunk); Assert.AreEqual("{0,-1:G}", chunk.ToString("F", null)); Assert.IsNull(chunk.Value); Assert.IsNotNull(chunk.Tag); Assert.AreEqual("0", chunk.Tag); Assert.AreEqual(-1, chunk.Alignment); Assert.AreEqual("G", chunk.Format); chunk = chunks[1]; Assert.IsNotNull(chunk); Assert.AreEqual(" ", chunk.Value); Assert.IsNull(chunk.Tag); }
public void TestEmpty() { FormatChunk[] chunks = FormatChunk.Parse(string.Empty).ToArray(); Assert.AreEqual(0, chunks.Length); }