public void ErrorFileShouldSaveParseContext() { var lib = new TagLib(); lib.Register(new Tags.Tiles()); lib.Register(new Sharp()); var factory = new FileLocatorFactory().CloneForTagLib(lib) as FileLocatorFactory; try { new TilesSet(); var tile = new TemplateTile( "test", factory.Handle("errorinfile.htm", true), null ); } catch (TemplateExceptionWithContext TEWC) { Assert.That(TEWC.Context, Is.Not.Null); Assert.That(TEWC.Context.LineNumber, Is.EqualTo(2)); string fullPath = Path.GetFullPath("errorinfile.htm"); TagException tagException = TagException.UnbalancedCloseingTag(new ForEach() { Group = new Core() }, new If() { Group = new Core() }).Decorate(TEWC.Context); Assert.That(TEWC.Message, Is.EqualTo(TemplateExceptionWithContext.ErrorInTemplate(fullPath, tagException).Message)); } }
private static void GuardClosingOfTag(ITag close, ITag open) { if (close.State != TagState.Closed) { throw TagException.ExpectedCloseTag(open.GetType()).Decorate(close.Context); } if (!Equals(close.GetType(), open.GetType())) { if (Equals(close.Group.Name, open.Group.Name) && Equals(close.TagName, open.TagName)) { return; //edge case. Close of nested tag with same name as parent tag } throw TagException.UnbalancedCloseingTag(open, close).Decorate(open.Context); } }
public void TestOfDifferentClosingTag() { try { Base().Parse("<c:forTokens step='2' items=\"1,2,3,4,5,6\" delims=\",\">${Item}</c:forEach>"); Assert.Fail("Expected exception"); } catch (TagException Te) { Assert.That(Te.MessageWithOutContext, Is.EqualTo(TagException.UnbalancedCloseingTag( new ForTokens() { Group = new Core() }, new ForEach() { Group = new Core() } ).Message)); } }