Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug about number only property name
- Loading branch information
seal
committed
Dec 18, 2017
1 parent
77557fc
commit 22c9039
Showing
9 changed files
with
171 additions
and
46 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
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
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,50 @@ | ||
package wu.seal.jsontokotlin.codeelements | ||
|
||
import org.junit.* | ||
import org.junit.Test | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Created by Seal.Wu on 2017/12/18. | ||
*/ | ||
class KClassNameTest { | ||
|
||
@org.junit.Test | ||
fun getLegalClassName() { | ||
|
||
val rawClassName = """ | ||
!@3214 12#$%n^&*(-a)_+-=m12335_e43{}|[]\\;':1",./<>?/*-+` | ||
""" | ||
|
||
val legalClassName = KClassName.getLegalClassName(rawClassName) | ||
|
||
assertTrue(legalClassName.startsWith("N")) | ||
assertTrue(legalClassName == "NAM12335E431") | ||
|
||
val rawClassName1 = "341@!$#43214%$#@%34" | ||
val legalClassName1 = KClassName.getLegalClassName(rawClassName1) | ||
assertTrue(legalClassName1.isNotEmpty()) | ||
assertTrue(legalClassName1 == "X3414321434") | ||
|
||
} | ||
|
||
@Test | ||
fun getName() { | ||
val rawClassName = """ | ||
!@3214 12#$%n^&*(-a)_+-=m12335_e43{}|[]\\;':1",./<>?/*-+` | ||
""" | ||
|
||
val legalClassName = KClassName.getName(rawClassName) | ||
|
||
assertTrue(legalClassName.startsWith("N")) | ||
assertTrue(legalClassName == "NAM12335E431") | ||
|
||
val rawClassName1 = "341@!$#43214%$#@%34" | ||
val legalClassName1 = KClassName.getName(rawClassName1) | ||
assertTrue(legalClassName1.isNotEmpty()) | ||
assertTrue(legalClassName1 == "X3414321434") | ||
|
||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
test/wu/seal/jsontokotlin/codeelements/KPropertyNameTest.kt
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,69 @@ | ||
package wu.seal.jsontokotlin.codeelements | ||
|
||
import org.junit.* | ||
import org.junit.Test | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Created by Seal.Wu on 2017/12/18. | ||
*/ | ||
class KPropertyNameTest { | ||
@org.junit.Test | ||
fun getName() { | ||
val originNmae = """ | ||
!@#$ -_32322 3 32%N^&*(-a)_+-=m123-35 e43{}|[]\\;':1",./<>?/*-+` | ||
""" | ||
val resultName = KPropertyName.getName(originNmae) | ||
|
||
assertTrue(resultName.startsWith("n")) | ||
assertTrue(resultName.endsWith("1")) | ||
assertTrue(resultName.contains("A")) | ||
assertTrue(resultName.contains("M")) | ||
assertTrue(resultName.contains("E")) | ||
|
||
|
||
val rawName = "#$@#4324324$$#@324" | ||
val legalName = KPropertyName.getName(rawName) | ||
assertTrue(legalName.isNotEmpty()) | ||
assertTrue(legalName.startsWith("x")) | ||
|
||
} | ||
|
||
@Test | ||
fun makePropertyName() { | ||
val originNmae = """ | ||
!@#$ -_32322 3 32%N^&*(-a)_+-=m123-35 e43{}|[]\\;':1",./<>?/*-+` | ||
""" | ||
val resultName = KPropertyName.makePropertyName(originNmae) | ||
|
||
assertTrue(originNmae == resultName) | ||
|
||
|
||
} | ||
|
||
@Test | ||
fun makePropertyName1() { | ||
val originNmae = """ | ||
!@#$ -_32322 3 32%N^&*(-a)_+-=m123-35 e43{}|[]\\;':1",./<>?/*-+` | ||
""" | ||
val resultNameNotToBeLegal = KPropertyName.makePropertyName(originNmae, false) | ||
|
||
assertTrue(originNmae == resultNameNotToBeLegal) | ||
|
||
val resultNameToBeLegal = KPropertyName.makePropertyName(originNmae, true) | ||
|
||
assertTrue(originNmae != resultNameToBeLegal) | ||
assertTrue(resultNameToBeLegal.startsWith("n")) | ||
assertTrue(resultNameToBeLegal.endsWith("1")) | ||
assertTrue(resultNameToBeLegal.contains("A")) | ||
assertTrue(resultNameToBeLegal.contains("M")) | ||
assertTrue(resultNameToBeLegal.contains("E")) | ||
|
||
val rawName = "#$@#4324324$$#@324" | ||
val legalName = KPropertyName.getName(rawName) | ||
assertTrue(legalName.isNotEmpty()) | ||
assertTrue(legalName.startsWith("x")) | ||
} | ||
|
||
} |