2023-03-17 14:51:08 +00:00
|
|
|
#include "references.hh"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
struct RewriteParams {
|
|
|
|
string originalString, finalString;
|
|
|
|
StringMap rewrites;
|
|
|
|
|
|
|
|
friend std::ostream& operator<<(std::ostream& os, const RewriteParams& bar) {
|
|
|
|
StringSet strRewrites;
|
|
|
|
for (auto & [from, to] : bar.rewrites)
|
|
|
|
strRewrites.insert(from + "->" + to);
|
|
|
|
return os <<
|
|
|
|
"OriginalString: " << bar.originalString << std::endl <<
|
|
|
|
"Rewrites: " << concatStringsSep(",", strRewrites) << std::endl <<
|
|
|
|
"Expected result: " << bar.finalString;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class RewriteTest : public ::testing::TestWithParam<RewriteParams> {
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(RewriteTest, IdentityRewriteIsIdentity) {
|
|
|
|
RewriteParams param = GetParam();
|
2024-05-01 23:25:46 +00:00
|
|
|
StringSource src{param.originalString};
|
|
|
|
ASSERT_EQ(RewritingSource(param.rewrites, src).drain(), param.finalString);
|
2023-03-17 14:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
references,
|
|
|
|
RewriteTest,
|
|
|
|
::testing::Values(
|
|
|
|
RewriteParams{ "foooo", "baroo", {{"foo", "bar"}, {"bar", "baz"}}},
|
|
|
|
RewriteParams{ "foooo", "bazoo", {{"fou", "bar"}, {"foo", "baz"}}},
|
2024-05-01 23:25:46 +00:00
|
|
|
RewriteParams{ "foooo", "foooo", {}},
|
|
|
|
RewriteParams{ "babb", "bbbb", {{"ab", "aa"}, {"babb", "bbbb"}}}
|
2023-03-17 14:51:08 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|