Monday, 13 December 2010

That wasn't quite right...

Small mistake in the last test: it was expecting the <func> tags to be included in the lua code, which wouldn't work.

Modified test:

        [Test]
        def load_func():
#              
#               code to run (supposedly, anyway)
#
                code = """
                                function lua_func()
                                        print "lua stuff"
                                end
                                --
                                -- need to call the function - like a
                                -- normal lua program in that respect
                                --
                                lua_func()
                """
#              
#               code embedded in <func> tags
#
                source = detab("""
                        <func>
                                ${code}
                        </func>
                """)
#              
#               create a reader, jump to the start of the func
#
                using r = XmlReader.Create(StringReader(source)):
                        r.ReadToFollowing("func")
#                      
#                       load it
#
                        func = Func()
                        func.load(r)
#
#                       and test!
#
                        Assert.AreEqual(detab(code), func.code)


Conforming implementation:

import System.Xml

class Func:
        [Property(code)]        _code as string

        def load(r as XmlReader):
                if r.IsEmptyElement:
                        print "warning: empty func"
                        r.Read()
                        return
                _code = /^\n/.Replace(r.ReadString(), "")
                r.ReadEndElement()



Now I need to read it as part of an option. Then probably again as part of a Choice...

No comments: