Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests, splitting out Consolonia.NUnit library and a ton of unit tests #143

Merged
merged 56 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f087bf5
Add support for Surragate sequences
tomlm Nov 6, 2024
9446c9b
fix release build warning.
tomlm Nov 6, 2024
637747c
* fix unit tests
tomlm Nov 6, 2024
559fe7b
Automated JetBrains cleanup
github-actions[bot] Nov 6, 2024
ef299e5
use Text...everything works except for double char emojiis
tomlm Nov 7, 2024
ebc751d
formatting merge
tomlm Nov 7, 2024
e0a2a52
use TextShaper.Text for render text instead of trying to render from …
tomlm Nov 7, 2024
352bb67
FINALLY I have emoticons rendering correctly
tomlm Nov 8, 2024
adeb5ea
added scroll bars to textlbock gallery page
tomlm Nov 8, 2024
c174f9b
update sample to show that CJK wide chars work
tomlm Nov 8, 2024
479460b
removed unused using statements
tomlm Nov 8, 2024
cc417f8
update unit tests for textblock
tomlm Nov 8, 2024
7e36247
lint feedback, adopt WcWidth for accurate calculation of char width
tomlm Nov 8, 2024
88ebb08
properly calculate GlyphInfos in textshaper
tomlm Nov 8, 2024
5891381
fix bugs found by coderabbit. Nice job code rabbit!
tomlm Nov 8, 2024
e4e247b
remove using
tomlm Nov 8, 2024
532ac52
add detection of complex emojii
tomlm Nov 8, 2024
b7c1e35
fix calc of glyph
tomlm Nov 8, 2024
8cab697
update unitestconsole
tomlm Nov 8, 2024
78710e5
add comment
tomlm Nov 8, 2024
2be4221
fix
tomlm Nov 8, 2024
265eb64
ah, finally figured out the using issue. Visual studio didn't conside…
tomlm Nov 8, 2024
8c76411
argh. Lint is killing me!
tomlm Nov 8, 2024
0b478fc
Automated JetBrains cleanup
github-actions[bot] Nov 8, 2024
9791ab4
Merge branch 'main' into tomlm/rune
tomlm Nov 9, 2024
6c008eb
Merge branch 'main' into tomlm/rune
tomlm Nov 9, 2024
272b00f
merge
tomlm Nov 9, 2024
d4fc7f1
make list readonly
tomlm Nov 9, 2024
019a80f
Automated JetBrains cleanup
github-actions[bot] Nov 9, 2024
a823630
cleanup
tomlm Nov 9, 2024
3a5efde
add comments
tomlm Nov 9, 2024
61b9697
Merge branch 'tomlm/rune' of https://github.com/jinek/Consolonia into…
tomlm Nov 9, 2024
40dedcc
removed accidental comment of /// instead of //
tomlm Nov 9, 2024
379870e
Automated JetBrains cleanup
github-actions[bot] Nov 9, 2024
e7be04e
rename files
tomlm Nov 9, 2024
b3f061b
update unit tests
tomlm Nov 9, 2024
4501daf
Merge branch 'tomlm/rune' into tomlm/tests
tomlm Nov 9, 2024
2cdcef3
Split unit tests out from consolonia support package
tomlm Nov 9, 2024
7658c8c
lint fixes
tomlm Nov 9, 2024
19c4e98
fix typo
tomlm Nov 9, 2024
0aa8d6b
more using
tomlm Nov 9, 2024
ee434d6
feedback from taskrabbit
tomlm Nov 9, 2024
de05026
d
tomlm Nov 9, 2024
89b24bd
Remove this NUnit.Internal This is suggested by CodeRabbit, doesn't s…
tomlm Nov 9, 2024
66553d4
Automated JetBrains cleanup
github-actions[bot] Nov 9, 2024
7ff4812
implement equality for Pixel, PixelForeground, PixelBackground, and s…
tomlm Nov 10, 2024
d858667
add hashcode unit test
tomlm Nov 10, 2024
2e4dd41
Automated JetBrains cleanup
github-actions[bot] Nov 10, 2024
428a67f
Merge branch 'main' into tomlm/tests
tomlm Nov 10, 2024
a03c8ec
cleanup from code merge
tomlm Nov 10, 2024
2c4c60a
fix lint
tomlm Nov 10, 2024
f0c50e7
Automated JetBrains cleanup
github-actions[bot] Nov 10, 2024
82addcc
bug fix on equality, update unit test to cover case
tomlm Nov 10, 2024
dca3aa2
Merge branch 'tomlm/tests' of https://github.com/jinek/Consolonia int…
tomlm Nov 10, 2024
14ae365
split complex test into individual test cases
tomlm Nov 10, 2024
cbb342e
avoid linq for creating glyph and advances array fix test names
tomlm Nov 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Consolonia.Core/Assembly.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Consolonia.TestsCore")]
[assembly: InternalsVisibleTo("Consolonia.Core.Tests")]

[assembly: CLSCompliant(false)] //todo: should we make it compliant?
8 changes: 4 additions & 4 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void DrawBitmap(IBitmapImpl source, double opacity, Rect sourceRect, Rect
Color background = GetBackgroundColorForQuadPixel(quadColors, quadPixel);

var imagePixel = new Pixel(
new PixelForeground(new SimpleSymbol(quadPixel), color: foreground),
new PixelForeground(new SimpleSymbol(quadPixel), foreground),
new PixelBackground(background));
CurrentClip.ExecuteWithClipping(new Point(px, py),
() =>
Expand Down Expand Up @@ -349,10 +349,10 @@ private void ApplyTextDecorationLineInternal(ref Point head, IPen pen, Line line
pixel =>
{
var newPixelForeground = new PixelForeground(pixel.Foreground.Symbol,
pixel.Foreground.Color,
pixel.Foreground.Weight,
pixel.Foreground.Style,
textDecoration,
pixel.Foreground.Color);
textDecoration);
return pixel.Blend(new Pixel(newPixelForeground, pixel.Background));
});
});
Expand Down Expand Up @@ -499,7 +499,7 @@ private void DrawPixelAndMoveHead(ref Point head, Line line, LineStyle? lineStyl
// Each glyph maps to a pixel as a starting point.
// Emoji's and Ligatures are complex strings, so they start at a point and then overlap following pixels
// the x and y are adjusted accodingly.
foreach (string glyph in text.GetGlyphs())
foreach (string glyph in text.GetGlyphs(_consoleWindow.Console.SupportsComplexEmoji))
{
Point characterPoint =
whereToDraw.Transform(Matrix.CreateTranslation(currentXPosition, currentYPosition));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace Consolonia.Core.Drawing.PixelBufferImplementation
{
/// <summary>
/// https://en.wikipedia.org/wiki/Box-drawing_character
/// </summary>
[DebuggerDisplay("DrawingBox {Text}")]
public struct DrawingBoxSymbol : ISymbol
public struct DrawingBoxSymbol : ISymbol, IEquatable<DrawingBoxSymbol>
{
// all 0bXXXX_0000 are special values
private const byte BoldSymbol = 0b0001_0000;
private const byte EmptySymbol = 0b0;
private readonly byte _upRightDownLeft;

public DrawingBoxSymbol(byte upRightDownLeft)
{
_upRightDownLeft = upRightDownLeft;
Text = GetBoxSymbol(_upRightDownLeft).ToString();
}

private byte _upRightDownLeft;

public string Text => GetBoxSymbol().ToString();
public string Text { get; private init; }

public ushort Width { get; } = 1;

/// <summary>
/// https://en.wikipedia.org/wiki/Code_page_437
/// </summary>
private char GetBoxSymbol()
private static char GetBoxSymbol(byte upRightDownLeft)
{
//DOS linedraw characters are not ordered in any programmatic manner, and calculating a particular character shape needs to use a look-up table. from https://en.wikipedia.org/wiki/Box-drawing_character

byte leftPart = (byte)(_upRightDownLeft & 0b1111_0000);
byte leftPart = (byte)(upRightDownLeft & 0b1111_0000);
bool hasLeftPart = leftPart > 0;

switch (_upRightDownLeft & 0b0000_1111)
switch (upRightDownLeft & 0b0000_1111)
{
case 0b0000_1000:
case 0b0000_0010:
Expand All @@ -56,7 +57,7 @@ private char GetBoxSymbol()

default:
{
return _upRightDownLeft switch
return upRightDownLeft switch
{
EmptySymbol => char.MinValue,
BoldSymbol => '█',
Expand Down Expand Up @@ -107,12 +108,13 @@ public ISymbol Blend(ref ISymbol symbolAbove)
{
if (symbolAbove.IsWhiteSpace()) return this;

if (symbolAbove is not DrawingBoxSymbol drawingBoxSymbol) return symbolAbove;
if (symbolAbove is not DrawingBoxSymbol drawingBoxSymbol)
return symbolAbove;

if (drawingBoxSymbol._upRightDownLeft == BoldSymbol || _upRightDownLeft == BoldSymbol)
_upRightDownLeft = BoldSymbol;
else
_upRightDownLeft |= drawingBoxSymbol._upRightDownLeft;
return this;
return new DrawingBoxSymbol(BoldSymbol);

return new DrawingBoxSymbol((byte)(_upRightDownLeft | drawingBoxSymbol._upRightDownLeft));
}

public static DrawingBoxSymbol UpRightDownLeftFromPattern(byte pattern, LineStyle lineStyle)
Expand All @@ -131,5 +133,30 @@ public static DrawingBoxSymbol UpRightDownLeftFromPattern(byte pattern, LineStyl
throw new ArgumentOutOfRangeException(nameof(lineStyle), lineStyle, null);
}
}

public bool Equals(DrawingBoxSymbol other)
{
return _upRightDownLeft == other._upRightDownLeft;
}

public override bool Equals([NotNullWhen(true)] object obj)
{
return obj is DrawingBoxSymbol other && Equals(other);
}

public override int GetHashCode()
{
return _upRightDownLeft.GetHashCode();
}

public static bool operator ==(DrawingBoxSymbol left, DrawingBoxSymbol right)
{
return left.Equals(right);
}

public static bool operator !=(DrawingBoxSymbol left, DrawingBoxSymbol right)
{
return !left.Equals(right);
}
}
}
89 changes: 70 additions & 19 deletions src/Consolonia.Core/Drawing/PixelBufferImplementation/Pixel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Avalonia.Media;

// ReSharper disable MemberCanBePrivate.Global
Expand All @@ -8,7 +9,7 @@
namespace Consolonia.Core.Drawing.PixelBufferImplementation
{
[DebuggerDisplay("'{Foreground.Symbol.Text}' [{Foreground.Color}, {Background.Color}]")]
public readonly struct Pixel
public readonly struct Pixel : IEquatable<Pixel>
{
public PixelForeground Foreground { get; }

Expand All @@ -18,52 +19,75 @@ public readonly struct Pixel

public Pixel(bool isCaret)
{
Foreground = new PixelForeground(new SimpleSymbol());
Background = new PixelBackground(PixelBackgroundMode.Transparent);
Foreground = new PixelForeground();
Background = new PixelBackground();
IsCaret = isCaret;
}

public Pixel(ISymbol symbol, Color foregroundColor, FontStyle style = FontStyle.Normal,
FontWeight weight = FontWeight.Normal, TextDecorationCollection textDecorations = null) : this(
new PixelForeground(symbol, weight, style, textDecorations, foregroundColor),
/// <summary>
/// Make a pixel foreground with transparent background
/// </summary>
/// <param name="symbol"></param>
/// <param name="foregroundColor"></param>
/// <param name="style"></param>
/// <param name="weight"></param>
/// <param name="textDecorations"></param>
public Pixel(ISymbol symbol,
Color foregroundColor,
FontStyle style = FontStyle.Normal,
FontWeight weight = FontWeight.Normal,
TextDecorationCollection textDecorations = null) : this(
new PixelForeground(symbol, foregroundColor, weight, style, textDecorations),
new PixelBackground(PixelBackgroundMode.Transparent))
{
}

public Pixel(Color backgroundColor) : this(
new PixelBackground(PixelBackgroundMode.Colored, backgroundColor))
{
}

public Pixel(PixelBackgroundMode mode) : this(new PixelBackground(mode))
{
}

public Pixel(PixelBackground background) : this(new PixelForeground(new SimpleSymbol()),
background)
/// <summary>
/// Make a pixel with only background color, but no foreground
/// </summary>
/// <param name="background"></param>
public Pixel(PixelBackground background) :
this(new PixelForeground(new SimpleSymbol(), Colors.Transparent),
background)
{
}

public Pixel(PixelForeground foreground, PixelBackground background, bool isCaret = false)
/// <summary>
/// Make a pixel with foreground and background
/// </summary>
/// <param name="foreground"></param>
/// <param name="background"></param>
/// <param name="isCaret"></param>
public Pixel(PixelForeground foreground,
PixelBackground background,
bool isCaret = false)
{
Foreground = foreground;
Background = background;
IsCaret = isCaret;
}

/// <summary>
/// Blend the pixelAbove with the this pixel.
/// </summary>
/// <param name="pixelAbove"></param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public Pixel Blend(Pixel pixelAbove)
{
PixelForeground newForeground;
PixelBackground newBackground;

if (pixelAbove.IsCaret) return new Pixel(Foreground, Background, true);

switch (pixelAbove.Background.Mode)
{
case PixelBackgroundMode.Colored:
// merge pixelAbove into this pixel using alpha channel.
Color mergedColors = MergeColors(Background.Color, pixelAbove.Background.Color);
newForeground = pixelAbove.Foreground;
newBackground = new PixelBackground(mergedColors);
return new Pixel(newForeground, newBackground);
return new Pixel(newForeground, newBackground, pixelAbove.IsCaret);

case PixelBackgroundMode.Transparent:
// if the foreground is transparent, ignore pixelAbove foreground.
Expand Down Expand Up @@ -108,5 +132,32 @@ private static Color MergeColors(Color target, Color source)

return new Color(0xFF, red, green, blue);
}

public bool Equals(Pixel other)
{
return Foreground.Equals(other.Foreground) &&
Background.Equals(other.Background) &&
IsCaret.Equals(IsCaret);
}
tomlm marked this conversation as resolved.
Show resolved Hide resolved

public override bool Equals([NotNullWhen(true)] object obj)
{
return obj is Pixel other && Equals(other);
}

public override int GetHashCode()
{
return HashCode.Combine(Foreground, Background, IsCaret);
}

public static bool operator ==(Pixel left, Pixel right)
{
return left.Equals(right);
}

public static bool operator !=(Pixel left, Pixel right)
{
return !left.Equals(right);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Avalonia.Media;

namespace Consolonia.Core.Drawing.PixelBufferImplementation
{
[DebuggerDisplay("[{Color}, {Mode}]")]
public readonly struct PixelBackground
public readonly struct PixelBackground : IEquatable<PixelBackground>
{
public PixelBackground()
{
Mode = PixelBackgroundMode.Transparent;
Color = Colors.Transparent;
}

public PixelBackground(Color color)
{
Mode = color.A == 0 ? PixelBackgroundMode.Transparent : PixelBackgroundMode.Colored;
Expand All @@ -15,7 +22,7 @@ public PixelBackground(Color color)

public PixelBackground(PixelBackgroundMode mode, Color? color = null)
{
Color = color ?? Colors.Black;
Color = color ?? Colors.Transparent;
Mode = mode;
}

Expand Down Expand Up @@ -44,5 +51,30 @@ public PixelBackground Shade()

return new PixelBackground(newMode, newColor);
}

public bool Equals(PixelBackground other)
{
return Color.Equals(other.Color) && Mode == other.Mode;
}

public override bool Equals([NotNullWhen(true)] object obj)
{
return obj is PixelBackground other && Equals(other);
}

public override int GetHashCode()
{
return HashCode.Combine(Color, Mode);
}

public static bool operator ==(PixelBackground left, PixelBackground right)
{
return left.Equals(right);
}

public static bool operator !=(PixelBackground left, PixelBackground right)
{
return !left.Equals(right);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@ public bool Equals(PixelBufferCoordinate secondPoint)
{
return X == secondPoint.X && Y == secondPoint.Y;
}

public override int GetHashCode()
{
return X ^ Y;
}
tomlm marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading
Loading