forked from UnderminersTeam/UndertaleModTool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request UnderminersTeam#1515 from Miepee/unit-test
Add proper unit testing project
- Loading branch information
Showing
6 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using UndertaleModLib; | ||
using UndertaleModLib.Models; | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace UndertaleModLibTests.Models; | ||
|
||
public class EmbeddedAudioTest | ||
{ | ||
[Theory] | ||
[InlineData(new byte[] | ||
{ | ||
4, 0, 0, 0, | ||
252, 253, 254, 255, | ||
})] | ||
|
||
public void TestUnserialize(byte[] data) | ||
{ | ||
using var stream = new MemoryStream(data); | ||
var reader = new UndertaleReader(stream); | ||
var embeddedAudio = new UndertaleEmbeddedAudio(); | ||
|
||
embeddedAudio.Unserialize(reader); | ||
|
||
Assert.True(embeddedAudio.Data.Length == BitConverter.ToInt32(data[..4])); | ||
Assert.Equal(embeddedAudio.Data, data[4..]); | ||
} | ||
|
||
[Fact] | ||
public void TestSerialize() | ||
{ | ||
using var stream = new MemoryStream(); | ||
var fullData = new byte[] { 4, 0, 0, 0, 252, 253, 254, 255 }; | ||
UndertaleEmbeddedAudio audio = new UndertaleEmbeddedAudio() | ||
{ | ||
Name = new UndertaleString("foobar"), | ||
Data = fullData[4..] | ||
}; | ||
var writer = new UndertaleWriter(stream); | ||
|
||
audio.Serialize(writer); | ||
|
||
Assert.True(stream.Length == fullData.Length); | ||
Assert.Equal(stream.ToArray(), fullData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using UndertaleModLib; | ||
using UndertaleModLib.Models; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace UndertaleModLibTests.Models; | ||
|
||
public class StringTest | ||
{ | ||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData("\n", "\n")] | ||
[InlineData("\n\r\n\r\n", "\n\r\n\r\n")] | ||
[InlineData("T\nh\ri\"s\\", "T\nh\ri\"s\\")] | ||
[InlineData(@"\n", "\n")] | ||
[InlineData(@"\n\r\n\r\n", "\n\r\n\r\n")] | ||
[InlineData(@"T\nh\ri\""s\\", "T\nh\ri\"s\\")] | ||
public void TestUnescapeText(string text, string expected) | ||
{ | ||
var result = UndertaleString.UnescapeText(text); | ||
|
||
Assert.Equal(result, expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "", true)] | ||
[InlineData(" ", "", true)] | ||
[InlineData("HELLO", "hello", true)] | ||
[InlineData("hello", "HELLO", true)] | ||
[InlineData("HEllO", "heLLo", true)] | ||
[InlineData("hello", "world", false)] | ||
[InlineData("world", "hello", false)] | ||
[InlineData(null, null, false)] | ||
[InlineData("hi", null, false)] | ||
[InlineData(null, "null", false)] | ||
public void TestSearchMatches(string text, string substring, bool expected) | ||
{ | ||
UndertaleString utString = new UndertaleString(text); | ||
|
||
var result = utString.SearchMatches(substring); | ||
|
||
Assert.Equal(result, expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData("I rule!", new byte[] {7, 0, 0, 0, 73, 32, 114, 117, 108, 101, 33, 0})] | ||
[InlineData("{]öÄü¢€ΩФЙw", new byte[] {20, 0, 0, 0, 123, 93, 195, 182, 195, 132, 195, 188, 194, 162, 226, 130, 172, 206, 169, 208, 164, 208, 153, 119, 0})] | ||
[InlineData("\ud83d\udc38\ud83d\ude03\ud83e\uddd1\ud83c\udffc\u200d\ud83d\ude80\ud83c\udff4\u200d\u2620\ufe0f", new byte[] {36, 0, 0, 0, 240, 159, 144, 184, 240, 159, 152, 131, 240, 159, 167, 145, 240, 159, 143, 188, 226, 128, 141, 240, 159, 154, 128, 240, 159, 143, 180, 226, 128, 141, 226, 152, 160, 239, 184, 143, 0})] | ||
public void TestSerialize(string input, byte[] expected) | ||
{ | ||
using var stream = new MemoryStream(); | ||
UndertaleString utString = new UndertaleString(input); | ||
var writer = new UndertaleWriter(stream); | ||
|
||
utString.Serialize(writer); | ||
|
||
Assert.Equal(stream.ToArray(), expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData(new byte[] {7, 0, 0, 0, 73, 32, 114, 117, 108, 101, 33, 0}, "I rule!")] | ||
[InlineData(new byte[] {20, 0, 0, 0, 123, 93, 195, 182, 195, 132, 195, 188, 194, 162, 226, 130, 172, 206, 169, 208, 164, 208, 153, 119, 0}, "{]öÄü¢€ΩФЙw")] | ||
[InlineData(new byte[] {36, 0, 0, 0, 240, 159, 144, 184, 240, 159, 152, 131, 240, 159, 167, 145, 240, 159, 143, 188, 226, 128, 141, 240, 159, 154, 128, 240, 159, 143, 180, 226, 128, 141, 226, 152, 160, 239, 184, 143, 0}, "\ud83d\udc38\ud83d\ude03\ud83e\uddd1\ud83c\udffc\u200d\ud83d\ude80\ud83c\udff4\u200d\u2620\ufe0f")] | ||
|
||
public void TestUnserialize(byte[] input, string expected) | ||
{ | ||
using var stream = new MemoryStream(input); | ||
var reader = new UndertaleReader(stream); | ||
var utString = new UndertaleString(); | ||
|
||
utString.Unserialize(reader); | ||
|
||
Assert.Equal(utString.Content, expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2"/> | ||
<PackageReference Include="xunit" Version="2.4.2"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\UndertaleModLib\UndertaleModLib.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters