TypefaceTests.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using Avalonia.Media;
  3. using Xunit;
  4. namespace Avalonia.Base.UnitTests.Media
  5. {
  6. public class TypefaceTests
  7. {
  8. [Fact]
  9. public void Exception_Should_Be_Thrown_If_FontWeight_LessThanEqualTo_Zero()
  10. {
  11. Assert.Throws<ArgumentException>(() => new Typeface("foo", (FontStyle)12, 0));
  12. }
  13. [Fact]
  14. public void Should_Be_Equal()
  15. {
  16. Assert.Equal(new Typeface("Font A"), new Typeface("Font A"));
  17. }
  18. [Fact]
  19. public void Should_Have_Equal_Hash()
  20. {
  21. Assert.Equal(new Typeface("Font A").GetHashCode(), new Typeface("Font A").GetHashCode());
  22. }
  23. [InlineData("Hello World 6", "Hello World 6", FontStyle.Normal, FontWeight.Normal)]
  24. [InlineData("Hello World Italic", "Hello World", FontStyle.Italic, FontWeight.Normal)]
  25. [InlineData("Hello World Italic Bold", "Hello World", FontStyle.Italic, FontWeight.Bold)]
  26. [InlineData("FontAwesome 6 Free Regular", "FontAwesome 6 Free", FontStyle.Normal, FontWeight.Normal)]
  27. [InlineData("FontAwesome 6 Free Solid", "FontAwesome 6 Free", FontStyle.Normal, FontWeight.Solid)]
  28. [InlineData("FontAwesome 6 Brands", "FontAwesome 6 Brands", FontStyle.Normal, FontWeight.Normal)]
  29. [Theory]
  30. public void Should_Get_Implicit_Typeface(string input, string familyName, FontStyle style, FontWeight weight)
  31. {
  32. var typeface = new Typeface(input);
  33. var normalizedTypeface = typeface.Normalize(out var normalizedFamilyName);
  34. Assert.Equal(familyName, normalizedFamilyName);
  35. Assert.Equal(style, normalizedTypeface.Style);
  36. Assert.Equal(weight, normalizedTypeface.Weight);
  37. Assert.Equal(FontStretch.Normal, normalizedTypeface.Stretch);
  38. }
  39. }
  40. }