Mercurial > web-gnusto
changeset 4:a4ad54a69e3b
Turned test.js into a real, runnable test.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 11 May 2008 12:18:44 -0700 |
parents | 2ce26a2407be |
children | 53d7cff492b9 |
files | test.js |
diffstat | 1 files changed, 44 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/test.js Sat May 10 22:46:42 2008 -0700 +++ b/test.js Sun May 11 12:18:44 2008 -0700 @@ -1,21 +1,56 @@ load("troll.js", "gnusto-engine.js"); +var gInputTimes = 0; +var gSetCursorTimes = 0; + function step() { var retval = 0; engine.run(); var effect = engine.effect(0); var text = engine.consoleText(); - if (text) - print('['+effect+'] '+text); + //if (text) + // print('['+effect+'] '+text); + + effect = '"' + effect + '"'; - if (effect=='SS' || effect=='TW' || effect=='SW' || effect=='SC') { - // harmless; carry on - } else if (effect=='RS') { + switch (effect) { + case GNUSTO_EFFECT_STYLE: + case GNUSTO_EFFECT_SPLITWINDOW: + case GNUSTO_EFFECT_SETWINDOW: + break; + case GNUSTO_EFFECT_SETCURSOR: + if (text) { + if (text != 'The Troll Room') + throw Error('Unexpected console text: "' + text + '"'); + gSetCursorTimes += 1; + } + break; + case GNUSTO_EFFECT_INPUT: + switch (gInputTimes) { + case 0: + engine.answer(1, 'quit'); + break; + case 1: + engine.answer(1, 'yes'); + break; + default: + throw Error('Unexpected input.'); + } + gInputTimes += 1; + break; + case GNUSTO_EFFECT_QUIT: + if (gInputTimes != 2) + throw Error('Did not receive proper input before quit effect.'); + if (gSetCursorTimes != 2) + throw Error('Did not receive proper set cursor effects ' + + 'before quit effect.'); retval = 1; - } else { - throw Error('*** UNKNOWN EFFECT. ***.\n'); - } + break; + default: + throw Error('Unexpected effect: ' + effect); + }; + return retval; } @@ -24,3 +59,4 @@ engine.loadStory(troll_z5); while (step() == 0) {} +print('Gnusto engine test run successfully.');