Commits

Matt Oswald committed bf0e13c

removed a lot of redundant functions by switching to SFINAE on std::string convertability

Comments (0)

Files changed (3)

Tests/UnitTests/Assert.Equal.cpp

     Assert.Throws<xUnitAssert>([=]() { Assert.Equal(expected, actual); });
 }
 
+FACT("const char * should be equal to char *")
+{
+    char actual[] = "hi";
+    Check.Equal("hi", actual);
+}
 
 }

xUnit++/src/xUnitAssert.cpp

     return OnSuccess();
 }
 
-xUnitFailure Assert::Equal(const char *expected, const char *actual, LineInfo &&lineInfo) const
-{
-    return Equal(std::string(expected), std::string(actual), std::move(lineInfo));
-}
-
-xUnitFailure Assert::Equal(const char *expected, const std::string &actual, LineInfo &&lineInfo) const
-{
-    return Equal(std::string(expected), actual, std::move(lineInfo));
-}
-
-xUnitFailure Assert::Equal(const std::string &expected, const char *actual, LineInfo &&lineInfo) const
-{
-    return Equal(expected, std::string(actual), std::move(lineInfo));
-}
-
 xUnitFailure Assert::Equal(float expected, float actual, int precision, LineInfo &&lineInfo) const
 {
     return Equal((double)expected, (double)actual, precision, std::move(lineInfo));
     return OnSuccess();
 }
 
-xUnitFailure Assert::NotEqual(const char *expected, const char *actual, LineInfo &&lineInfo) const
-{
-    return NotEqual(std::string(expected), std::string(actual), std::move(lineInfo));
-}
-
-xUnitFailure Assert::NotEqual(const char *expected, const std::string &actual, LineInfo &&lineInfo) const
-{
-    return NotEqual(std::string(expected), actual, std::move(lineInfo));
-}
-
-xUnitFailure Assert::NotEqual(const std::string &expected, const char *actual, LineInfo &&lineInfo) const
-{
-    return NotEqual(expected, std::string(actual), std::move(lineInfo));
-}
-
 xUnitFailure Assert::Fail(LineInfo &&lineInfo) const
 {
     return OnFailure(std::move(xUnitAssert(callPrefix + "Fail", std::move(lineInfo))));
     return OnSuccess();
 }
 
-xUnitFailure Assert::DoesNotContain(const char *actualString, const char *value, LineInfo &&lineInfo) const
-{
-    const auto a = std::string(actualString);
-    const auto v = std::string(value);
-    return DoesNotContain(a, v, std::move(lineInfo));
-}
-
-xUnitFailure Assert::DoesNotContain(const char *actualString, const std::string &value, LineInfo &&lineInfo) const
-{
-    const auto a = std::string(actualString);
-    return DoesNotContain(a, value, std::move(lineInfo));
-}
-
-xUnitFailure Assert::DoesNotContain(const std::string &actualString, const char *value, LineInfo &&lineInfo) const
-{
-    const auto v = std::string(value);
-    return DoesNotContain(actualString, v, std::move(lineInfo));
-}
-
 xUnitFailure Assert::DoesNotContain(const std::string &actualString, const std::string &value, LineInfo &&lineInfo) const
 {
     auto found = actualString.find(value);
     return OnSuccess();
 }
 
-xUnitFailure Assert::Contains(const char *actualString, const char *value, LineInfo &&lineInfo) const
-{
-    const auto a = std::string(actualString);
-    const auto v = std::string(value);
-    return Contains(a, v, std::move(lineInfo));
-}
-
-xUnitFailure Assert::Contains(const char *actualString, const std::string &value, LineInfo &&lineInfo) const
-{
-    const auto a = std::string(actualString);
-    return Contains(a, value, std::move(lineInfo));
-}
-
-xUnitFailure Assert::Contains(const std::string &actualString, const char *value, LineInfo &&lineInfo) const
-{
-    const auto v = std::string(value);
-    return Contains(actualString, v, std::move(lineInfo));
-}
-
 xUnitFailure Assert::Contains(const std::string &actualString, const std::string &value, LineInfo &&lineInfo) const
 {
     if (actualString.find(value) == std::string::npos)

xUnit++/xUnit++/xUnitAssert.h

     static double round(double value, size_t precision);
 
     template<typename T>
-    static std::string RangeToString(T &&begin, T &&end)
+    static std::string RangeToString(T begin, T end)
     {
         typedef decltype(*begin) val_type;
 
         std::string result = "[ ";
 
-        std::for_each(std::forward<T>(begin), std::forward<T>(end), [&result](val_type &&val) { result += ToString(std::forward<val_type>(val)) + ", "; });
+        std::for_each(std::forward<T>(begin), std::forward<T>(end), [&result](val_type val) { result += ToString(std::forward<val_type>(val)) + ", "; });
 
         result[result.size() - 2] = ' ';
         result[result.size() - 1] = ']';
     }
 
     template<typename TExpected, typename TActual>
-    xUnitFailure Equal(TExpected expected, TActual actual, LineInfo &&lineInfo = LineInfo()) const
+    typename std::enable_if<
+        !std::is_constructible<std::string, TExpected>::value || !std::is_constructible<std::string, TActual>::value,
+        xUnitFailure>::type Equal(TExpected expected, TActual actual, LineInfo &&lineInfo = LineInfo()) const
     {
         return Equal(std::forward<TExpected>(expected), std::forward<TActual>(actual), [](TExpected &&expected, TActual &&actual) { return expected == actual; }, std::move(lineInfo));
     }
 
-    xUnitFailure Equal(const char *expected, const char *actual, LineInfo &&lineInfo = LineInfo()) const;
-    xUnitFailure Equal(const char *expected, const std::string &actual, LineInfo &&lineInfo = LineInfo()) const;
-    xUnitFailure Equal(const std::string &expected, const char *actual, LineInfo &&lineInfo = LineInfo()) const;
+    template<typename TExpected, typename TActual>
+    typename std::enable_if<
+        std::is_constructible<std::string, TExpected>::value && std::is_constructible<std::string, TActual>::value,
+        xUnitFailure>::type Equal(TExpected expected, TActual actual, LineInfo &&lineInfo = LineInfo()) const
+    {
+        return Equal(std::string(std::forward<TExpected>(expected)), std::string(std::forward<TActual>(actual)), std::move(lineInfo));
+    }
+
     xUnitFailure Equal(const std::string &expected, const std::string &actual, LineInfo &&lineInfo = LineInfo()) const;
+
     xUnitFailure Equal(float expected, float actual, int precision, LineInfo &&lineInfo = LineInfo()) const;
     xUnitFailure Equal(double expected, double actual, int precision, LineInfo &&lineInfo = LineInfo()) const;
 
     }
 
     template<typename TExpected, typename TActual>
-    xUnitFailure NotEqual(TExpected expected, TActual actual, LineInfo &&lineInfo = LineInfo()) const
+    typename std::enable_if<
+        !std::is_constructible<std::string, TExpected>::value || !std::is_constructible<std::string, TActual>::value,
+        xUnitFailure>::type NotEqual(TExpected expected, TActual actual, LineInfo &&lineInfo = LineInfo()) const
     {
         return NotEqual(std::forward<TExpected>(expected), std::forward<TActual>(actual), [](TExpected &&expected, TActual &&actual) { return expected == actual; }, std::move(lineInfo));
     }
 
-    xUnitFailure NotEqual(const char *expected, const char *actual, LineInfo &&lineInfo = LineInfo()) const;
-    xUnitFailure NotEqual(const char *expected, const std::string &actual, LineInfo &&lineInfo = LineInfo()) const;
-    xUnitFailure NotEqual(const std::string &expected, const char *actual, LineInfo &&lineInfo = LineInfo()) const;
+    template<typename TExpected, typename TActual>
+    typename std::enable_if<
+        std::is_constructible<std::string, TExpected>::value && std::is_constructible<std::string, TActual>::value,
+        xUnitFailure>::type NotEqual(TExpected expected, TActual actual, LineInfo &&lineInfo = LineInfo()) const
+    {
+        return NotEqual(std::string(std::forward<TExpected>(expected)), std::string(std::forward<TActual>(actual)), std::move(lineInfo));
+    }
+
     xUnitFailure NotEqual(const std::string &expected, const std::string &actual, LineInfo &&lineInfo = LineInfo()) const;
 
     template<typename TExpected, typename TActual, typename TComparer>
     }
 
     template<typename TSequence, typename T>
-    xUnitFailure DoesNotContain(const TSequence &sequence, T &&value, LineInfo &&lineInfo = LineInfo()) const
+    typename std::enable_if<
+        !std::is_constructible<std::string, TSequence>::value || !std::is_constructible<std::string, T>::value,
+        xUnitFailure
+    >::type DoesNotContain(const TSequence &sequence, T &&value, LineInfo &&lineInfo = LineInfo()) const
     {
         using std::begin;
         using std::end;
         return OnSuccess();
     }
 
-    xUnitFailure DoesNotContain(const char *actualString, const char *value, LineInfo &&lineInfo = LineInfo()) const;
-    xUnitFailure DoesNotContain(const char *actualString, const std::string &value, LineInfo &&lineInfo = LineInfo()) const;
-    xUnitFailure DoesNotContain(const std::string &actualString, const char *value, LineInfo &&lineInfo = LineInfo()) const;
+    template<typename TActualString, typename TValueString>
+    typename std::enable_if<
+        std::is_constructible<std::string, TActualString>::value && std::is_constructible<std::string, TValueString>::value,
+        xUnitFailure
+    >::type DoesNotContain(TActualString actualString, TValueString value, LineInfo &&lineInfo = LineInfo()) const
+    {
+        return DoesNotContain(std::string(std::forward<TActualString>(actualString)), std::string(std::forward<TValueString>(value)), std::move(lineInfo));
+    }
+
     xUnitFailure DoesNotContain(const std::string &actualString, const std::string &value, LineInfo &&lineInfo = LineInfo()) const;
 
     template<typename TSequence, typename TPredicate>
     }
 
     template<typename TSequence, typename T>
-    xUnitFailure Contains(const TSequence &sequence, T &&value, LineInfo &&lineInfo = LineInfo()) const
+    typename std::enable_if<
+        !std::is_constructible<std::string, TSequence>::value || !std::is_constructible<std::string, T>::value,
+        xUnitFailure
+    >::type Contains(const TSequence &sequence, T &&value, LineInfo &&lineInfo = LineInfo()) const
     {
         using std::begin;
         using std::end;
         return OnSuccess();
     }
 
-    xUnitFailure Contains(const char *actualString, const char *value, LineInfo &&lineInfo = LineInfo()) const;
-    xUnitFailure Contains(const char *actualString, const std::string &value, LineInfo &&lineInfo = LineInfo()) const;
-    xUnitFailure Contains(const std::string &actualString, const char *value, LineInfo &&lineInfo = LineInfo()) const;
+    template<typename TActualString, typename TValueString>
+    typename std::enable_if<
+        std::is_constructible<std::string, TActualString>::value && std::is_constructible<std::string, TValueString>::value,
+        xUnitFailure
+    >::type Contains(TActualString actualString, TValueString value, LineInfo &&lineInfo = LineInfo()) const
+    {
+        return Contains(std::string(std::forward<TActualString>(actualString)), std::string(std::forward<TValueString>(value)), std::move(lineInfo));
+    }
+
     xUnitFailure Contains(const std::string &actualString, const std::string &value, LineInfo &&lineInfo = LineInfo()) const;
 
     template<typename TActual, typename TRange>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.