Skip to content

Commit 6f714c9

Browse files
committed
Implement test. Fixed bug revealed by test. Man that named block is ugly, I do those a lot, I wonder if I'm missing the trademarked Zig "one obvious way to do it".
1 parent bb2bb28 commit 6f714c9

File tree

3 files changed

+106
-8
lines changed

3 files changed

+106
-8
lines changed

src/main.zig

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ fn applyIniDeinliningRulesRecursivelyNode(allocator: Allocator, node: *Node, pro
15161516
if (strEql(nodeProperty, property)) {
15171517
if (node.children.items.len > 0) {
15181518
const className: []const u8 = nodeValue;
1519-
var moduleName: []const u8 = "Base.rte";
1519+
var moduleNameOptional: ?[]const u8 = null;
15201520
var presetNameOptional: ?[]const u8 = null;
15211521

15221522
var isOriginalPreset: bool = false;
@@ -1542,7 +1542,7 @@ fn applyIniDeinliningRulesRecursivelyNode(allocator: Allocator, node: *Node, pro
15421542
// This lets it respect when well written mods intentionally reference non-Base data entities.
15431543
if (presetNameOptional) |presetName| {
15441544
if (indexOf(u8, presetName, "/")) |modulePrefixEnd| {
1545-
moduleName = presetName[0..modulePrefixEnd];
1545+
moduleNameOptional = presetName[0..modulePrefixEnd];
15461546
presetNameOptional = presetName[modulePrefixEnd + 1 ..];
15471547
}
15481548
}
@@ -1554,7 +1554,7 @@ fn applyIniDeinliningRulesRecursivelyNode(allocator: Allocator, node: *Node, pro
15541554
// If we're set to deinline, then we're making a new preset definition in this module.
15551555
// This means the constant reference should certainly point to this module.
15561556
if (deinliningFlag) {
1557-
moduleName = moduleSpace.moduleName;
1557+
moduleNameOptional = moduleSpace.moduleName;
15581558

15591559
const duplicateNode = Node{
15601560
.property = "AddEffect",
@@ -1571,13 +1571,16 @@ fn applyIniDeinliningRulesRecursivelyNode(allocator: Allocator, node: *Node, pro
15711571
if (presetNameOptional) |presetName| {
15721572
// If this was copied from something, and it isn't an original preset,
15731573
// then check if it is pointing to something within this module.
1574-
if (isCopyOf and !isOriginalPreset) {
1575-
if (moduleSpace.entityDefinitions.get(className)) |presetNameSpace| {
1576-
if (presetNameSpace.get(presetName) != null) {
1577-
moduleName = moduleSpace.moduleName;
1574+
const moduleName: []const u8 = moduleNameOptional orelse moduleNameDeterminingBlock: {
1575+
if (isCopyOf and !isOriginalPreset) {
1576+
if (moduleSpace.entityDefinitions.get(className)) |presetNameSpace| {
1577+
if (presetNameSpace.get(presetName) != null) {
1578+
break :moduleNameDeterminingBlock moduleSpace.moduleName;
1579+
}
15781580
}
15791581
}
1580-
}
1582+
break :moduleNameDeterminingBlock "Base.rte";
1583+
};
15811584

15821585
node.value = try allocPrint(allocator, "{s}/{s}/{s}", .{ className, moduleName, presetName });
15831586
} else {
@@ -2622,6 +2625,10 @@ test "updated" {
26222625
try testDirectory("updated", false);
26232626
}
26242627

2628+
test "constant_reference" {
2629+
try testDirectory("constant_reference", false);
2630+
}
2631+
26252632
fn testDirectory(comptime directory_name: []const u8, is_invalid_test: bool) !void {
26262633
var iterable_tests = try std.fs.cwd().openDir("tests/" ++ directory_name, .{ .iterate = true });
26272634
defer iterable_tests.close();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
AddEffect = MOSRotating
2+
CopyOf = LikeACasingOrSomething
3+
PresetName = InThisMod
4+
5+
AddEffect = MOSRotating
6+
CopyOf = LikeACasingOrSomething
7+
PresetName = InThisModAndBase
8+
9+
AddEffect = MOSRotating
10+
CopyOf = InThisMod
11+
PresetName = DefinedInline
12+
13+
AddEffect = MOSRotating
14+
PresetName = DefinedWrongOrder
15+
CopyOf = InThisMod
16+
17+
AddEffect = PEmitter
18+
CopyOf = Whatever Really
19+
AddEmission = Emission
20+
EmittedParticle = MOSRotating/Base.rte/NotInThisMod
21+
AddEmission = Emission
22+
EmittedParticle = MOSRotating/Bar.rte/InThisMod
23+
AddEmission = Emission
24+
EmittedParticle = MOSRotating/Bar.rte/DefinedInline
25+
AddEmission = Emission
26+
EmittedParticle = MOSRotating/Bar.rte/DefinedWrongOrder
27+
AddEmission = Emission
28+
EmittedParticle = MOSRotating/Bar.rte/InThisMod
29+
AddEmission = Emission
30+
EmittedParticle = MOSRotating/Bar.rte/InThisModAndBase
31+
AddEmission = Emission
32+
EmittedParticle = MOSRotating/Base.rte/InThisModAndBase
33+
AddEmission = Emission
34+
EmittedParticle = MOSRotating/Browncoats.rte/InBrowncoats
35+
AddEmission = Emission
36+
EmittedParticle = MOSRotating/Base.rte/InBase
37+
38+
AddLoadout = Loadout
39+
AddCargoItem = MOSRotating/Base.rte/AssumeBase
40+
AddCargoItem = MOSRotating/Base.rte/DontDefineBecauseLoadoutAssumeBase
41+
AddCargoItem = MOSRotating/Bar.rte/UseGivenModule
42+
AddCargoItem = MOSRotating/Browncoats.rte/UseOtherGivenModule
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
AddEffect = MOSRotating
2+
CopyOf = LikeACasingOrSomething
3+
PresetName = InThisMod
4+
5+
AddEffect = MOSRotating
6+
CopyOf = LikeACasingOrSomething
7+
PresetName = InThisModAndBase
8+
9+
AddEffect = PEmitter
10+
CopyOf = Whatever Really
11+
AddEmission = Emission
12+
EmittedParticle = MOSRotating
13+
CopyOf = NotInThisMod
14+
AddEmission = Emission
15+
EmittedParticle = MOSRotating
16+
CopyOf = InThisMod
17+
AddEmission = Emission
18+
EmittedParticle = MOSRotating
19+
CopyOf = InThisMod
20+
PresetName = DefinedInline
21+
AddEmission = Emission
22+
EmittedParticle = MOSRotating
23+
PresetName = DefinedWrongOrder
24+
CopyOf = InThisMod
25+
AddEmission = Emission
26+
EmittedParticle = MOSRotating
27+
CopyOf = Bar.rte/InThisMod
28+
AddEmission = Emission
29+
EmittedParticle = MOSRotating
30+
CopyOf = Bar.rte/InThisModAndBase
31+
AddEmission = Emission
32+
EmittedParticle = MOSRotating
33+
CopyOf = Base.rte/InThisModAndBase
34+
AddEmission = Emission
35+
EmittedParticle = MOSRotating
36+
CopyOf = Browncoats.rte/InBrowncoats
37+
AddEmission = Emission
38+
EmittedParticle = MOSRotating
39+
CopyOf = Base.rte/InBase
40+
41+
AddLoadout = Loadout
42+
AddCargoItem = MOSRotating
43+
CopyOf = AssumeBase
44+
AddCargoItem = MOSRotating
45+
PresetName = DontDefineBecauseLoadoutAssumeBase
46+
AddCargoItem = MOSRotating
47+
CopyOf = Bar.rte/UseGivenModule
48+
AddCargoItem = MOSRotating
49+
CopyOf = Browncoats.rte/UseOtherGivenModule

0 commit comments

Comments
 (0)