Skip to content

Commit

Permalink
Fix and test ClassInstance.addInputTags (#121)
Browse files Browse the repository at this point in the history
* Fix and test ClassInstance.addInputTags

* Update fix
  • Loading branch information
modmuss50 authored Jan 3, 2024
1 parent 979f50c commit b22c17e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/net/fabricmc/tinyremapper/ClassInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void addInputTags(InputTag[] tags) {

if (missingTags == 0) return;

newTags = Arrays.copyOf(tags, oldTags.length + missingTags);
newTags = Arrays.copyOf(oldTags, oldTags.length + missingTags);

for (InputTag newTag : tags) {
boolean found = false;
Expand All @@ -129,6 +129,8 @@ void addInputTags(InputTag[] tags) {
missingTags--;
}
}

assert missingTags == 0;
}
} while (!inputTagsUpdater.compareAndSet(this, oldTags, newTags));
}
Expand Down
58 changes: 58 additions & 0 deletions src/test/java/net/fabricmc/tinyremapper/ClassInstanceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2021, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package net.fabricmc.tinyremapper;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import org.junit.jupiter.api.Test;

public class ClassInstanceTest {
@Test
void addInputTags() {
InputTag tag1 = new InputTag();
InputTag tag2 = new InputTag();

ClassInstance classInstance = new ClassInstance(null, false, new InputTag[]{}, null, new byte[]{});
assertEquals(0, classInstance.getInputTags().length);

classInstance.addInputTags(new InputTag[]{tag1});
assertEquals(1, classInstance.getInputTags().length);
assertContains(tag1, classInstance.getInputTags());

classInstance.addInputTags(new InputTag[]{tag1});
assertEquals(1, classInstance.getInputTags().length);
assertContains(tag1, classInstance.getInputTags());

classInstance.addInputTags(new InputTag[]{tag2});
assertEquals(2, classInstance.getInputTags().length);
assertContains(tag1, classInstance.getInputTags());
assertContains(tag2, classInstance.getInputTags());
}

private static <T> void assertContains(T value, T[] array) {
for (T t : array) {
if (t == value) {
return;
}
}

fail("Array does not contain value: " + value);
}
}

0 comments on commit b22c17e

Please sign in to comment.