I am currently implementing my own programming language. Until now I have written:
An
Error
class for errors (to be thrown) encountered while processing the input source code;Some
SyntaxError
functions (each one with a different tag, passed with a template, likeSyntaxError<malformed_number>()
orSyntaxError<unexpected_symbol>
) which help constructingError
objects with different error messages (for now I only got this, but I will soon haveFunctionError
s,IndexError
s and so on);A
Token
class which contains the informations about each token (line in the string at which it was when it was encountered, the type which can bestring
,number
... things like that);Finally, a
lexer
function which takes as imput a string of source code and returns astd::list<Token*>
object. Internally, it uses a few helper functions (buildname
,builsymbol
,skipcomment
...) to help mantain the code organized.
I didn't follow any particular programming technique will coding this, but I now feel the urge to follow those that go under the Test Developement Programming name.
But I have a few concerns:
First, what do I have to test in the above code? Of course the
lexer
function should be tested deeply, and maybe also the helper functions it uses (I guess), but what about the other things?Second, how do I test functions with a non-trivial output? Online I see a lot of examples comparing simple numbers or strings, but how does one write a test for a function which returns a list of pointers to objects whitout having to write too much for a single test case?