FormattedTextSourceTests.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. using System.Collections.Generic;
  2. using Avalonia.Media;
  3. using Avalonia.Media.TextFormatting;
  4. using Avalonia.Utilities;
  5. using Xunit;
  6. namespace Avalonia.Base.UnitTests.Media.TextFormatting
  7. {
  8. public class FormattedTextSourceTests
  9. {
  10. [Fact]
  11. public void GetTextRun_WithTwoTextStyleOverrides_ShouldGenerateCorrectFirstRun()
  12. {
  13. //Prepare a sample text: The two "He" at the beginning of each line should be displayed with other TextRunProperties
  14. string text = "Hello World\r\nHello";
  15. Typeface typeface = new Typeface();
  16. GenericTextRunProperties defaultTextRunProperties = new GenericTextRunProperties(typeface);
  17. IReadOnlyList<ValueSpan<TextRunProperties>> textStyleOverrides = new List<ValueSpan<TextRunProperties>>()
  18. {
  19. new ValueSpan<TextRunProperties>(0, 2, new GenericTextRunProperties(typeface, backgroundBrush: Brushes.Aqua)),
  20. new ValueSpan<TextRunProperties>(13, 2, new GenericTextRunProperties(typeface, backgroundBrush: Brushes.Aqua)),
  21. };
  22. FormattedTextSource textSource = new FormattedTextSource(text, defaultTextRunProperties, textStyleOverrides);
  23. TextRun textRun = textSource.GetTextRun(0);
  24. Assert.Equal(2, textRun.Length);
  25. Assert.Equal("He", textRun.Text.ToString());
  26. }
  27. }
  28. }