Skip to content

Commit 7c3e4a0

Browse files
committed
Add tests for all current BCL cultures, and expand parser to support three-letter locales
1 parent 8a7671f commit 7c3e4a0

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/NuGet.Core/NuGet.Packaging/ContentModel/ManagedCodeConventions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private static object CodeLanguage_Parser(string name, PatternTable table)
148148
return name;
149149
}
150150

151-
private static object Locale_Parser(string name, PatternTable table)
151+
internal static object Locale_Parser(string name, PatternTable table)
152152
{
153153
if (table != null)
154154
{
@@ -161,7 +161,8 @@ private static object Locale_Parser(string name, PatternTable table)
161161

162162
// We use a heuristic here for common locale codes. Locale codes are often
163163
// * two characters for the language: en, es, fr, de
164-
if (name.Length == 2)
164+
// * three characters for the language: agq
165+
if (name.Length == 2 || name.Length == 3)
165166
{
166167
return name;
167168
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using System.Globalization;
6+
using System.Linq;
7+
using Xunit;
8+
9+
namespace NuGet.Client.Test
10+
{
11+
public class ContentModelResourceTests
12+
{
13+
[MemberData(nameof(AllCultures))]
14+
[Theory]
15+
public void CanParseEverySystemKnownCultureResource(CultureInfo culture)
16+
{
17+
var result = ManagedCodeConventions.Locale_Parser(culture.Name, null);
18+
Assert.Equal(culture.Name, result as string);
19+
}
20+
21+
public static IEnumerable<object[]> AllCultures()
22+
{
23+
return CultureInfo.GetCultures(CultureTypes.AllCultures).Where(c => !string.IsNullOrEmpty(c.Name)).Select(culture => new[] { culture });
24+
}
25+
}
26+
}
27+

0 commit comments

Comments
 (0)