84 lines
2.4 KiB
Bash
Executable File
84 lines
2.4 KiB
Bash
Executable File
#!/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"
|
|
testscene="
|
|
TYPE input
|
|
|
|
OBJECT door
|
|
ACTION open GO $scene_opendoor
|
|
ACTION invalid
|
|
ACTION unknown UNKNOWNCMD foo
|
|
ACTION badgo GO
|
|
|
|
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"
|
|
}
|
|
|