💾 Archived View for gmi.noulin.net › gitRepositories › md4c › file › test › coverage.txt.gmi captured on 2024-08-18 at 18:50:26. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

md4c

Log

Files

Refs

README

LICENSE

coverage.txt (6405B)

     1 
     2 # Coverage
     3 
     4 This file is just a collection of unit tests not covered elsewhere.
     5 
     6 Most notably regression tests, tests improving code coverage and other useful
     7 things may drop here.
     8 
     9 (However any tests requiring any additional command line option, like enabling
    10 an extension, must be included in their respective files.)
    11 
    12 
    13 ## GitHub Issues
    14 
    15 ### [Issue 2](https://github.com/mity/md4c/issues/2)
    16 
    17 Raw HTML block:
    18 
    19 ```````````````````````````````` example
    20 <gi att1=tok1 att2=tok2>
    21 .
    22 <gi att1=tok1 att2=tok2>
    23 ````````````````````````````````
    24 
    25 Inline:
    26 
    27 ```````````````````````````````` example
    28 foo <gi att1=tok1 att2=tok2> bar
    29 .
    30 <p>foo <gi att1=tok1 att2=tok2> bar</p>
    31 ````````````````````````````````
    32 
    33 Inline with a line break:
    34 
    35 ```````````````````````````````` example
    36 foo <gi att1=tok1
    37 att2=tok2> bar
    38 .
    39 <p>foo <gi att1=tok1
    40 att2=tok2> bar</p>
    41 ````````````````````````````````
    42 
    43 
    44 ### [Issue 4](https://github.com/mity/md4c/issues/4)
    45 
    46 ```````````````````````````````` example
    47 ![alt text with *entity* &copy;](img.png 'title')
    48 .
    49 <p><img src="img.png" alt="alt text with entity ©" title="title"></p>
    50 ````````````````````````````````
    51 
    52 
    53 ### [Issue 9](https://github.com/mity/md4c/issues/9)
    54 
    55 ```````````````````````````````` example
    56 > [foo
    57 > bar]: /url
    58 >
    59 > [foo bar]
    60 .
    61 <blockquote>
    62 <p><a href="/url">foo
    63 bar</a></p>
    64 </blockquote>
    65 ````````````````````````````````
    66 
    67 ### [Issue 10](https://github.com/mity/md4c/issues/10)
    68 ```````````````````````````````` example
    69 [x]:
    70 x
    71 - <?
    72 
    73   x
    74 .
    75 <ul>
    76 <li><?
    77 <p>x</p>
    78 </li>
    79 </ul>
    80 ````````````````````````````````
    81 
    82 ### [Issue 11](https://github.com/mity/md4c/issues/11)
    83 ```````````````````````````````` example
    84 x [link](/url "foo &ndash; bar") x
    85 .
    86 <p>x <a href="/url" title="foo – bar">link</a> x</p>
    87 ````````````````````````````````
    88 
    89 ### [Issue 15](https://github.com/mity/md4c/issues/15)
    90 ```````````````````````````````` example
    91 ***b* c*
    92 .
    93 <p>*<em><em>b</em> c</em></p>
    94 ````````````````````````````````
    95 
    96 
    97 ### [Issue 14](https://github.com/mity/md4c/issues/14)
    98 ```````````````````````````````` example
    99 a***b* c*
   100 .
   101 <p>a*<em><em>b</em> c</em></p>
   102 ````````````````````````````````
   103 
   104 
   105 ### [Issue 21](https://github.com/mity/md4c/issues/21)
   106 ```````````````````````````````` example
   107 a*b**c*
   108 .
   109 <p>a<em>b**c</em></p>
   110 ````````````````````````````````
   111 
   112 
   113 ### [Issue 24](https://github.com/mity/md4c/issues/24)
   114 ```````````````````````````````` example
   115 [a](<b>c)
   116 .
   117 <p><a href="%3Cb%3Ec">a</a></p>
   118 ````````````````````````````````
   119 
   120 
   121 ## Code coverage
   122 
   123 ### `md_is_unicode_whitespace__()`
   124 
   125 Unicode whitespace (here U+2000) forms a word boundary so these cannot be
   126 resolved as emphasis span because there is no closer mark.
   127 
   128 ```````````````````````````````` example
   129 *foo *bar
   130 .
   131 <p>*foo *bar</p>
   132 ````````````````````````````````
   133 
   134 
   135 ### `md_is_unicode_punct__()`
   136 
   137 Ditto for Unicode punctuation (here U+00A1).
   138 
   139 ```````````````````````````````` example
   140 *foo¡*bar
   141 .
   142 <p>*foo¡*bar</p>
   143 ````````````````````````````````
   144 
   145 
   146 ### `md_get_unicode_fold_info()`
   147 
   148 ```````````````````````````````` example
   149 [Příliš žluťoučký kůň úpěl ďábelské ódy.]
   150 
   151 [PŘÍLIŠ ŽLUŤOUČKÝ KŮŇ ÚPĚL ĎÁBELSKÉ ÓDY.]: /url
   152 .
   153 <p><a href="/url">Příliš žluťoučký kůň úpěl ďábelské ódy.</a></p>
   154 ````````````````````````````````
   155 
   156 
   157 ### `md_decode_utf8__()` and `md_decode_utf8_before__()`
   158 
   159 ```````````````````````````````` example
   160 á*Á (U+00E1, i.e. two byte UTF-8 sequence)
   161  *  (U+2000, i.e. three byte UTF-8 sequence)
   162 .
   163 <p>á*Á (U+00E1, i.e. two byte UTF-8 sequence)
   164  *  (U+2000, i.e. three byte UTF-8 sequence)</p>
   165 ````````````````````````````````
   166 
   167 
   168 ### `md_is_link_destination_A()`
   169 
   170 
   171 ```````````````````````````````` example
   172 [link](</url\.with\.escape>)
   173 .
   174 <p><a href="/url.with.escape">link</a></p>
   175 ````````````````````````````````
   176 
   177 
   178 ### `md_link_label_eq()`
   179 
   180 
   181 ```````````````````````````````` example
   182 [foo bar]
   183 
   184 [foo bar]: /url
   185 .
   186 <p><a href="/url">foo bar</a></p>
   187 ````````````````````````````````
   188 
   189 
   190 ### `md_is_inline_link_spec()`
   191 
   192 ```````````````````````````````` example
   193 > [link](/url 'foo
   194 > bar')
   195 .
   196 <blockquote>
   197 <p><a href="/url" title="foo
   198 bar">link</a></p>
   199 </blockquote>
   200 ````````````````````````````````
   201 
   202 
   203 ### `md_build_ref_def_hashtable()`
   204 
   205 All link labels in the following example all have the same FNV1a hash (after
   206 normalization of the label, which means after converting to a vector of Unicode
   207 codepoints and lowercase folding).
   208 
   209 So the example triggers quite complex code paths which are not otherwise easily
   210 tested.
   211 
   212 ```````````````````````````````` example
   213 [foo]: /foo
   214 [qnptgbh]: /qnptgbh
   215 [abgbrwcv]: /abgbrwcv
   216 [abgbrwcv]: /abgbrwcv2
   217 [abgbrwcv]: /abgbrwcv3
   218 [abgbrwcv]: /abgbrwcv4
   219 [alqadfgn]: /alqadfgn
   220 
   221 [foo]
   222 [qnptgbh]
   223 [abgbrwcv]
   224 [alqadfgn]
   225 [axgydtdu]
   226 .
   227 <p><a href="/foo">foo</a>
   228 <a href="/qnptgbh">qnptgbh</a>
   229 <a href="/abgbrwcv">abgbrwcv</a>
   230 <a href="/alqadfgn">alqadfgn</a>
   231 [axgydtdu]</p>
   232 ````````````````````````````````
   233 
   234 For the sake of completeness, the following C program was used to find the hash
   235 collisions by brute force:
   236 
   237 ~~~
   238 
   239 #include <stdio.h>
   240 #include <string.h>
   241 
   242 
   243 static unsigned etalon;
   244 
   245 
   246 
   247 #define MD_FNV1A_BASE       2166136261
   248 #define MD_FNV1A_PRIME      16777619
   249 
   250 static inline unsigned
   251 fnv1a(unsigned base, const void* data, size_t n)
   252 {
   253     const unsigned char* buf = (const unsigned char*) data;
   254     unsigned hash = base;
   255     size_t i;
   256 
   257     for(i = 0; i < n; i++) {
   258         hash ^= buf[i];
   259         hash *= MD_FNV1A_PRIME;
   260     }
   261 
   262     return hash;
   263 }
   264 
   265 
   266 static unsigned
   267 unicode_hash(const char* data, size_t n)
   268 {
   269     unsigned value;
   270     unsigned hash = MD_FNV1A_BASE;
   271     int i;
   272 
   273     for(i = 0; i < n; i++) {
   274         value = data[i];
   275         hash = fnv1a(hash, &value, sizeof(unsigned));
   276     }
   277 
   278     return hash;
   279 }
   280 
   281 
   282 static void
   283 recurse(char* buffer, size_t off, size_t len)
   284 {
   285     int ch;
   286 
   287     if(off < len - 1) {
   288         for(ch = 'a'; ch <= 'z'; ch++) {
   289             buffer[off] = ch;
   290             recurse(buffer, off+1, len);
   291         }
   292     } else {
   293         for(ch = 'a'; ch <= 'z'; ch++) {
   294             buffer[off] = ch;
   295             if(unicode_hash(buffer, len) == etalon) {
   296                 printf("Dup: %.*s\n", (int)len, buffer);
   297             }
   298         }
   299     }
   300 }
   301 
   302 int
   303 main(int argc, char** argv)
   304 {
   305     char buffer[32];
   306     int len;
   307 
   308     if(argc < 2)
   309         etalon = unicode_hash("foo", 3);
   310     else
   311         etalon = unicode_hash(argv[1], strlen(argv[1]));
   312 
   313     for(len = 1; len <= sizeof(buffer); len++)
   314         recurse(buffer, 0, len);
   315 
   316     return 0;
   317 }
   318 ~~~