summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/stllike/replace_variable_test.cpp
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-04-20 08:14:28 +0000
committerArne Juul <arnej@verizonmedia.com>2020-04-20 08:20:58 +0000
commit2d8577655b5e5cbcc414330029b4c7585d6a9fa2 (patch)
tree365cae0d788fa693cf3f10bbf82e95ba485a172d /vespalib/src/tests/stllike/replace_variable_test.cpp
parent9ab0ef70e9ed4f422df67603f26bcb0c7918fdc4 (diff)
add utility for replacing a variable in a string
Diffstat (limited to 'vespalib/src/tests/stllike/replace_variable_test.cpp')
-rw-r--r--vespalib/src/tests/stllike/replace_variable_test.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/vespalib/src/tests/stllike/replace_variable_test.cpp b/vespalib/src/tests/stllike/replace_variable_test.cpp
new file mode 100644
index 00000000000..d32bf67a23d
--- /dev/null
+++ b/vespalib/src/tests/stllike/replace_variable_test.cpp
@@ -0,0 +1,24 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/vespalib/stllike/replace_variable.h>
+#include <vespa/vespalib/gtest/gtest.h>
+
+using namespace vespalib;
+
+TEST(ReplaceVariableTest, simple_usage)
+{
+ EXPECT_EQ("vv", replace_variable("x", "x", "vv"));
+ EXPECT_EQ("f(vv)", replace_variable("f(x)", "x", "vv"));
+ EXPECT_EQ("vv(f)", replace_variable("x(f)", "x", "vv"));
+ EXPECT_EQ("3*vv", replace_variable("3*x", "x", "vv"));
+ EXPECT_EQ("f(vv,vv,y)", replace_variable("f(x,x,y)", "x", "vv"));
+
+ EXPECT_EQ("f(xx)", replace_variable("f(xx)", "x", "vv"));
+ EXPECT_EQ("f(ax)", replace_variable("f(ax)", "x", "vv"));
+ EXPECT_EQ("f(xa)", replace_variable("f(xa)", "x", "vv"));
+ EXPECT_EQ("f(axa)", replace_variable("f(axa)", "x", "vv"));
+
+ EXPECT_EQ("f(vv)", replace_variable("f(x_y)", "x_y", "vv"));
+}
+
+GTEST_MAIN_RUN_ALL_TESTS()