diff options
author | Allan Wang <me@allanwang.ca> | 2019-03-31 20:15:03 -0400 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-03-31 20:15:03 -0400 |
commit | b464f91668b1985e59b5555450011783da771211 (patch) | |
tree | 4b85c9a2725d73f6f5562d8f98fe44170a754f4e /app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt | |
parent | 8f5976ca9a8ca67f24314486b5ecf8cc0f369967 (diff) | |
download | frost-b464f91668b1985e59b5555450011783da771211.tar.gz frost-b464f91668b1985e59b5555450011783da771211.tar.bz2 frost-b464f91668b1985e59b5555450011783da771211.zip |
Add stricter parsing tests
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt index 5709bb9f..90c8848c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt @@ -38,7 +38,7 @@ import org.jsoup.select.Elements * The return type must be nonnull if no parsing errors occurred, as null signifies a parse error * If null really must be allowed, use Optionals */ -interface FrostParser<out T : Any> { +interface FrostParser<out T : ParseData> { /** * Name associated to parser @@ -76,11 +76,15 @@ const val FALLBACK_TIME_MOD = 1000000 data class FrostLink(val text: String, val href: String) -data class ParseResponse<out T>(val cookie: String, val data: T) { +data class ParseResponse<out T: ParseData>(val cookie: String, val data: T) { override fun toString() = "ParseResponse\ncookie: $cookie\ndata:\n$data" } -interface ParseNotification { +interface ParseData { + val isEmpty: Boolean +} + +interface ParseNotification : ParseData { fun getUnreadNotifications(data: CookieModel): List<NotificationContent> } @@ -95,7 +99,7 @@ internal fun <T> List<T>.toJsonString(tag: String, indent: Int) = StringBuilder( * T should have a readable toString() function * [redirectToText] dictates whether all data should be converted to text then back to document before parsing */ -internal abstract class FrostParserBase<out T : Any>(private val redirectToText: Boolean) : FrostParser<T> { +internal abstract class FrostParserBase<out T : ParseData>(private val redirectToText: Boolean) : FrostParser<T> { final override fun parse(cookie: String?) = parseFromUrl(cookie, url) |