[fast]と高速化経路のテストを追加

このコミットが含まれているのは:
routersys committed 2026-07-05 16:12:51 +09:00
1 親 b618a3093b
コミット d4443a1eef
2ファイル変更
+127 -3

検索条件に一致するファイルはありません

+65
ファイルの表示
@@ -578,5 +578,70 @@ namespace LuaScript.Tests
{
Assert.Equal("for i = 0, 10 do end", Rewrite("for i in <0..10> do end"));
}
[Theory]
[InlineData("[fast] obj.fill(0, 0, 0, 255)", " __fast_fill(0, 0, 0, 255)")]
[InlineData("[fast] obj.convolve(k, 3)", " __fast_convolve(k, 3)")]
[InlineData("[fast] obj.resize(100, 100)", " __fast_resize(100, 100)")]
[InlineData("[ fast ] obj.resize(100, 100)", " __fast_resize(100, 100)")]
[InlineData("[fast]obj.fill()", "__fast_fill()")]
[InlineData(" [fast] obj.fill()", " __fast_fill()")]
public void Fast_RewritesAcceleratedPrimitive(string source, string expected)
{
Assert.Equal(expected, Rewrite(source));
}
[Fact]
public void Fast_RewritesInsideBlock()
{
Assert.Equal(
"for i = 1, 3 do __fast_fill(i, i, i, 255) end",
Rewrite("for i in <1..3> do [fast] obj.fill(i, i, i, 255) end"));
}
[Theory]
[InlineData("x = t[fast]")]
[InlineData("x = obj.data[fast]")]
[InlineData("x = f()[fast]")]
[InlineData("t = { [fast] = 1 }")]
[InlineData("x = \"[fast] obj.fill()\"")]
[InlineData("-- [fast] obj.fill()")]
public void Fast_DoesNotTouchNonMarkerBrackets(string source)
{
Assert.Equal(source, Rewrite(source));
}
[Fact]
public void Fast_OnUnsupportedTargetStripsMarkerAndReportsDiagnostic()
{
var (code, _, diagnostics) = LuaSyntaxExtensions.RewriteWithMap("[fast] obj.draw(0)");
Assert.Equal(" obj.draw(0)", code);
var diagnostic = Assert.Single(diagnostics);
Assert.Equal(1, diagnostic.Line);
Assert.Contains("fast", diagnostic.Message);
}
[Fact]
public void Fast_OnNonObjTargetReportsDiagnostic()
{
var (code, _, diagnostics) = LuaSyntaxExtensions.RewriteWithMap("[fast] local x = 1");
Assert.Equal(" local x = 1", code);
Assert.Single(diagnostics);
}
[Fact]
public void Fast_SupportedTargetEmitsNoDiagnostic()
{
var (_, _, diagnostics) = LuaSyntaxExtensions.RewriteWithMap("[fast] obj.fill(0, 0, 0, 255)");
Assert.Empty(diagnostics);
}
[Fact]
public void Fast_ReportsDiagnosticLineWithinBlock()
{
var (_, _, diagnostics) = LuaSyntaxExtensions.RewriteWithMap("obj.x = 1\n[fast] obj.draw(0)");
var diagnostic = Assert.Single(diagnostics);
Assert.Equal(2, diagnostic.Line);
}
}
}
+62 -3
ファイルの表示
@@ -1919,7 +1919,7 @@ namespace LuaScript.Tests
_pixelProcessor = processor;
bool ok = RunWorker(
"obj.fill(10, 20, 30, 40, 0, 0, 1024, 1024)",
"__fast_fill(10, 20, 30, 40, 0, 0, 1024, 1024)",
Fields(w, h, 0d), NoStringParams, () => pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
out bool dirty, out _, out _, out _, out _, out string? error);
@@ -1941,7 +1941,7 @@ namespace LuaScript.Tests
_pixelProcessor = processor;
bool ok = RunWorker(
"obj.convolve({1, 2, 3, 4, 5, 6, 7, 8, 9}, 3, 45, 6)",
"__fast_convolve({1, 2, 3, 4, 5, 6, 7, 8, 9}, 3, 45, 6)",
Fields(w, h, 0d), NoStringParams, () => pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
out bool dirty, out _, out _, out _, out _, out string? error);
@@ -1968,7 +1968,7 @@ namespace LuaScript.Tests
var fields = Fields(w, h, 0d);
bool ok = RunWorker(
"obj.resize(512, 512, 'nearest') obj.x = obj.w obj.y = obj.h",
"__fast_resize(512, 512, 'nearest') obj.x = obj.w obj.y = obj.h",
fields, NoStringParams, () => pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
out bool dirty, out bool replaced, out byte[]? result, out int rw, out int rh, out string? error);
@@ -1987,6 +1987,63 @@ namespace LuaScript.Tests
Assert.Equal(0x43, result[^1]);
}
[Fact]
public void PixelProcess_DefaultFill_SkipsHostProcessor()
{
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
const int w = 1024, h = 1024;
var pixels = new byte[w * h * 4];
var processor = new RecordingPixelProcessor { FillResult = true };
_pixelProcessor = processor;
bool ok = RunWorker(
"obj.fill(10, 20, 30, 40, 0, 0, 1024, 1024)",
Fields(w, h, 0d), NoStringParams, () => pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
out _, out _, out _, out _, out _, out string? error);
Assert.True(ok, error);
Assert.Equal(0, processor.FillCalls);
}
[Fact]
public void PixelProcess_DefaultConvolve_SkipsHostProcessor()
{
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
const int w = 200, h = 200;
var pixels = new byte[w * h * 4];
var processor = new RecordingPixelProcessor { ConvolveResult = true };
_pixelProcessor = processor;
bool ok = RunWorker(
"obj.convolve({1, 2, 3, 4, 5, 6, 7, 8, 9}, 3, 45, 6)",
Fields(w, h, 0d), NoStringParams, () => pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
out _, out _, out _, out _, out _, out string? error);
Assert.True(ok, error);
Assert.Equal(0, processor.ConvolveCalls);
}
[Fact]
public void PixelProcess_DefaultResize_SkipsHostProcessor()
{
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
const int w = 2, h = 2;
var pixels = new byte[w * h * 4];
var processor = new RecordingPixelProcessor { ResizeResult = true };
_pixelProcessor = processor;
bool ok = RunWorker(
"obj.resize(512, 512, 'nearest')",
Fields(w, h, 0d), NoStringParams, () => pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
out _, out _, out _, out _, out _, out string? error);
Assert.True(ok, error);
Assert.Equal(0, processor.ResizeCalls);
}
[Fact]
public void Fill_WritesPremultipliedColor()
{
@@ -2206,6 +2263,7 @@ namespace LuaScript.Tests
public bool ResizeResult { get; init; }
public int FillCalls { get; private set; }
public int ConvolveCalls { get; private set; }
public int ResizeCalls { get; private set; }
public int Size { get; private set; }
public double Divisor { get; private set; }
public double Offset { get; private set; }
@@ -2238,6 +2296,7 @@ namespace LuaScript.Tests
public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target)
{
ResizeCalls++;
TargetWidth = targetWidth;
TargetHeight = targetHeight;
Linear = linear;