diff --git a/scripts/app_command.lua b/scripts/app_command.lua index 973eed4d3..28787feba 100644 --- a/scripts/app_command.lua +++ b/scripts/app_command.lua @@ -4,6 +4,8 @@ -- This file is released under the terms of the MIT license. -- Read LICENSE.txt for more information. +dofile('./test_utils.lua') + do -- Undo/Redo commands (like app.undo/redo()) local s = Sprite(32, 32) assert(s.width == 32) @@ -133,3 +135,34 @@ do -- CanvasSize app.command.CanvasSize{ top=2, right=4, bottom=8 } assert(s.bounds == Rectangle(0, 0, 38, 42)) end + +do -- ReplaceColor + local s = Sprite(4, 4) + local cel = app.activeCel + local red = Color(255, 0, 0) + local yellow = Color(255, 255, 0) + local blue = Color(0, 0, 255) + local r = red.rgbaPixel + local y = yellow.rgbaPixel + local b = blue.rgbaPixel + + expect_eq(cel.bounds, Rectangle(0, 0, 4, 4)) + expect_img(cel.image, + { 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0 }) + + app.useTool{ brush=Brush(1), color=red, points={Point(1,1)} } + app.useTool{ brush=Brush(1), color=yellow, points={Point(2,2)} } + expect_eq(cel.bounds, Rectangle(1, 1, 2, 2)) + expect_img(cel.image, + { r, 0, + 0, y }) + + app.command.ReplaceColor{ ui=false, from=red, to=blue } + expect_eq(cel.bounds, Rectangle(1, 1, 2, 2)) + expect_img(cel.image, + { b, 0, + 0, y }) +end