#!/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 . ## 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" kickinmsg="MSG Doesn't look like it's going to budge" testscene=" TYPE input OBJECT door DEFAULT MSG What about the door? ACTION open GO $scene_opendoor ACTION unknown UNKNOWNCMD foo ACTION multi $multiactions ACTION kick in $kickinmsg OBJECT foo ACTION bar MSG Foo bar OBJECT cow ACTION moo MSG MOOOOOOOOOOOOOOOOOO! STORY This is a test scene. " tryinput() { process-input "$1" <<< "$testscene" } # 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" } # unknown actions on known objects should simply output an empty string assert-equal "$( tryinput "fondle door" )" "" || { 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)" } # simply naming an object should question the user's intentions assert-equal "$( tryinput "door" )" "MSG What about door?" || { fail "Naming object should ask user what their intention is" } # if a single word is entered, and it's not a known object, we don't know what # to do (maybe in the future we'll want to scan possible actions and make # suggestions) assert-equal "$( tryinput "tickle" )" "MSG Please elaborate." || { fail "Naming an unknown object should prompt user to elaborate" } # multi-word actions should be supported assert-equal "$( tryinput "kick in door" )" "$kickinmsg" || { fail "Multi-word actions should be supported" }