Author: zturner Date: Sat Aug 27 11:35:15 2016 New Revision: 279919 URL: http://llvm.org/viewvc/llvm-project?rev=279919&view=rev Log: Add some unit tests for StringExtractor::GetNameColonValue.
These are helpful on their own, but will be even more useful once the GetNameColonValue is updated to return StringRefs instead of std::strings. Modified: lldb/trunk/unittests/Utility/StringExtractorTest.cpp Modified: lldb/trunk/unittests/Utility/StringExtractorTest.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/StringExtractorTest.cpp?rev=279919&r1=279918&r2=279919&view=diff ============================================================================== --- lldb/trunk/unittests/Utility/StringExtractorTest.cpp (original) +++ lldb/trunk/unittests/Utility/StringExtractorTest.cpp Sat Aug 27 11:35:15 2016 @@ -403,4 +403,57 @@ TEST_F (StringExtractorTest, GetHexBytes ASSERT_EQ('2', *ex.Peek()); } +TEST_F(StringExtractorTest, GetNameColonValueSuccess) +{ + const char kNameColonPairs[] = "key1:value1;key2:value2;"; + StringExtractor ex(kNameColonPairs); + std::string name; + std::string value; + EXPECT_TRUE(ex.GetNameColonValue(name, value)); + EXPECT_EQ("key1", name); + EXPECT_EQ("value1", value); + EXPECT_TRUE(ex.GetNameColonValue(name, value)); + EXPECT_EQ("key2", name); + EXPECT_EQ("value2", value); + EXPECT_EQ(0, ex.GetBytesLeft()); +} + + +TEST_F(StringExtractorTest, GetNameColonValueContainsColon) +{ + const char kNameColonPairs[] = "key1:value1:value2;key2:value3;"; + StringExtractor ex(kNameColonPairs); + + std::string name; + std::string value; + EXPECT_TRUE(ex.GetNameColonValue(name, value)); + EXPECT_EQ("key1", name); + EXPECT_EQ("value1:value2", value); + EXPECT_TRUE(ex.GetNameColonValue(name, value)); + EXPECT_EQ("key2", name); + EXPECT_EQ("value3", value); + EXPECT_EQ(0, ex.GetBytesLeft()); +} + +TEST_F(StringExtractorTest, GetNameColonValueNoSemicolon) +{ + const char kNameColonPairs[] = "key1:value1"; + StringExtractor ex(kNameColonPairs); + + std::string name; + std::string value; + EXPECT_FALSE(ex.GetNameColonValue(name, value)); + EXPECT_EQ(0, ex.GetBytesLeft()); +} + +TEST_F(StringExtractorTest, GetNameColonValueNoColon) +{ + const char kNameColonPairs[] = "key1value1;"; + StringExtractor ex(kNameColonPairs); + + std::string name; + std::string value; + EXPECT_FALSE(ex.GetNameColonValue(name, value)); + EXPECT_EQ(0, ex.GetBytesLeft()); +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits