コード例 #1
0
		public void CollapsesWhiteSpaceInParentBlocks()
		{
			var factory = new Factory();

			// "Message:{{#this~}} Hello {{~/this~}} There"
			var document = factory.Document(
				factory.Text("Message:"),
				factory.Tag("this",
					factory.TagElement("this",
						factory.MetaCode("{{", T.OpenTag),
						factory.MetaCode("#", T.Hash),
						factory.Expression(factory.Parameter("this")),
						factory.MetaCode("~", T.Tilde),
						factory.MetaCode("}}", T.CloseTag)),
					factory.WhiteSpace(1),
					factory.Text("Hello"),
					factory.WhiteSpace(1),
						factory.TagElement("this",
							factory.MetaCode("{{", T.OpenTag),
							factory.MetaCode("~", T.Tilde),
							factory.MetaCode("/", T.Slash),
							factory.Expression(factory.Parameter("this")),
							factory.MetaCode("~", T.Tilde),
							factory.MetaCode("}}", T.CloseTag))),
				factory.WhiteSpace(1),
				factory.Text("There"));

			factory = new Factory();

			// "Message:{{#this~}}Hello{{~/this~}}There"
			var expected = factory.Document(
				factory.Text("Message:"),
				factory.Tag("this",
					factory.TagElement("this",
						factory.MetaCode("{{", T.OpenTag),
						factory.MetaCode("#", T.Hash),
						factory.Expression(factory.Parameter("this")),
						factory.MetaCode("~", T.Tilde),
						factory.MetaCode("}}", T.CloseTag)),
					factory.WhiteSpace(1, collapsed: true),
					factory.Text("Hello"),
					factory.WhiteSpace(1, collapsed: true),
						factory.TagElement("this",
							factory.MetaCode("{{", T.OpenTag),
							factory.MetaCode("~", T.Tilde),
							factory.MetaCode("/", T.Slash),
							factory.Expression(factory.Parameter("this")),
							factory.MetaCode("~", T.Tilde),
							factory.MetaCode("}}", T.CloseTag))),
				factory.WhiteSpace(1, collapsed: true),
				factory.Text("There"));

			var visitor = new WhiteSpaceCollapsingParserVisitor();
			visitor.VisitBlock(document);

			var builder = new StringBuilder();
			var comparer = new EquivalanceComparer(builder, 0);

			Assert.True(comparer.Equals(expected, document), builder.ToString());
		}