-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/orgzly/orgzly-android
- Loading branch information
Showing
124 changed files
with
1,767 additions
and
700 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
25 changes: 25 additions & 0 deletions
25
app/src/androidTest/java/com/orgzly/android/misc/LogSomethingNotTest.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,25 @@ | ||
package com.orgzly.android.misc | ||
|
||
import android.os.Environment | ||
import android.util.Log | ||
import com.orgzly.android.OrgzlyTest | ||
import org.junit.Test | ||
|
||
class LogSomethingNotTest : OrgzlyTest() { | ||
@Test | ||
fun testLink() { | ||
Log.i( | ||
"XXX", String.format( | ||
""" | ||
Environment.getExternalStorageDirectory: %s | ||
context.filesDir: %s | ||
context.getExternalFilesDir(null): %s | ||
context.getExternalFilesDir(DOWNLOADS): %s""".trimIndent(), | ||
Environment.getExternalStorageDirectory(), | ||
context.filesDir, | ||
context.getExternalFilesDir(null), | ||
context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) | ||
) | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package com.orgzly.android.util | ||
|
||
import android.os.Environment | ||
import android.text.style.URLSpan | ||
import com.orgzly.android.ui.views.style.FileLinkSpan | ||
import com.orgzly.android.ui.views.style.IdLinkSpan | ||
import org.hamcrest.CoreMatchers.equalTo | ||
import org.junit.After | ||
import org.junit.Assert.assertThat | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
@@ -18,70 +18,99 @@ class OrgFormatterLinkTest(private val param: Parameter) : OrgFormatterTest() { | |
|
||
data class Span(val start: Int, val end: Int, val klass: Class<*>) | ||
|
||
data class Parameter(val input: String, val output: String, val startEnd: List<Span>) | ||
data class Parameter( | ||
val inputString: String, | ||
val outputString: String, | ||
val expectedSpans: List<Span>) | ||
|
||
@Before | ||
@Throws(Exception::class) | ||
override fun setUp() { | ||
super.setUp() | ||
|
||
File(Environment.getExternalStorageDirectory(), "orgzly-tests").let { dir -> | ||
File(context.cacheDir, "orgzly-tests").let { dir -> | ||
if (!dir.exists() && !dir.mkdirs()) { | ||
throw IOException("Failed to create $dir") | ||
} | ||
|
||
MiscUtils.writeStringToFile("Lorem ipsum", File(dir, "document.txt")) | ||
|
||
val classLoader = javaClass.classLoader | ||
?: throw IOException("Failed to get a class loader for $javaClass") | ||
?: throw IOException("Failed to get a class loader for $javaClass") | ||
|
||
classLoader.getResourceAsStream("assets/images/logo.png").use { stream -> | ||
MiscUtils.writeStreamToFile(stream, File(dir, "logo.png")) | ||
} | ||
} | ||
} | ||
|
||
@After | ||
override fun tearDown() { | ||
super.tearDown() | ||
|
||
File(context.cacheDir, "orgzly-tests").let { dir -> | ||
dir.deleteRecursively() | ||
} | ||
} | ||
|
||
companion object { | ||
@JvmStatic @Parameterized.Parameters(name = "{index}: {0}") | ||
fun data(): Collection<Parameter> { | ||
return listOf( | ||
Parameter("[[orgzly-tests/document.txt]]", "orgzly-tests/document.txt", listOf(Span(0, 25, FileLinkSpan::class.java))), | ||
Parameter("[[./document.txt]]", "./document.txt", listOf(Span(0, 14, FileLinkSpan::class.java))), | ||
Parameter("[[/document.txt]]", "/document.txt", listOf(Span(0, 13, FileLinkSpan::class.java))), | ||
Parameter("[[document.txt]]", "document.txt", listOf(Span(0, 12, FileLinkSpan::class.java))), | ||
Parameter("[[orgzly-tests/document.txt]]", "orgzly-tests/document.txt", listOf(Span(0, 25, FileLinkSpan::class.java))), | ||
Parameter("[[./document.txt]]", "./document.txt", listOf(Span(0, 14, FileLinkSpan::class.java))), | ||
Parameter("[[/document.txt]]", "/document.txt", listOf(Span(0, 13, FileLinkSpan::class.java))), | ||
Parameter("[[document.txt]]", "document.txt", listOf(Span(0, 12, FileLinkSpan::class.java))), | ||
|
||
Parameter("file:orgzly-tests/document.txt", "file:orgzly-tests/document.txt", listOf(Span(0, 30, FileLinkSpan::class.java))), | ||
Parameter("[[file:orgzly-tests/document.txt]]", "file:orgzly-tests/document.txt", listOf(Span(0, 30, FileLinkSpan::class.java))), | ||
Parameter("[[file:orgzly-tests/document.txt][Document]]", "Document", listOf(Span(0, 8, FileLinkSpan::class.java))), | ||
|
||
Parameter("file:orgzly-tests/document.txt", "file:orgzly-tests/document.txt", listOf(Span(0, 30, FileLinkSpan::class.java))), | ||
Parameter("[[file:orgzly-tests/document.txt]]", "file:orgzly-tests/document.txt", listOf(Span(0, 30, FileLinkSpan::class.java))), | ||
Parameter("[[file:orgzly-tests/document.txt][Document]]", "Document", listOf(Span(0, 8, FileLinkSpan::class.java))), | ||
Parameter("id:45DFE015-255E-4B86-B957-F7FD77364DCA", "id:45DFE015-255E-4B86-B957-F7FD77364DCA", listOf(Span(0, 39, IdLinkSpan::class.java))), | ||
Parameter("[[id:45DFE015-255E-4B86-B957-F7FD77364DCA]]", "id:45DFE015-255E-4B86-B957-F7FD77364DCA", listOf(Span(0, 39, IdLinkSpan::class.java))), | ||
Parameter("id:foo", "id:foo", listOf(Span(0, 6, IdLinkSpan::class.java))), | ||
Parameter("[[id:foo]]", "id:foo", listOf(Span(0, 6, IdLinkSpan::class.java))), | ||
|
||
Parameter("id:45DFE015-255E-4B86-B957-F7FD77364DCA", "id:45DFE015-255E-4B86-B957-F7FD77364DCA", listOf(Span(0, 39, IdLinkSpan::class.java))), | ||
Parameter("[[id:45DFE015-255E-4B86-B957-F7FD77364DCA]]", "id:45DFE015-255E-4B86-B957-F7FD77364DCA", listOf(Span(0, 39, IdLinkSpan::class.java))), | ||
Parameter("id:foo", "id:foo", listOf(Span(0, 6, IdLinkSpan::class.java))), | ||
Parameter("[[id:foo]]", "id:foo", listOf(Span(0, 6, IdLinkSpan::class.java))), | ||
Parameter("mailto:[email protected]", "mailto:[email protected]", listOf(Span(0, 14, URLSpan::class.java))), | ||
Parameter("[[mailto:[email protected]]]", "mailto:[email protected]", listOf(Span(0, 14, URLSpan::class.java))), | ||
|
||
Parameter("mailto:[email protected]", "mailto:[email protected]", listOf(Span(0, 14, URLSpan::class.java))), | ||
Parameter("[[mailto:[email protected]]]", "mailto:[email protected]", listOf(Span(0, 14, URLSpan::class.java))), | ||
Parameter("[[id:123][[a] b]]", "[a] b", listOf(Span(0, 5, IdLinkSpan::class.java))), | ||
Parameter("[[id:123][[a] b]] [[./456][[c] d]]", "[a] b [c] d", listOf(Span(0, 5, IdLinkSpan::class.java), Span(6, 11, FileLinkSpan::class.java))), | ||
|
||
Parameter("[[id:123][[a] b]]", "[a] b", listOf(Span(0, 5, IdLinkSpan::class.java))), | ||
Parameter("[[id:123][[a] b]] [[./456][[c] d]]", "[a] b [c] d", listOf(Span(0, 5, IdLinkSpan::class.java), Span(6, 11, FileLinkSpan::class.java))), | ||
Parameter("[[gnus:msgid][subject]]", "subject", listOf(Span(0, 7, FileLinkSpan::class.java))), | ||
Parameter("[[gnus:\\[Gmail\\]/All Mail#msgid][subject]]", "subject", listOf(Span(0, 7, FileLinkSpan::class.java))), | ||
|
||
Parameter("[[gnus:msgid][subject]]", "subject", listOf(Span(0, 7, FileLinkSpan::class.java))), | ||
Parameter("[[gnus:\\[Gmail\\]/All Mail#msgid][subject]]", "subject", listOf(Span(0, 7, FileLinkSpan::class.java))) | ||
Parameter("[[id:a][b]] [[id:1][2]]", "b 2", listOf(Span(0, 1, IdLinkSpan::class.java), Span(2, 3, IdLinkSpan::class.java))), | ||
Parameter("[[id:a][b]][[id:1][2]]", "b2", listOf(Span(0, 1, IdLinkSpan::class.java), Span(1, 2, IdLinkSpan::class.java))), | ||
|
||
// Do not linkify | ||
Parameter("strhttp://orgzly.com/", "strhttp://orgzly.com/", emptyList()), | ||
Parameter("Need activity with <action android:name=\"android.intent.action.VIEW\"/>", "Need activity with <action android:name=\"android.intent.action.VIEW\"/>", emptyList()) | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun testLink() { | ||
val spannable = OrgSpannable(param.input) | ||
val parseResult = ParseResult(param.inputString) | ||
|
||
val msg = "${param.inputString} -> ${parseResult.outputString}" | ||
|
||
assertThat( | ||
"Number of spans found is different then expected: $msg", | ||
parseResult.foundSpans.size, | ||
equalTo(param.expectedSpans.size)) | ||
|
||
assertThat(parseResult.outputString, equalTo(param.outputString)) | ||
|
||
assertThat(spannable.string, equalTo(param.output)) | ||
assertThat(spannable.spans.size, equalTo(param.startEnd.size)) | ||
for (i in parseResult.foundSpans.indices) { | ||
assertThat(parseResult.foundSpans[i].start, equalTo(param.expectedSpans[i].start)) | ||
assertThat(parseResult.foundSpans[i].end, equalTo(param.expectedSpans[i].end)) | ||
|
||
for (i in spannable.spans.indices) { | ||
assertThat(spannable.spans[i].start, equalTo(param.startEnd[i].start)) | ||
assertThat(spannable.spans[i].end, equalTo(param.startEnd[i].end)) | ||
assertThat(spannable.spans[i].span.javaClass.simpleName, equalTo(param.startEnd[i].klass.simpleName)) | ||
assertThat( | ||
"Found span class is different then expected: $msg", | ||
parseResult.foundSpans[i].span.javaClass.simpleName, | ||
equalTo(param.expectedSpans[i].klass.simpleName)) | ||
} | ||
} | ||
} |
Oops, something went wrong.