gsgp/test/test-process-input

104 lines
2.8 KiB
Plaintext
Raw Normal View History

2011-08-24 00:58:18 -04:00
#!/bin/bash
#
# Tests input processor
#
# Copyright (C) 2011 Mike Gerwitz
#
# This file is part of gsgp. This program is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
mypath=$( dirname $0 )
. "$mypath/common"
# ensure it throws an error if we don't provide it with scene data (via stdin)
process-input "foo bar" 2>/dev/null <<< "" && {
simplefail "Should fail if no scene data is provided"
}
# test data
scene_opendoor="opendoor"
doorspeak="Yo. I'm a door."
multiactions="
MSG foo
WAIT
GO somewhereelse
"
2011-08-24 00:58:18 -04:00
testscene="
TYPE input
OBJECT door
DEFAULT MSG What about the door?
ACTION open
GO $scene_opendoor
ACTION unknown
UNKNOWNCMD foo
ACTION multi
$multiactions
2011-08-24 00:58:18 -04:00
OBJECT foo
ACTION bar
MSG Foo bar
OBJECT cow
ACTION moo
MSG MOOOOOOOOOOOOOOOOOO!
2011-08-24 00:58:18 -04:00
STORY
This is a test scene.
"
tryinput()
{
process-input "$1" <<< "$testscene"
}
# ensure it doesn't accept too many words
process-input "foo bar baz" 2>/dev/null <<< "data" && {
simplefail "Shouldn't allow more words than can be interpreted"
}
# should allow actions on known objects
assert-equal "$( tryinput "open door" )" "GO $scene_opendoor" || {
fail "Should be able to perform known actions on known objects"
}
# actions on unknown objects should simply output an empty string
assert-equal "$( tryinput "open idkwhat" )" "" || {
fail "Should not be able to perform actions on unknown objects"
2011-08-24 00:58:18 -04:00
}
# unknown actions on known objects should simply output an empty string
assert-equal "$( tryinput "fondle door" )" "" || {
2011-08-24 00:58:18 -04:00
simplefail "Should not be able to perform unknown actions on known objects"
}
# all commands associated with an action should be returned (left trimmed)
expected=$( sed 's/ \+//' <<< "$multiactions" )
assert-equal "$( tryinput "multi door" )" "$expected" || {
fail "All commands for a multi-line action should be returned"
}
# should not fall through to another object (action exists in object below the
# first)
assert-equal "$( tryinput "bar door" )" "" || {
fail "Actions should not fall through to other objects"
}
# fallthrough shouldn't occur if no newline separates objects
assert-equal "$( tryinput "moo foo" )" "" || {
fail "Actions should not fall through to other objects (missing nl)"
}