SDOM - Simple SDL Document Object Model
A lightweight, extensible Document Object Model for SDL-based applications.
Loading...
Searching...
No Matches
SDOM_UnitTests.hpp
Go to the documentation of this file.
1// SDOM_UnitTests.hpp
2
3#pragma once
4
5#include <SDOM/SDOM.hpp>
6
7namespace SDOM
8{
10 {
11 public:
12 static void printTest(const std::string& objName, const std::string& testName)
13 {
14 std::cout << CLR::indent() << CLR::LT_BLUE << "[" << objName << "] " << CLR::LT_BLUE << testName << " ..." << CLR::RESET;
15 fflush(stdout); // Ensure immediate output
16 }
17
18 // static void printTest(const std::string& objName, const std::string& testName)
19 // {
20 // std::cout << CLR::indent() << CLR::LT_BLUE << "[" << objName << "] " << CLR::LT_BLUE << testName << " ";
21 // CLR::get_cursor_pos(UnitTests::_saved_row, UnitTests::_saved_col);
22 // std::cout << "..." << CLR::RESET;
23 // fflush(stdout); // Ensure immediate output
24 // }
25
26 static void printResult(const std::string& testName, bool passed)
27 {
28 std::cout << "\b\b\b\b"; // Erase the " ..." part
29 std::cout << (passed ? CLR::GREEN + " [PASSED]" : CLR::fg_rgb(255, 0, 0) + " [FAILED]") << CLR::RESET << std::endl;
30 }
31
32 // static void printResult(const std::string& testName, bool passed)
33 // {
34 // CLR::save_cursor();
35 // CLR::set_cursor_pos(UnitTests::_saved_row, UnitTests::_saved_col);
36 // std::cout << (passed ? CLR::GREEN + " [PASSED]" : CLR::fg_rgb(255, 0, 0) + " [FAILED]") << CLR::RESET << std::endl;
37 // CLR::restore_cursor();
38 // }
39
40 // A helper to run and print a test
41 template<typename Func>
42 static bool run(const std::string& objName, const std::string& testName, Func&& testFunc)
43 {
44 printTest(objName, testName);
45 bool result = testFunc();
46 printResult(testName, result);
47 return result;
48 }
49
50 private:
51 static int _saved_row;
52 static int _saved_col;
53 };
54} // namespace SDOM
static std::string indent()
Returns spaces for the current indentation level.
Definition SDOM_CLR.hpp:370
static const std::string fg_rgb(Byte r, Byte g, Byte b)
Returns ANSI escape sequence to set 24-bit (RGB) foreground color.
Definition SDOM_CLR.hpp:109
static const std::string GREEN
ANSI escape sequence for green foreground.
Definition SDOM_CLR.hpp:268
static const std::string RESET
ANSI escape sequence to reset formatting.
Definition SDOM_CLR.hpp:245
static const std::string LT_BLUE
ANSI escape sequence for light blue foreground.
Definition SDOM_CLR.hpp:279
Definition SDOM_UnitTests.hpp:10
static void printResult(const std::string &testName, bool passed)
Definition SDOM_UnitTests.hpp:26
static void printTest(const std::string &objName, const std::string &testName)
Definition SDOM_UnitTests.hpp:12
static bool run(const std::string &objName, const std::string &testName, Func &&testFunc)
Definition SDOM_UnitTests.hpp:42
Contains all core classes and utilities for the SDOM library.
Definition lua_BindHelpers.hpp:7