Recently Written · git

sbm-android

sbm bookmarks for Android: fuzzy search, share to add, sync with bm and the browser add-on

git clone https://github.com/equwal/sbm-android

Log | Files | Refs


app/src/test/java/com/equwal/sbm/PreviewTest.kt (1689 bytes)

1 package com.equwal.sbm
2 
3 import net.jqwik.api.Arbitraries
4 import net.jqwik.api.Arbitrary
5 import net.jqwik.api.Combinators
6 import net.jqwik.api.Example
7 import net.jqwik.api.ForAll
8 import net.jqwik.api.Property
9 import net.jqwik.api.Provide
10 
11 class PreviewTest {
12     // The part of a web address after the scheme: a host, then a path.
13     @Provide
14     fun rests(): Arbitrary<String> {
15         val host = Arbitraries.strings().withCharRange('a', 'z').withChars('.', '-', '0', '9').ofMinLength(1).ofMaxLength(20)
16         val path = Arbitraries.strings().withCharRange('!', '~').ofMaxLength(40)
17             .map { if (it.isEmpty() || it[0] in "/?#") it else "/$it" }
18         return Combinators.combine(host, path).`as` { h, p -> h + p }
19     }
20 
21     @Provide
22     fun schemes(): Arbitrary<String> = Arbitraries.of("http://", "https://", "HTTP://", "Https://")
23 
24     @Property
25     fun `a web page shows at its address with https`(@ForAll("schemes") scheme: String, @ForAll("rests") rest: String): Boolean =
26         Preview.address(scheme + rest) == "https://$rest"
27 
28     @Property
29     fun `the preview only ever loads https addresses, and loads them as they are`(@ForAll text: String): Boolean {
30         val a = Preview.address(text) ?: return true
31         return a.startsWith("https://") && Preview.address(a) == a
32     }
33 
34     @Example
35     fun `addresses that are no web page have no preview`() {
36         for (u in listOf("javascript:alert(1)", "data:text/html,x", "file:///etc/passwd", "intent://x#Intent;end",
37             "market://details?id=x", "ftp://example.org/", "about:blank", "example.org", "", "https://", "http:///x")) {
38             check(Preview.address(u) == null) { u }
39         }
40     }
41 }