mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Basic] Add a utility function for parsing an editor placeholder.
Swift SVN r26214
This commit is contained in:
54
unittests/Basic/EditorPlaceholderTest.cpp
Normal file
54
unittests/Basic/EditorPlaceholderTest.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "swift/Basic/EditorPlaceholder.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace swift;
|
||||
|
||||
TEST(EditorPlaceholder, EditorPlaceholders) {
|
||||
const char *Text = "<#this is simple#>";
|
||||
EditorPlaceholderData Data = *parseEditorPlaceholder(Text);
|
||||
EXPECT_EQ(EditorPlaceholderKind::Basic, Data.Kind);
|
||||
EXPECT_EQ("this is simple", Data.Display);
|
||||
EXPECT_TRUE(Data.Type.empty());
|
||||
EXPECT_TRUE(Data.TypeForExpansion.empty());
|
||||
|
||||
Text = "<#T##x: Int##Int#>";
|
||||
Data = *parseEditorPlaceholder(Text);
|
||||
EXPECT_EQ(EditorPlaceholderKind::Typed, Data.Kind);
|
||||
EXPECT_EQ("x: Int", Data.Display);
|
||||
EXPECT_EQ("Int", Data.Type);
|
||||
EXPECT_EQ("Int", Data.TypeForExpansion);
|
||||
|
||||
Text = "<#T##x: Int##Blah##()->Int#>";
|
||||
Data = *parseEditorPlaceholder(Text);
|
||||
EXPECT_EQ(EditorPlaceholderKind::Typed, Data.Kind);
|
||||
EXPECT_EQ("x: Int", Data.Display);
|
||||
EXPECT_EQ("Blah", Data.Type);
|
||||
EXPECT_EQ("()->Int", Data.TypeForExpansion);
|
||||
|
||||
// Fallback.
|
||||
Text = "<#T##x: Int#>";
|
||||
Data = *parseEditorPlaceholder(Text);
|
||||
EXPECT_EQ(EditorPlaceholderKind::Basic, Data.Kind);
|
||||
EXPECT_EQ("T##x: Int", Data.Display);
|
||||
EXPECT_TRUE(Data.Type.empty());
|
||||
EXPECT_TRUE(Data.TypeForExpansion.empty());
|
||||
}
|
||||
|
||||
TEST(EditorPlaceholder, InvalidEditorPlaceholders) {
|
||||
const char *Text = "<#foo";
|
||||
Optional<EditorPlaceholderData> DataOpt = parseEditorPlaceholder(Text);
|
||||
EXPECT_FALSE(DataOpt.hasValue());
|
||||
|
||||
Text = "foo#>";
|
||||
DataOpt = parseEditorPlaceholder(Text);
|
||||
EXPECT_FALSE(DataOpt.hasValue());
|
||||
|
||||
Text = "#foo#>";
|
||||
DataOpt = parseEditorPlaceholder(Text);
|
||||
EXPECT_FALSE(DataOpt.hasValue());
|
||||
|
||||
Text = " <#foo#>";
|
||||
DataOpt = parseEditorPlaceholder(Text);
|
||||
EXPECT_FALSE(DataOpt.hasValue());
|
||||
}
|
||||
Reference in New Issue
Block a user