Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ModuleManager/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static bool Contains(this string str, string value, out int index)
if (str == null) throw new ArgumentNullException(nameof(str));
if (value == null) throw new ArgumentNullException(nameof(value));

index = str.IndexOf(value, StringComparison.CurrentCultureIgnoreCase);
index = str.IndexOf(value, StringComparison.OrdinalIgnoreCase);
return index != -1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ModuleManager/Patches/PassSpecifiers/AfterPassSpecifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public bool CheckNeeds(INeedsChecker needsChecker, IPatchProgress progress)
return result;
}

public string Descriptor => $":AFTER[{mod.ToUpper()}]";
public string Descriptor => $":AFTER[{mod.ToUpperInvariant()}]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public bool CheckNeeds(INeedsChecker needsChecker, IPatchProgress progress)
return result;
}

public string Descriptor => $":BEFORE[{mod.ToUpper()}]";
public string Descriptor => $":BEFORE[{mod.ToUpperInvariant()}]";
}
}
2 changes: 1 addition & 1 deletion ModuleManager/Patches/PassSpecifiers/ForPassSpecifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public bool CheckNeeds(INeedsChecker needsChecker, IPatchProgress progress)
return result;
}

public string Descriptor => $":FOR[{mod.ToUpper()}]";
public string Descriptor => $":FOR[{mod.ToUpperInvariant()}]";
}
}
2 changes: 1 addition & 1 deletion ModuleManager/Patches/PassSpecifiers/LastPassSpecifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public LastPassSpecifier(string mod)
}

public bool CheckNeeds(INeedsChecker needsChecker, IPatchProgress progress) => true;
public string Descriptor => $":LAST[{mod.ToUpper()}]";
public string Descriptor => $":LAST[{mod.ToUpperInvariant()}]";
}
}
16 changes: 8 additions & 8 deletions ModuleManager/Patches/ProtoPatchBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ProtoPatch Build(UrlDir.UrlConfig urlConfig, Command command, ITagList ta
if (tag.trailer != null)
progress.Warning(urlConfig, "unrecognized trailer: '" + tag.trailer + "' on: " + urlConfig.SafeUrl());

if (tag.key.Equals("NEEDS", StringComparison.CurrentCultureIgnoreCase))
if (tag.key.Equals("NEEDS", StringComparison.OrdinalIgnoreCase))
{
if (needs != null)
{
Expand All @@ -71,7 +71,7 @@ public ProtoPatch Build(UrlDir.UrlConfig urlConfig, Command command, ITagList ta

needs = tag.value;
}
else if (tag.key.Equals("HAS", StringComparison.CurrentCultureIgnoreCase))
else if (tag.key.Equals("HAS", StringComparison.OrdinalIgnoreCase))
{
if (command == Command.Insert)
{
Expand All @@ -93,7 +93,7 @@ public ProtoPatch Build(UrlDir.UrlConfig urlConfig, Command command, ITagList ta

has = tag.value;
}
else if (tag.key.Equals("FIRST", StringComparison.CurrentCultureIgnoreCase))
else if (tag.key.Equals("FIRST", StringComparison.OrdinalIgnoreCase))
{
if (tag.value != null)
{
Expand All @@ -114,7 +114,7 @@ public ProtoPatch Build(UrlDir.UrlConfig urlConfig, Command command, ITagList ta

passSpecifier = new FirstPassSpecifier();
}
else if (tag.key.Equals("BEFORE", StringComparison.CurrentCultureIgnoreCase))
else if (tag.key.Equals("BEFORE", StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(tag.value))
{
Expand All @@ -137,7 +137,7 @@ public ProtoPatch Build(UrlDir.UrlConfig urlConfig, Command command, ITagList ta

passSpecifier = new BeforePassSpecifier(tag.value, urlConfig);
}
else if (tag.key.Equals("FOR", StringComparison.CurrentCultureIgnoreCase))
else if (tag.key.Equals("FOR", StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(tag.value))
{
Expand All @@ -160,7 +160,7 @@ public ProtoPatch Build(UrlDir.UrlConfig urlConfig, Command command, ITagList ta

passSpecifier = new ForPassSpecifier(tag.value, urlConfig);
}
else if (tag.key.Equals("AFTER", StringComparison.CurrentCultureIgnoreCase))
else if (tag.key.Equals("AFTER", StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(tag.value))
{
Expand All @@ -183,7 +183,7 @@ public ProtoPatch Build(UrlDir.UrlConfig urlConfig, Command command, ITagList ta

passSpecifier = new AfterPassSpecifier(tag.value, urlConfig);
}
else if (tag.key.Equals("LAST", StringComparison.CurrentCultureIgnoreCase))
else if (tag.key.Equals("LAST", StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(tag.value))
{
Expand All @@ -206,7 +206,7 @@ public ProtoPatch Build(UrlDir.UrlConfig urlConfig, Command command, ITagList ta

passSpecifier = new LastPassSpecifier(tag.value);
}
else if (tag.key.Equals("FINAL", StringComparison.CurrentCultureIgnoreCase))
else if (tag.key.Equals("FINAL", StringComparison.OrdinalIgnoreCase))
{
if (tag.value != null)
{
Expand Down
25 changes: 25 additions & 0 deletions ModuleManagerTests/Extensions/StringExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,31 @@ public void TestContains(string str, string test, bool expectedResult, int expec
Assert.Equal(expectedIndex, index);
}

[InlineData("abc:first", ":FIRST", 3)]
[InlineData("abc:FINAL", ":final", 3)]
[InlineData("abc:Has[def]", ":HAS[", 3)]
[Theory]
public void TestContains__CaseInsensitive(string str, string test, int expectedIndex)
{
bool result = str.Contains(test, out int index);
Assert.True(result);
Assert.Equal(expectedIndex, index);
}

[InlineData("abc:first", ":FIRST", 3)]
[InlineData("abc:FINAL", ":final", 3)]
[InlineData("abc:Has[def]", ":HAS[", 3)]
[Theory]
public void TestContains__CaseInsensitive__TurkishCulture(string str, string test, int expectedIndex)
{
using (new TemporaryCulture(TemporaryCulture.TURKISH))
{
bool result = str.Contains(test, out int index);
Assert.True(result);
Assert.Equal(expectedIndex, index);
}
}

[Fact]
public void TestContains__NullStr()
{
Expand Down
1 change: 1 addition & 0 deletions ModuleManagerTests/ModuleManagerTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<Compile Include="Extensions\UrlFileExtensionsTest.cs" />
<Compile Include="InGameTestRunnerTest.cs" />
<Compile Include="LoggingAssertionHelpers.cs" />
<Compile Include="TemporaryCulture.cs" />
<Compile Include="Logging\StreamLoggerTest.cs" />
<Compile Include="Logging\UnityLoggerTest.cs" />
<Compile Include="Logging\LogSplitterTest.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,14 @@ public void TestDescriptor()
{
Assert.Equal(":AFTER[MOD1]", passSpecifier.Descriptor);
}

[Fact]
public void TestDescriptor__TurkishCulture()
{
using (new TemporaryCulture(TemporaryCulture.TURKISH))
{
Assert.Equal(":AFTER[MINI]", new AfterPassSpecifier("mini", urlConfig).Descriptor);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,14 @@ public void TestDescriptor()
{
Assert.Equal(":BEFORE[MOD1]", passSpecifier.Descriptor);
}

[Fact]
public void TestDescriptor__TurkishCulture()
{
using (new TemporaryCulture(TemporaryCulture.TURKISH))
{
Assert.Equal(":BEFORE[MINI]", new BeforePassSpecifier("mini", urlConfig).Descriptor);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,14 @@ public void TestDescriptor()
{
Assert.Equal(":FOR[MOD1]", passSpecifier.Descriptor);
}

[Fact]
public void TestDescriptor__TurkishCulture()
{
using (new TemporaryCulture(TemporaryCulture.TURKISH))
{
Assert.Equal(":FOR[MINI]", new ForPassSpecifier("mini", urlConfig).Descriptor);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,14 @@ public void TestDescriptor()
{
Assert.Equal(":LAST[MOD1]", passSpecifier.Descriptor);
}

[Fact]
public void TestDescriptor__TurkishCulture()
{
using (new TemporaryCulture(TemporaryCulture.TURKISH))
{
Assert.Equal(":LAST[MINI]", new LastPassSpecifier("mini").Descriptor);
}
}
}
}
52 changes: 52 additions & 0 deletions ModuleManagerTests/Patches/ProtoPatchBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,32 @@ public void TestBuild__First__Case2()
Assert.IsType<FirstPassSpecifier>(protoPatch.passSpecifier);
}

[Fact]
public void TestBuild__First__TurkishCulture()
{
ITagList tagList = Substitute.For<ITagList>();
tagList.PrimaryTag.Returns(new Tag("NODE", null, null));
tagList.GetEnumerator().Returns(new ArrayEnumerator<Tag>(
new Tag("first", null, null)
));

ProtoPatch protoPatch;
using (new TemporaryCulture(TemporaryCulture.TURKISH))
{
protoPatch = builder.Build(urlConfig, Command.Copy, tagList);
}

EnsureNoErrors();

Assert.Same(urlConfig, protoPatch.urlConfig);
Assert.Equal(Command.Copy, protoPatch.command);
Assert.Equal("NODE", protoPatch.nodeType);
Assert.Null(protoPatch.nodeName);
Assert.Null(protoPatch.needs);
Assert.Null(protoPatch.has);
Assert.IsType<FirstPassSpecifier>(protoPatch.passSpecifier);
}

[Fact]
public void TestBuild__Before()
{
Expand Down Expand Up @@ -610,6 +636,32 @@ public void TestBuild__Final__Case2()
Assert.IsType<FinalPassSpecifier>(protoPatch.passSpecifier);
}

[Fact]
public void TestBuild__Final__TurkishCulture()
{
ITagList tagList = Substitute.For<ITagList>();
tagList.PrimaryTag.Returns(new Tag("NODE", null, null));
tagList.GetEnumerator().Returns(new ArrayEnumerator<Tag>(
new Tag("final", null, null)
));

ProtoPatch protoPatch;
using (new TemporaryCulture(TemporaryCulture.TURKISH))
{
protoPatch = builder.Build(urlConfig, Command.Copy, tagList);
}

EnsureNoErrors();

Assert.Same(urlConfig, protoPatch.urlConfig);
Assert.Equal(Command.Copy, protoPatch.command);
Assert.Equal("NODE", protoPatch.nodeType);
Assert.Null(protoPatch.nodeName);
Assert.Null(protoPatch.needs);
Assert.Null(protoPatch.has);
Assert.IsType<FinalPassSpecifier>(protoPatch.passSpecifier);
}

[Fact]
public void TestBuild__Insert__InsertPass()
{
Expand Down
25 changes: 25 additions & 0 deletions ModuleManagerTests/TemporaryCulture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Globalization;
using System.Threading;

namespace ModuleManagerTests
{
public sealed class TemporaryCulture : IDisposable
{
// Lowercase i and uppercase I are not a case pair in this culture
public const string TURKISH = "tr-TR";

private readonly CultureInfo originalCulture;

public TemporaryCulture(string name)
{
originalCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo(name);
}

public void Dispose()
{
Thread.CurrentThread.CurrentCulture = originalCulture;
}
}
}