Skip to content

Commit

Permalink
Move to NUnit 4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ygg01 committed Dec 31, 2023
1 parent 0f1b0b3 commit 4ff788e
Show file tree
Hide file tree
Showing 23 changed files with 222 additions and 208 deletions.
1 change: 1 addition & 0 deletions Linguini.Bench/Linguini.Bench.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="NUnit" Version="4.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 3 additions & 9 deletions Linguini.Bundle.Test/Linguini.Bundle.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<TargetFrameworks>netstandard2.1;net6.0</TargetFrameworks>
<OutputType>Library</OutputType>
<PackageVersion>0.7.0</PackageVersion>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="YamlDotNet" Version="11.0.1" />
</ItemGroup>
Expand All @@ -24,10 +24,4 @@
<AdditionalFiles Include="..\PluralRules.Generator\cldr_data\ordinals.xml" />
<AdditionalFiles Include="..\PluralRules.Generator\cldr_data\plurals.xml" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="IndexRange" Version="1.0.2" PrivateAssets="all" />
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
<PackageReference Include="System.Memory" Version="4.5.4" PrivateAssets="all" />
</ItemGroup>
</Project>
89 changes: 45 additions & 44 deletions Linguini.Bundle.Test/Unit/BundleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Linguini.Bundle.Types;
using Linguini.Shared.Types.Bundle;
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace Linguini.Bundle.Test.Unit
{
Expand Down Expand Up @@ -48,11 +49,11 @@ public void TestDefaultBundleOptions()
{
var defaultBundleOpt = new FluentBundleOption();
var bundle = FluentBundle.MakeUnchecked(defaultBundleOpt);
Assert.AreEqual(CultureInfo.CurrentCulture, bundle.Culture);
Assert.IsNull(bundle.FormatterFunc);
Assert.IsNull(bundle.TransformFunc);
Assert.IsTrue(bundle.UseIsolating);
Assert.AreEqual(100, bundle.MaxPlaceable);
Assert.That(CultureInfo.CurrentCulture, Is.EqualTo(bundle.Culture));
Assert.That(bundle.FormatterFunc, Is.Null);
Assert.That(bundle.TransformFunc, Is.Null);
Assert.That(bundle.UseIsolating);
Assert.That(100, Is.EqualTo(bundle.MaxPlaceable));
}

[Test]
Expand All @@ -72,15 +73,15 @@ public void TestNonDefaultBundleOptions()
}
};
var bundle = FluentBundle.MakeUnchecked(defaultBundleOpt);
Assert.AreEqual(new CultureInfo("en"), bundle.Culture);
Assert.AreEqual(defaultBundleOpt.FormatterFunc, bundle.FormatterFunc);
Assert.AreEqual(defaultBundleOpt.TransformFunc, bundle.TransformFunc);
Assert.AreEqual(defaultBundleOpt.UseIsolating, bundle.UseIsolating);
Assert.AreEqual(defaultBundleOpt.MaxPlaceable, bundle.MaxPlaceable);
Assert.IsTrue(bundle.TryGetFunction("zero", out var zero));
Assert.AreEqual(_zeroFunc, zero?.Function);
Assert.IsTrue(bundle.TryGetFunction("id", out var id));
Assert.AreEqual(_idFunc, id?.Function);
Assert.That(new CultureInfo("en"), Is.EqualTo(bundle.Culture));
Assert.That(defaultBundleOpt.FormatterFunc, Is.EqualTo(bundle.FormatterFunc));
Assert.That(defaultBundleOpt.TransformFunc, Is.EqualTo(bundle.TransformFunc));
Assert.That(defaultBundleOpt.UseIsolating, Is.EqualTo(bundle.UseIsolating));
Assert.That(defaultBundleOpt.MaxPlaceable, Is.EqualTo(bundle.MaxPlaceable));
Assert.That(bundle.TryGetFunction("zero", out var zero));
Assert.That(_zeroFunc, Is.EqualTo(zero?.Function));
Assert.That(bundle.TryGetFunction("id", out var id));
Assert.That(_idFunc, Is.EqualTo(id?.Function));
}

[Test]
Expand All @@ -92,17 +93,17 @@ public void TestReplaceMessage()
.AddResource(_replace1);

var bundle = bundler.UncheckedBuild();
Assert.IsTrue(bundle.TryGetAttrMessage("term1", null, out _, out var termMsg));
Assert.AreEqual("val1", termMsg);
Assert.IsTrue(bundle.TryGetAttrMessage("term2", null, out _, out var termMsg2));
Assert.AreEqual("val2", termMsg2);
Assert.That(bundle.TryGetAttrMessage("term1", null, out _, out var termMsg));
Assert.That("val1", Is.EqualTo(termMsg));
Assert.That(bundle.TryGetAttrMessage("term2", null, out _, out var termMsg2));
Assert.That("val2", Is.EqualTo(termMsg2));

bundle.AddResourceOverriding(_replace2);
Assert.IsTrue(bundle.TryGetAttrMessage("term2", null, out _, out _));
Assert.IsTrue(bundle.TryGetAttrMessage("term1", null, out _, out termMsg));
Assert.AreEqual("xxx", termMsg);
Assert.IsTrue(bundle.TryGetAttrMessage("new1.attr", null, out _, out var newMsg));
Assert.AreEqual("6", newMsg);
Assert.That(bundle.TryGetAttrMessage("term2", null, out _, out _));
Assert.That(bundle.TryGetAttrMessage("term1", null, out _, out termMsg));
Assert.That("xxx", Is.EqualTo(termMsg));
Assert.That(bundle.TryGetAttrMessage("new1.attr", null, out _, out var newMsg));
Assert.That("6", Is.EqualTo(newMsg));
}

[Test]
Expand Down Expand Up @@ -130,7 +131,7 @@ public void TestReadme()
.UncheckedBuild();

var message = bundle.GetAttrMessage("hello-user", ("username", (FluentString)"Test"));
Assert.AreEqual("Hello, Test!", message);
Assert.That("Hello, Test!", Is.EqualTo(message));
}

[Test]
Expand Down Expand Up @@ -163,7 +164,7 @@ public void TestConcurrencyBundler()
Parallel.For(0, 10, i => bundler.AddResource($"term-2= {i}", out _));
Parallel.For(0, 10, i => bundler.TryGetAttrMessage("term-1", null, out _, out _));
Parallel.For(0, 10, i => bundler.AddResourceOverriding($"term-2= {i + 1}"));
Assert.True(bundler.HasMessage("term-1"));
Assert.That(bundler.HasMessage("term-1"));
}

[Test]
Expand All @@ -179,7 +180,7 @@ public void TestConcurrencyOption()
Parallel.For(0, 10, i => optBundle.AddResource($"term-2= {i}", out _));
Parallel.For(0, 10, i => optBundle.TryGetAttrMessage("term-1", null, out _, out _));
Parallel.For(0, 10, i => optBundle.AddResourceOverriding($"term-2= {i + 1}"));
Assert.True(optBundle.HasMessage("term-1"));
Assert.That(optBundle.HasMessage("term-1"));
}

[Test]
Expand All @@ -192,7 +193,7 @@ public void TestExample()
.UncheckedBuild();

var message = bundler.GetAttrMessage("hello-user", ("username", (FluentString)"Test"));
Assert.AreEqual("Hello, Test!", message);
Assert.That("Hello, Test!", Is.EqualTo(message));
}

[Test]
Expand All @@ -206,8 +207,8 @@ public void TestFuncAddBehavior()

bundle.TryAddFunction("id", _idFunc);

Assert.IsFalse(bundle.TryAddFunction("id", _zeroFunc));
Assert.IsTrue(bundle.AddFunctionOverriding("id", _zeroFunc));
Assert.That(bundle.TryAddFunction("id", _zeroFunc), Is.False);
Assert.That(bundle.AddFunctionOverriding("id", _zeroFunc));
Assert.Throws<KeyNotFoundException>(() => bundle.AddFunctionUnchecked("id", _zeroFunc));
}

Expand All @@ -224,8 +225,8 @@ public void TestBehavior(string idWithAttr, bool found)
.AddResource(_replace2)
.UncheckedBuild();

Assert.AreEqual(bundle.TryGetAttrMessage(idWithAttr, null, out _, out _),
bundle.HasAttrMessage(idWithAttr));
Assert.That(bundle.TryGetAttrMessage(idWithAttr, null, out _, out _),
Is.EqualTo(bundle.HasAttrMessage(idWithAttr)));
}

[Test]
Expand All @@ -241,8 +242,8 @@ public void TestHasAttrMessage(string idWithAttr, bool found)
.AddResource(_replace2)
.UncheckedBuild();

Assert.AreEqual(bundle.TryGetAttrMessage(idWithAttr, null, out _, out _),
bundle.HasAttrMessage(idWithAttr));
Assert.That(bundle.TryGetAttrMessage(idWithAttr, null, out _, out _),
Is.EqualTo(bundle.HasAttrMessage(idWithAttr)));
}

public static IEnumerable<TestCaseData> TestBundleErrors
Expand Down Expand Up @@ -287,14 +288,14 @@ public void TestDynamicReference(string input)
var (bundle, err) = LinguiniBuilder.Builder(useExperimental: true).Locale("en-US")
.AddResource(input)
.Build();
Assert.IsEmpty(err);
Assert.That(err, Is.Empty);
var args = new Dictionary<string, IFluentType>()
{
["attacker"] = (FluentReference)"cat",
["defender"] = (FluentReference)"dog",
};
Assert.True(bundle.TryGetMessage("attack-log", args, out _, out var message));
Assert.AreEqual("Cat attacked Dog.", message);
Assert.That(bundle.TryGetMessage("attack-log", args, out _, out var message));
Assert.That("Cat attacked Dog.", Is.EqualTo(message));
}

private const string Macros = @"
Expand All @@ -317,13 +318,13 @@ public void TestMacrosFail()
var (bundle, err) = LinguiniBuilder.Builder(useExperimental: true).Locale("en-US")
.AddResource(Macros)
.Build();
Assert.IsEmpty(err);
Assert.That(err, Is.Empty);
var args = new Dictionary<string, IFluentType>
{
["style"] = (FluentString)"chicago",
};
Assert.True(bundle.TryGetMessage("call-attr-no-args", args, out _, out var message));
Assert.AreEqual("It", message);
Assert.That(bundle.TryGetMessage("call-attr-no-args", args, out _, out var message));
Assert.That("It", Is.EqualTo(message));
}
private const string DynamicSelectors = @"
-creature-fairy = fairy
Expand All @@ -344,19 +345,19 @@ public void TestDynamicSelectors()
.Locale("en-US")
.AddResource(DynamicSelectors)
.Build();
Assert.IsEmpty(err);
Assert.That(err, Is.Empty);
var args = new Dictionary<string, IFluentType>
{
["object"] = (FluentReference)"creature-elf",
};
Assert.True(bundle.TryGetMessage("you-see", args, out _, out var message1));
Assert.AreEqual("You see an elf.", message1);
Assert.That(bundle.TryGetMessage("you-see", args, out _, out var message1));
Assert.That("You see an elf.", Is.EqualTo(message1));
args = new Dictionary<string, IFluentType>
{
["object"] = (FluentReference)"creature-fairy",
};
Assert.True(bundle.TryGetMessage("you-see", args, out _, out var message2));
Assert.AreEqual("You see a fairy.", message2);
Assert.That(bundle.TryGetMessage("you-see", args, out _, out var message2));
Assert.That("You see a fairy.", Is.EqualTo(message2));
}
}
}
4 changes: 2 additions & 2 deletions Linguini.Bundle.Test/Unit/SharedTypesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class SharedTypesTest
[TestCase("err", null)]
public void TestPluralCategoryHelper(string? input, PluralCategory? expected)
{
Assert.AreEqual(expected != null, input.TryPluralCategory(out var actual));
Assert.AreEqual(expected, actual);
Assert.That(expected != null, Is.EqualTo(input.TryPluralCategory(out var actual)));
Assert.That(expected, Is.EqualTo(actual));
}
}
}
8 changes: 4 additions & 4 deletions Linguini.Bundle.Test/Unit/TestRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ private static void TestData(string cultureStr, RuleType type, bool isDecimal, s
: Convert.ToInt32(Math.Floor(midDouble), CultureInfo.InvariantCulture);

var actualStart = GetPluralCategory(info, type, start);
Assert.AreEqual(expected, actualStart, $"Failed on start of range: {start}");
Assert.That(expected, Is.EqualTo(actualStart), $"Failed on start of range: {start}");
var actualEnd = GetPluralCategory(info, type, end);
Assert.AreEqual(expected, actualEnd, $"Failed on end of range: {end}");
Assert.That(expected, Is.EqualTo(actualEnd), $"Failed on end of range: {end}");
var actualMid = GetPluralCategory(info, type, mid);
Assert.AreEqual(expected, actualMid, $"Failed on middle of range: {mid}");
Assert.That(expected, Is.EqualTo(actualMid), $"Failed on middle of range: {mid}");
}
else
{
var value = FluentNumber.FromString(lower);
var actual = GetPluralCategory(info, type, value);
Assert.AreEqual(expected, actual);
Assert.That(expected, Is.EqualTo(actual));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Linguini.Bundle.Test/Unit/TestUnicodeUnescaping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void TestUnescape(string input, string expected)
StringWriter stringWriter = new();
UnicodeUtil.WriteUnescapedUnicode(input.AsMemory(), stringWriter);

Assert.AreEqual(expected, stringWriter.ToString());
Assert.That(expected, Is.EqualTo(stringWriter.ToString()));
}
}
}
10 changes: 5 additions & 5 deletions Linguini.Bundle.Test/Yaml/YamlSuiteParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ public void YamlTestSuiteMethod(ResolverTestSuite parsedTestSuite, LinguiniBuild
if (assert.Missing != null)
{
var notMissing = testBundle.HasMessage(assert.Id);
Assert.AreEqual(!assert.Missing, notMissing);
Assert.That(!assert.Missing, Is.EqualTo(notMissing));
}
else
{
testBundle.TryGetMessage(assert.Id, assert.Attribute, assert.Args,
out var errs,
out var actualValue);
Assert.AreEqual(assert.ExpectedValue, actualValue, test.TestName);
Assert.That(assert.ExpectedValue, Is.EqualTo(actualValue), test.TestName);
AssertErrorCases(assert.ExpectedErrors, errs, test.TestName);
}
}
Expand Down Expand Up @@ -192,16 +192,16 @@ private static void AssertErrorCases(List<ResolverTestSuite.ResolverTestError> e
IList<FluentError> errs,
String testName)
{
Assert.AreEqual(expectedErrors.Count, errs.Count, testName);
Assert.That(expectedErrors.Count, Is.EqualTo(errs.Count), testName);
for (var i = 0; i < expectedErrors.Count; i++)
{
var actualError = errs[i];
var expectedError = expectedErrors[i];

Assert.AreEqual(expectedError.Type, actualError.ErrorKind());
Assert.That(expectedError.Type, Is.EqualTo(actualError.ErrorKind()));
if (expectedError.Description != null)
{
Assert.AreEqual(expectedError.Description, actualError.ToString());
Assert.That(expectedError.Description, Is.EqualTo(actualError.ToString()));
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Linguini.Bundle/FluentBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ private FluentBundle()
EnableExtensions = false;
}

/// <summary>
/// Creates a new instance of FluentBundle with the specified options, possibly throwing exceptions if errors
/// are encountered.
/// </summary>
/// <param name="option">The options to configure the FluentBundle.</param>
/// <returns>A new instance of FluentBundle with the specified options.</returns>
public static FluentBundle MakeUnchecked(FluentBundleOption option)
{
var bundle = ConstructBundle(option);
Expand Down
8 changes: 1 addition & 7 deletions Linguini.Bundle/Linguini.Bundle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ It provides easy to use and extend system for describing translations.</Descript
<AdditionalFiles Include="..\PluralRules.Generator\cldr_data\ordinals.xml" />
<AdditionalFiles Include="..\PluralRules.Generator\cldr_data\plurals.xml" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="System.Memory" Version="4.5.4" PrivateAssets="all" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" PrivateAssets="all" />
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
<PackageReference Include="IndexRange" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>


<ItemGroup>
<None Include="..\linguini.jpg" PackagePath="">
Expand Down
4 changes: 4 additions & 0 deletions Linguini.Serialization/Linguini.Serialization.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="4.0.1" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions Linguini.Shared/Linguini.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
</None>
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="4.0.1" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Linguini.Syntax.Tests/IO/NonValidCharInputTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class NonValidCharInputTest
public void OperationOnNonCalleeReturnFalse(string input)
{
var span = input.AsSpan();
Assert.False(span.IsCallee());
Assert.That(span.IsCallee(), Is.False);
}
}
}
Loading

0 comments on commit 4ff788e

Please sign in to comment.