#GoogleTest for classes that have a constructor

3 messages · Page 1 of 1 (latest)

foggy lake
#

Hello, i'm trying to implement a test for a class Lexer which is defined like this

class Lexer {
public:
    Lexer(std::string program);
    SyntaxToken lex();
private:
    char current();
    char peekNext();
    char lookAhead(int offset);
    void advance();
    int index = 0;
    std::string program;

    unsigned int row = 0;
};

but it has a default constructor that accepts a std::string program.
So in the method

TEST_F(LexerTest, LexerInit)
{

}

what should I do?

I saw this post on stackoverflow https://stackoverflow.com/questions/38207346/specify-constructor-arguments-for-a-google-test-fixture but it deosn't seem great. Do I have to override all the Lexer's methods? Copy and paste other methods?

devout bladeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

foggy lake
#

!solved