diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 000000000..e4b157b9a --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,46 @@ +#! /bin/sh +# Copyright (C) 2018 David Capello + +if [[ "$ASEPRITE" == "" ]]; then + echo ASEPRITE env var must be pointing to the Aseprite executable + exit 1 +fi + +function fail() { + echo FAIL + echo $BASH_SOURCE:$BASH_LINENO: error: $* + exit 1 +} + +echo ---------------------------------------------------------------------- +echo $ASEPRITE --version +$ASEPRITE --version + +echo ---------------------------------------------------------------------- +echo "Testing console..." +$ASEPRITE -b --script scripts/console_assert.js > tmp +! grep -q Error tmp && fail +! grep -q "this should be in the output" tmp && fail +grep -q "this should not be in the output" tmp && fail + +$ASEPRITE -b --script scripts/console_log.js > tmp +cat >tmp_expected < tmp ; then + fail + fi +done + +echo ---------------------------------------------------------------------- +echo Done +echo ---------------------------------------------------------------------- diff --git a/scripts/app_pixel_color.js b/scripts/app_pixel_color.js new file mode 100644 index 000000000..1e7d1ecb7 --- /dev/null +++ b/scripts/app_pixel_color.js @@ -0,0 +1,9 @@ +// Copyright (C) 2018 David Capello + +var pc = app.pixelColor +console.assert(0 == pc.rgba(0, 0, 0, 0)) +console.assert(1 == pc.rgbaR(pc.rgba(1, 2, 3, 4))) +console.assert(2 == pc.rgbaG(pc.rgba(1, 2, 3, 4))) +console.assert(3 == pc.rgbaB(pc.rgba(1, 2, 3, 4))) +console.assert(4 == pc.rgbaA(pc.rgba(1, 2, 3, 4))) +console.assert(0xff104080 == pc.rgba(0x80, 0x40, 0x10, 0xff)) diff --git a/scripts/app_version.js b/scripts/app_version.js new file mode 100644 index 000000000..03c3bcb8e --- /dev/null +++ b/scripts/app_version.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 David Capello + +console.assert(app.version[0] == "1") +console.assert(app.version[1] == ".") diff --git a/scripts/console_assert.js b/scripts/console_assert.js new file mode 100644 index 000000000..cfa0729c5 --- /dev/null +++ b/scripts/console_assert.js @@ -0,0 +1,6 @@ +// Copyright (C) 2018 David Capello + +console.assert(true) +console.log("this should be in the output") +console.assert(false) +console.log("this should not be in the output") diff --git a/scripts/console_log.js b/scripts/console_log.js new file mode 100644 index 000000000..bd856a026 --- /dev/null +++ b/scripts/console_log.js @@ -0,0 +1,4 @@ +// Copyright (C) 2018 David Capello + +console.log("hello world") +console.log(1, 2, 3) diff --git a/scripts/constants.js b/scripts/constants.js new file mode 100644 index 000000000..911eef2b7 --- /dev/null +++ b/scripts/constants.js @@ -0,0 +1,5 @@ +// Copyright (C) 2018 David Capello + +console.assert(ColorMode.RGB == 0) +console.assert(ColorMode.GRAYSCALE == 1) +console.assert(ColorMode.INDEXED == 2) diff --git a/scripts/point.js b/scripts/point.js new file mode 100644 index 000000000..616a049cd --- /dev/null +++ b/scripts/point.js @@ -0,0 +1,21 @@ +// Copyright (C) 2018 David Capello + +var pt = new Point() +console.assert(pt.x == 0) +console.assert(pt.y == 0) + +pt = new Point(1, 2) +console.assert(pt.x == 1) +console.assert(pt.y == 2) + +var pt2 = new Point(pt) +console.assert(pt2.x == 1) +console.assert(pt2.y == 2) + +pt.x = 5; +pt.y = 6; +console.assert(pt.x == 5) +console.assert(pt.y == 6) + +// TODO fix this +console.log(JSON.stringify(pt)) diff --git a/scripts/rectangle.js b/scripts/rectangle.js new file mode 100644 index 000000000..ce3b650aa --- /dev/null +++ b/scripts/rectangle.js @@ -0,0 +1,31 @@ +// Copyright (C) 2018 David Capello + +var rc = new Rectangle() +console.assert(rc.x == 0) +console.assert(rc.y == 0) +console.assert(rc.width == 0) +console.assert(rc.height == 0) + +rc = new Rectangle(1, 2, 3, 4) +console.assert(rc.x == 1) +console.assert(rc.y == 2) +console.assert(rc.width == 3) +console.assert(rc.height == 4) + +var rc2 = new Rectangle(rc) +console.assert(rc2.x == 1) +console.assert(rc2.y == 2) +console.assert(rc2.width == 3) +console.assert(rc2.height == 4) + +rc.x = 5; +rc.y = 6; +rc.width = 7; +rc.height = 8; +console.assert(rc.x == 5) +console.assert(rc.y == 6) +console.assert(rc.width == 7) +console.assert(rc.height == 8) + +// TODO fix this +console.log(JSON.stringify(rc)) diff --git a/scripts/selection.js b/scripts/selection.js new file mode 100644 index 000000000..08abfd7c1 --- /dev/null +++ b/scripts/selection.js @@ -0,0 +1,29 @@ +// Copyright (C) 2018 David Capello + +// Isolated selection +var a = new Selection() +console.assert(a.bounds.x == 0) +console.assert(a.bounds.y == 0) +console.assert(a.bounds.width == 0) +console.assert(a.bounds.height == 0) + +a.select(1, 2, 3, 4); +console.assert(a.bounds.x == 1) +console.assert(a.bounds.y == 2) +console.assert(a.bounds.width == 3) +console.assert(a.bounds.height == 4) + +a.select({ 'x': 5, 'y': 6, 'width': 7, 'height': 8 }) +console.assert(a.bounds.x == 5) +console.assert(a.bounds.y == 6) +console.assert(a.bounds.width == 7) +console.assert(a.bounds.height == 8) + +a.deselect(); +console.assert(a.bounds.x == 0) +console.assert(a.bounds.y == 0) +console.assert(a.bounds.width == 0) +console.assert(a.bounds.height == 0) + +// Selection related to a sprite +// TODO diff --git a/scripts/size.js b/scripts/size.js new file mode 100644 index 000000000..8561babbb --- /dev/null +++ b/scripts/size.js @@ -0,0 +1,21 @@ +// Copyright (C) 2018 David Capello + +var sz = new Size() +console.assert(sz.width == 0) +console.assert(sz.height == 0) + +sz = new Size(3, 4) +console.assert(sz.width == 3) +console.assert(sz.height == 4) + +var sz2 = new Size(sz) +console.assert(sz2.width == 3) +console.assert(sz2.height == 4) + +sz.width = 7; +sz.height = 8; +console.assert(sz.width == 7) +console.assert(sz.height == 8) + +// TODO fix this +console.log(JSON.stringify(sz)) diff --git a/scripts/sprite.js b/scripts/sprite.js new file mode 100644 index 000000000..42a199df0 --- /dev/null +++ b/scripts/sprite.js @@ -0,0 +1,31 @@ +// Copyright (C) 2018 David Capello + +var a = new Sprite(32, 64) +console.assert(a.width == 32) +console.assert(a.height == 64) +console.assert(a.colorMode == ColorMode.RGB) // RGB by default +a.selection.select(2, 3, 4, 5) +console.assert(a.selection.bounds.x == 2) +console.assert(a.selection.bounds.y == 3) +console.assert(a.selection.bounds.width == 4) +console.assert(a.selection.bounds.height == 5) +a.crop() +console.assert(a.width == 4) +console.assert(a.height == 5) +a.resize(6, 8) +console.assert(a.width == 6) +console.assert(a.height == 8) +a.crop({ 'x': -1, 'y': -1, 'width': 20, 'height': 30 }) +console.assert(a.width == 20) +console.assert(a.height == 30) + +// resize sprite setting width/height +a.width = 8 +a.height = 10 +console.assert(a.width == 8) +console.assert(a.height == 10) + +var b = new Sprite(4, 4, ColorMode.INDEXED) +console.assert(b.width == 4) +console.assert(b.height == 4) +console.assert(b.colorMode == ColorMode.INDEXED)