diff --git a/test/test-process-input b/test/test-process-input index 7663ba7..c476c85 100755 --- a/test/test-process-input +++ b/test/test-process-input @@ -28,14 +28,18 @@ process-input "foo bar" 2>/dev/null <<< "" && { # test data scene_opendoor="opendoor" +doorspeak="Yo. I'm a door." testscene=" TYPE input OBJECT door + DEFAULT MSG What about the door? ACTION open GO $scene_opendoor ACTION invalid ACTION unknown UNKNOWNCMD foo ACTION badgo GO + ACTION talk MSG $doorspeak + ACTION badtalk MSG STORY This is a test scene. @@ -81,3 +85,13 @@ 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" +} + diff --git a/util/process-input b/util/process-input index 9ce9fa8..15e2642 100755 --- a/util/process-input +++ b/util/process-input @@ -2,6 +2,11 @@ # # Processes input text and outputs result # +# This script will return one of two commands with an associated argument, which +# should be interpreted as follows: +# - MSG - Output the provided message +# - GO - Go to the scene matching the provided id +# # Copyright (C) 2011 Mike Gerwitz # # This file is part of gsgp. This program is free software: you can @@ -60,18 +65,29 @@ fi # what type of command should we execute? cmd=$( cut -d' ' -f1 <<< "$action_data" ) -target=$( cut -s -d' ' -f2 <<< "$action_data" ) +arg=$( cut -s -d' ' -f2- <<< "$action_data" ) case "$cmd" in GO) - if [ ! "$target" ]; then + if [ ! "$arg" ]; then echo "ERROR: GO command requires target scene" >&2 exit 4 fi # the action will be to go to the target scene - echo "GO $target" + echo "GO $arg" ;; + + MSG) + if [ ! "$arg" ]; then + echo "ERROR: MSG requires an output string" >&2 + exit 4 + fi + + # the MSG action will indicate that a message should be output + echo "MSG $arg" + ;; + *) echo "ERROR: Unknown command '$cmd' for action: $words" >&2 exit 4