Line data Source code
1 : #include "../inc/options/options.h"
2 : #include <catch2/catch_test_macros.hpp>
3 :
4 36 : TEST_CASE("Pruebas de la clase Options", "[options]") {
5 36 : using nicole::Options;
6 36 : using std::filesystem::path;
7 :
8 36 : SECTION("Constructor y métodos de acceso") {
9 9 : const Options opt{
10 9 : true, true, true, true, true, "binario", "ruta/archivo.cpp"};
11 9 : REQUIRE(opt.help() == true);
12 9 : REQUIRE(opt.optimize() == true);
13 9 : REQUIRE(opt.printTree() == true);
14 9 : REQUIRE(opt.printIR() == true);
15 9 : REQUIRE(opt.validateTree() == true);
16 9 : REQUIRE(opt.binaryName() == "binario");
17 9 : REQUIRE(opt.entryFilePath() == path{"ruta/archivo.cpp"});
18 9 : }
19 :
20 36 : SECTION("Valores por defecto") {
21 9 : const Options opt{false, false, true, true, true, "", ""};
22 9 : REQUIRE(opt.help() == false);
23 9 : REQUIRE(opt.optimize() == false);
24 9 : REQUIRE(opt.binaryName().empty());
25 9 : REQUIRE(opt.entryFilePath().empty());
26 9 : }
27 :
28 36 : SECTION("Modificación de atributos") {
29 9 : Options opt{false, false, true, true, true, "binario", "ruta/archivo.cpp"};
30 : // Simulando cambios en los atributos
31 9 : opt = Options{true,
32 9 : true,
33 9 : true,
34 9 : true,
35 9 : true,
36 9 : "nuevo_binario",
37 9 : "nueva_ruta/nuevo_archivo.cpp"};
38 9 : REQUIRE(opt.help() == true);
39 9 : REQUIRE(opt.optimize() == true);
40 9 : REQUIRE(opt.binaryName() == "nuevo_binario");
41 9 : REQUIRE(opt.entryFilePath() == path{"nueva_ruta/nuevo_archivo.cpp"});
42 9 : }
43 :
44 36 : SECTION("Comparación de objetos Options") {
45 9 : const Options opt1{
46 9 : true, false, true, true, true, "binario", "ruta/archivo.cpp"};
47 9 : const Options opt2{
48 9 : true, false, true, true, true, "binario", "ruta/archivo.cpp"};
49 9 : const Options opt3{false,
50 9 : true,
51 9 : true,
52 9 : true,
53 9 : true,
54 9 : "otro_binario",
55 9 : "otra_ruta/otro_archivo.cpp"};
56 :
57 9 : REQUIRE(opt1.help() == opt2.help());
58 9 : REQUIRE(opt1.optimize() == opt2.optimize());
59 9 : REQUIRE(opt1.printTree() == opt2.printTree());
60 9 : REQUIRE(opt1.printIR() == opt2.printIR());
61 9 : REQUIRE(opt1.binaryName() == opt2.binaryName());
62 9 : REQUIRE(opt1.entryFilePath() == opt2.entryFilePath());
63 :
64 9 : REQUIRE(opt1.help() != opt3.help());
65 9 : REQUIRE(opt1.optimize() != opt3.optimize());
66 9 : REQUIRE(opt1.printTree() == opt3.printTree());
67 9 : REQUIRE(opt1.printIR() == opt3.printIR());
68 :
69 9 : REQUIRE(opt1.binaryName() != opt3.binaryName());
70 9 : REQUIRE(opt1.entryFilePath() != opt3.entryFilePath());
71 9 : }
72 36 : }
|