From 4ce7e29a37a5cff23385a0c3ba5335ad0dcb6522 Mon Sep 17 00:00:00 2001 From: evgeny Date: Sun, 4 Oct 2026 19:08:39 +0200 Subject: [PATCH] Share URL boundary fixtures between Android and Qt tests --- .../tests/test_message_links.kt | 21 +++++++++++++++++++ tools/chatgui/tests/message_links_cases.tsv | 16 ++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tools/chatgui-android/tests/test_message_links.kt create mode 100644 tools/chatgui/tests/message_links_cases.tsv diff --git a/tools/chatgui-android/tests/test_message_links.kt b/tools/chatgui-android/tests/test_message_links.kt new file mode 100644 index 00000000..7bfd35c1 --- /dev/null +++ b/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) { + 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") +} diff --git a/tools/chatgui/tests/message_links_cases.tsv b/tools/chatgui/tests/message_links_cases.tsv new file mode 100644 index 00000000..247bc980 --- /dev/null +++ b/tools/chatgui/tests/message_links_cases.tsv @@ -0,0 +1,16 @@ +# textexpected 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+/==