134 lines
4.2 KiB
Dart
134 lines
4.2 KiB
Dart
import 'package:rimworld_modman/mod.dart';
|
|
import 'package:rimworld_modman/mod_list.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
const root = r'C:/Users/Administrator/Seafile/Games-RimWorld';
|
|
const modsRoot = '$root/294100';
|
|
const configRoot = '$root/AppData/RimWorld by Ludeon Studios/Config';
|
|
const configPath = '$configRoot/ModsConfig.xml';
|
|
const logsPath = '$root/ModManager';
|
|
|
|
Map<String, Mod> generateDummyMods() {
|
|
final dummyMod = Mod(
|
|
name: 'Dummy Mod',
|
|
id: 'dummy',
|
|
path: '',
|
|
versions: ["1.5"],
|
|
description: '',
|
|
dependencies: [],
|
|
loadAfter: [],
|
|
loadBefore: [],
|
|
incompatibilities: [],
|
|
size: 0,
|
|
isBaseGame: false,
|
|
isExpansion: false,
|
|
enabled: false,
|
|
);
|
|
|
|
final dummyMods = {
|
|
'harmony': dummyMod.copyWith(
|
|
name: 'Harmony',
|
|
id: 'harmony',
|
|
loadBefore: ["ludeon.rimworld"],
|
|
size: 47,
|
|
),
|
|
'prepatcher': dummyMod.copyWith(
|
|
name: 'Prepatcher',
|
|
id: 'prepatcher',
|
|
loadAfter: ["ludeon.rimworld"],
|
|
dependencies: ["harmony"],
|
|
size: 47,
|
|
),
|
|
'ludeon.rimworld': dummyMod.copyWith(
|
|
name: 'RimWorld',
|
|
id: 'ludeon.rimworld',
|
|
isBaseGame: true,
|
|
),
|
|
'ludeon.rimworld.anomaly': dummyMod.copyWith(
|
|
name: 'RimWorld Anomaly',
|
|
id: 'ludeon.rimworld.anomaly',
|
|
isExpansion: true,
|
|
),
|
|
'disabledDummy': dummyMod.copyWith(
|
|
name: 'Disabled Dummy',
|
|
id: 'disabledDummy',
|
|
),
|
|
'yuuuge': dummyMod.copyWith(name: 'Yuuuge', id: 'yuuuge', size: 1000000),
|
|
'smol': dummyMod.copyWith(name: 'Smol', id: 'smol', size: 1),
|
|
'incompatible': dummyMod.copyWith(
|
|
name: 'Incompatible',
|
|
id: 'incompatible',
|
|
size: 1,
|
|
incompatibilities: ['harmony'],
|
|
),
|
|
};
|
|
|
|
return dummyMods;
|
|
}
|
|
|
|
void main() {
|
|
final dummyMods = generateDummyMods();
|
|
final dummyList = ModList();
|
|
dummyList.mods = dummyMods;
|
|
dummyList.enableAll();
|
|
dummyList.setEnabled('disabledDummy', false);
|
|
dummyList.setEnabled('incompatible', false);
|
|
final sortedMods = dummyList.generateLoadOrder();
|
|
|
|
group('Test sorting', () {
|
|
test('Harmony should load before RimWorld', () {
|
|
final harmonyIndex = sortedMods.indexOf('harmony');
|
|
final rimworldIndex = sortedMods.indexOf('ludeon.rimworld');
|
|
expect(harmonyIndex, lessThan(rimworldIndex));
|
|
});
|
|
test('Prepatcher should load after Harmony and RimWorld', () {
|
|
final prepatcherIndex = sortedMods.indexOf('prepatcher');
|
|
final harmonyIndex = sortedMods.indexOf('harmony');
|
|
final rimworldIndex = sortedMods.indexOf('ludeon.rimworld');
|
|
expect(prepatcherIndex, greaterThan(harmonyIndex));
|
|
expect(prepatcherIndex, greaterThan(rimworldIndex));
|
|
});
|
|
test('RimWorld should load before Anomaly', () {
|
|
final rimworldIndex = sortedMods.indexOf('ludeon.rimworld');
|
|
final anomalyIndex = sortedMods.indexOf('ludeon.rimworld.anomaly');
|
|
expect(rimworldIndex, lessThan(anomalyIndex));
|
|
});
|
|
test('Disabled dummy mod should not be loaded', () {
|
|
final disabledIndex = sortedMods.indexOf('disabledDummy');
|
|
expect(disabledIndex, isNegative);
|
|
});
|
|
test("yuuuge mod should load before smol", () {
|
|
final smolIndex = sortedMods.indexOf('smol');
|
|
final yuuugeIndex = sortedMods.indexOf('yuuuge');
|
|
expect(yuuugeIndex, lessThan(smolIndex));
|
|
});
|
|
test('Error generating load order with incompatible mods', () {
|
|
dummyList.setEnabled('incompatible', true);
|
|
expect(() => dummyList.generateLoadOrder(), throwsException);
|
|
});
|
|
});
|
|
|
|
final dummyMods2 = generateDummyMods();
|
|
final dummyList2 = ModList();
|
|
dummyList2.mods = dummyMods2;
|
|
dummyList2.disableAll();
|
|
dummyList2.setEnabled('prepatcher', true);
|
|
final sortedMods2 = dummyList2.loadRequired();
|
|
group('Test loadRequired', () {
|
|
test(
|
|
'Harmony should get enabled by loadRequired as a dependency of prepatcher',
|
|
() {
|
|
final harmonyIndex = sortedMods2.indexOf('harmony');
|
|
expect(harmonyIndex, isNot(-1));
|
|
},
|
|
);
|
|
test('No other mods should get enabled', () {
|
|
for (final mod in dummyMods2.keys) {
|
|
if (mod != 'prepatcher' && mod != 'harmony') {
|
|
expect(sortedMods2.indexOf(mod), isNegative);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|