private static void TestFormat(string expected, string format, TokenOptions options, params object[] tokenValueObjects) { foreach (object tokenValues in tokenValueObjects) { string result = TokenFormatter.Format(format, tokenValues, options); Assert.AreEqual(expected, result); } }
public void PropertyAccessModifier() { var obj = new PropertyAccess(); Assert.AreEqual("Value", TokenFormatter.Format("{PublicValue}", obj)); Assert.AreEqual("Value", TokenFormatter.Format("{InternalValue}", obj, TokenOptions.NonPublicAccess)); Assert.ThrowsException <KeyNotFoundException>(() => TokenFormatter.Format("{InternalValue}", obj)); }
public void EscapedTokenMarkers() { Assert.AreEqual("{", TokenFormatter.Format("{{", new object())); Assert.AreEqual("}{", TokenFormatter.Format("}}{{", new object())); Assert.AreEqual("{0}", TokenFormatter.Format("{{{Length}}}", string.Empty)); Assert.AreEqual("{Length}", TokenFormatter.Format("{{Length}}", string.Empty)); Assert.ThrowsException <FormatException>(() => TokenFormatter.Format("Unescaped { brace", string.Empty)); Assert.ThrowsException <FormatException>(() => TokenFormatter.Format("Unescaped } brace", string.Empty)); }
public void TokenFormatter_Converts_Tokens_Into_Proper_Signs() { var input = "(2+3)*4/5-6.7+cos(60deg)+sin(30deg)+tan(45deg)+2a^2+sqrt(16)"; var tokenizer = new Tokenizer(); tokenizer.Tokenize(input, null); var underTest = new TokenFormatter(); var result = underTest.Format(tokenizer.Tokens); result.Should().Be("(2+3)*4/5-6.7+0.5+0.5+1.0+2*a^2+16^0.5"); }
public void TokenValueNotFound() { string format = "Name: {x?[missing]}"; var obj = new Dictionary <string, object>(); var ex = Assert.ThrowsException <KeyNotFoundException>(() => TokenFormatter.Format(format, obj)); Assert.IsTrue(ex.Message.Contains("'x'", StringComparison.Ordinal)); ex = Assert.ThrowsException <KeyNotFoundException>(() => TokenFormatter.Format(format, obj)); Assert.IsTrue(ex.Message.Contains("'x'", StringComparison.Ordinal)); Assert.AreEqual("Name: [missing]", TokenFormatter.Format(format, obj, TokenOptions.AllowMissingKeys)); }
public void GeneralTokenizerTest() { var formatString = "{P},{P}, {F},{L}, {P}\n{P}\n{P}\n{M} {Suffix} .... {asdfasdfasdf}"; var foo = new Foo() { First = "Joshua", Last = "Miller", Middle = "Boop", Suffix = "Dr" }; var tokenFormatter = new TokenFormatter <Foo>(new FooExtractor(), new Tokenizer(), new DataApplier(), new RuleApplier()); var output = tokenFormatter.Format(foo, formatString); }
public void TokenValueFormat() { Assert.AreEqual("0005", TokenFormatter.Format("{Value:D4}", new { Value = 5 })); Assert.AreEqual("0005", TokenFormatter.Format("{Object.Value:D4}", new { Object = new { Value = 5 } })); }