Yinzuo Jiang | 360c512 | 2024-07-13 19:02:10 +0200 | [diff] [blame] | 1 | " Tests for Vim :TOhtml |
| 2 | |
| 3 | source check.vim |
| 4 | |
| 5 | func s:setup_basic(src_name) |
| 6 | let lines =<< trim END |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | |
| 10 | int isprime(int n) |
| 11 | { |
| 12 | if (n <= 1) |
| 13 | return 0; |
| 14 | |
| 15 | for (int i = 2; i <= n / 2; i++) |
| 16 | if (n % i == 0) |
| 17 | return 0; |
| 18 | |
| 19 | return 1; |
| 20 | } |
| 21 | |
| 22 | int main(int argc, char *argv[]) |
| 23 | { |
| 24 | int n = 7; |
| 25 | |
| 26 | printf("%d is %s prime\n", n, isprime(n) ? "a" : "not a"); |
| 27 | |
| 28 | return 0; |
| 29 | } |
| 30 | END |
| 31 | call writefile(lines, a:src_name) |
| 32 | exe 'edit ' . a:src_name |
| 33 | TOhtml |
| 34 | write |
| 35 | endfunc |
| 36 | |
| 37 | func s:cleanup_basic(src_name) |
| 38 | call delete(a:src_name) |
| 39 | call delete(a:src_name . ".html") |
| 40 | endfunc |
| 41 | |
| 42 | source $VIMRUNTIME/plugin/tohtml.vim |
| 43 | |
| 44 | func Test_tohtml_basic() |
| 45 | let src_name = "Test_tohtml_basic.c" |
| 46 | call s:setup_basic(src_name) |
| 47 | let expected = readfile("samples/" . src_name . ".html") |
| 48 | let actual = readfile(src_name . ".html") |
| 49 | call assert_equal(expected[0:3], actual[0:3]) |
| 50 | " Ignore the title |
| 51 | call assert_equal(expected[5:11], actual[5:11]) |
| 52 | " Ignore pre and body css |
| 53 | call assert_equal(expected[14:], actual[14:]) |
| 54 | call s:cleanup_basic(src_name) |
| 55 | endfunc |
| 56 | |
| 57 | func Test_tohtml_basic_no_css() |
| 58 | let g:html_use_css = 0 |
| 59 | let src_name = "Test_tohtml_basic_no_css.c" |
| 60 | call s:setup_basic(src_name) |
| 61 | let expected = readfile("samples/" . src_name . ".html") |
| 62 | let actual = readfile(src_name . ".html") |
| 63 | call assert_equal(expected[0:3], actual[0:3]) |
| 64 | " Ignore the title |
| 65 | call assert_equal(expected[5:10], actual[5:10]) |
| 66 | " Ignore body's inline css |
| 67 | call assert_equal(expected[12:], actual[12:]) |
| 68 | call s:cleanup_basic(src_name) |
| 69 | unlet g:html_use_css |
| 70 | endfunc |
| 71 | |
| 72 | " vim: shiftwidth=2 sts=2 expandtab |