Skip to content

Commit

Permalink
Fix FileSpec import detection (outfoxx#10)
Browse files Browse the repository at this point in the history
* Fix FileSpec import detection

* Exec CI on Java 11
  • Loading branch information
kdubb authored Mar 13, 2021
1 parent a84b139 commit a43fb95
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:

- uses: actions/checkout@v2

- uses: actions/setup-java@v1
with:
java-version: '11'

- name: Build & Test
uses: burrunan/gradle-cache-action@v1
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:

- uses: actions/checkout@v2

- uses: actions/setup-java@v1
with:
java-version: '11'

- name: Build & Test
uses: burrunan/gradle-cache-action@v1
with:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ on:
branches: [ master ]

jobs:
build-test-publish:
publish:
runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v2

- uses: actions/setup-java@v1
with:
java-version: '11'

- name: Build Docs
uses: burrunan/gradle-cache-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/outfoxx/typescriptpoet/FileSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private constructor(
val importsCollector = CodeWriter(NullAppendable, indent)
importsCollector.use { emit(it, directory) }

val absPath = directory.resolve(modulePath)
val absPath = directory.resolve(modulePath).toAbsolutePath()

val importedSymbols =
importsCollector.referencedSymbols<SymbolSpec.Imported>()
Expand Down
81 changes: 81 additions & 0 deletions src/test/java/io/outfoxx/typescriptpoet/test/FileSpecTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package io.outfoxx.typescriptpoet.test

import io.outfoxx.typescriptpoet.ClassSpec
import io.outfoxx.typescriptpoet.FileSpec
import io.outfoxx.typescriptpoet.InterfaceSpec
import io.outfoxx.typescriptpoet.Modifier
import io.outfoxx.typescriptpoet.ModuleSpec
import io.outfoxx.typescriptpoet.SymbolSpec
import io.outfoxx.typescriptpoet.TypeAliasSpec
Expand All @@ -27,10 +29,89 @@ import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import java.nio.file.Path

@DisplayName("FileSpec Tests")
class FileSpecTests {

@Test
@DisplayName("Imports are not generated when type & class are exported together into relative directory")
fun testImportDetect() {

val ifaceBuilder =
InterfaceSpec.builder("Test")
.addModifiers(Modifier.EXPORT)
.build()

val classBuilder =
ClassSpec.builder("Test")
.addModifiers(Modifier.EXPORT)
.addMixin(TypeName.standard("Test@!test"))
.build()

val testFile =
FileSpec.builder("test")
.addInterface(ifaceBuilder)
.addClass(classBuilder)
.build()

assertThat(
buildString {
testFile.writeTo(this, Path.of("tester"))
},
equalTo(
"""
export interface Test {
}
export class Test implements Test {
}
""".trimIndent()
)
)
}

@Test
@DisplayName("Imports are not generated when type & class are exported together into absolute directory")
fun testImportDetectAbsolute() {

val ifaceBuilder =
InterfaceSpec.builder("Test")
.addModifiers(Modifier.EXPORT)
.build()

val classBuilder =
ClassSpec.builder("Test")
.addModifiers(Modifier.EXPORT)
.addMixin(TypeName.standard("Test@!test"))
.build()

val testFile =
FileSpec.builder("test")
.addInterface(ifaceBuilder)
.addClass(classBuilder)
.build()

assertThat(
buildString {
testFile.writeTo(this, Path.of("tester").toAbsolutePath())
},
equalTo(
"""
export interface Test {
}
export class Test implements Test {
}
""".trimIndent()
)
)
}

@Test
@DisplayName("Tags on builders can be retrieved on builders and built specs")
fun testTags() {
Expand Down

0 comments on commit a43fb95

Please sign in to comment.