Friday, 10 December 2010

The Conditional That Came Back From The Grave

Once more unto the breach, dear friends! We're about to get the result of our choice with the third menu item unlocked. So we push a number onto the  input queue, and run the scene again

        stage:iq_insert(3)
        rc = narrator:play(stage)
        assert_true(rc)


And Bang! I haven't defined narrative "thinking"

         <narrative Name="thinking">
          <snippet> You try the door. It isn't locked. </snippet>
          <snippet> You have left the room </snippet>
         </narrative>


No funcs needed, and we just fall off the end, since that will indicate that
the scene is (finally!) over

That passes. Just a few more tests

        --
        -- make sure we're on the right branch
        --
        assert_equal(                                   -- new narrative
                "thinking", narrator.narrative.name
        )
        assert_equal(0, narrator.index)                 -- index rewound


That's confirmed us as at the top of the thinking thread. One more play should
end it.

        rc = narrator:play(stage)
        assert_false(rc)

Returns false because there's nothing left to do - and it passes! Whoo-hoo!

        assert_equal(2, stage:num_oq())                 -- 2 in o/p queue
        assert_equal("text", stage:oq(1).type)
        assert_equal(
                "You try the door. It isn't locked.",
                stage:oq(1).value
        )
        assert_equal("text", stage:oq(2).type)
        assert_equal(                                   -- second snippet
                "You have left the room", stage:oq(2).value
        )


And that passes too! We're done :D

No comments: