Browse Source

Share URL boundary fixtures between Android and Qt tests

master
evgeny 6 days ago
parent
commit
4ce7e29a37
  1. 21
      tools/chatgui-android/tests/test_message_links.kt
  2. 16
      tools/chatgui/tests/message_links_cases.tsv

21
tools/chatgui-android/tests/test_message_links.kt

@ -0,0 +1,21 @@
import com.utun.chat.data.MessageLinks
import java.io.File
/** Один набор адресов и границ для Qt и Android, включая UTF-16 после emoji. */
fun main(args: Array<String>) {
var count = 0
File(args.single()).readLines().filter { it.isNotEmpty() && !it.startsWith("#") }.forEach { line ->
val columns = line.split('\t')
val text = columns.first().replace("\\n", "\n")
val links = MessageLinks.parse(text)
check(links.map { it.url } == columns.drop(1)) { "URLs differ: text=$text actual=$links expected=${columns.drop(1)}" }
var end = 0
for (link in links) {
check(link.start >= end && text.substring(link.start, link.end) == link.url)
end = link.end
}
count++
}
check(count >= 15)
println("PASS: $count shared message-link cases; original URLs and UTF-16 ranges preserved")
}

16
tools/chatgui/tests/message_links_cases.tsv

@ -0,0 +1,16 @@
# text<TAB>expected full URLs; literal \n is decoded as a newline
Открой (https://example.com/a(b)?q=1#part), затем http://example.org/. https://example.com/a(b)?q=1#part http://example.org/
https://пример.рф/путь?ключ=значение#раздел https://пример.рф/путь?ключ=значение#раздел
✨ https://example.com/✨?q=👋 и utun://abc+/==. https://example.com/✨?q=👋 utun://abc+/==
HTTPS://EXAMPLE.COM:8443/path?q=a%20b&x=2#f HTTPS://EXAMPLE.COM:8443/path?q=a%20b&x=2#f
https://[::1]:443/a https://[::1]:443/a
«https://example.com/a» "http://example.org/b". https://example.com/a http://example.org/b
http:// https://?x=1 http:///path https://example.com:70000/ https://example.com/%GG
mailto:a@example.com ftp://example.com www.example.com javascript:alert(1)
https://example.com/a[0]}! https://example.com/a[0]
https://example.com/a?q=(x) https://example.com/a?q=(x)
https://example.com/a после https://example.com/a
https://example.com/a.\nhttp://example.org/b https://example.com/a http://example.org/b
https://example.com:bad/
https://user:password@example.com/a https://user:password@example.com/a
UTUN://abc+/==
Can't render this file because it has a wrong number of fields in line 2.
Loading…
Cancel
Save