lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] odd/mst-in-product-db ad62dfe 1/2: Demonstrate need


From: Greg Chicares
Subject: [lmi-commits] [lmi] odd/mst-in-product-db ad62dfe 1/2: Demonstrate need for double MST expansion
Date: Thu, 18 Jul 2019 10:39:46 -0400 (EDT)

branch: odd/mst-in-product-db
commit ad62dfec5ea79e9fdec60b3c1963374b52ea753b
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Demonstrate need for double MST expansion
    
    Calling interpolate_string() only once doesn't expand {{}} variables
    in its argument string, but calling it twice does do so.
---
 interpolate_string_test.cpp | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/interpolate_string_test.cpp b/interpolate_string_test.cpp
index d3f6c9f..f91f6b5 100644
--- a/interpolate_string_test.cpp
+++ b/interpolate_string_test.cpp
@@ -23,12 +23,36 @@
 
 #include "interpolate_string.hpp"
 
+#include "map_lookup.hpp"
 #include "test_tools.hpp"
 
+#include <map>
 #include <stdexcept>
 
+std::map<std::string,std::string> m =
+    {{"v0", "abc"}
+    ,{"v1", "def"}
+    ,{"v2", "{{v0}}"}
+    };
+
+std::string mst_lookup(std::string const& s, interpolate_lookup_kind k)
+{
+    if(interpolate_lookup_kind::partial == k)
+        throw std::runtime_error("MST 'partials' not supported");
+    return map_lookup(m, s);
+}
+
+std::string mst(std::string const& s)
+{
+    return interpolate_string(s.c_str(), mst_lookup);
+}
+
 int test_main(int, char*[])
 {
+    BOOST_TEST_EQUAL("_def_abc_", mst("_{{v1}}_{{v0}}_"));
+    BOOST_TEST_EQUAL(" abc ", mst(" {{v2}} ")); // This fails--must call mst() 
twice.
+    BOOST_TEST_EQUAL(" abc ", mst(mst(" {{v2}} ")));
+
     auto const test_interpolate = [](char const* s)
         {
         return interpolate_string



reply via email to

[Prev in Thread] Current Thread [Next in Thread]