gsgp/test/test-process-input

103 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."
2011-08-24 00:58:18 -04:00
testscene="
TYPE input
OBJECT door
DEFAULT MSG What about the door?
2011-08-24 00:58:18 -04:00
ACTION invalid
ACTION open
GO $scene_opendoor
ACTION unknown
UNKNOWNCMD foo
ACTION badgo
GO
ACTION talk
MSG $doorspeak
ACTION badtalk
MSG
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"
}
# should not allow actions on unknown objects
assert-equal "$( tryinput "open idkwhat" )" "MSG Cannot open idkwhat" || {
simplefail "Should not be able to perform actions on unknown objects"
}
# should not allow unknown actions on known objects
assert-equal "$( tryinput "fondle door" )" "MSG Cannot fondle door" || {
simplefail "Should not be able to perform unknown actions on known objects"
}
# action requires associated command
assert-equal "$( tryinput "invalid door" )" "MSG Cannot invalid door" || {
simplefail "ACTION directive should require valid command"
}
# should fail on unknown command
tryinput "unknown door" 2>/dev/null && {
simplefail "ACTION directive should fail on unknwon command"
}
# GO should require a scene
tryinput "badgo door" 2>/dev/null && {
simplefail "GO command should require a target scene"
}
# MSG should return a message
assert-equal "$( tryinput "talk door" )" "MSG $doorspeak" || {
fail "MSG command should return a message"
}
# MSG command should require an argument
tryinput "badtalk door" 2>/dev/null && {
simplefail "MSG should require output text"
}