Skip to content

Commit

Permalink
update unit tests for textblock
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlm committed Nov 8, 2024
1 parent 479460b commit cc417f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
27 changes: 19 additions & 8 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
Expand Down Expand Up @@ -582,14 +583,24 @@ private void DrawPixelAndMoveHead(ref Point head, Line line, LineStyle? lineStyl
{
if (!GlyphMetrics.TryGetValue(glyph, out width))
{
var (originalLeft, originalTop) = Console.GetCursorPosition();
Console.SetCursorPosition((int)characterPoint.X, (int)characterPoint.Y);
Console.Write(glyph);
var (left, top) = Console.GetCursorPosition();
width = (ushort)(left - (int)characterPoint.X);
Debug.WriteLine($"{glyph} {width}");
GlyphMetrics[glyph] = width;
Console.SetCursorPosition(originalLeft, originalTop);
try
{

var (originalLeft, originalTop) = Console.GetCursorPosition();
Console.SetCursorPosition((int)characterPoint.X, (int)characterPoint.Y);
Console.Write(glyph);
var (left, top) = Console.GetCursorPosition();
width = (ushort)(left - (int)characterPoint.X);
Debug.WriteLine($"{glyph} {width}");
GlyphMetrics[glyph] = width;
Console.SetCursorPosition(originalLeft, originalTop);
}
catch (IOException)
{
// IOException happens when running unit tests TODO: We should emulate this better
width = 1;
GlyphMetrics[glyph] = width;
}
}
}
var symbol = new SimpleSymbol(glyph, width);
Expand Down
12 changes: 9 additions & 3 deletions src/Tests/Consolonia.GalleryTests/TextBlockTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Drawing;

Check warning on line 1 in src/Tests/Consolonia.GalleryTests/TextBlockTests.cs

View workflow job for this annotation

GitHub Actions / build

"[RedundantUsingDirective] Using directive is not required by the code and can be safely removed" on /home/runner/work/Consolonia/Consolonia/src/Tests/Consolonia.GalleryTests/TextBlockTests.cs(1,1)
using System.Threading.Tasks;
using Avalonia.Controls;

Check warning on line 3 in src/Tests/Consolonia.GalleryTests/TextBlockTests.cs

View workflow job for this annotation

GitHub Actions / build

"[RedundantUsingDirective] Using directive is not required by the code and can be safely removed" on /home/runner/work/Consolonia/Consolonia/src/Tests/Consolonia.GalleryTests/TextBlockTests.cs(3,1)
using Avalonia.Media;

Check warning on line 4 in src/Tests/Consolonia.GalleryTests/TextBlockTests.cs

View workflow job for this annotation

GitHub Actions / build

"[RedundantUsingDirective] Using directive is not required by the code and can be safely removed" on /home/runner/work/Consolonia/Consolonia/src/Tests/Consolonia.GalleryTests/TextBlockTests.cs(4,1)
using Consolonia.GalleryTests.Base;
using Consolonia.TestsCore;
using NUnit.Framework;
Expand All @@ -18,9 +21,12 @@ protected override Task PerformSingleTest()
"Right aligned text│",

// multiline
"│Lorem ipsum dolor sit amet, consectetur adipiscing elit.│",
@"│Vivamus magna. Cras in mi at felis aliquet congue. Ut a │",
@"│est eget ligula molestie gravida. Curabitur massa. Donec│");
"│Lorem ipsum dolor sit amet, consectetur adipiscing",
"│elit. Vivamus magna. Cras in mi at felis aliquet",
"│congue. Ut a est eget ligula molestie gravida.",
// special chars, emojis, etc.
"𐓏𐓘𐓻𐓘𐓻𐓟 𐒻𐓟", "𝄞","🎵", "“𝔉𝔞𝔫𝔠𝔶”","ff","fi","½");

}
}
}

0 comments on commit cc417f8

Please sign in to comment.