From 1f9a94734462ba3ca856a27a49716ce3084d435e Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Fri, 6 Jan 2023 15:21:59 +0200 Subject: [PATCH] Add tests for creating ACJ and QMJ instances --- .../ArchitecturyCommonJsonTest.groovy | 56 +++++++++++++++++++ .../test/unit/quilt/QuiltModJsonTest.groovy | 56 +++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/architectury/ArchitecturyCommonJsonTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/architectury/ArchitecturyCommonJsonTest.groovy index d126ceae..8e8ca991 100644 --- a/src/test/groovy/net/fabricmc/loom/test/unit/architectury/ArchitecturyCommonJsonTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/unit/architectury/ArchitecturyCommonJsonTest.groovy @@ -24,10 +24,66 @@ package net.fabricmc.loom.test.unit.architectury +import com.google.gson.JsonObject import dev.architectury.loom.metadata.ArchitecturyCommonJson import spock.lang.Specification +import spock.lang.TempDir + +import java.nio.charset.StandardCharsets +import java.nio.file.Path class ArchitecturyCommonJsonTest extends Specification { + private static final String OF_TEST_INPUT = '{"accessWidener":"foo.accesswidener"}' + + @TempDir + Path tempDir + + def "create from byte[]"() { + given: + def bytes = OF_TEST_INPUT.getBytes(StandardCharsets.UTF_8) + when: + def acj = ArchitecturyCommonJson.of(bytes) + then: + acj.accessWidener == 'foo.accesswidener' + } + + def "create from String"() { + when: + def acj = ArchitecturyCommonJson.of(OF_TEST_INPUT) + then: + acj.accessWidener == 'foo.accesswidener' + } + + def "create from File"() { + given: + def file = new File(tempDir.toFile(), 'architectury.common.json') + file.text = OF_TEST_INPUT + when: + def acj = ArchitecturyCommonJson.of(file) + then: + acj.accessWidener == 'foo.accesswidener' + } + + def "create from Path"() { + given: + def path = tempDir.resolve('architectury.common.json') + path.text = OF_TEST_INPUT + when: + def acj = ArchitecturyCommonJson.of(path) + then: + acj.accessWidener == 'foo.accesswidener' + } + + def "create from JsonObject"() { + given: + def json = new JsonObject() + json.addProperty('accessWidener', 'foo.accesswidener') + when: + def acj = ArchitecturyCommonJson.of(json) + then: + acj.accessWidener == 'foo.accesswidener' + } + def "read access widener"() { given: def acj = ArchitecturyCommonJson.of(jsonText) diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/quilt/QuiltModJsonTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/quilt/QuiltModJsonTest.groovy index 189bb8bd..e606d9e2 100644 --- a/src/test/groovy/net/fabricmc/loom/test/unit/quilt/QuiltModJsonTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/unit/quilt/QuiltModJsonTest.groovy @@ -24,10 +24,66 @@ package net.fabricmc.loom.test.unit.quilt +import com.google.gson.JsonObject import dev.architectury.loom.metadata.QuiltModJson import spock.lang.Specification +import spock.lang.TempDir + +import java.nio.charset.StandardCharsets +import java.nio.file.Path class QuiltModJsonTest extends Specification { + private static final String OF_TEST_INPUT = '{"access_widener":"foo.accesswidener"}' + + @TempDir + Path tempDir + + def "create from byte[]"() { + given: + def bytes = OF_TEST_INPUT.getBytes(StandardCharsets.UTF_8) + when: + def qmj = QuiltModJson.of(bytes) + then: + qmj.accessWidener == 'foo.accesswidener' + } + + def "create from String"() { + when: + def qmj = QuiltModJson.of(OF_TEST_INPUT) + then: + qmj.accessWidener == 'foo.accesswidener' + } + + def "create from File"() { + given: + def file = new File(tempDir.toFile(), 'quilt.mod.json') + file.text = OF_TEST_INPUT + when: + def qmj = QuiltModJson.of(file) + then: + qmj.accessWidener == 'foo.accesswidener' + } + + def "create from Path"() { + given: + def path = tempDir.resolve('quilt.mod.json') + path.text = OF_TEST_INPUT + when: + def qmj = QuiltModJson.of(path) + then: + qmj.accessWidener == 'foo.accesswidener' + } + + def "create from JsonObject"() { + given: + def json = new JsonObject() + json.addProperty('access_widener', 'foo.accesswidener') + when: + def qmj = QuiltModJson.of(json) + then: + qmj.accessWidener == 'foo.accesswidener' + } + def "read access widener"() { given: def qmj = QuiltModJson.of(jsonText)