blob: a6f57a893cabc5cf46ff357532af9bfcd7888296 [file] [log] [blame]
Bram Moolenaar622b3562020-07-27 20:02:41 +02001" Test for MzScheme interface and mzeval() function
2
Bram Moolenaar622b3562020-07-27 20:02:41 +02003CheckFeature mzscheme
4
5func MzRequire()
6 redir => l:mzversion
7 mz (version)
8 redir END
9 if strpart(l:mzversion, 1, 1) < "4"
10 " MzScheme versions < 4.x:
11 mz (require (prefix vim- vimext))
12 else
13 " newer versions:
14 mz (require (prefix-in vim- 'vimext))
15 mz (require r5rs)
16 endif
17endfunc
18
19func Test_mzscheme()
20 new
21 let lines =<< trim END
22 1 line 1
23 2 line 2
24 3 line 3
25 END
26 call setline(1, lines)
27
28 call MzRequire()
29 mz (define l '("item0" "dictionary with list OK" "item2"))
30 mz (define h (make-hash))
31 mz (hash-set! h "list" l)
32
33 call cursor(1, 1)
34 " change buffer contents
35 mz (vim-set-buff-line (vim-eval "line('.')") "1 changed line 1")
36 call assert_equal('1 changed line 1', getline(1))
37
38 " scalar test
39 let tmp_string = mzeval('"string"')
40 let tmp_1000 = '1000'->mzeval()
41 call assert_equal('string1000', tmp_string .. tmp_1000)
42
43 " dictionary containing a list
44 call assert_equal('dictionary with list OK', mzeval("h")["list"][1])
45
46 call cursor(2, 1)
47 " circular list (at the same time test lists containing lists)
48 mz (set-car! (cddr l) l)
49 let l2 = mzeval("h")["list"]
50 call assert_equal(l2[2], l2)
51
52 " funcrefs
53 mz (define vim:max (vim-eval "function('max')"))
54 mz (define m (vim:max '(1 100 8)))
55 let m = mzeval('m')
56 call assert_equal(100, m)
57
58 close!
59endfunc
60
61" vim: shiftwidth=2 sts=2 expandtab