MCPcopy Create free account
hub / github.com/Kitware/CMake / testMethod_substr_AtStart

Function testMethod_substr_AtStart

Tests/CMakeLib/testString.cxx:803–848  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

801}
802
803static bool testMethod_substr_AtStart(cm::String str)
804{
805 {
806 cm::String substr = str.substr(0, 2);
807 ASSERT_TRUE(substr.data() == str.data());
808 ASSERT_TRUE(substr.size() == 2);
809
810 // c_str() not at the end of the buffer internally mutates.
811 char const* substr_c = substr.c_str();
812 ASSERT_TRUE(std::strcmp(substr_c, "ab") == 0);
813 ASSERT_TRUE(substr_c != str.data());
814 ASSERT_TRUE(substr.data() != str.data());
815 ASSERT_TRUE(substr.size() == 2);
816 ASSERT_TRUE(substr.is_stable());
817
818 // str() does not need to internally mutate after c_str() did so
819 ASSERT_TRUE(substr.str() == "ab");
820 ASSERT_TRUE(substr.is_stable());
821 ASSERT_TRUE(substr.data() == substr_c);
822 ASSERT_TRUE(substr.size() == 2);
823 ASSERT_TRUE(substr.c_str() == substr_c);
824 }
825
826 {
827 cm::String substr = str.substr(0, 2);
828 ASSERT_TRUE(substr.data() == str.data());
829 ASSERT_TRUE(substr.size() == 2);
830 ASSERT_TRUE(!substr.is_stable());
831
832 // str() internally mutates.
833 ASSERT_TRUE(substr.str() == "ab");
834 ASSERT_TRUE(substr.is_stable());
835 ASSERT_TRUE(substr.data() != str.data());
836 ASSERT_TRUE(substr.size() == 2);
837 ASSERT_TRUE(substr.c_str() != str.data());
838
839 // c_str() does not internally after str() did so
840 char const* substr_c = substr.c_str();
841 ASSERT_TRUE(std::strcmp(substr_c, "ab") == 0);
842 ASSERT_TRUE(substr_c == substr.data());
843 ASSERT_TRUE(substr.size() == 2);
844 ASSERT_TRUE(substr.is_stable());
845 }
846
847 return true;
848}
849
850static bool testMethod_substr_AtStartBorrowed()
851{

Calls 6

c_strMethod · 0.80
is_stableMethod · 0.80
strMethod · 0.80
substrMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…