static void ReplaceTextSpans_ManualTestCases_TestCase(string bbCode, string expected, Func <string, IList <TextSpanReplaceInfo> > getTextSpansToReplace, Func <TagNode, bool> tagFilter) { var tree1 = BBCodeTestUtil.GetParserForTest(ErrorMode.Strict, false, BBTagClosingStyle.AutoCloseElement, false).ParseSyntaxTree(bbCode); var tree2 = BBCode.ReplaceTextSpans(tree1, getTextSpansToReplace ?? (txt => Array.Empty <TextSpanReplaceInfo>()), tagFilter); Assert.Equal(expected, tree2.ToBBCode()); }
public void ContentTransformer_EmptyAttribute_CanChooseValueFromAttributeRenderingContext() { var parser = BBCodeTestUtil.GetParserForTest(ErrorMode.Strict, true, BBTagClosingStyle.AutoCloseElement, false); Assert.Equal(@"<a href=""http://codekicker.de"">http://codekicker.de</a>", parser.ToHtml(@"[url2]http://codekicker.de[/url2]")); Assert.Equal(@"<a href=""http://codekicker.de"">http://codekicker.de</a>", parser.ToHtml(@"[url2=http://codekicker.de]http://codekicker.de[/url2]")); }
public void ToTextDoesNotCrash() { var input = RandomValue.String(); var parser = BBCodeTestUtil.GetParserForTest(ErrorMode.ErrorFree, true, BBTagClosingStyle.AutoCloseElement, false); var text = parser.ParseSyntaxTree(input).ToText(); Assert.True(text.Length <= input.Length); }
public void NoScript_AnyInput_Tree() { var parser = BBCodeTestUtil.GetParserForTest(ErrorMode.ErrorFree, true, BBTagClosingStyle.AutoCloseElement, false); var tree = BBCodeTestUtil.CreateRootNode(parser.Tags.ToArray()); var output = tree.ToHtml(); Assert.True(!output.Contains("<script")); }
public void Roundtrip() { var parser = BBCodeTestUtil.GetParserForTest(RandomValue.Object <ErrorMode>(), false, BBTagClosingStyle.AutoCloseElement, false); var tree = BBCodeTestUtil.CreateRootNode(parser.Tags.ToArray()); var bbcode = tree.ToBBCode(); var tree2 = parser.ParseSyntaxTree(bbcode); Assert.True(tree == tree2); }
public void TextNodesCannotBeSplit() { var parser = BBCodeTestUtil.GetParserForTest(RandomValue.Object <ErrorMode>(), true, BBTagClosingStyle.AutoCloseElement, false); SequenceNode tree; try { tree = parser.ParseSyntaxTree(RandomValue.String()); } catch (BBCodeParsingException) { return; } AssertTextNodesNotSplit(tree); }
public void Roundtrip2() { var parser = BBCodeTestUtil.GetParserForTest(RandomValue.Object <ErrorMode>(), false, BBTagClosingStyle.AutoCloseElement, false); SequenceNode tree; try { tree = parser.ParseSyntaxTree(RandomValue.String()); } catch (BBCodeParsingException) { tree = null; } var bbcode = tree.ToBBCode(); var tree2 = parser.ParseSyntaxTree(bbcode); Assert.True(tree == tree2); }
public static string BBEncodeForTest(string bbCode, ErrorMode errorMode, BBTagClosingStyle listItemBbTagClosingStyle, bool enableIterationElementBehavior) { return(BBCodeTestUtil.GetParserForTest(errorMode, true, listItemBbTagClosingStyle, enableIterationElementBehavior).ToHtml(bbCode).Replace("\r", "").Replace("\n", "<br/>")); }