csharpdeeb25a2 | 1 | using CascadeIDE.Views.SkiaKit; |
| 2 | using Xunit; |
| 3 | |
| 4 | namespace CascadeIDE.Tests; |
| 5 | |
| 6 | public sealed class SkiaPlainTextLayoutTests |
| 7 | { |
| 8 | [Fact] |
| 9 | public void HitTest_returns_caret_index_inside_text() |
| 10 | { |
| 11 | const string text = "hello world"; |
| 12 | Assert.True(SkiaPlainTextLayout.TryHitTestCaretIndex( |
| 13 | text, |
| 14 | localX: 40f, |
| 15 | localY: 8f, |
| 16 | maxWidth: 200f, |
| 17 | fontSize: 12f, |
| 18 | lineHeight: 17f, |
| 19 | out var index)); |
| 20 | Assert.InRange(index, 1, text.Length); |
| 21 | } |
| 22 | |
| 23 | [Fact] |
| 24 | public void CaretLine_aligns_with_hit_test_at_same_x() |
| 25 | { |
| 26 | const string text = "abcdef"; |
| 27 | const float width = 180f; |
| 28 | const float fontSize = 12f; |
| 29 | const float lineHeight = 17f; |
| 30 | Assert.True(SkiaPlainTextLayout.TryHitTestCaretIndex( |
| 31 | text, 50f, 8f, width, fontSize, lineHeight, out var index)); |
| 32 | Assert.True(SkiaPlainTextLayout.TryGetCaretLine( |
| 33 | text, |
| 34 | index, |
| 35 | width, |
| 36 | fontSize, |
| 37 | lineHeight, |
| 38 | new SkiaSharp.SKPoint(0, 0), |
| 39 | out var caretX, |
| 40 | out _, |
| 41 | out _)); |
| 42 | Assert.True(caretX >= 0f); |
| 43 | } |
| 44 | } |
| 45 | |
View only · write via MCP/CIDE