Commits

David Mugnai  committed c5d099e

test module for the slam parser

  • Participants
  • Parent commits 6caf0ee

Comments (0)

Files changed (2)

File CMakeLists.txt

 include_directories(${PROJECT_SOURCE_DIR})
 link_directories(${PROJECT_BINARY_DIR})
 
+aux_source_directory(slam SLAM_DIR)
+aux_source_directory(expr EXPR_DIR)
+add_library(slam ${SLAM_DIR} ${EXPR_DIR})
+
 add_executable(test_expr tests/test_expr.cpp)
 add_dependencies(test_expr gtest)
 target_link_libraries(test_expr libgtest.a libgtest_main.a pthread)
 
-aux_source_directory(slam SLAM_DIR)
-aux_source_directory(expr EXPR_DIR)
-add_library(slam ${SLAM_DIR} ${EXPR_DIR})
+add_executable(test_slam_parser tests/test_slam_parser.cpp)
+add_dependencies(test_slam_parser gtest)
+target_link_libraries(test_slam_parser libgtest.a libgtest_main.a pthread slam)
 
 add_executable(main main.cpp)
 target_link_libraries(main slam)

File tests/test_slam_parser.cpp

+#include "slam.h"
+#include "gtest/gtest.h"
+
+using slam::ast::Tag;
+using slam::parser::parse;
+
+TEST(BasicParser, just_one_tag) {
+    auto result = static_cast<Tag*>(parse("html"));
+    EXPECT_EQ(result->name, "html");
+    EXPECT_EQ(result->children.size(), 0);
+    EXPECT_EQ(result->attribs.size(), 0);
+}
+
+TEST(BasicParser, one_child) {
+    auto result = static_cast<Tag*>(parse("html\n  head"));
+    EXPECT_EQ(result->name, "html");
+    EXPECT_EQ(result->children.size(), 1);
+
+    auto child = static_cast<Tag*>(result->children[0]);
+    EXPECT_EQ(child->name, "head");
+}