FormattedTextSourceTests.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233
  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. var textSource = new FormattedTextSource(text, defaultTextRunProperties, textStyleOverrides);
  23. var textRun = textSource.GetTextRun(0);
  24. Assert.NotNull(textRun);
  25. Assert.Equal(2, textRun.Length);
  26. Assert.Equal("He", textRun.Text.ToString());
  27. }
  28. }
  29. }