From d8200651e8e2d68e613a66fec899a3faaf3cc153 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 7 Sep 2018 14:09:10 -0300 Subject: [PATCH] Move sprite selection tests to selection.lua file --- scripts/selection.lua | 80 ++++++++++++++++++++++++++++--------------- scripts/sprite.lua | 21 ++---------- 2 files changed, 54 insertions(+), 47 deletions(-) diff --git a/scripts/selection.lua b/scripts/selection.lua index 68b7cff57..778b2913f 100644 --- a/scripts/selection.lua +++ b/scripts/selection.lua @@ -4,34 +4,58 @@ -- Read LICENSE.txt for more information. -- Isolated selection -local a = Selection() -assert(a.bounds.x == 0) -assert(a.bounds.y == 0) -assert(a.bounds.width == 0) -assert(a.bounds.height == 0) -assert(a.isEmpty) +do + local a = Selection() + assert(a.bounds.x == 0) + assert(a.bounds.y == 0) + assert(a.bounds.width == 0) + assert(a.bounds.height == 0) + assert(a.isEmpty) -a:select(1, 2, 3, 4) -assert(a.bounds.x == 1) -assert(a.bounds.y == 2) -assert(a.bounds.width == 3) -assert(a.bounds.height == 4) -assert(not a.isEmpty) -assert(a:contains(1, 2)) -assert(a:contains(1+3-1, 2+4-1)) -assert(not a:contains(0, 1)) -assert(not a:contains(1+3, 2+4)) + a:select(1, 2, 3, 4) + assert(a.bounds.x == 1) + assert(a.bounds.y == 2) + assert(a.bounds.width == 3) + assert(a.bounds.height == 4) + assert(not a.isEmpty) + assert(a:contains(1, 2)) + assert(a:contains(1+3-1, 2+4-1)) + assert(not a:contains(0, 1)) + assert(not a:contains(1+3, 2+4)) -a:select{x=5, y=6, width=7, height=8} -assert(a.bounds.x == 5) -assert(a.bounds.y == 6) -assert(a.bounds.width == 7) -assert(a.bounds.height == 8) + a:select{x=5, y=6, width=7, height=8} + assert(a.bounds.x == 5) + assert(a.bounds.y == 6) + assert(a.bounds.width == 7) + assert(a.bounds.height == 8) -a:deselect() -assert(a.bounds.x == 0) -assert(a.bounds.y == 0) -assert(a.bounds.width == 0) -assert(a.bounds.height == 0) -assert(a.isEmpty) -assert(not a:contains(0, 0)) + a:deselect() + assert(a.bounds.x == 0) + assert(a.bounds.y == 0) + assert(a.bounds.width == 0) + assert(a.bounds.height == 0) + assert(a.isEmpty) + assert(not a:contains(0, 0)) +end + +-- Sprite Selection +do + local spr = Sprite(32, 32) + local sel = spr.selection + assert(sel.bounds.x == 0) + assert(sel.bounds.y == 0) + assert(sel.bounds.width == 0) + assert(sel.bounds.height == 0) + + sel:selectAll() + assert(sel.bounds.x == 0) + assert(sel.bounds.y == 0) + assert(sel.bounds.width == spr.width) + assert(sel.bounds.height == spr.height) + + sel:select(2, 3, 4, 5) + assert(sel.bounds.x == 2) + assert(sel.bounds.y == 3) + assert(sel.bounds.width == 4) + assert(sel.bounds.height == 5) +end diff --git a/scripts/sprite.lua b/scripts/sprite.lua index 7cb56ab9c..b6c4d3988 100644 --- a/scripts/sprite.lua +++ b/scripts/sprite.lua @@ -8,25 +8,8 @@ assert(a.width == 32) assert(a.height == 64) assert(a.colorMode == ColorMode.RGB) -- RGB by default --- Sprite Selection -local s = a.selection -assert(s.bounds.x == 0) -assert(s.bounds.y == 0) -assert(s.bounds.width == 0) -assert(s.bounds.height == 0) - -s:selectAll() -assert(s.bounds.x == 0) -assert(s.bounds.y == 0) -assert(s.bounds.width == a.width) -assert(s.bounds.height == a.height) - -s:select(2, 3, 4, 5) -assert(s.bounds.x == 2) -assert(s.bounds.y == 3) -assert(s.bounds.width == 4) -assert(s.bounds.height == 5) - +-- Crop and resize +a.selection:select(2, 3, 4, 5) a:crop() assert(a.width == 4) assert(a.height == 5)