add test for tint::utils::ReplaceAll

The new test proves that the algorithm needs to advance 'pos'
past the replacement string.

Change-Id: Ia8fdf6b2c08d6af09e8e631c1d8661752edcb7ce
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66660
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
David Neto 2021-10-15 19:24:10 +00:00 committed by Tint LUCI CQ
parent 153f09e29c
commit 186618dfef
2 changed files with 5 additions and 1 deletions

View File

@ -23,7 +23,7 @@ namespace utils {
/// @param str the string to apply replacements to
/// @param substr the string to search for
/// @param replacement the replacement string to use instead of `substr`
/// @returns `str` with all occurrances of `substr` replaced with `replacement`
/// @returns `str` with all occurrences of `substr` replaced with `replacement`
inline std::string ReplaceAll(std::string str,
const std::string& substr,
const std::string& replacement) {

View File

@ -27,6 +27,10 @@ TEST(StringTest, ReplaceAll) {
ASSERT_EQ("xyxybbcc", ReplaceAll("aabbcc", "a", "xy"));
ASSERT_EQ("aaxyxycc", ReplaceAll("aabbcc", "b", "xy"));
ASSERT_EQ("aabbxyxy", ReplaceAll("aabbcc", "c", "xy"));
// Replacement string includes the searched-for string.
// This proves that the algorithm needs to advance 'pos'
// past the replacement.
ASSERT_EQ("aabxybbxybcc", ReplaceAll("aabbcc", "b", "bxyb"));
}
} // namespace