Funkin/tests/unit/source/funkin/data/level/LevelRegistryTest.hx
Eric 279277b18c Unit Tests: Coverage Reporting and Github Actions Integration (#131)
* Initial test suite

* Fix some build warnings

* Implemented working unit tests with coverage

* Reduced some warnings

* Fix a mac-specific issue

* Add 2 additional unit test classes.

* Multiple new unit tests

* Some fixins

* Remove auto-generated file

* WIP on hiding ignored tests

* Added list of debug hotkeys

* Remove old website

* Remove empty file

* Add more unit tests

* Fix bug where arrows would nudge BF

* Fix bug where ctrl/alt would flash capsules

* Fixed bug where bf-old easter egg broke

* Remove duplicate lines

* More test-related stuff

* Some code cleanup

* Add mocking and a test assets folder

* More TESTS!

* Update Hmm...

* Update artist on Monster

* More minor fixes to individual functions

* 1.38% unit test coverage!

* Even more tests? :O

* More unit test work

* Rework migration for BaseRegistry

* gameover fix

* Fix an issue with Lime

* Fix issues with version parsing on data files

* 100 total unit tests!

* Added even MORE unit tests!

* Additional test tweaks :3

* Fixed tests on windows by updating libraries.

* A bunch of smaller syntax tweaks.

* New crash handler catches and logs critical errors!

* Chart editor now has null safety enabled.

* Null safety on all tests

* New Level data test

* Generate proper code coverage reports!

* Disable null safety on ChartEditorState for unit testing

* Update openfl to use latest fixes for crash reporting

* Added unit test to Github Workflow

* Updated unit tests to compile with null safety enabled by inlining assertions.

* Added coverage gutters as a recommended extension

* Impreovements to tests involving exceptions

* Disable a few incomplete tests.

* Add scripts for building unit coverage reports on linux

---------

Co-authored-by: Cameron Taylor <cameron.taylor.ninja@gmail.com>
2023-08-30 18:31:59 -04:00

146 lines
4 KiB
Haxe

package funkin.data.level;
import funkin.data.level.LevelRegistry;
import funkin.ui.story.Level;
import massive.munit.Assert;
import massive.munit.async.AsyncFactory;
import massive.munit.util.Timer;
@:nullSafety
@:access(funkin.ui.story.Level)
@:access(funkin.data.level.LevelRegistry)
class LevelRegistryTest extends FunkinTest
{
public function new()
{
super();
}
@BeforeClass
public function beforeClass():Void
{
LevelRegistry.instance.loadEntries();
}
@AfterClass
public function afterClass():Void {}
@Before
public function setup():Void {}
@After
public function tearDown():Void {}
@Test
public function testValid():Void
{
Assert.isNotNull(LevelRegistry.instance);
}
@Test
public function testParseEntryData():Void
{
var result:Null<LevelData> = LevelRegistry.instance.parseEntryData("test");
Assert.isNotNull(result);
Assert.areEqual("1.0.0", result.version);
Assert.areEqual("TEACHING TIME", result.name);
Assert.areEqual("storymenu/titles/tutorial", result.titleAsset);
Assert.areEqual(2, result.props.length);
Assert.areEqual("storymenu/props/gf", result.props[0].assetPath);
Assert.areEqual(1.0, result.props[0].scale);
Assert.areEqual(2, result.props[0].danceEvery);
Assert.areEqual([80, 80], result.props[0].offsets);
var anims = result.props[0].animations;
Assert.isNotNull(anims);
Assert.areEqual(2, anims.length);
var anim0 = anims[0];
Assert.isNotNull(anim0);
Assert.areEqual("danceLeft", anim0.name);
Assert.areEqual("idle0", anim0.prefix);
Assert.areEqual([30, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], anim0.frameIndices);
var anim1 = anims[1];
Assert.isNotNull(anim1);
Assert.areEqual("danceRight", anim1.name);
Assert.areEqual("idle0", anim1.prefix);
Assert.areEqual([15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], anim1.frameIndices);
Assert.areEqual("storymenu/props/bf", result.props[1].assetPath);
Assert.areEqual(1.0, result.props[1].scale);
Assert.areEqual(2, result.props[1].danceEvery);
Assert.areEqual([150, 80], result.props[1].offsets);
anims = result.props[1].animations;
Assert.isNotNull(anims);
Assert.areEqual(2, anims.length);
anim0 = anims[0];
Assert.isNotNull(anim0);
Assert.areEqual("idle", anim0.name);
Assert.areEqual("idle0", anim0.prefix);
Assert.areEqual(24, anim0.frameRate);
anim1 = anims[1];
Assert.isNotNull(anim1);
Assert.areEqual("confirm", anim1.name);
Assert.areEqual("confirm0", anim1.prefix);
Assert.areEqual(24, anim1.frameRate);
Assert.areEqual("#F9CF51", result.background);
Assert.areEqual(["tutorial"], result.songs);
}
@Test
public function testCreateEntry():Void
{
var result:Null<Level> = LevelRegistry.instance.createEntry("test");
Assert.isNotNull(result);
Assert.areEqual("Level(test)", result.toString());
Assert.areEqual("TEACHING TIME", result.getTitle());
Assert.areEqual(true, result.isUnlocked());
Assert.areEqual(true, result.isVisible());
}
@Test
public function testFetchEntry():Void
{
var result:Null<Level> = LevelRegistry.instance.fetchEntry("test");
Assert.isNotNull(result);
Assert.areEqual("Level(test)", result.toString());
Assert.areEqual("TEACHING TIME", result.getTitle());
Assert.areEqual(true, result.isUnlocked());
Assert.areEqual(true, result.isVisible());
}
@Test
@Ignore("Requires redoing validation.")
public function testCreateEntryBlankPath():Void
{
FunkinAssert.validateThrows(function() {
var result:Null<Level> = LevelRegistry.instance.createEntry("blankpathtest");
}, function(err) {
return err == "Could not parse level data for id: blankpathtest";
});
}
@Test
@Ignore("Requires redoing validation.")
public function testFetchBadEntry():Void
{
var result:Null<Level> = LevelRegistry.instance.fetchEntry("blablabla");
Assert.isNull(result);
var result2:Null<Level> = LevelRegistry.instance.fetchEntry("blankpathtest");
Assert.isNull(result2);
}
}