Index: runtime/vm/assert.h |
=================================================================== |
--- runtime/vm/assert.h (revision 2528) |
+++ runtime/vm/assert.h (working copy) |
@@ -49,6 +49,9 @@ |
void StringEquals(const E& expected, const A& actual); |
template<typename E, typename A> |
+ void IsSubstring(const E& needle, const A& haystack); |
+ |
+ template<typename E, typename A> |
void LessThan(const E& left, const A& right); |
template<typename E, typename A> |
@@ -140,6 +143,18 @@ |
template<typename E, typename A> |
+void DynamicAssertionHelper::IsSubstring(const E& needle, const A& haystack) { |
+ std::stringstream ess, ass; |
+ ess << needle; |
+ ass << haystack; |
+ std::string es = ess.str(), as = ass.str(); |
+ if (as.find(es) != std::string::npos) return; |
+ Fail("expected <\"%s\"> to be a substring of <\"%s\">", |
+ es.c_str(), as.c_str()); |
+} |
+ |
+ |
+template<typename E, typename A> |
void DynamicAssertionHelper::LessThan(const E& left, const A& right) { |
if (left < right) return; |
std::stringstream ess, ass; |
@@ -248,6 +263,9 @@ |
#define EXPECT_STREQ(expected, actual) \ |
dart::Expect(__FILE__, __LINE__).StringEquals((expected), (actual)) |
+#define EXPECT_SUBSTRING(needle, haystack) \ |
+ dart::Expect(__FILE__, __LINE__).IsSubstring((needle), (haystack)) |
+ |
#define EXPECT_LT(left, right) \ |
dart::Expect(__FILE__, __LINE__).LessThan((left), (right)) |