PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/SharpTAL.Tests/TALTests/TALReplaceTests.cs

https://bitbucket.org/rlacko/sharptal
C# | 92 lines | 81 code | 11 blank | 0 comment | 0 complexity | acd27d1d7ff295eda307f20d4ed34e9c MD5 | raw file
Possible License(s): Apache-2.0
  1. namespace SharpTAL.SharpTALTests.TALTests
  2. {
  3. using System;
  4. using System.Text;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.IO;
  8. using System.Reflection;
  9. using NUnit.Framework;
  10. using SharpTAL.TemplateCache;
  11. [TestFixture]
  12. public class TALReplaceTests
  13. {
  14. public static Dictionary<string, object> globals;
  15. [TestFixtureSetUp]
  16. public void SetUpClass()
  17. {
  18. }
  19. [TestFixtureTearDown]
  20. public void CleanupClass()
  21. {
  22. }
  23. [SetUp]
  24. public void SetUp()
  25. {
  26. string entry = @"Some structure: <b tal:content=""weblog/subject""></b>";
  27. Dictionary<string, string> weblog = new Dictionary<string, string>
  28. {
  29. { "subject", "Test subject" },
  30. { "entry", entry }
  31. };
  32. globals = new Dictionary<string, object>();
  33. globals.Add("test", "testing");
  34. globals.Add("one", new List<object>() { 1 });
  35. globals.Add("two", new List<object>() { "one", "two" });
  36. globals.Add("three", new List<object>() { 1, "Two", 3 });
  37. globals.Add("weblog", weblog);
  38. }
  39. public static void RunTest(string template, string expected, string errMsg)
  40. {
  41. string actual = new Template(template).Render(globals);
  42. actual = actual.Replace("{", "{{").Replace("}", "}}");
  43. Assert.AreEqual(expected, actual, "{1} - {0}template: {2}{0}actual: {3}{0}expected: {4}",
  44. Environment.NewLine, errMsg, template, actual, expected);
  45. }
  46. [Test]
  47. public void TestContentNull()
  48. {
  49. RunTest(@"<html><p tal:replace=""null""></p></html>",
  50. "<html></html>",
  51. "Content of nothing did not remove tag.");
  52. }
  53. [Test]
  54. public void TestContentDefault()
  55. {
  56. RunTest(@"<html><p tal:replace=""default"">Original</p></html>",
  57. "<html><p>Original</p></html>",
  58. "Content of default did not evaluate to existing content without tags");
  59. }
  60. [Test]
  61. public void TestContentString()
  62. {
  63. RunTest(@"<html><p tal:replace=""test"">Original</p></html>",
  64. "<html>testing</html>",
  65. "Content of string did not evaluate to contain string");
  66. }
  67. [Test]
  68. public void TestContentStructure()
  69. {
  70. Dictionary<string, object> weblog = new Dictionary<string, object>
  71. {
  72. { "subject", "Test subject" },
  73. };
  74. globals["weblog"] = weblog;
  75. string macros = @"<p metal:define-macro=""entry"">Some structure: <b tal:content='weblog[""subject""]'></b></p>";
  76. RunTest(macros + @"<html><p metal:use-macro='macros[""entry""]'>Original</p></html>",
  77. "<html><p>Some structure: <b>Test subject</b></p></html>",
  78. "Content of Structure did not evaluate to expected result");
  79. }
  80. }
  81. }