mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-11-05 14:24:28 +00:00
42d8d55067
* 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. * Set versions for flixel-ui and hamcrest --------- Co-authored-by: Cameron Taylor <cameron.taylor.ninja@gmail.com>
64 lines
2 KiB
Haxe
64 lines
2 KiB
Haxe
package funkin.util;
|
|
|
|
import thx.semver.Version;
|
|
import thx.semver.VersionRule;
|
|
|
|
/**
|
|
* Remember, increment the patch version (1.0.x) if you make a bugfix,
|
|
* increment the minor version (1.x.0) if you make a new feature (but previous content is still compatible),
|
|
* and increment the major version (x.0.0) if you make a breaking change (e.g. new API or reorganized file format).
|
|
*/
|
|
class VersionUtil
|
|
{
|
|
/**
|
|
* Checks that a given verison number satisisfies a given version rule.
|
|
* Version rule can be complex, e.g. "1.0.x" or ">=1.0.0,<1.1.0", or anything NPM supports.
|
|
*/
|
|
public static function validateVersion(version:thx.semver.Version, versionRule:thx.semver.VersionRule):Bool
|
|
{
|
|
try
|
|
{
|
|
return version.satisfies(versionRule);
|
|
}
|
|
catch (e)
|
|
{
|
|
trace('[VERSIONUTIL] Invalid semantic version: ${version}');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Checks that a given verison number satisisfies a given version rule.
|
|
* Version rule can be complex, e.g. "1.0.x" or ">=1.0.0,<1.1.0", or anything NPM supports.
|
|
*/
|
|
public static function validateVersionStr(version:String, versionRule:String):Bool
|
|
{
|
|
try
|
|
{
|
|
var version:thx.semver.Version = version;
|
|
var versionRule:thx.semver.VersionRule = versionRule;
|
|
return version.satisfies(versionRule);
|
|
}
|
|
catch (e)
|
|
{
|
|
trace('[VERSIONUTIL] Invalid semantic version: ${version}');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get and parse the semantic version from a JSON string.
|
|
* @param input The JSON string to parse.
|
|
* @return The semantic version, or null if it could not be parsed.
|
|
*/
|
|
public static function getVersionFromJSON(input:String):Null<thx.semver.Version>
|
|
{
|
|
var parsed = SerializerUtil.fromJSON(input);
|
|
if (parsed == null) return null;
|
|
if (parsed.version == null) return null;
|
|
var versionStr:String = parsed.version; // Dynamic -> String cast
|
|
var version:thx.semver.Version = versionStr; // Implicit, not explicit, cast.
|
|
return version;
|
|
}
|
|
}
|