1 #include <catch.hpp> 2 3 #include <internal/token.hpp> 4 #include <internal/tokens.hpp> 5 #include <internal/simple_config_origin.hpp> 6 #include <internal/values/config_boolean.hpp> 7 #include <internal/values/config_boolean.hpp> 8 #include "test_utils.hpp" 9 10 using namespace std; 11 using namespace hocon; 12 using namespace hocon::test_utils; 13 14 TEST_CASE("token equality", "[tokens]") { 15 16 SECTION("singleton token equality") { 17 REQUIRE(*tokens::start_token() == *tokens::start_token()); 18 REQUIRE_FALSE(*tokens::start_token() == *tokens::end_token()); 19 } 20 21 SECTION("value token equality") { 22 value true_value(make_shared<config_boolean>(fake_origin("fake"), true)); 23 value other_true(make_shared<config_boolean>(fake_origin("other fake"), true)); 24 value false_value(make_shared<config_boolean>(fake_origin("fake"), false)); 25 26 REQUIRE(true_value == other_true); 27 REQUIRE_FALSE(true_value == false_value); 28 } 29 30 SECTION("line token equality") { 31 line line_value(fake_origin()); 32 line other_line(fake_origin("other fake")); 33 ignored_whitespace not_a_line(fake_origin(), " "); 34 35 REQUIRE(line_value == other_line); 36 REQUIRE_FALSE(line_value == not_a_line); 37 } 38 39 SECTION("unquoted text token equality") { 40 unquoted_text text(fake_origin(), "no quotes"); 41 unquoted_text other_text(fake_origin("other fake"), "no quotes"); 42 unquoted_text different_text(fake_origin(), "still no quotes"); 43 ignored_whitespace not_unquoted_text(fake_origin(), " "); 44 45 REQUIRE(text == other_text); 46 REQUIRE_FALSE(text == different_text); 47 REQUIRE_FALSE(text == not_unquoted_text); 48 } 49 50 SECTION("ignored whitespace equality") { 51 ignored_whitespace three_spaces(fake_origin(), " "); 52 ignored_whitespace three_more_spaces(fake_origin("other fake"), " "); 53 ignored_whitespace two_spaces(fake_origin(), " "); 54 unquoted_text not_whitespace(fake_origin(), "foo"); 55 56 REQUIRE(three_spaces == three_more_spaces); 57 REQUIRE_FALSE(three_spaces == two_spaces); 58 REQUIRE_FALSE(three_spaces == not_whitespace); 59 } 60 61 SECTION("problem token equality") { 62 problem problem_token(fake_origin(), "test exception", "it broke", false); 63 problem other_problem(fake_origin("other fake"), "test exception", "it broke", false); 64 ignored_whitespace not_a_problem(fake_origin(), " "); 65 66 REQUIRE(problem_token == other_problem); 67 REQUIRE_FALSE(problem_token == not_a_problem); 68 } 69 70 SECTION("comment equality") { 71 comment comment_token(fake_origin(), "my comment"); 72 comment other_comment(fake_origin("other fake"), "my comment"); 73 comment different_comment(fake_origin(), "a different comment"); 74 ignored_whitespace not_a_comment(fake_origin(), " "); 75 76 REQUIRE(comment_token == other_comment); 77 REQUIRE_FALSE(comment_token == different_comment); 78 REQUIRE_FALSE(comment_token == not_a_comment); 79 80 // Comment comparison only deals with the actual text, not the marker 81 hash_comment hash(fake_origin(), "my comment"); 82 double_slash_comment slashes(fake_origin("other origin"), "my comment"); 83 84 REQUIRE(hash == slashes); 85 } 86 87 SECTION("substitution equality") { 88 token_list expression1; 89 expression1.push_back(make_shared<line>(fake_origin())); 90 expression1.push_back(make_shared<line>(fake_origin("other"))); 91 92 token_list expression1_dup; 93 expression1_dup.push_back(make_shared<line>(fake_origin())); 94 expression1_dup.push_back(make_shared<line>(fake_origin("other"))); 95 96 token_list expression2; 97 expression2.push_back(make_shared<line>(fake_origin())); 98 99 substitution sub(fake_origin(), false, move(expression1)); 100 substitution other_sub(fake_origin("other"), false, move(expression1_dup)); 101 substitution different_sub(fake_origin(), false, move(expression2)); 102 line not_a_sub(fake_origin("line")); 103 104 REQUIRE(sub == other_sub); 105 REQUIRE_FALSE(sub == different_sub); 106 REQUIRE_FALSE(sub == not_a_sub); 107 } 108 } 109