Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
d4n3436 committed Jun 28, 2024
1 parent e4e2f47 commit bee7886
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Apis/Dictionary/DictionaryFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private static string FormatHtml(string htmlText, bool newLineExample = false)
{
builder.Append($"\n> *{content}*");
} // Sometimes there's text instead of numbers in a superscript class (e.g., satire)
else if (className == "superscript" && content.Length == 1 && content[0] >= '0' && content[0] <= '9')
else if (className == "superscript" && content is [>= '0' and <= '9'])
{
builder.Append(SuperscriptDigits[content[0] - '0']);
}
Expand Down
1 change: 1 addition & 0 deletions src/Apis/Genius/LyricsConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private static void IterateContent(in JsonElement element, StringBuilder builder
{
builder.Append('\u200b'); // Append zero-width space to prevent markdown from breaking
}

builder.Append(markDownStart);

if (element.TryGetProperty("children", out var children))
Expand Down
2 changes: 1 addition & 1 deletion src/Apis/WolframAlpha/ArrayOrObjectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override IReadOnlyList<T> Read(ref Utf8JsonReader reader, Type typeToConv
return reader.TokenType switch
{
JsonTokenType.StartArray => JsonSerializer.Deserialize<IReadOnlyList<T>>(ref reader)!,
JsonTokenType.StartObject => new[] { JsonSerializer.Deserialize<T>(ref reader)! },
JsonTokenType.StartObject => [JsonSerializer.Deserialize<T>(ref reader)!],
_ => throw new JsonException("Token type must be either array or object.")
};
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Fergun.Tests/Apis/WolframAlphaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void ArrayOrObjectConverter_Throws_Exceptions()
options.Converters.Add(new ArrayOrObjectConverter<string>());

Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<IReadOnlyList<string>>("true", options));
Assert.Throws<NotSupportedException>(() => JsonSerializer.Serialize<IReadOnlyList<string>>(new[] { "test" }, options));
Assert.Throws<NotSupportedException>(() => JsonSerializer.Serialize<IReadOnlyList<string>>(["test"], options));
}

public static TheoryData<string, WolframAlphaErrorInfo?> GetWolframAlphaErrorInfoConverterData()
Expand Down
3 changes: 2 additions & 1 deletion tests/Fergun.Tests/Extensions/MessageExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void IMessage_GetText_Should_Return_Text_From_Content_And_Embed(string co
{
var messageMock = new Mock<IMessage>();
messageMock.SetupGet(x => x.Content).Returns(content);
messageMock.SetupGet(x => x.Embeds).Returns(new[] { embed });
messageMock.SetupGet(x => x.Embeds).Returns([embed]);

string[] parts = messageMock.Object.GetText().Split('\n', StringSplitOptions.RemoveEmptyEntries);

Expand All @@ -44,6 +44,7 @@ public void IMessage_GetText_Should_Return_Text_From_Content_And_Embed(string co
{
Assert.Equal(embed.Author.Value.Name, parts[index++]);
}

Assert.Equal(embed.Title, parts[index++]);
Assert.Equal(embed.Description, parts[index]);
if (embed.Footer is not null)
Expand Down
1 change: 1 addition & 0 deletions tests/Fergun.Tests/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static IUser CreateMockedUser(Faker? faker = null, bool pomelo = false)

return userMock.Object;
}

public static IGuildUser CreateMockedGuildUser(Faker? faker = null, bool pomelo = false)
{
faker ??= new Faker();
Expand Down

0 comments on commit bee7886

Please sign in to comment.