Skip to content

Commit

Permalink
Add Test
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Jun 11, 2024
1 parent 204ed48 commit 11e4d99
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ class TestPreprocessor : public TestFixture {
TEST_CASE(testMissingIncludeCheckConfig);

TEST_CASE(limitsDefines);

TEST_CASE(hashCalculation);
}

std::string getConfigsStr(const char filedata[], const char *arg = nullptr) {
Expand All @@ -284,6 +286,16 @@ class TestPreprocessor : public TestFixture {
return ret;
}

std::size_t getHash(const char filedata[]) {
Settings settings;
Preprocessor preprocessor(settings, *this);
std::vector<std::string> files;
std::istringstream istr(filedata);
simplecpp::TokenList tokens(istr,files);
tokens.removeComments();
return preprocessor.calculateHash(tokens, "");
}

void Bug2190219() {
const char filedata[] = "#ifdef __cplusplus\n"
"cpp\n"
Expand Down Expand Up @@ -2510,6 +2522,20 @@ class TestPreprocessor : public TestFixture {
"if ( l > $2147483647 ) { }\n"
"}", actual);
}

void hashCalculation() {
// #12383
const char code[] = "int a;";
const char code2[] = "int a;"; // extra space
const char code3[] = "\n\nint a;"; // extra new line

ASSERT_EQUALS(getHash(code), getHash(code));
ASSERT_EQUALS(getHash(code2), getHash(code2));
ASSERT_EQUALS(getHash(code3), getHash(code3));
ASSERT(getHash(code) != getHash(code2));
ASSERT(getHash(code) != getHash(code3));
ASSERT(getHash(code2) != getHash(code3));
}
};

REGISTER_TEST(TestPreprocessor)

0 comments on commit 11e4d99

Please sign in to comment.