Commits

David Mugnai committed 2f07e7e

test: SingleGrammarRuleTest rewritten to works with expr_type (boost::variant)

Comments (0)

Files changed (2)

tests/test_expr.cpp

 using expr::ast::Node;
 using expr::parser::ExprGrammar;
 
-template<typename T>
-using SingleRule = slam::test::SingleGrammarRuleTest<ExprGrammar<string::const_iterator>, T>;
+using expr::types::expr_type;
+using SingleRule = slam::test::SingleGrammarRuleTest<ExprGrammar<string::const_iterator>, expr_type>;
 
-struct InterpolationRuleTest : SingleRule<double> {
+struct InterpolationRuleTest : SingleRule {
     void SetUp() {
-        SingleRule<double>::SetUp();
+        SingleRule::SetUp();
         this->context->put("a", 42);
     }
 };
     TGrammar grammar;
     expr::context::Context* context;
 
+    struct are_strict_equals : boost::static_visitor<bool>
+    {
+        template<typename T>
+        bool operator()( T const& lhs, T const& rhs ) const {
+            EXPECT_EQ(lhs, rhs);
+            return lhs == rhs;
+        }
+
+        template<typename T, typename U>
+        bool operator()(T const&, U const&) const {
+            ADD_FAILURE() << "cannot compare different types";
+            return false;
+        }
+
+        template<typename T>
+        bool operator()(T const&, expr::types::callable const&) const {
+            ADD_FAILURE() << "callable cannot be compared";
+            return false;
+        }
+
+        template<typename T>
+        bool operator()(expr::types::callable const&, T const&) const {
+            ADD_FAILURE() << "callable cannot be compared";
+            return false;
+        }
+
+        bool operator()(expr::types::callable const&, expr::types::callable const&) const {
+            ADD_FAILURE() << "callable cannot be compared";
+            return false;
+        }
+    };
+
     virtual void SetUp() {
         context = new expr::context::Context();
     }
             auto expected_value = get<2>(test);
             auto value = node->evaluate(*this->context);
 
-            using value_type = decltype(expected_value);
-            value_type* evaluated_value = boost::get<value_type>(&value);
-
-            EXPECT_NE(evaluated_value, nullptr);
-            EXPECT_EQ(expected_value, *evaluated_value);
+            boost::apply_visitor(are_strict_equals(), expected_value, value);
         }
     }
 };