public void TestResolvableEnumeration() { DictionaryResolvable resolvable = new DictionaryResolvable { { "A", new List <IResolvable> { new DictionaryResolvable { { "A", "A" }, { "B", "B" }, { "C", "C" }, }, new DictionaryResolvable { { "A", "D" }, { "B", "E" }, { "C", "F" }, }, new DictionaryResolvable { { "A", "G" }, { "B", "H" }, { "C", "J" }, { "<INDEX>", "I" } } } } }; FormatBuilder builder = new FormatBuilder().AppendFormat("{0:{A:[{<ITEMS>:{<INDEX>} {A} {B} {C}}{<JOIN>:, }]}}", resolvable); Assert.AreEqual("[0 A B C, 1 D E F, I G H J]", builder.ToString()); }
public void TestNestedResolver() { DictionaryResolvable resolvable = new DictionaryResolvable { { "A", new DictionaryResolvable { {"A", "aa"}, {"B", "ab"} } }, { "B", new DictionaryResolvable { {"A", "ba"}, {"B", "bb"} } } }; FormatBuilder builder = new FormatBuilder().AppendFormat("{0:{A:{B:{A}}} {B:{A:{B}}}}", resolvable); Assert.AreEqual("aa bb", builder.ToString()); /* WHY???? * Step 1: {0:...} is resolved to 'resolvable' * Step 2: There's a format, so the resolvable is called to resolve it. * Step 3: {A:...} and {B:...} are resolved to two new Resolvables (the two inside the dictionary above). * This bits, important, these are the last two resolvables on the stack... * Step 4: {B:{A}} is resolved to "ab" (note not a resolvable), and {A:{B}} is resolved to "ba". * Step 5: {A} is resolved by the resolvable on the stack at that point (the one belonging to 'A') as the B * is not a resolvable itself. Therefore the A is "aa". Similarly for the {B}. * * {Context:\r\n{Key}\t: {Value}} => * {Context.Resource:\r\n{Key}\t: {Value} */ }
public void TestNestedResolver() { DictionaryResolvable resolvable = new DictionaryResolvable { { "A", new DictionaryResolvable { { "A", "aa" }, { "B", "ab" } } }, { "B", new DictionaryResolvable { { "A", "ba" }, { "B", "bb" } } } }; FormatBuilder builder = new FormatBuilder().AppendFormat("{0:{A:{B:{A}}} {B:{A:{B}}}}", resolvable); Assert.AreEqual("aa bb", builder.ToString()); /* WHY???? * Step 1: {0:...} is resolved to 'resolvable' * Step 2: There's a format, so the resolvable is called to resolve it. * Step 3: {A:...} and {B:...} are resolved to two new Resolvables (the two inside the dictionary above). * This bits, important, these are the last two resolvables on the stack... * Step 4: {B:{A}} is resolved to "ab" (note not a resolvable), and {A:{B}} is resolved to "ba". * Step 5: {A} is resolved by the resolvable on the stack at that point (the one belonging to 'A') as the B * is not a resolvable itself. Therefore the A is "aa". Similarly for the {B}. * * {Context:\r\n{Key}\t: {Value}} => * {Context.Resource:\r\n{Key}\t: {Value} */ }
public void TestResolvableEnumeration() { DictionaryResolvable resolvable = new DictionaryResolvable { { "A", new List<IResolvable> { new DictionaryResolvable { {"A", "A"}, {"B", "B"}, {"C", "C"}, }, new DictionaryResolvable { {"A", "D"}, {"B", "E"}, {"C", "F"}, }, new DictionaryResolvable { {"A", "G"}, {"B", "H"}, {"C", "J"}, {"<INDEX>", "I"} } } } }; FormatBuilder builder = new FormatBuilder().AppendFormat("{0:{A:[{<ITEMS>:{<INDEX>} {A} {B} {C}}{<JOIN>:, }]}}", resolvable); Assert.AreEqual("[0 A B C, 1 D E F, I G H J]", builder.ToString()); }