Example #1
0
 def test2(self):
     obj = PreProcess();
     obj.text = ['/* comment runs on beyond file ...', '....']
     err = obj.strip_comments(obj.text)
     self.assert_(err == ParserError.ERR_UNTERMINATED_COMMENT ,
                 "Expected ParserError.ERR_UNTERMINATED_COMMENT (errnum %d) but saw %d." % \
                 ( ParserError.ERR_UNTERMINATED_COMMENT, err) )
Example #2
0
    def test1(self):
        obj = PreProcess();

        obj.text = [ '// hello Greg', 'line 2', 'Line 3 // after line 2 // but not this',
        'line /* not this*/4', '"line 5 /* not a comment; a // string."',
        '/* comment, not a "string"', 'still a comment.*/', 
        'li/* */ne/* comment */ 8 // comment', 'line 9 bad string ends in dub quotes"',
        '"line \\"10\\" in quotes like this:\\""', '/* short in long // */',
        'line 12 // short c before long /* */', '/**/ line 13 // ultra short long comment',
        'line 14 /* long comment ending at EOL */',
        'line 15 /* lc starts here', 'and goes on thru 16 // ', 'ends here */ line 17 /* */',
        'last line' ]

        good_LoS = [ '','line 2','Line 3 ','line 4','"line 5 /* not a comment; a // string."'
                    ,'','','line 8 ','line 9 bad string ends in dub quotes"'
                    ,'"line \\"10\\" in quotes like this:\\""','','line 12 ',' line 13 ','line 14 '
                    ,'line 15 ','',' line 17 ',
                    'last line']

        err = obj.strip_comments(obj.text)
        self.assert_(err==0, "test1 Unexpected err %d returned from strip_comments()" % err )
        for ix  in xrange(len(obj.text)):
            self.assert_( obj.text[ix] == good_LoS[ix] ,
                        "test1 Line %d saw '%s'\nbut expected: '%s'" % (ix, obj.text[ix], good_LoS[ix]) )