public void AppendTest() { var sb = new StringBuilder(); var fsb = new FormattedStringBuilder(); sb.Append(true); fsb.Append(true); sb.Append((byte)10); fsb.Append((byte)10); sb.Append((decimal)10.0); fsb.Append((decimal)10.0); sb.Append(3.14); fsb.Append(3.14); sb.Append(3.14f); fsb.Append(3.14f); sb.Append((short)10); fsb.Append((short)10); sb.Append(19); fsb.Append(19); sb.Append(1L); fsb.Append(1L); sb.Append((object)"aaa"); fsb.Append((object)"aaa"); sb.Append('1'); fsb.Append('1'); sb.Append("text text"); fsb.Append("text text"); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); }
public void FormattedStringBuilderEndToEnd1() { var classificationFormatMap = new MockClassificationFormatMap(); var htmlMarkupProvider = new HtmlMarkupProvider( classificationFormatMap, MockClassificationType.Default, Brushes.White); var classifier = new MockClassifier(); var formattedStringBuilder = new FormattedStringBuilder( htmlMarkupProvider, classifier, MockClassificationType.Default, waitIndicator: null); var snapshot = new MockTextSnapshot("bla"); var spans = new NormalizedSnapshotSpanCollection(new [] { new SnapshotSpan(snapshot, 0, 3) }); var actualResult = formattedStringBuilder.AppendSnapshotSpans(spans); var expectedResult = "<pre style=\"font-family:Consolas;font-size:12;color:black;background:white;\">b<span style=\"color:blue;\">l</span>a\r\n</pre>"; Assert.AreEqual(expectedResult, actualResult); }
public void InsertTest() { var sb = new StringBuilder(); var fsb = new FormattedStringBuilder(); sb.Append("abcdefghijk"); fsb.Append("abcdefghijk"); sb.Insert(3, true); fsb.Insert(3, true); sb.Insert(3, (byte)10); fsb.Insert(3, (byte)10); sb.Insert(3, (decimal)10.0); fsb.Insert(3, (decimal)10.0); sb.Insert(3, 3.14); fsb.Insert(3, 3.14); sb.Insert(3, 3.14f); fsb.Insert(3, 3.14f); sb.Insert(3, (short)10); fsb.Insert(3, (short)10); sb.Insert(3, 19); fsb.Insert(3, 19); sb.Insert(3, 1L); fsb.Insert(3, 1L); sb.Insert(3, (object)"aaa"); fsb.Insert(3, (object)"aaa"); sb.Insert(3, 'c'); fsb.Insert(3, 'c'); sb.Insert(3, "sfg"); fsb.Insert(3, "sfg"); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); }
public void Generate(FormattedStringBuilder stringBuilder, string[] references) { foreach (string reference in references) { stringBuilder.AppendLine($"using {reference};"); } }
public static FormattedStringBuilder Italic(this FormattedStringBuilder source) { source.Append("<i>"); source.PushToEnd("</i>"); return(source); }
public static FormattedStringBuilder Bold(this FormattedStringBuilder source) { source.Append("<b>"); source.PushToEnd("</b>"); return(source); }
private void GenerateMembers(FormattedStringBuilder stringBuilder, IMemberGenerationTemplate memberGenerationTemplate, IList <MemberDetails> members) { foreach (MemberDetails details in members) { memberGenerationTemplate.Generate(stringBuilder, details.Name, details.Type, details.Cardinality); } }
public static FormattedStringBuilder Color(this FormattedStringBuilder source, string color) { source.Append("<color="); source.Append(color); source.Append(">"); source.PushToEnd("</color>"); return(source); }
public static FormattedStringBuilder Size(this FormattedStringBuilder source, int size) { source.Append("<size="); source.Append(size.ToString()); source.Append(">"); source.PushToEnd("</size>"); return(source); }
//[Fact] not ready yet public void Create_default_format_with_builder() { string actual = new FormattedStringBuilder() .AddTime("H:mm:ss") .AddText("|") .AddLevel(-7) .AddText("|") .Build(); Assert.Equal("{time:H:mm:ss,fff}|{level,-7}|{source}|{message}{error}", actual); }
public void AppendLineTest() { var sb = new StringBuilder(); var fsb = new FormattedStringBuilder(); sb.AppendLine(); fsb.AppendLine(); sb.AppendLine("aaa"); fsb.AppendLine("aaa"); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); }
public void Generate(FormattedStringBuilder stringBuilder, string className, Visibility visibility, IMemberGenerationTemplate propertyGenerationTemplate, IList <MemberDetails> memberDetails) { string modifier = visibility.Equals(Visibility.Private) ? "private" : "public"; stringBuilder.AppendLine($"{modifier} class {className}"); stringBuilder.AppendLine("{"); stringBuilder.LevelDown(); GenerateMembers(stringBuilder, propertyGenerationTemplate, memberDetails); stringBuilder.LevelUp(); stringBuilder.AppendLine("}"); }
public void Generate(FormattedStringBuilder stringBuilder, string propertyName, string propertyType, Cardinality cardinality) { switch (cardinality) { case Cardinality.OneToOne: stringBuilder.AppendLine($"public virtual {propertyType} {propertyName} {{ get; set; }}"); break; case Cardinality.OneToMany: stringBuilder.AppendLine($"public virtual IList<{propertyType}> {propertyName} {{ get; private set;}}"); break; default: throw new NotSupportedException($"Cardinality {cardinality} is not supported for this template."); } }
public void Empty() { var sb = new FormattedStringBuilder(); sb.Append("") .Append(FormattedString.Empty) .Append(new FormattedString("")) .Append(new FormattedString("", new ConsoleFormat(Foreground: AnsiColor.Red))) .Append(new FormattedString("", new FormatSpan(0, 0, new ConsoleFormat(Foreground: AnsiColor.Red)))); Assert.Equal(0, sb.Length); Assert.Equal(FormattedString.Empty, sb.ToFormattedString()); sb.Clear(); Assert.Equal(0, sb.Length); Assert.Equal(FormattedString.Empty, sb.ToFormattedString()); }
public void RemoveTest() { var sb = new StringBuilder(); var fsb = new FormattedStringBuilder(); sb.Append("abcdefghijk"); fsb.Append("abcdefghijk"); sb.Remove(0, 2); fsb.Remove(0, 2); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); sb.Remove(sb.Length - 3, 3); fsb.Remove(fsb.Length - 3, 3); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); Assert.AreEqual(fsb.Length, sb.Length); }
public void FontTest() { var span = new Span() { Text = "text", FontAttributes = FontAttributes.Bold }; FormattedString a = new FormattedStringBuilder().Append(span).ToFormattedString(); var aText = "<span font=\"bold\">text</span>"; span.FontAttributes = FontAttributes.Bold | FontAttributes.Italic; FormattedString b = new FormattedStringBuilder().Append(span).ToFormattedString(); var bText = "<span font=\"italic-bold\">text</span>"; Assert.AreEqual(converter.SerializeObject(a), aText); Assert.AreEqual(converter.SerializeObject(b), bText); Assert.AreEqual(spanEquals(a, converter.DeserializeObject(converter.SerializeObject(a))), true); Assert.AreEqual(spanEquals(b, converter.DeserializeObject(converter.SerializeObject(b))), true); }
public void FontSizeTest() { var span = new Span() { Text = "test\ntest", FontSize = FontSize.UltraBig }; FormattedString a = new FormattedStringBuilder().Append(span).ToFormattedString(); var aText = "<span font-size=\"ultra-big\">test<br>test</span>"; span.FontSize = FontSize.Normal; FormattedString b = new FormattedStringBuilder().Append(span).ToFormattedString(); var bText = "<span>test<br>test</span>"; Assert.AreEqual(converter.SerializeObject(a), aText); Assert.AreEqual(converter.SerializeObject(b), bText); Assert.AreEqual(spanEquals(a, converter.DeserializeObject(converter.SerializeObject(a))), true); Assert.AreEqual(spanEquals(b, converter.DeserializeObject(converter.SerializeObject(b))), true); }
public void ColorTest() { var span = new Span() { Text = "text", ForegroundColor = new SpanColor(1, 2, 3, 4) }; FormattedString a = new FormattedStringBuilder().Append(span).ToFormattedString(); var aText = "<span f-color=\"1,2,3,4\">text</span>"; span.ForegroundColor = SpanColor.DefaultValue; span.BackgroundColor = new SpanColor(4, 3, 2, 1); FormattedString b = new FormattedStringBuilder().Append(span).ToFormattedString(); var bText = "<span b-color=\"4,3,2,1\">text</span>"; Assert.AreEqual(converter.SerializeObject(a), aText); Assert.AreEqual(converter.SerializeObject(b), bText); Assert.AreEqual(spanEquals(a, converter.DeserializeObject(converter.SerializeObject(a))), true); Assert.AreEqual(spanEquals(b, converter.DeserializeObject(converter.SerializeObject(b))), true); }
public void Append() { var sb = new FormattedStringBuilder(); sb.Append("1") .Append(FormattedString.Empty) .Append("2", new FormatSpan(0, 1, new ConsoleFormat(Foreground: AnsiColor.Red))) .Append("34", new FormatSpan(0, 1, new ConsoleFormat(Foreground: AnsiColor.Green)), new FormatSpan(1, 1, new ConsoleFormat(Foreground: AnsiColor.Yellow))); Assert.Equal(4, sb.Length); Assert.Equal( new FormattedString( "1234", new FormatSpan(1, 1, new ConsoleFormat(Foreground: AnsiColor.Red)), new FormatSpan(2, 1, new ConsoleFormat(Foreground: AnsiColor.Green)), new FormatSpan(3, 1, new ConsoleFormat(Foreground: AnsiColor.Yellow))), sb.ToFormattedString()); sb.Clear(); Assert.Equal(0, sb.Length); Assert.Equal(FormattedString.Empty, sb.ToFormattedString()); }
public static FormattedStringBuilder Yellow(this FormattedStringBuilder source) => source.Color("yellow");
public static FormattedStringBuilder Navy(this FormattedStringBuilder source) => source.Color("navy");
public static FormattedStringBuilder Olive(this FormattedStringBuilder source) => source.Color("olive");
public static FormattedStringBuilder Orange(this FormattedStringBuilder source) => source.Color("orange");
public static FormattedStringBuilder Purple(this FormattedStringBuilder source) => source.Color("purple");
public static FormattedStringBuilder Red(this FormattedStringBuilder source) => source.Color("red");
public static FormattedStringBuilder Silver(this FormattedStringBuilder source) => source.Color("silver");
public static FormattedStringBuilder Teal(this FormattedStringBuilder source) => source.Color("teal");
public void ReplaceTest() { var sb = new StringBuilder(); var fsb = new FormattedStringBuilder(); sb.Append("ashgilassfianvlaih"); fsb.Append("ashgilassfianvlaih"); sb.Replace('a', 'b'); fsb.Replace('a', 'b'); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); sb.Clear(); fsb.Clear(); sb.Append("aaaaaaaaaaaaaaaaaaaaaaaaa"); fsb.Append("aaaaaaaaaaaaaaaaaaaaaaaaa"); sb.Replace('a', 'b', 2, 4); fsb.Replace('a', 'b', 2, 4); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); sb.Clear(); fsb.Clear(); sb.Append("aaaaaaaaaaaaaaaaaaaaaaaaa"); fsb.Append("aaaaaaaaaaaaaaaaaaaaaaaaa"); sb.Replace("a", "[]"); fsb.Replace("a", "[]"); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); Assert.AreEqual(fsb.Length, sb.Length); sb.Replace("[]", "a"); fsb.Replace("[]", "a"); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); Assert.AreEqual(fsb.Length, sb.Length); sb.Replace("aaa", "b"); fsb.Replace("aaa", "b"); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); Assert.AreEqual(fsb.Length, sb.Length); sb.Replace("b", "a", 1, 2); fsb.Replace("b", "a", 1, 2); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); Assert.AreEqual(fsb.Length, sb.Length); sb.Replace("a", ""); fsb.Replace("a", ""); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); Assert.AreEqual(fsb.Length, sb.Length); sb.Clear(); fsb.Clear(); sb.Append("aaaaaaaaaaaaaaaaaaaaaaaaa"); fsb.Append("aaaaaaaaaaaaaaaaaaaaaaaaa"); sb.Replace("c", "[]"); fsb.Replace("c", "[]"); Assert.AreEqual(fsb.ToFormattedString().Text, sb.ToString()); Assert.AreEqual(fsb.Length, sb.Length); }
public static FormattedStringBuilder White(this FormattedStringBuilder source) => source.Color("white");
public void Generate(FormattedStringBuilder formattedStringBuilder, string @namespace) { formattedStringBuilder.AppendLine($"namespace {@namespace}"); formattedStringBuilder.AppendLine(); }
public string GenerateHtml(NormalizedSnapshotSpanCollection spans, IWpfTextView textView) { if (spans == null || spans.Count == 0) { return ""; } // this will trigger loading of the package // so we can ensure ToolsOptionsPage gets created and // ToolsOptionsPage.Instance gets set var dte = (_DTE)_serviceProvider.GetService(typeof(_DTE)); var props = dte.Properties[CopyAsHtmlPackage.CategoryName, CopyAsHtmlPackage.PageName]; IClassificationFormatMap formatMap = _classificationFormatMappingService.GetClassificationFormatMap(textView); IClassificationType defaultClassificationType = _classificationTypeRegistry.GetClassificationType("text"); HtmlMarkupProvider htmlMarkupProvider = new HtmlMarkupProvider( formatMap, defaultClassificationType, textView.Background); IClassifier classifier = _classifierAggregatorService.GetClassifier(textView.TextBuffer); var formattedStringBuilder = new FormattedStringBuilder( htmlMarkupProvider, classifier, defaultClassificationType, this.WaitIndicator); string result = formattedStringBuilder.AppendSnapshotSpans(spans); var classifierDispose = classifier as System.IDisposable; if (classifierDispose != null) { classifierDispose.Dispose(); } return result; }