mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-15 19:52:05 +00:00
Add some scripts to test the current JavaScript API
This commit is contained in:
parent
4132dadf53
commit
075966fe18
46
run-tests.sh
Executable file
46
run-tests.sh
Executable file
@ -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 <<EOF
|
||||
hello world
|
||||
1 2 3
|
||||
EOF
|
||||
! diff -u tmp tmp_expected && fail
|
||||
|
||||
echo ----------------------------------------------------------------------
|
||||
echo "Testing scripts..."
|
||||
for jsfile in scripts/*.js ; do
|
||||
[[ $jsfile =~ console ]] && continue
|
||||
|
||||
echo "Running $jsfile"
|
||||
if ! $ASEPRITE -b --script $jsfile > tmp ; then
|
||||
fail
|
||||
fi
|
||||
done
|
||||
|
||||
echo ----------------------------------------------------------------------
|
||||
echo Done
|
||||
echo ----------------------------------------------------------------------
|
9
scripts/app_pixel_color.js
Normal file
9
scripts/app_pixel_color.js
Normal file
@ -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))
|
4
scripts/app_version.js
Normal file
4
scripts/app_version.js
Normal file
@ -0,0 +1,4 @@
|
||||
// Copyright (C) 2018 David Capello
|
||||
|
||||
console.assert(app.version[0] == "1")
|
||||
console.assert(app.version[1] == ".")
|
6
scripts/console_assert.js
Normal file
6
scripts/console_assert.js
Normal file
@ -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")
|
4
scripts/console_log.js
Normal file
4
scripts/console_log.js
Normal file
@ -0,0 +1,4 @@
|
||||
// Copyright (C) 2018 David Capello
|
||||
|
||||
console.log("hello world")
|
||||
console.log(1, 2, 3)
|
5
scripts/constants.js
Normal file
5
scripts/constants.js
Normal file
@ -0,0 +1,5 @@
|
||||
// Copyright (C) 2018 David Capello
|
||||
|
||||
console.assert(ColorMode.RGB == 0)
|
||||
console.assert(ColorMode.GRAYSCALE == 1)
|
||||
console.assert(ColorMode.INDEXED == 2)
|
21
scripts/point.js
Normal file
21
scripts/point.js
Normal file
@ -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))
|
31
scripts/rectangle.js
Normal file
31
scripts/rectangle.js
Normal file
@ -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))
|
29
scripts/selection.js
Normal file
29
scripts/selection.js
Normal file
@ -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
|
21
scripts/size.js
Normal file
21
scripts/size.js
Normal file
@ -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))
|
31
scripts/sprite.js
Normal file
31
scripts/sprite.js
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user