Skip to content

Commit

Permalink
chore: sharping
Browse files Browse the repository at this point in the history
  • Loading branch information
elringus committed Sep 26, 2024
1 parent 5a9a27f commit 24c2672
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion backend/Naninovel.Common.Test/Bridging/ServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private Task<MockTransport[]> Connect (int count)
private async Task<T> MockIncomingAsync<T> (MockTransport transport)
where T : IClientMessage, new()
{
var messages = await MockIncomingAsync<T>(new[] { transport });
var messages = await MockIncomingAsync<T>([transport]);
return messages[0];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class ManagedTextDetectorTest
{
public static IEnumerable<object[]> Facts { get; } = new[] {
public static IEnumerable<object[]> Facts { get; } = [
IsInline(""),
IsInline("foo: bar"),
IsInline("; comment"),
Expand All @@ -12,7 +12,7 @@ public class ManagedTextDetectorTest
IsMultiline("; comment\n# id\nfoo bar baz"),
IsMultiline("# foo\nauthor: text"),
IsMultiline("author: text\n# id")
};
];

[Theory, MemberData(nameof(Facts))]
public void ParseTheory (string text, bool isMultiline)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class ManagedTextDocumentTest
[Fact]
public void CanBeConstructedFromRecordsCollection ()
{
Assert.Equal(new ManagedTextRecord[] { new("foo") }, new ManagedTextDocument(new ManagedTextRecord[] { new("foo") }).Records);
Assert.Equal([new("foo")], new ManagedTextDocument([new("foo")]).Records);
Assert.Empty(new ManagedTextDocument(Array.Empty<ManagedTextRecord>()).Records);
}

Expand All @@ -24,15 +24,15 @@ public void HeaderIsAssigned ()
[Fact]
public void CanCheckIfContainsRecordByKey ()
{
var doc = new ManagedTextDocument(new ManagedTextRecord[] { new("foo") });
var doc = new ManagedTextDocument([new("foo")]);
Assert.True(doc.Contains("foo"));
Assert.False(doc.Contains("bar"));
}

[Fact]
public void CanGetByKey ()
{
var doc = new ManagedTextDocument(new ManagedTextRecord[] { new("foo") });
var doc = new ManagedTextDocument([new("foo")]);
Assert.Equal("foo", doc.Get("foo").Key);
}

Expand All @@ -45,7 +45,7 @@ public void ThrowsWhenGettingUnknownRecord ()
[Fact]
public void CanTryGetByKey ()
{
var doc = new ManagedTextDocument(new ManagedTextRecord[] { new("foo") });
var doc = new ManagedTextDocument([new("foo")]);
Assert.False(doc.TryGet("bar", out var record));
Assert.True(doc.TryGet("foo", out record));
Assert.Equal("foo", record.Key);
Expand Down
14 changes: 7 additions & 7 deletions backend/Naninovel.Common.Test/Metadata/ConstantEvaluatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ public void WhenNullOrEmptyReturnsEmpty ()
[Fact]
public void WhenDoesntContainExpressionsReturnsUnmodified ()
{
Assert.Equal(new[] { "foo" }, Evaluate("foo"));
Assert.Equal(["foo"], Evaluate("foo"));
}

[Fact]
public void CanResolveScript ()
{
inspectedScriptPath = "foo";
Assert.Equal(new[] { "foo" }, Evaluate("{$Script}"));
Assert.Equal(["foo"], Evaluate("{$Script}"));
}

[Fact]
public void DoesntModifyContentOutsideOfExpression ()
{
inspectedScriptPath = "bar";
Assert.Equal(new[] { "foo/bar" }, Evaluate("foo/{$Script}"));
Assert.Equal(["foo/bar"], Evaluate("foo/{$Script}"));
}

[Fact]
public void CanInjectParamValues ()
{
getParamValue = (id, idx) => id == "1" ? "foo" : "bar";
Assert.Equal(new[] { "foo/bar" }, Evaluate("{:1}/{:2}"));
Assert.Equal(["foo/bar"], Evaluate("{:1}/{:2}"));
}

[Fact]
Expand All @@ -51,23 +51,23 @@ public void CanUseNullCoalescing ()
{
inspectedScriptPath = "bar";
getParamValue = (id, idx) => id == "foo" ? "foo" : null;
Assert.Equal(new[] { "foobar" }, Evaluate("{:foo??:bar}{:bar??$Script}"));
Assert.Equal(["foobar"], Evaluate("{:foo??:bar}{:bar??$Script}"));
}

[Fact]
public void CanGetEnumerableParamValue ()
{
inspectedScriptPath = "nya";
getParamValue = (id, idx) => idx == 0 ? "foo" : idx == 1 ? "bar" : null;
Assert.Equal(new[] { "foo/bar/nya" }, Evaluate("{:foo[0]}/{:bar[1]}/{:nya[2]??$Script}"));
Assert.Equal(["foo/bar/nya"], Evaluate("{:foo[0]}/{:bar[1]}/{:nya[2]??$Script}"));
}

[Fact]
public void CanConcatenate ()
{
inspectedScriptPath = "nya";
getParamValue = (id, idx) => idx == 0 ? "foo" : idx == 1 ? "bar" : null;
Assert.Equal(new[] { "foo/bar/nya", "nya/foo", "foo" }, Evaluate("{:foo[0]}/{:bar[1]}/{:nya[2]??$Script}+{$Script}/foo+{:foo[0]}"));
Assert.Equal(["foo/bar/nya", "nya/foo", "foo"], Evaluate("{:foo[0]}/{:bar[1]}/{:nya[2]??$Script}+{$Script}/foo+{:foo[0]}"));
}

[Fact]
Expand Down
10 changes: 5 additions & 5 deletions backend/Naninovel.Common.Test/Observing/NotifierTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public void InvokesNotificationOnEachObserver ()
{
var observer = new Mock<IMockObserver>();
var registry = new Mock<IObserverRegistry<IMockObserver>>();
registry.SetupGet(r => r.Observers).Returns(new[] { observer.Object });
registry.SetupGet(r => r.Observers).Returns([observer.Object]);
var notifier = new ObserverNotifier<IMockObserver>(registry.Object);
notifier.Notify(o => o.Handle());
observer.Verify(o => o.Handle(), Times.Once);
Expand All @@ -20,7 +20,7 @@ public async Task InvokesNotificationTaskOnEachObserver ()
{
var observer = new Mock<IMockObserver>();
var registry = new Mock<IObserverRegistry<IMockObserver>>();
registry.SetupGet(r => r.Observers).Returns(new[] { observer.Object });
registry.SetupGet(r => r.Observers).Returns([observer.Object]);
var notifier = new ObserverNotifier<IMockObserver>(registry.Object);
await notifier.NotifyAsync(o => o.HandleAsync());
observer.Verify(o => o.HandleAsync(), Times.Once);
Expand All @@ -33,7 +33,7 @@ public void ByDefaultNotifiesInOrder ()
var observer1 = new Mock<IMockObserver>();
var observer2 = new Mock<IMockObserver>();
var registry = new Mock<IObserverRegistry<IMockObserver>>();
registry.SetupGet(r => r.Observers).Returns(new[] { observer1.Object, observer2.Object });
registry.SetupGet(r => r.Observers).Returns([observer1.Object, observer2.Object]);
observer1.Setup(o => o.Handle()).Callback(() => Assert.Equal(1, ++notifyCounter));
observer2.Setup(o => o.Handle()).Callback(() => Assert.Equal(2, ++notifyCounter));
var notifier = new ObserverNotifier<IMockObserver>(registry.Object);
Expand All @@ -47,7 +47,7 @@ public void CanChangeNotifyOrder ()
var observer1 = new Mock<IMockObserver>();
var observer2 = new Mock<IMockObserver>();
var registry = new Mock<IObserverRegistry<IMockObserver>>();
registry.SetupGet(r => r.Observers).Returns(new[] { observer1.Object, observer2.Object });
registry.SetupGet(r => r.Observers).Returns([observer1.Object, observer2.Object]);
observer1.Setup(o => o.Handle()).Callback(() => Assert.Equal(2, ++notifyCounter));
observer2.Setup(o => o.Handle()).Callback(() => Assert.Equal(1, ++notifyCounter));
var notifier = new ObserverNotifier<IMockObserver>(registry.Object);
Expand All @@ -63,7 +63,7 @@ public async Task CanChangeNotifyOrderAsync ()
observer1.Setup(o => o.HandleAsync()).Callback(() => Assert.Equal(2, ++notifyCounter));
observer2.Setup(o => o.HandleAsync()).Callback(() => Assert.Equal(1, ++notifyCounter));
var registry = new Mock<IObserverRegistry<IMockObserver>>();
registry.SetupGet(r => r.Observers).Returns(new[] { observer1.Object, observer2.Object });
registry.SetupGet(r => r.Observers).Returns([observer1.Object, observer2.Object]);
var notifier = new ObserverNotifier<IMockObserver>(registry.Object);
await notifier.NotifyAsync(o => o.HandleAsync(), o => o.Reverse());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public void CommandLineToStringIsCorrect ()
[Fact]
public void GenericLineToStringIsCorrect ()
{
var line = new GenericLine(new GenericPrefix("a", "b"), new IGenericContent[] {
var line = new GenericLine(new GenericPrefix("a", "b"), [
new MixedValue([new PlainText("x")]),
new InlinedCommand(new("i", Array.Empty<Parameter>()))
});
]);
Assert.Equal("a.b: x[i]", line.ToString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void NullElementsAreEmpty ()
[Fact]
public void WhenAllElementsAreNullPreservesThem ()
{
Assert.Equal(",", serializer.Serialize(new string[] { null, null }));
Assert.Equal(",", serializer.Serialize([null, null]));
}

[Fact]
Expand Down

0 comments on commit 24c2672

Please sign in to comment.