Sunday, 12 December 2010

Saving Snippets

This is  bit of a monster



        [Test]
        def save_with_snippets():
                sc = Scene()
                sc.name         = "has_narratives"
                sc.default      = "narrative_1"
                sc.desc         = "see if narratives export correctly"
#
#               add a narrative with a pair of snippets
#
                n = sc.Add_narrative("narrative_1", "first narrative")
                n.Add(Snippet("Oh no!"))
                n.Add(Snippet("I appear to be caught in a test harness!", true))
#
#               do it again
#
                n = sc.Add_narrative("narrative_2", "second narrative")
                n.Add(Snippet("I have to get out of here", true))
                n.Add(Snippet("I don't want to be here if the test fails"))
#
#               this is what we expect the output to look like
#
                target = detab("""
                        <scene name="has_narratives" default="narrative_1" desc="see if narratives export correctly">
                         <narrative name="narrative_1" desc="first narrative">
                          <snippet>Oh no!</snippet>
                          <snippet cut="true">I appear to be caught in a test harness!</snippet>
                         </narrative>
                         <narrative name="narrative_2" desc="second narrative">
                          <snippet cut="true">I have to get out of here</snippet>
                          <snippet>I don't want to be here if the test fails</snippet>
                         </narrative>
                        </scene>
                """)
#
#               save using stringwriter
#
                using sw = StringWriter():
                        sc.save(sw)
#
#                       stringifying the writer gets the underlying string
#
                        result = "${sw}"
                        Assert.AreEqual(target, result)

That passes.

Still, the monstrosity of the test case is undeniable. I really need to test things like this from the narrative or snippet level. Of course, then I wouldn't be able to test that the it all loaded correct;y from the Scene level. I'm missing something here.

Never mind, in the absence of an epiphany, let's carry on as we are...

No comments: