From: Mike D. Lowis Date: Tue, 29 May 2012 16:34:46 +0000 (-0400) Subject: Added comparison operators to Token for easier unit testing X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=ef69c9ef3c3e545ac9717eda57a99de3aee5aefe;p=archive%2Fparse-utils.git Added comparison operators to Token for easier unit testing --- diff --git a/source/lexer/token/token.cpp b/source/lexer/token/token.cpp index 8a4008d..233aae5 100644 --- a/source/lexer/token/token.cpp +++ b/source/lexer/token/token.cpp @@ -53,3 +53,15 @@ int Token::column() const return tok_col; } +bool Token::operator ==(const Token& rhs) const +{ + return ( (tok_type == rhs.type()) && + (tok_line == rhs.line()) && + (tok_col == rhs.column()) && + (tok_text.compare( rhs.text() ) == 0) ); +} + +bool Token::operator !=(const Token& rhs) const +{ + return !( *this == rhs ); +} diff --git a/source/lexer/token/token.h b/source/lexer/token/token.h index 7550bd4..baedf6c 100644 --- a/source/lexer/token/token.h +++ b/source/lexer/token/token.h @@ -25,6 +25,8 @@ class Token int line() const; void column(int col); int column() const; + bool operator ==(const Token &other) const; + bool operator !=(const Token &other) const; }; #endif