let s:sfile = expand('') function! s:reload(d) exe "so" a:d."/plugin/zencoding.vim" for f in split(globpath(a:d, 'autoload/**/*.vim'), "\n") silent! exe "so" f endfor endfunction call s:reload(expand(':h')) function! s:show_type(type) echohl Search | echon "[" a:type "]\n" | echohl None echo "\r" endfunction function! s:show_category(category) echohl MatchParen | echon "[" a:category "]\n" | echohl None echo "\r" endfunction function! s:escape(str) let str = a:str let str = substitute(str, "\n", '\\n', 'g') let str = substitute(str, "\t", '\\t', 'g') return str endfunction function! s:show_title(no, title) let title = s:escape(a:title) let width = &columns - 23 echohl ModeMsg | echon "\rtesting #".printf("%03d", a:no) echohl None | echon ": " . (len(title) < width ? (title.repeat(' ', width-len(title))) : strpart(title, 0, width)) . ' ... ' endfunction function! s:show_skip(no, title) let title = s:escape(a:title) let width = &columns - 23 echohl WarningMsg | echon "\rskipped #".printf("%03d", a:no) echohl None | echon ": " . (len(title) < width ? (title.repeat(' ', width-len(title))) : strpart(title, 0, width)) . ' ... ' echo "" endfunction function! s:show_ok() echohl Title | echon "ok\n" | echohl None echo "" endfunction function! s:show_ng(no, expect, got) echohl WarningMsg | echon "ng\n" | echohl None echohl ErrorMsg | echo "failed test #".a:no | echohl None set more echohl WarningMsg | echo printf("expect(%d):", len(a:expect)) | echohl None echo join(split(a:expect, "\n", 1), "|\n") echohl WarningMsg | echo printf("got(%d):", len(a:got)) | echohl None echo join(split(a:got, "\n", 1), "|\n") let cs = split(a:expect, '\zs') for c in range(len(cs)) if c < len(a:got) if a:expect[c] != a:got[c] echohl WarningMsg | echo "differ at:" | echohl None echo a:expect[c :-1] break endif endif endfor echo "" throw "stop" endfunction function! s:test(...) let type = get(a:000, 0, '') let name = get(a:000, 1, '') let index = get(a:000, 2, '') let testgroups = eval(join(filter(split(substitute(join(readfile(s:sfile), "\n"), '.*\nfinish\n', '', ''), '\n', 1), "v:val !~ '^\"'"))) for testgroup in testgroups if len(type) > 0 && testgroup.type != type | continue | endif call s:show_type(testgroup.type) let type = testgroup.type for category in testgroup.categories if len(name) > 0 && substitute(category.name,' ','_','g') != name | continue | endif call s:show_category(category.name) let tests = category.tests let start = reltime() for n in range(len(tests)) if len(index) > 0 && n != index | continue | endif let query = tests[n].query let result = tests[n].result if has_key(tests[n], 'skip') && tests[n].skip != 0 call s:show_skip(n+1, query) continue endif if stridx(query, '$$$$') != -1 silent! 1new silent! exe "setlocal ft=".type silent! let key = matchstr(query, '.*\$\$\$\$\zs.*\ze\$\$\$\$') if len(key) > 0 exe printf('let key = "%s"', key) else let key = "\," endif silent! let query = substitute(query, '\$\$\$\$.*\$\$\$\$', '$$$$', '') silent! call setline(1, split(query, "\n")) let cmd = "normal gg0/\\$\\$\\$\\$\ri\\\\".key if stridx(result, '$$$$') != -1 let cmd .= '$$$$' endif silent! exe cmd unlet! res | let res = join(getline(1, line('$')), "\n") silent! bw! call s:show_title(n+1, query) else call s:show_title(n+1, query) unlet! res | let res = zencoding#ExpandWord(query, type, 0) endif if stridx(result, '$$$$') != -1 if res ==# result call s:show_ok() else call s:show_ng(n+1, result, res) endif else if res ==# result call s:show_ok() else call s:show_ng(n+1, result, res) endif endif endfor echo "past:".reltimestr(reltime(start))."\n" endfor endfor endfunction function! s:do_tests(...) try if exists('g:user_zen_settings') let s:old_user_zen_settings = g:user_zen_settings let g:user_zen_settings = { 'indentation': "\t" } endif let oldmore = &more let &more = 0 call call('s:test', a:000) echo "done" catch echoerr v:exception finally let &more=oldmore if exists('g:user_zen_settings') let g:user_zen_settings = s:old_user_zen_settings endif endtry endfunction function! g:zencoding_unittest_complete(arglead, cmdline, cmdpos) let args = split(a:cmdline, '\s\+', 1) let testgroups = eval(join(filter(split(substitute(join(readfile(s:sfile), "\n"), '.*\nfinish\n', '', ''), '\n', 1), "v:val !~ '^\"'"))) try if len(args) == 2 return filter(map(testgroups, 'v:val.type'), 'stridx(v:val,args[1])!=-1') elseif len(args) == 3 return map(filter(testgroups, 'v:val.type==args[1]')[0].categories, 'substitute(v:val.name," ","_","g")') endif catch endtry return [] endfunction command! -nargs=* -complete=customlist,g:zencoding_unittest_complete ZenCodingUnitTest call s:do_tests() finish [ { 'type': "html", 'categories': [ { 'name': 'expand abbreviation', 'tests': [ { 'query': "div", 'result': "
\n", }, { 'query': "div#wrapper", 'result': "
\n", }, { 'query': "div.box", 'result': "
\n", }, { 'query': "a[title=TITLE]", 'result': "\n", }, { 'query': "div#wrapper.box", 'result': "
\n", }, { 'query': "div#wrapper.box.current", 'result': "
\n", }, { 'query': "div#wrapper.box.current[title=TITLE rel]", 'result': "
\n", }, { 'query': "div#main+div#sub", 'result': "
\n
\n", }, { 'query': "div#main>div#sub", 'result': "
\n\t
\n
\n", }, { 'query': "html:xt>div#header>div#logo+ul#nav>li.item-$*5>a", 'result': "\n\n\n\t\n\t\n\n\n\t
\n\t\t
\n\t\t
    \n\t\t\t
  • \n\t\t\t
  • \n\t\t\t
  • \n\t\t\t
  • \n\t\t\t
  • \n\t\t
\n\t
\n\t\n\n", }, { 'query': "ol>li*2", 'result': "
    \n\t
  1. \n\t
  2. \n
\n", }, { 'query': "a", 'result': "\n", }, { 'query': "obj", 'result': "\n", }, { 'query': "cc:ie6>p+blockquote#sample$.so.many.classes*2", 'result': "", }, { 'query': "tm>if>div.message", 'result': "\n\t\n\t\t
\n\t
\n
\n", }, { 'query': "html:4t>div#wrapper>div#header+div#contents+div#footer", 'result': "\n\n\n\t\n\t\n\n\n\t
\n\t\t
\n\t\t
\n\t\t
\n\t
\n\t\n\n", }, { 'query': "a[href=http://www.google.com/].foo#hoge", 'result': "\n", }, { 'query': "a[href=http://www.google.com/]{Google}", 'result': "Google\n", }, { 'query': "{ZenCoding}", 'result': "ZenCoding", }, { 'query': "a+b", 'result': "\n\n", }, { 'query': "a>b>i\n", }, { 'query': "a>b>i<\n\n", }, { 'query': "blockquote>b>i<\n\n", }, { 'query': "a[href=foo][class=bar]", 'result': "\n", }, { 'query': "a[a=b][b=c=d][e]{foo}*2", 'result': "foo\nfoo\n", }, { 'query': "a[a=b][b=c=d][e]*2{foo}", 'result': "\n\nfoo", }, { 'query': "a*2{foo}a", 'result': "\n\nfoo\n", }, { 'query': "a{foo}*2>b", 'result': "foo\nfoo\n", }, { 'query': "a*2{foo}>b", 'result': "\n\nfoo", }, { 'query': "table>tr>td.name#foo+td*3", 'result': "\n\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\n
\n", }, { 'query': "div#header + div#footer", 'result': "
\n
\n", }, { 'query': "#header + div#footer", 'result': "
\n
\n", }, { 'query': "#header > ul > li < p{Footer}", 'result': "
\n\t
    \n\t\t
  • \n\t
\n\t

Footer

\n
\n", }, { 'query': "a#foo$$$*3", 'result': "\n\n\n", }, { 'query': "ul+", 'result': "
    \n\t
  • \n
\n", }, { 'query': "table+", 'result': "\n\t\n\t\t\n\t\n
\n", }, { 'query': "#header>li<#content", 'result': "
\n\t
  • \n
    \n
    \n", }, { 'query': "(#header>li)<#content", 'result': "
    \n\t
  • \n
    \n
    \n", }, { 'query': "a>b>i<\n
    \n", }, { 'query': "(#header>h1)+#content+#footer", 'result': "
    \n\t

    \n
    \n
    \n
    \n", }, { 'query': "(#header>h1)+(#content>(#main>h2+div#entry$.section*5>(h3>a)+div>p*3+ul+)+(#utilities))+(#footer>address)", 'result': "
    \n\t

    \n
    \n
    \n\t
    \n\t\t

    \n\t\t
    \n\t\t\t

    \n\t\t\t
    \n\t\t\t\t

    \n\t\t\t\t

    \n\t\t\t\t

    \n\t\t\t\t
      \n\t\t\t\t\t
    • \n\t\t\t\t
    \n\t\t\t
    \n\t\t
    \n\t\t
    \n\t\t\t

    \n\t\t\t
    \n\t\t\t\t

    \n\t\t\t\t

    \n\t\t\t\t

    \n\t\t\t\t
      \n\t\t\t\t\t
    • \n\t\t\t\t
    \n\t\t\t
    \n\t\t
    \n\t\t
    \n\t\t\t

    \n\t\t\t
    \n\t\t\t\t

    \n\t\t\t\t

    \n\t\t\t\t

    \n\t\t\t\t
      \n\t\t\t\t\t
    • \n\t\t\t\t
    \n\t\t\t
    \n\t\t
    \n\t\t
    \n\t\t\t

    \n\t\t\t
    \n\t\t\t\t

    \n\t\t\t\t

    \n\t\t\t\t

    \n\t\t\t\t
      \n\t\t\t\t\t
    • \n\t\t\t\t
    \n\t\t\t
    \n\t\t
    \n\t\t
    \n\t\t\t

    \n\t\t\t
    \n\t\t\t\t

    \n\t\t\t\t

    \n\t\t\t\t

    \n\t\t\t\t
      \n\t\t\t\t\t
    • \n\t\t\t\t
    \n\t\t\t
    \n\t\t
    \n\t
    \n\t
    \n
    \n
    \n\t
    \n
    \n", }, { 'query': "(div>(ul*2)*2)+(#utilities)", 'result': "
    \n\t
      \n\t
        \n\t
          \n\t
            \n
            \n
            \n", }, { 'query': "table>(tr>td*3)*4", 'result': "\n\t\n\t\t\n\t\t\n\t\t\n\t\n\t\n\t\t\n\t\t\n\t\t\n\t\n\t\n\t\t\n\t\t\n\t\t\n\t\n\t\n\t\t\n\t\t\n\t\t\n\t\n
            \n", }, { 'query': "(((a#foo+a#bar)*2)*3)", 'result': "\n\n\n\n\n\n\n\n\n\n\n\n", }, { 'query': "div#box$*3>h3+p*2", 'result': "
            \n\t

            \n\t

            \n\t

            \n
            \n
            \n\t

            \n\t

            \n\t

            \n
            \n
            \n\t

            \n\t

            \n\t

            \n
            \n" }, { 'query': "div#box.foo$$$.bar$$$*3", 'result': "
            \n
            \n
            \n", }, { 'query': "div#box$*3>h3+p.bar*2|e", 'result': "<div id=\"box1\">\n\t&lt;h3&gt;&lt;/h3&gt;\n\t&lt;p class=\"bar\"&gt;&lt;/p&gt;\n\t&lt;p class=\"bar\"&gt;&lt;/p&gt;\n</div>\n<div id=\"box2\">\n\t&lt;h3&gt;&lt;/h3&gt;\n\t&lt;p class=\"bar\"&gt;&lt;/p&gt;\n\t&lt;p class=\"bar\"&gt;&lt;/p&gt;\n</div>\n<div id=\"box3\">\n\t&lt;h3&gt;&lt;/h3&gt;\n\t&lt;p class=\"bar\"&gt;&lt;/p&gt;\n\t&lt;p class=\"bar\"&gt;&lt;/p&gt;\n</div>\n", }, { 'query': "div>div#page>p.title+p|c", 'result': "
            \n\t\n\t
            \n\t\t\n\t\t

            \n\t\t\n\t\t

            \n\t
            \n\t\n
            \n", }, { 'query': "link:css", 'result': "\n", }, { 'query': "a[title=\"Hello', world\" rel]", 'result': "\n", }, { 'query': "div>a#foo{bar}", 'result': "\n", }, { 'query': ".content{Hello!}", 'result': "
            Hello!
            \n", }, { 'query': "div.logo+(div#navigation)+(div#links)", 'result': "
            \n
            \n
            \n", }, { 'query': "h1{header}+{Text}+a[href=http://link.org]{linktext}+{again some text}+a[href=http://anoterlink.org]{click me!}+{some final text}", 'result': "

            header

            \nTextlinktext\nagain some textclick me!\nsome final text", }, { 'query': "a{&}+div{&&}", 'result': "&\n
            &&
            \n", }, { 'query': "span$$$$\\,$$$$", 'result': "", }, { 'query': "foo span$$$$\\,$$$$", 'result': "foo ", }, { 'query': "foo span$$$$\\,$$$$ bar", 'result': "foo bar", }, { 'query': "foo $$$$\\ve\\,p\\$$$$bar baz", 'result': "foo

            bar

            baz", }, { 'query': "foo $$$$\\vee\\,p\\$$$$bar baz", 'result': "foo

            bar baz

            ", }, { 'query': "f div.boxes>article.box2>header>(hgroup>h2{aaa}+h3{bbb})+p{ccc}$$$$", 'result': "f
            \n\t
            \n\t\t
            \n\t\t\t
            \n\t\t\t\t

            aaa

            \n\t\t\t\t

            bbb

            \n\t\t\t
            \n\t\t\t

            ccc

            \n\t\t
            \n\t
            \n
            ", }, { 'query': "div.boxes>(div.box2>section>h2{a}+p{b})+(div.box1>section>h2{c}+p{d}+p{e}+(bq>h2{f}+h3{g})+p{h})", 'result': "
            \n\t
            \n\t\t
            \n\t\t\t

            a

            \n\t\t\t

            b

            \n\t\t
            \n\t
            \n\t
            \n\t\t
            \n\t\t\t

            c

            \n\t\t\t

            d

            \n\t\t\t

            e

            \n\t\t\t
            \n\t\t\t\t

            f

            \n\t\t\t\t

            g

            \n\t\t\t
            \n\t\t\t

            h

            \n\t\t
            \n\t
            \n
            \n", }, ], }, { 'name': 'split join tag', 'tests': [ { 'query': "
            \n\t$$$$\\j$$$$\n
            ", 'result': "
            \n\t\n
            ", }, { 'query': "
            \n\tj$$$$/>\n
            ", 'result': "
            \n\t\n
            ", }, ], }, { 'name': 'toggle comment', 'tests': [ { 'query': "
            \n\t$$$$\\/$$$$\n
            ", 'result': "
            \n\t\n
            ", }, { 'query': "
            \n\t\n
            ", 'result': "
            \n\t\n
            ", }, ], }, { 'name': 'image size', 'tests': [ { 'query': "img[src=http://mattn.kaoriya.net/images/logo.png]$$$$\\,\\i$$$$", 'result': "\"\"", }, { 'query': "img[src=/logo.png]$$$$\\,\\i$$$$", 'result': "\"\"", }, ], }, { 'name': 'move next prev', 'tests': [ { 'query': "foo+bar+baz[dankogai=\"\"]$$$$\\,\\gg0\\n\\n\\n\\Byw:%d _\\p$$$$", 'result': "dankogai", }, ], }, ], }, { 'type': 'css', 'categories': [ { 'name': 'expand abbreviation', 'tests': [ { 'query': "@i", 'result': "@import url();", }, { 'query': "fs:n", 'result': "font-style: normal;", }, { 'query': "fl:l|fc", 'result': "float: left;", }, { 'query': "bg+$$$$", 'result': "background: #FFF url($$$$) 0 0 no-repeat;", }, ], }, ], }, { 'type': 'haml', 'categories': [ { 'name': 'expand abbreviation', 'tests': [ { 'query': "div>p+ul#foo>li.bar$[foo=bar][bar=baz]*3>{baz}", 'result': "%div\n %p\n %ul#foo\n %li.bar1{ :foo => \"bar\", :bar => \"baz\" } baz\n %li.bar2{ :foo => \"bar\", :bar => \"baz\" } baz\n %li.bar3{ :foo => \"bar\", :bar => \"baz\" } baz\n", }, { 'query': "div>p+ul#foo>li.bar$[foo=bar][bar=baz]*3>{baz}|haml", 'result': "%div\n %p\n %ul#foo\n %li.bar1{ :foo => \"bar\", :bar => \"baz\" } baz\n %li.bar2{ :foo => \"bar\", :bar => \"baz\" } baz\n %li.bar3{ :foo => \"bar\", :bar => \"baz\" } baz\n", }, { 'query': "a*3|haml", 'result': "%a{ :href => \"\" }\n%a{ :href => \"\" }\n%a{ :href => \"\" }\n", }, { 'query': ".content{Hello!}|haml", 'result': "%div.content Hello!\n", }, ], }, { 'name': 'expand abbreviation', 'tests': [ { 'query': "%a foo\n bar$$$$\\j$$$$", 'result': "%a ", }, { 'query': "$$$$\\j$$$$%a ", 'result': "%a $$$$", }, ], }, { 'name': 'toggle comment', 'tests': [ { 'query': "%a{ :href => \"http://www.google.com\"$$$$\\/$$$$ } hello", 'result': "-# %a{ :href => \"http://www.google.com\" } hello", }, { 'query': "-# %a{ :href => \"http://www.google.com\"$$$$\\/$$$$ } hello", 'result': "%a{ :href => \"http://www.google.com\" } hello", }, ], }, ], }, { 'type': 'slim', 'categories': [ { 'name': 'expand abbreviation', 'tests': [ { 'query': "div>p+ul#foo>li.bar$[foo=bar][bar=baz]*3>{baz}", 'result': "div\n p\n ul id=\"foo\"\n li foo=\"bar\" bar=\"baz\" class=\"bar1\"\n | baz\n li foo=\"bar\" bar=\"baz\" class=\"bar2\"\n | baz\n li foo=\"bar\" bar=\"baz\" class=\"bar3\"\n | baz\n", }, { 'query': "div>p+ul#foo>li.bar$[foo=bar][bar=baz]*3>{baz}|slim", 'result': "div\n p\n ul id=\"foo\"\n li foo=\"bar\" bar=\"baz\" class=\"bar1\"\n | baz\n li foo=\"bar\" bar=\"baz\" class=\"bar2\"\n | baz\n li foo=\"bar\" bar=\"baz\" class=\"bar3\"\n | baz\n", }, { 'query': "a*3|slim", 'result': "a href=\"\"\na href=\"\"\na href=\"\"\n", }, { 'query': ".content{Hello!}|slim", 'result': "div class=\"content\"\n | Hello!\n", }, ], }, { 'name': 'split join tag', 'tests': [ { 'query': "a\n | foo$$$$\\j$$$$", 'result': "a", }, { 'query': "a$$$$\\j$$$$", 'result': "a\n | $$$$", }, ], }, { 'name': 'toggle comment', 'tests': [ { 'query': "a href=\"http://www.google.com\"$$$$\\/$$$$\n | hello", 'result': "/a href=\"http://www.google.com\"\n | hello", }, { 'query': "/a href=\"http://www.google.com\"$$$$\\/$$$$\n | hello", 'result': "a href=\"http://www.google.com\"\n | hello", }, ], }, ], }, { 'type': 'xsl', 'categories': [ { 'name': 'expand abbreviation', 'tests': [ { 'query': "vari", 'result': "\n", }, { 'query': "ap>wp", 'result': "\n\t\n\n", }, ], }, ], }, { 'type': 'xsd', 'categories': [ { 'name': 'expand abbreviation', 'tests': [ { 'query': "xsd:w3c", 'result': "\n\n\t\n", }, ], }, ], }, { 'type': 'mustache', 'categories': [ { 'name': 'expand abbreviation', 'tests': [ { 'name': "div#{{foo}}", 'query': "div#{{foo}}", 'type': "mustache", 'result': "
            \n", }, { 'name': "div.{{foo}}", 'query': "div.{{foo}}", 'type': "mustache", 'result': "
            \n", }, ], }, ], }, ] " vim:set et: