Skip to content

Commit

Permalink
Merge pull request #43569 from zaytsev-victor/Fixes43267
Browse files Browse the repository at this point in the history
Enable DateTime completion in string interpolation format strings.
  • Loading branch information
CyrusNajmabadi authored Jun 23, 2020
2 parents 16bd662 + 45588cc commit 4129ecb
Show file tree
Hide file tree
Showing 10 changed files with 537 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,235 @@ class c
End If
End Using
End Function

<WpfTheory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function ExplicitInvoke_StringInterpolation1(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
using System;
class c
{
void goo(DateTime d)
{
_ = $"Text {d:$$}";
}
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendInvokeCompletionList()
Await state.AssertSelectedCompletionItem("G", inlineDescription:=FeaturesResources.general_long_date_time)
state.SendTab()
Await state.AssertNoCompletionSession()
Assert.Contains("_ = $""Text {d:G}""", state.GetLineTextFromCaretPosition(), StringComparison.Ordinal)
End Using
End Function

<WpfTheory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function ExplicitInvoke_StringInterpolation2(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
using System;
class c
{
void goo(DateTime d)
{
_ = @$"Text {d:$$}";
}
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendInvokeCompletionList()
Await state.AssertSelectedCompletionItem("G", inlineDescription:=FeaturesResources.general_long_date_time)
state.SendTab()
Await state.AssertNoCompletionSession()
Assert.Contains("_ = @$""Text {d:G}""", state.GetLineTextFromCaretPosition(), StringComparison.Ordinal)
End Using
End Function

<WpfTheory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function ExplicitInvoke_OverwriteExisting_StringInterpolation1(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
using System;
class c
{
void goo(DateTime d)
{
_ = $"Text {d:ff$$}";
}
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendInvokeCompletionList()
Await state.AssertSelectedCompletionItem("ff")
state.SendDownKey()
Await state.AssertSelectedCompletionItem("FF")
state.SendTab()
Await state.AssertNoCompletionSession()
Assert.Contains("_ = $""Text {d:FF}""", state.GetLineTextFromCaretPosition(), StringComparison.Ordinal)
End Using
End Function

<WpfTheory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function ExplicitInvoke_OverwriteExisting_StringInterpolation2(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
using System;
class c
{
void goo(DateTime d)
{
_ = @$"Text {d:ff$$}";
}
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendInvokeCompletionList()
Await state.AssertSelectedCompletionItem("ff")
state.SendDownKey()
Await state.AssertSelectedCompletionItem("FF")
state.SendTab()
Await state.AssertNoCompletionSession()
Assert.Contains("_ = @$""Text {d:FF}""", state.GetLineTextFromCaretPosition(), StringComparison.Ordinal)
End Using
End Function

<WpfTheory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TypeChar_BeginningOfWord_StringInterpolation1(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
using System;
class c
{
void goo(DateTime d)
{
_ = $"Text {d:$$}";
}
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendTypeChars("f")
Await state.AssertCompletionSession()
Await state.AssertSelectedCompletionItem("f")
End Using
End Function

<WpfTheory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TypeChar_BeginningOfWord_StringInterpolation2(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
using System;
class c
{
void goo(DateTime d)
{
_ = $@"Text {d:$$}";
}
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendTypeChars("f")
Await state.AssertCompletionSession()
Await state.AssertSelectedCompletionItem("f")
End Using
End Function

<WpfTheory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TestExample1_StringInterpolation1(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
using System;
class c
{
void goo(DateTime d)
{
_ = $"Text {d:hh:mm:$$}";
}
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendInvokeCompletionList()
state.SendTypeChars("ss")
Await state.AssertSelectedCompletionItem("ss", inlineDescription:=FeaturesResources.second_2_digits)

Dim description = Await state.GetSelectedItemDescriptionAsync()
Dim text = description.Text

If CultureInfo.CurrentCulture.Name <> "en-US" Then
Assert.Contains($"hh:mm:ss (en-US) → 01:45:30", text)
Assert.Contains($"hh:mm:ss ({CultureInfo.CurrentCulture.Name}) → 01:45:30", text)
Else
Assert.Contains("hh:mm:ss → 01:45:30", text)
End If
End Using
End Function

<WpfTheory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TestExample1_StringInterpolation2(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
using System;
class c
{
void goo(DateTime d)
{
_ = @$"Text {d:hh:mm:$$}";
}
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendInvokeCompletionList()
state.SendTypeChars("ss")
Await state.AssertSelectedCompletionItem("ss", inlineDescription:=FeaturesResources.second_2_digits)

Dim description = Await state.GetSelectedItemDescriptionAsync()
Dim text = description.Text

If CultureInfo.CurrentCulture.Name <> "en-US" Then
Assert.Contains($"hh:mm:ss (en-US) → 01:45:30", text)
Assert.Contains($"hh:mm:ss ({CultureInfo.CurrentCulture.Name}) → 01:45:30", text)
Else
Assert.Contains("hh:mm:ss → 01:45:30", text)
End If
End Using
End Function

<WpfTheory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TypeChar_MiddleOfWord_StringInterpolation1(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
using System;
class c
{
void goo(DateTime d)
{
_ = $"Text {date:f$$}";
}
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendTypeChars("f")
Await state.AssertNoCompletionSession()
End Using
End Function

<WpfTheory, CombinatorialData, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TypeChar_MiddleOfWord_StringInterpolation2(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
using System;
class c
{
void goo(DateTime d)
{
_ = @$"Text {date:f$$}";
}
}
]]></Document>, showCompletionInArgumentLists:=showCompletionInArgumentLists)

state.SendTypeChars("f")
Await state.AssertNoCompletionSession()
End Using
End Function
End Class
End Namespace
Loading

0 comments on commit 4129ecb

Please sign in to comment.