diff --git a/test/test-process-input b/test/test-process-input index 2e54150..dafec75 100755 --- a/test/test-process-input +++ b/test/test-process-input @@ -48,6 +48,13 @@ OBJECT door ACTION multi $multiactions +OBJECT foo + ACTION bar + MSG Foo bar +OBJECT cow + ACTION moo + MSG MOOOOOOOOOOOOOOOOOO! + STORY This is a test scene. " @@ -69,7 +76,7 @@ assert-equal "$( tryinput "open door" )" "GO $scene_opendoor" || { # actions on unknown objects should simply output an empty string assert-equal "$( tryinput "open idkwhat" )" "" || { - simplefail "Should not be able to perform actions on unknown objects" + fail "Should not be able to perform actions on unknown objects" } # unknown actions on known objects should simply output an empty string @@ -83,3 +90,14 @@ 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)" +} + diff --git a/util/process-input b/util/process-input index 4a2689f..c2dde11 100755 --- a/util/process-input +++ b/util/process-input @@ -45,9 +45,14 @@ object=$( cut -d' ' -f2 <<< "$words" ) # check for am action on a known object and output the associated commands, left # trimmed awk " - /OBJECT $object/,/^$/ { + /OBJECT $object/ { found = 1 + getline } + found && /^[ \\t]*$|^[A-Z]/ { + found = 0 + } + /^( |\\t)ACTION $action$/ { if ( found ) { getline