filepeek

A library to look up kotlin source files

License

License

GroupId

GroupId

com.christophsturm
ArtifactId

ArtifactId

filepeek
Last Version

Last Version

0.1.3
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

filepeek
A library to look up kotlin source files
Project URL

Project URL

https://github.com/christophsturm/filepeek
Source Code Management

Source Code Management

https://github.com/christophsturm/filepeek.git

Download filepeek

Dependencies

runtime (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.30
org.jetbrains.kotlin : kotlin-reflect jar 1.4.30

Project Modules

There are no modules declared in this project.

Download CircleCI

FilePeek

FilePeek is a library that finds sourcecode to be used in assertion libs and test runners.

Get it from bintray:

repositories {
    jcenter() // or
    // maven { url  "https://dl.bintray.com/christophsturm/maven" }
}
dependencies{
    implementation("com.christophsturm:filepeek:0.1.1")
}

example use:

    private val fileName = "src/test/kotlin/filepeektest/FilePeekTest.kt"

    private val filePeek = FilePeek(listOf("filepeek."))
    @Test
    fun `can get FileInfo`() {
        val fileInfo = filePeek.getCallerFileInfo()

        expectThat(fileInfo) {
            get(FileInfo::sourceFileName)
                .endsWith(fileName)
            get(FileInfo::line)
                .isEqualTo("""val fileInfo = filePeek.getCallerFileInfo()""")
            get(FileInfo::methodName)
                .isEqualTo("""can get FileInfo""")
        }
    }

multiline calls work too, lines are read and joined until the method call is complete.

there is also a utility class that extracts a lambda body from a method call

    @Test
    fun `extracts the body`() {
        Assertions.assertEquals(
            "name",
            LambdaBody("get", """get { name }.isEqualTo("Ziggy")""").body
        )
    }

Versions

Version
0.1.3