From ef69c9ef3c3e545ac9717eda57a99de3aee5aefe Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Tue, 29 May 2012 12:34:46 -0400 Subject: [PATCH] Added comparison operators to Token for easier unit testing --- source/lexer/token/token.cpp | 12 ++++++++++++ source/lexer/token/token.h | 2 ++ 2 files changed, 14 insertions(+) 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 -- 2.51.0