Skip to content

Commit

Permalink
Merge pull request #211 from TedZen/3.4.0-bugfix#198
Browse files Browse the repository at this point in the history
bug fixed #198
  • Loading branch information
wuseal authored Jul 29, 2019
2 parents cec1293 + 2964b28 commit 10d1851
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ data class Property(
append(annotationsCode).append(separatorBetweenAnnotationAndProperty)
}
}
append(keyword).append(" ").append(name).append(": ").append(type)
append(keyword).append(" ")
append(if (name.first().isDigit() || name.contains('$')) "`$name`" else name)
append(": ").append(type)
if (value.isNotBlank()) {
append(" = ").append(value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ interface IProperty {

}

class KProperty(private val rawPropertyName: String, private val propertyType: String, private val propertyValue: String) : IProperty {
class KProperty(rawPropertyName: String, private val propertyType: String, private val propertyValue: String) : IProperty {

private val noLinebreakPropertyName = rawPropertyName.replace("\n","\\n").take(255)

override fun getPropertyStringBlock(): String {

val blockBuilder = StringBuilder()

blockBuilder.append(NoneSupporter.getNoneLibSupporterProperty(rawPropertyName, propertyType))
blockBuilder.append(NoneSupporter.getNoneLibSupporterProperty(noLinebreakPropertyName, propertyType))

return blockBuilder.toString()
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/kotlin/extensions/ted/zeng/BugTest198.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package extensions.ted.zeng

import com.winterbe.expekt.should
import org.junit.Before
import org.junit.Test
import wu.seal.jsontokotlin.ConfigManager
import wu.seal.jsontokotlin.codeelements.KProperty
import wu.seal.jsontokotlin.test.TestConfig

class BugTest198 {
@Before
fun setup(){
TestConfig.isTestModel = true
ConfigManager.indent = 0
}
@Test
fun propertyNameCheck(){
val kp = KProperty("X\n\nX","Int","1")
kp.getPropertyStringBlock().should.equal("val X\\n\\nX: Int")

}


}

0 comments on commit 10d1851

Please sign in to comment.