]> git.mdlowis.com Git - archive/parse-utils.git/commitdiff
Added comparison operators to Token for easier unit testing
authorMike D. Lowis <mike@mdlowis.com>
Tue, 29 May 2012 16:34:46 +0000 (12:34 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Tue, 29 May 2012 16:34:46 +0000 (12:34 -0400)
source/lexer/token/token.cpp
source/lexer/token/token.h

index 8a4008d79c1cfb0df746e111cb217269f2f937f5..233aae55d234ec95ad2b25099da6ff79af16b8ef 100644 (file)
@@ -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 );
+}
index 7550bd43c08f6a072e201c4aa5cb0dc8ba6c08cd..baedf6cf8a6566447fa427cdec0fd4a6cdfb4315 100644 (file)
@@ -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