-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove new dictionaryexpression and keep as snippet only (#3652)
Fixes #3471
- Loading branch information
Showing
20 changed files
with
301 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
...nt-csharp/generator/Microsoft.Generator.CSharp/src/Expressions/NewDictionaryExpression.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...arp/generator/Microsoft.Generator.CSharp/test/Expressions/NewDictionaryExpressionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.Generator.CSharp.Expressions; | ||
using NUnit.Framework; | ||
using static Microsoft.Generator.CSharp.Snippets.Snippet; | ||
|
||
|
||
namespace Microsoft.Generator.CSharp.Tests.Expressions | ||
{ | ||
public class NewDictionaryExpressionTests | ||
{ | ||
[Test] | ||
public void UseNewInstanceExpression() | ||
{ | ||
var expression = new NewInstanceExpression(typeof(Dictionary<string, int>), [], new DictionaryInitializerExpression(new Dictionary<ValueExpression, ValueExpression> | ||
{ | ||
{ Literal("x"), Literal(1) }, | ||
{ Literal("y"), Literal(2) } | ||
})); | ||
using CodeWriter writer = new(); | ||
expression.Write(writer); | ||
var actual = writer.ToString(false); | ||
Assert.AreEqual(Helpers.GetExpectedFromFile(), actual); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...sharp/generator/Microsoft.Generator.CSharp/test/Expressions/NewInstanceExpressionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.Generator.CSharp.Expressions; | ||
using NUnit.Framework; | ||
using static Microsoft.Generator.CSharp.Snippets.Snippet; | ||
|
||
namespace Microsoft.Generator.CSharp.Tests.Expressions | ||
{ | ||
internal class NewInstanceExpressionTests | ||
{ | ||
[Test] | ||
public void ValidateAnonymousSingleLine() | ||
{ | ||
using CodeWriter writer = new CodeWriter(); | ||
new NewInstanceExpression(null, [], new ObjectInitializerExpression(new Dictionary<ValueExpression, ValueExpression> | ||
{ | ||
{ Identifier("key"), Literal(1) } | ||
}, | ||
true)).Write(writer); | ||
Assert.AreEqual("new { key = 1 }", writer.ToString(false)); | ||
} | ||
|
||
[Test] | ||
public void ValidateAnonymousWithPropertiesSingleLine() | ||
{ | ||
using CodeWriter writer = new CodeWriter(); | ||
new NewInstanceExpression(null, [], new ObjectInitializerExpression(new Dictionary<ValueExpression, ValueExpression> | ||
{ | ||
{ Identifier("key"), Literal(1) }, | ||
{ Identifier("value"), Literal(2) } | ||
}, | ||
true)).Write(writer); | ||
Assert.AreEqual("new { key = 1, value = 2 }", writer.ToString(false)); | ||
} | ||
|
||
} | ||
} |
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
...CSharp/test/Expressions/TestData/NewDictionaryExpressionTests/UseNewInstanceExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
new global::System.Collections.Generic.Dictionary<string, int> | ||
{ | ||
{ "x", 1 }, | ||
{ "y", 2 } | ||
} |
Oops, something went wrong.