LCOV - code coverage report
Current view: top level - test/parsingAnalysis - test_ast_utils.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 60.0 % 35 21
Test Date: 2025-04-18 15:53:49 Functions: 66.7 % 3 2

            Line data    Source code
       1              : #include "../../inc/parsingAnalysis/builder.h"
       2              : #include <catch2/catch_test_macros.hpp>
       3              : #include <memory>
       4              : 
       5              : using namespace nicole;
       6              : 
       7            9 : TEST_CASE("AST_IMPORT class methods", "[AST_IMPORT]") {
       8            9 :   Location loc{"file", 0, 0};
       9            9 :   Token token{TokenType::OPERATOR_ADD, "+", loc};
      10            9 :   AST_IMPORT astImport{0, SourceLocation{token, token}, "/path/to/file"};
      11              : 
      12            9 :   REQUIRE(astImport.path() == std::filesystem::path{"/path/to/file"});
      13            9 : }
      14              : 
      15              : bool areASTStatementsEqual(const std::shared_ptr<AST_STATEMENT> &lhs,
      16            0 :                            const std::shared_ptr<AST_STATEMENT> &rhs) {
      17              :   // Verifica si ambos punteros son nulos
      18            0 :   if (!lhs && !rhs)
      19            0 :     return true;
      20              :   // Verifica si solo uno de los punteros es nulo
      21            0 :   if (!lhs || !rhs)
      22            0 :     return false;
      23              :   // Compara los tipos de las expresiones
      24            0 :   if (lhs->expression()->type() != rhs->expression()->type())
      25            0 :     return false;
      26              :   // Realiza comparaciones específicas según el tipo de expresión
      27              :   // Por ejemplo, si es AST_BOOL, compara los valores booleanos
      28            0 :   if (lhs->expression()->type() == AST_TYPE::BOOL) {
      29            0 :     auto lhsBool = std::dynamic_pointer_cast<AST_BOOL>(lhs->expression());
      30            0 :     auto rhsBool = std::dynamic_pointer_cast<AST_BOOL>(rhs->expression());
      31            0 :     return lhsBool && rhsBool && lhsBool->value() == rhsBool->value();
      32            0 :   }
      33            0 :   return false; // Por defecto, se considera que no son iguales
      34            0 : }
      35              : 
      36            9 : TEST_CASE("AST_PRINT class methods", "[AST_PRINT]") {
      37            9 :   Location loc{"file", 0, 0};
      38            9 :   Token token{TokenType::OPERATOR_ADD, "+", loc};
      39            9 :   auto astBool1 = *Builder::createStatement(
      40            9 :       SourceLocation{token, token},
      41            9 :       *Builder::createBool(SourceLocation{token, token}, true));
      42            9 :   auto astBool2 = *Builder::createStatement(
      43            9 :       SourceLocation{token, token},
      44            9 :       *Builder::createBool(SourceLocation{token, token}, false));
      45            9 :   auto astComma = std::vector<std::shared_ptr<AST>>{astBool1, astBool2};
      46              : 
      47            9 :   AST_PRINT astPrint{0, SourceLocation{token, token}, astComma};
      48              : 
      49            9 :   REQUIRE(astPrint.values() == astComma);
      50            9 :   REQUIRE(astPrint.values()[0] == astBool1);
      51            9 :   REQUIRE(astPrint.values()[1] == astBool2);
      52            9 : }
        

Generated by: LCOV version 2.0-1