-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix subscribers_local not being optional (#23)
- Loading branch information
Showing
4 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import java.io.BufferedReader | ||
import java.io.InputStream | ||
import java.io.InputStreamReader | ||
import kotlin.reflect.full.primaryConstructor | ||
import kotlin.test.Test | ||
import kotlin.test.fail | ||
|
||
class DatatypesValidation { | ||
private val versions = listOf("v0x18", "v0x19") | ||
|
||
@Test | ||
fun `all datatypes that are nullable should also be optional`() { | ||
versions.flatMap { getClasses(this.javaClass.classLoader, "it/vercruysse/lemmyapi/$it/datatypes") } | ||
.forEach { clazz -> | ||
val kClass = clazz.kotlin | ||
if (kClass.isData) { | ||
val primaryConstructor = kClass.primaryConstructor | ||
primaryConstructor?.parameters?.forEach { parameter -> | ||
if (parameter.type.isMarkedNullable && !parameter.isOptional) { | ||
fail("Parameter ${parameter.name} of class ${clazz.name} is nullable but not optional") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Throws(Exception::class) | ||
private fun getClasses(cl: ClassLoader, pack: String): List<Class<*>> { | ||
val dottedPackage = pack.replace("[/]".toRegex(), ".") | ||
val classes: MutableList<Class<*>> = ArrayList() | ||
val upackage = cl.getResource(pack) | ||
|
||
val dis = BufferedReader(InputStreamReader(upackage?.getContent() as InputStream)) | ||
var line: String? | ||
while ((dis.readLine().also { line = it }) != null) { | ||
if (line!!.endsWith(".class")) { | ||
classes.add(Class.forName(dottedPackage + "." + line!!.substring(0, line!!.lastIndexOf('.')))) | ||
} | ||
} | ||
return classes | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters