-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feedback (added extension method to format string with double quotes)
- Loading branch information
Kartheek Penagamuri
committed
Oct 21, 2022
1 parent
fcd3951
commit 43e303d
Showing
3 changed files
with
50 additions
and
2 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
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,13 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace NuGet.Common | ||
{ | ||
internal static class StringExtensions | ||
{ | ||
internal static string FormatWithDoubleQuotes(this string s) | ||
{ | ||
return s == null ? s : $@"""{s}"""; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
test/NuGet.Core.Tests/NuGet.Common.Test/StringExtensionsTests.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,35 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace NuGet.Common.Test | ||
{ | ||
public class StringExtensionsTests | ||
{ | ||
[Fact] | ||
public void FormatWithDoubleQuotes_WhenNullIsPassedReturnsNull_Success() | ||
{ | ||
string actual = null; | ||
string formatted = actual.FormatWithDoubleQuotes(); | ||
Assert.Equal(actual, formatted); | ||
} | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData("/home/user/NuGet AppData/share")] | ||
[InlineData("/home/user/NuGet/share")] | ||
[InlineData(@"c:\users\NuGet App\Share")] | ||
[InlineData(@"c:\users\NuGet\Share")] | ||
public void FormatWithDoubleQuotes_WhenNonNullStringIsPassedReturnsFormattedString_Success(string actual) | ||
{ | ||
string formatted = actual.FormatWithDoubleQuotes(); | ||
Assert.Equal($@"""{actual}""", formatted); | ||
} | ||
} | ||
} |