#!/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 " testscene=" TYPE input OBJECT door DEFAULT MSG What about the door? ACTION open GO $scene_opendoor ACTION unknown UNKNOWNCMD foo ACTION multi $multiactions OBJECT foo ACTION bar MSG Foo bar OBJECT cow ACTION moo MSG MOOOOOOOOOOOOOOOOOO! 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" } # 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)" }