mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-04 20:25:56 +00:00
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:
parent
153f09e29c
commit
186618dfef
@ -23,7 +23,7 @@ namespace utils {
|
|||||||
/// @param str the string to apply replacements to
|
/// @param str the string to apply replacements to
|
||||||
/// @param substr the string to search for
|
/// @param substr the string to search for
|
||||||
/// @param replacement the replacement string to use instead of `substr`
|
/// @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,
|
inline std::string ReplaceAll(std::string str,
|
||||||
const std::string& substr,
|
const std::string& substr,
|
||||||
const std::string& replacement) {
|
const std::string& replacement) {
|
||||||
|
@ -27,6 +27,10 @@ TEST(StringTest, ReplaceAll) {
|
|||||||
ASSERT_EQ("xyxybbcc", ReplaceAll("aabbcc", "a", "xy"));
|
ASSERT_EQ("xyxybbcc", ReplaceAll("aabbcc", "a", "xy"));
|
||||||
ASSERT_EQ("aaxyxycc", ReplaceAll("aabbcc", "b", "xy"));
|
ASSERT_EQ("aaxyxycc", ReplaceAll("aabbcc", "b", "xy"));
|
||||||
ASSERT_EQ("aabbxyxy", ReplaceAll("aabbcc", "c", "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
|
} // namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user