-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
seal
committed
Apr 18, 2018
1 parent
f8b63cf
commit c929954
Showing
6 changed files
with
204 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,26 @@ | ||
package wu.seal.jsontokotlin.utils | ||
|
||
import wu.seal.jsontokotlin.ConfigManager | ||
|
||
/** | ||
* Class Code Filter | ||
* Created by Seal.Wu on 2018/4/18. | ||
*/ | ||
object ClassCodeFilter { | ||
|
||
/** | ||
* when not in `innerClassModel` and the class spit with `\n\n` then remove the duplicate class | ||
*/ | ||
fun removeDuplicateClassCode(generateClassesString: String): String { | ||
|
||
if (ConfigManager.isInnerClassModel.not()) { | ||
|
||
val set = mutableSetOf<String>() | ||
set.addAll(generateClassesString.split("\n\n")) | ||
return set.joinToString("\n\n") | ||
|
||
} else { | ||
return generateClassesString | ||
} | ||
} | ||
} |
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,87 @@ | ||
package wu.seal.jsontokotlin.utils | ||
|
||
import com.winterbe.expekt.should | ||
import org.junit.Test | ||
import wu.seal.jsontokotlin.test.TestConfig | ||
|
||
/** | ||
* Created by Seal.Wu on 2018/4/18. | ||
*/ | ||
class ClassCodeFilterTest { | ||
|
||
private val withDuplicateClassString = """data class Test( | ||
val user_id: String = "", | ||
val password: String = "", | ||
val gender: Int = 0, | ||
val birthday: String = "", | ||
val phone: String = "", | ||
val name: String = "", | ||
val cons: Int = 0, | ||
val gps_info: String = "", | ||
val activity_time: String = "", | ||
val sign: String = "", | ||
val vip: String = "", | ||
val being_liked_num: Int = 0, | ||
val info: Info = Info(), | ||
val tag: List<String> = listOf(), | ||
val interest: Interest = Interest(), | ||
val answer: List<Answer> = listOf(), | ||
val media: List<Media> = listOf(), | ||
val friend_show: FriendShow = FriendShow() | ||
) | ||
data class Info( | ||
val industry: String = "", | ||
val work: String = "", | ||
val comp: String = "", | ||
val city: String = "", | ||
val hauntedly: String = "" | ||
) | ||
data class Interest( | ||
val sports: List<String> = listOf(), | ||
val music: List<String> = listOf(), | ||
val food: List<String> = listOf(), | ||
val movie: List<String> = listOf(), | ||
val books_and_comic: List<String> = listOf(), | ||
val footprint: List<String> = listOf() | ||
) | ||
data class FriendShow( | ||
val cover: String = "", | ||
val show_list: List<Show> = listOf() | ||
) | ||
data class Show( | ||
val media: List<Media> = listOf(), | ||
val time: String = "", | ||
val title: String = "" | ||
) | ||
data class Media( | ||
val type: Int = 0, | ||
val url: String = "", | ||
val order: Int = 0 | ||
) | ||
data class Media( | ||
val type: Int = 0, | ||
val url: String = "", | ||
val order: Int = 0 | ||
) | ||
data class Answer( | ||
val a: String = "", | ||
val q: String = "" | ||
)""" | ||
|
||
@Test | ||
fun removeDuplicateClassCode() { | ||
TestConfig.isInnerClassModel = false | ||
withDuplicateClassString.indexOf("data class Media(").should.not.be.equal(withDuplicateClassString.lastIndexOf("data class Media(")) | ||
val removeDuplicateClassCode = ClassCodeFilter.removeDuplicateClassCode(withDuplicateClassString) | ||
removeDuplicateClassCode.indexOf("data class Media(").should.be.equal(removeDuplicateClassCode.lastIndexOf("data class Media(")) | ||
|
||
println(removeDuplicateClassCode) | ||
} | ||
} |
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,84 @@ | ||
package wu.seal.jsontokotlin.utils | ||
|
||
import com.google.gson.JsonArray | ||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonObject | ||
import com.google.gson.JsonParser | ||
import com.winterbe.expekt.should | ||
import org.junit.Test | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Created by Seal.Wu on 2018/4/18. | ||
*/ | ||
class TypeHelperKtTest { | ||
|
||
@Test | ||
fun getPrimitiveTypeTest() { | ||
} | ||
|
||
@Test | ||
fun getJsonObjectTypeTest() { | ||
} | ||
|
||
@Test | ||
fun getChildTypeTest() { | ||
getChildType("List<List<List<Boy>>>").should.be.equal("Boy") | ||
} | ||
|
||
@Test | ||
fun getOutTypeTest() { | ||
} | ||
|
||
@Test | ||
fun getRawTypeTest() { | ||
} | ||
|
||
@Test | ||
fun getArrayTypeTest() { | ||
val jsonArrayBool = JsonArray() | ||
jsonArrayBool.add(true) | ||
getArrayType("good_friends", jsonArrayBool).should.be.equal("List<Boolean>") | ||
|
||
val jsonArrayInt = JsonArray() | ||
jsonArrayInt.add(1) | ||
getArrayType("good_friends", jsonArrayInt).should.be.equal("List<Int>") | ||
|
||
val jsonArrayObj = JsonArray() | ||
val jsonObject = JsonObject() | ||
jsonObject.add("name", JsonParser().parse("seal")) | ||
jsonArrayObj.add(jsonObject) | ||
getArrayType("good_friends", jsonArrayObj).should.be.equal("List<GoodFriend>") | ||
|
||
val jsonArrayObj1 = JsonArray() | ||
val jsonObject1 = JsonObject() | ||
jsonObject1.add("name", JsonParser().parse("seal")) | ||
jsonArrayObj1.add(jsonObject1) | ||
getArrayType("show_list", jsonArrayObj1).should.be.equal("List<Show>") | ||
} | ||
|
||
@Test | ||
fun isExpectedJsonObjArrayTypeTest() { | ||
val jsonArray = JsonArray() | ||
jsonArray.add(true) | ||
isExpectedJsonObjArrayType(jsonArray).should.be.`false` | ||
jsonArray.removeAll { true } | ||
jsonArray.add(1) | ||
isExpectedJsonObjArrayType(jsonArray).should.be.`false` | ||
jsonArray.removeAll { true } | ||
jsonArray.add(JsonObject()) | ||
isExpectedJsonObjArrayType(jsonArray).should.be.`true` | ||
} | ||
|
||
@Test | ||
fun adjustPropertyNameForGettingArrayChildTypeTest() { | ||
adjustPropertyNameForGettingArrayChildType("").should.be.equal("X") | ||
adjustPropertyNameForGettingArrayChildType("List").should.be.equal("") | ||
adjustPropertyNameForGettingArrayChildType("arrayList").should.be.equal("Array") | ||
adjustPropertyNameForGettingArrayChildType("Apples").should.be.equal("Apple") | ||
adjustPropertyNameForGettingArrayChildType("Activities").should.be.equal("Activity") | ||
adjustPropertyNameForGettingArrayChildType("Book_List").should.be.equal("Book") | ||
adjustPropertyNameForGettingArrayChildType("show_list").should.be.equal("Show") | ||
} | ||
} |