Browse files

Version 0.0.3: Initial upload

  • Loading branch information...
0 parents commit e241eaa153f3bea15c48ca97eec5da9bf0d39e87 Kana Natsuno committed with Mar 12, 2010
6 .mduem/cache/Makefile.variables
@@ -0,0 +1,6 @@
+all_files_in_repos := Makefile autoload/vspec.vim bin/vspec doc/vspec.txt test/context.expected test/context.input test/custom-matcher.expected test/custom-matcher.input test/no-test.expected test/no-test.input test/tools.expected test/tools.input test/typical-content.expected test/typical-content.input
+current_branch := master
+origin_name := origin
+origin_uri := ../.
+repos_name := vim-vspec
+version := 0.0.3
12 Makefile
@@ -0,0 +1,12 @@
+# Makefile for vim-vspec
+
+INSTALLATION_DIR := $(HOME)/.vim
+TARGETS_STATIC = $(filter %.vim %.txt,$(all_files_in_repos))
+TARGETS_ARCHIVED = $(all_files_in_repos) mduem/Makefile
+
+
+
+
+include mduem/Makefile
+
+# __END__
13 README
@@ -0,0 +1,13 @@
+This is a mirror of http://www.vim.org/scripts/script.php?script_id=3012
+
+*vspec* is a Vim library plugin to test Vim script.
+
+
+Requirements:
+- Vim 7.2 or later
+
+Latest version:
+http://github.com/kana/vim-vspec
+
+Document in HTML format:
+http://kana.github.com/config/vim/vspec.html
526 autoload/vspec.vim
@@ -0,0 +1,526 @@
+" vspec - Test framework for Vim script
+" Version: 0.0.3
+" Copyright (C) 2009-2010 kana <http://whileimautomaton.net/>
+" License: MIT license {{{
+" Permission is hereby granted, free of charge, to any person obtaining
+" a copy of this software and associated documentation files (the
+" "Software"), to deal in the Software without restriction, including
+" without limitation the rights to use, copy, modify, merge, publish,
+" distribute, sublicense, and/or sell copies of the Software, and to
+" permit persons to whom the Software is furnished to do so, subject to
+" the following conditions:
+"
+" The above copyright notice and this permission notice shall be included
+" in all copies or substantial portions of the Software.
+"
+" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+" }}}
+" Variables "{{{1
+
+let s:EXPR_HINT_SCOPE = '{}'
+let s:EXPR_HINT_SID = 's:'
+
+let s:FALSE = 0
+let s:TRUE = !s:FALSE
+
+let s:VALID_MATCHERS_EQUALITY = [
+\ '!=',
+\ '==',
+\ 'is',
+\ 'isnot',
+\
+\ '!=?',
+\ '==?',
+\ 'is?',
+\ 'isnot?',
+\
+\ '!=#',
+\ '==#',
+\ 'is#',
+\ 'isnot#',
+\ ]
+let s:VALID_MATCHERS_REGEXP = [
+\ '!~',
+\ '=~',
+\
+\ '!~?',
+\ '=~?',
+\
+\ '!~#',
+\ '=~#',
+\ ]
+let s:VALID_MATCHERS_ORDERING = [
+\ '<',
+\ '<=',
+\ '>',
+\ '>=',
+\
+\ '<?',
+\ '<=?',
+\ '>?',
+\ '>=?',
+\
+\ '<#',
+\ '<=#',
+\ '>#',
+\ '>=#',
+\ ]
+let s:VALID_MATCHERS_CUSTOM = [
+\ 'be',
+\ ]
+let s:VALID_MATCHERS = (s:VALID_MATCHERS_CUSTOM
+\ + s:VALID_MATCHERS_EQUALITY
+\ + s:VALID_MATCHERS_ORDERING
+\ + s:VALID_MATCHERS_REGEXP)
+
+let s:context_stack = []
+
+let s:custom_matchers = {} " alias => function
+
+let s:saved_scope = {}
+
+
+
+
+
+
+
+
+" Interface "{{{1
+function! Call(...) "{{{2
+ return call('vspec#call', a:000)
+endfunction
+
+
+
+
+function! Ref(...) "{{{2
+ return call('vspec#ref', a:000)
+endfunction
+
+
+
+
+function! Set(...) "{{{2
+ return call('vspec#set', a:000)
+endfunction
+
+
+
+
+function! vspec#call(function_name, ...) "{{{2
+ return call(substitute(a:function_name, '^s:', s:hint_sid(), ''), a:000)
+endfunction
+
+
+
+
+function! vspec#customize_matcher(alias, function) "{{{2
+ let s:custom_matchers[a:alias] = a:function
+endfunction
+
+
+
+
+function! vspec#hint(info) "{{{2
+ if has_key(a:info, 'scope')
+ let s:EXPR_HINT_SCOPE = a:info.scope
+ call vspec#cmd_SaveContext()
+ endif
+
+ if has_key(a:info, 'sid')
+ let s:EXPR_HINT_SID = a:info.sid
+ endif
+
+ return
+endfunction
+
+
+
+
+function! vspec#ref(variable_name) "{{{2
+ if a:variable_name =~# '^s:'
+ return s:hint_scope()[a:variable_name[2:]]
+ else
+ echoerr 'Invalid variable_name:' string(a:variable_name)
+ endif
+endfunction
+
+
+
+
+function! vspec#set(variable_name, value) "{{{2
+ if a:variable_name =~# '^s:'
+ let _ = s:hint_scope()
+ let _[a:variable_name[2:]] = a:value
+ else
+ echoerr 'Invalid variable_name:' string(a:variable_name)
+ endif
+ return
+endfunction
+
+
+
+
+function! vspec#test(spec_file) "{{{2
+ call s:push_context({
+ \ 'total_expectations': 0,
+ \ 'failures': [],
+ \ })
+
+ source `=a:spec_file`
+
+ let current_context = s:current_context()
+ for describer in s:extract_describers()
+ let current_context.describer = describer
+
+ echo '====' s:description_from_describer(describer)
+ call {describer.function_name}()
+ echon "\n"
+ endfor
+
+ call s:output_summary(s:pop_context())
+
+ return
+endfunction
+
+
+
+
+function! vspec#_scope() "{{{2
+ return s:
+endfunction
+
+
+
+
+function! vspec#_sid() "{{{2
+ return maparg('<SID>', 'n')
+endfunction
+nnoremap <SID> <SID>
+
+
+
+
+" Commands "{{{2
+
+command! -nargs=+ It call vspec#cmd_It(<q-args>)
+
+command! -nargs=0 ResetContext call vspec#cmd_ResetContext()
+command! -nargs=0 SaveContext call vspec#cmd_SaveContext()
+
+command! -nargs=+ Should
+\ call vspec#cmd_Should(s:parse_should_args(<q-args>, 'raw'),
+\ map(s:parse_should_args(<q-args>, 'eval'),
+\ 'eval(v:val)'))
+
+
+
+
+" Predefined Custom Matchers "{{{2
+
+function! vspec#_matcher_true(value)
+ return type(a:value) == type(0) ? !!(a:value) : !!0
+endfunction
+call vspec#customize_matcher('true', function('vspec#_matcher_true'))
+
+function! vspec#_matcher_false(value)
+ return type(a:value) == type(0) ? !(a:value) : !!0
+endfunction
+call vspec#customize_matcher('false', function('vspec#_matcher_false'))
+
+
+
+
+
+
+
+
+" Misc. "{{{1
+function! vspec#cmd_It(message) "{{{2
+ let _ = s:current_context()
+ let _.group = a:message
+ echo '---- It' a:message "\n"
+ return
+endfunction
+
+
+
+
+function! vspec#cmd_ResetContext() "{{{2
+ call extend(s:hint_scope(), deepcopy(s:saved_scope), 'force')
+ return
+endfunction
+
+
+
+
+function! vspec#cmd_SaveContext() "{{{2
+ let s:saved_scope = deepcopy(s:hint_scope())
+ return
+endfunction
+
+
+
+
+function! vspec#cmd_Should(exprs, values) "{{{2
+ let [expr_actual, expr_matcher, expr_expected] = a:exprs
+ let [Value_actual, Value_matcher, Value_expected] = a:values
+ let current_context = s:current_context()
+
+ if s:matches_p(Value_actual, Value_matcher, Value_expected)
+ echon '.'
+ else
+ echon 'x'
+ call add(current_context.failures,
+ \ [current_context.describer,
+ \ current_context.group,
+ \ a:exprs,
+ \ a:values])
+ endif
+ let current_context.total_expectations += 1
+
+ return
+endfunction
+
+
+
+
+" Context "{{{2
+function! s:current_context() "{{{3
+ return s:context_stack[-1]
+endfunction
+
+
+function! s:pop_context() "{{{3
+ return remove(s:context_stack, -1)
+endfunction
+
+
+function! s:push_context(context) "{{{3
+ call add(s:context_stack, a:context)
+ return
+endfunction
+
+
+
+
+function! s:description_from_describer(describer) "{{{2
+ return join([a:describer.feature_name,
+ \ substitute(a:describer.case, '_', ' ', 'g')],
+ \ ' ')
+endfunction
+
+
+
+
+function! s:extract_describers() "{{{2
+ let f = {}
+ function! f.normalize(function_name)
+ let _ = split(a:function_name, '__')
+ let describer = {}
+ let describer.function_name = a:function_name
+ let describer.feature_name = _[1]
+ let describer.case = join(_[2:], '__')
+ return describer
+ endfunction
+
+ redir => function_names
+ silent function /
+ redir END
+
+ let _ = split(function_names, '\n')
+ let PATTERN = '\v^function \zs(\<SNR\>\d+_describe__\w+)\ze\('
+ call map(_, 'matchstr(v:val, PATTERN)')
+ call filter(_, 'v:val != ""')
+ call map(_, 'substitute(v:val, "<SNR>", "\<SNR>", "")')
+ call map(_, 'f.normalize(v:val)')
+ call sort(_)
+
+ return _
+endfunction
+
+
+
+
+function! s:hint_scope() "{{{2
+ return eval(s:EXPR_HINT_SCOPE)
+endfunction
+
+
+
+
+function! s:hint_sid() "{{{2
+ return eval(s:EXPR_HINT_SID)
+endfunction
+
+
+
+
+function! s:matches_p(value_actual, expr_matcher, value_expected) "{{{2
+ if !s:valid_matcher_p(a:expr_matcher)
+ " FIXME: Useful message
+ echoerr 'Invalid a:expr_matcher:' string(a:expr_matcher)
+ return s:FALSE
+ endif
+
+ if s:valid_matcher_custom_p(a:expr_matcher)
+ let custom_matcher_name = a:value_expected
+ if !has_key(s:custom_matchers, custom_matcher_name)
+ echoerr 'Unknown custom matcher:' string(custom_matcher_name)
+ return s:FALSE
+ endif
+ let MatchesP = s:custom_matchers[custom_matcher_name]
+ return MatchesP(a:value_actual)
+ elseif s:valid_matcher_equality_p(a:expr_matcher)
+ let type_equality = type(a:value_actual) == type(a:value_expected)
+ if s:valid_matcher_negative_p(a:expr_matcher) && !type_equality
+ return s:TRUE
+ else
+ return eval('a:value_actual ' . a:expr_matcher . ' a:value_expected')
+ endif
+ elseif s:valid_matcher_ordering_p(a:expr_matcher)
+ if type(a:value_actual) != type(a:value_expected)
+ return s:FALSE
+ endif
+ if !(s:orderable_type_p(a:value_actual)
+ \ && s:orderable_type_p(a:value_expected))
+ return s:FALSE
+ endif
+ return eval('a:value_actual ' . a:expr_matcher . ' a:value_expected')
+ elseif s:valid_matcher_regexp_p(a:expr_matcher)
+ if type(a:value_actual) != type('') || type(a:value_expected) != type('')
+ return s:FALSE
+ endif
+ return eval('a:value_actual ' . a:expr_matcher . ' a:value_expected')
+ else
+ return eval('a:value_actual ' . a:expr_matcher . ' a:value_expected')
+ endif
+endfunction
+
+
+
+
+function! s:orderable_type_p(value) "{{{2
+ " FIXME: +float
+ return type(a:value) == type(0) || type(a:value) == type('')
+endfunction
+
+
+
+
+function! s:output_summary(context) "{{{2
+ echon "\n"
+ echon "\n"
+ echo '**** Result ****'
+
+ let previous_describer = {}
+ for [describer, group, exprs, values] in a:context.failures
+ if describer isnot previous_describer
+ echon "\n"
+ echon "\n"
+ echo 'In' s:description_from_describer(describer)
+ endif
+
+ echon "\n"
+ echo 'It' group
+ echo 'FAILED:' join(exprs, ' ')
+ if s:valid_matcher_custom_p(values[1])
+ echo ' got:' string(values[0])
+ elseif s:valid_matcher_equality_p(values[1])
+ echo ' expected:' string(values[2])
+ echo ' got:' string(values[0])
+ else
+ echo ' lhs:' string(values[0])
+ echo ' rhs:' string(values[2])
+ endif
+
+ let previous_describer = describer
+ endfor
+
+ echo printf("\n\n%s examples, %s failures\n",
+ \ a:context.total_expectations,
+ \ len(a:context.failures))
+ return
+endfunction
+
+
+
+
+function! s:parse_should_args(s, mode) "{{{2
+ let CMPS = join(map(copy(s:VALID_MATCHERS), 'escape(v:val, "=!<>~#?")'), '|')
+ let _ = matchlist(a:s, printf('\C\v^(.{-})\s+(%%(%s)[#?]?)\s+(.*)$', CMPS))
+ let tokens = _[1:3]
+ let [_actual, _matcher, _expected] = copy(tokens)
+ let [actual, matcher, expected] = copy(tokens)
+
+ if a:mode ==# 'eval'
+ if s:valid_matcher_p(_matcher)
+ let matcher = string(_matcher)
+ endif
+ if s:valid_matcher_custom_p(_matcher)
+ let expected = string(_expected)
+ endif
+ endif
+
+ return [actual, matcher, expected]
+endfunction
+
+
+
+
+function! s:valid_matcher_p(expr_matcher) "{{{2
+ return 0 <= index(s:VALID_MATCHERS, a:expr_matcher)
+endfunction
+
+
+
+
+function! s:valid_matcher_custom_p(expr_matcher) "{{{2
+ return 0 <= index(s:VALID_MATCHERS_CUSTOM, a:expr_matcher)
+endfunction
+
+
+
+
+function! s:valid_matcher_equality_p(expr_matcher) "{{{2
+ return 0 <= index(s:VALID_MATCHERS_EQUALITY, a:expr_matcher)
+endfunction
+
+
+
+
+function! s:valid_matcher_negative_p(expr_matcher) "{{{2
+ " FIXME: Ad hoc way.
+ return s:valid_matcher_p(a:expr_matcher) && a:expr_matcher =~# '\(!\|not\)'
+endfunction
+
+
+
+
+function! s:valid_matcher_ordering_p(expr_matcher) "{{{2
+ return 0 <= index(s:VALID_MATCHERS_ORDERING, a:expr_matcher)
+endfunction
+
+
+
+
+function! s:valid_matcher_regexp_p(expr_matcher) "{{{2
+ return 0 <= index(s:VALID_MATCHERS_REGEXP, a:expr_matcher)
+endfunction
+
+
+
+
+
+
+
+
+" __END__ "{{{1
+" vim: foldmethod=marker
39 bin/vspec
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+if [ "$#" = '0' ] || [ "$1" = '-h' ] || [ "$1" = '--help' ]
+then
+ echo "Usage: $0 {input-script} [{non-standard-runtimepath} ...]"
+ exit
+fi
+
+driver_script=",,$$.vim"
+input_script="$1"
+shift # Now $@ is expanded to all {non-standard-runtimepath}s.
+
+
+
+
+cat <<END >"$driver_script"
+ function s:main()
+ let standard_paths = split(&runtimepath, ',')[1:-1]
+ let non_standard_paths = ['$(echo "$@" | sed "s/ */', '/g")']
+ let all_paths = copy(standard_paths)
+ for i in non_standard_paths
+ let all_paths = [i] + all_paths + [i . '/after']
+ endfor
+ let &runtimepath = join(all_paths, ',')
+
+ 1 verbose call vspec#test('$input_script')
+ qall!
+ endfunction
+ call s:main()
+END
+
+vim -u NONE -i NONE -N -e -s -S "$driver_script" 2>&1 | sed "s|$(pwd)|.|g"
+
+
+
+
+rm -f "$driver_script"
+
+#__END__
31 doc/tags
@@ -0,0 +1,31 @@
+:It vspec.txt /*:It*
+:ResetContext vspec.txt /*:ResetContext*
+:SaveContext vspec.txt /*:SaveContext*
+:Should vspec.txt /*:Should*
+Call() vspec.txt /*Call()*
+Ref() vspec.txt /*Ref()*
+Set() vspec.txt /*Set()*
+bin/vspec vspec.txt /*bin\/vspec*
+vspec vspec.txt /*vspec*
+vspec#call() vspec.txt /*vspec#call()*
+vspec#customize_matcher() vspec.txt /*vspec#customize_matcher()*
+vspec#hint() vspec.txt /*vspec#hint()*
+vspec#ref() vspec.txt /*vspec#ref()*
+vspec#set() vspec.txt /*vspec#set()*
+vspec#test() vspec.txt /*vspec#test()*
+vspec-bugs vspec.txt /*vspec-bugs*
+vspec-changelog vspec.txt /*vspec-changelog*
+vspec-changelog-0.0.0 vspec.txt /*vspec-changelog-0.0.0*
+vspec-changelog-0.0.1 vspec.txt /*vspec-changelog-0.0.1*
+vspec-changelog-0.0.2 vspec.txt /*vspec-changelog-0.0.2*
+vspec-changelog-0.0.3 vspec.txt /*vspec-changelog-0.0.3*
+vspec-commands vspec.txt /*vspec-commands*
+vspec-contents vspec.txt /*vspec-contents*
+vspec-custom-matcher vspec.txt /*vspec-custom-matcher*
+vspec-examples vspec.txt /*vspec-examples*
+vspec-external-commands vspec.txt /*vspec-external-commands*
+vspec-functions vspec.txt /*vspec-functions*
+vspec-interface vspec.txt /*vspec-interface*
+vspec-introduction vspec.txt /*vspec-introduction*
+vspec-predefined-custom-matchers vspec.txt /*vspec-predefined-custom-matchers*
+vspec.txt vspec.txt /*vspec.txt*
302 doc/vspec.txt
@@ -0,0 +1,302 @@
+*vspec.txt* Test framework for Vim script
+
+Version 0.0.3
+Script ID: 3012
+Copyright (C) 2009-2010 kana <http://whileimautomaton.net/>
+License: MIT license {{{
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+}}}
+
+CONTENTS *vspec-contents*
+
+Introduction |vspec-introduction|
+Interface |vspec-interface|
+ External Commands |vspec-external-commands|
+ Commands |vspec-commands|
+ Functions |vspec-functions|
+Examples |vspec-examples|
+Bugs |vspec-bugs|
+Changelog |vspec-changelog|
+
+
+
+
+==============================================================================
+INTRODUCTION *vspec-introduction*
+
+*vspec* is a Vim library plugin to test Vim script.
+
+
+Requirements:
+- Vim 7.2 or later
+
+Latest version:
+http://github.com/kana/vim-vspec
+
+Document in HTML format:
+http://kana.github.com/config/vim/vspec.html
+
+
+
+
+==============================================================================
+INTERFACE *vspec-interface*
+
+------------------------------------------------------------------------------
+EXTERNAL COMMANDS *vspec-external-commands*
+
+ *bin/vspec*
+bin/vspec {input-script} [{non-standard-runtimepath} ...]
+ Utility command to test Vim script with vspec.
+
+ {input-script} is the path to a file which is a test
+ script written with vspec.
+
+ {non-standard-runtimepath} is the path to a directory
+ to use as a part of 'runtimepath' while executing
+ {input-script}.
+
+ Examples:
+>
+ $ ./bin/vspec test/context.input .
+<
+
+------------------------------------------------------------------------------
+COMMANDS *vspec-commands*
+
+:It {message} *:It*
+ Describe a group of expectations (which are described
+ by |:Should|).
+
+ {message} is a string which represents a description
+ of expectations after :It. This message is just used
+ for output.
+
+ Examples:
+>
+ :It "should match case-sensitively"
+ :Should 'abc' =~ 'a'
+ :Should 'abc' !~ 'A'
+<
+
+:ResetContext *:ResetContext*
+ Reset the current context of a script with one saved
+ by |:SaveContext|.
+
+ To use this feature, you have to tell "scope" hint to
+ vspec with |vspec#hint()|.
+
+:SaveContext *:SaveContext*
+ Save the current context of a script, i.e., an
+ snapshot of script-local variables defined in the
+ script. See also |:ResetContext|.
+
+ :SaveContext is automatically executed whenever
+ |vspec#hint()| is called with "scope" hint.
+
+ To use this feature, you have to tell "scope" hint to
+ vspec with |vspec#hint()|.
+
+:Should {actual} {matcher} {expected} *:Should*
+ Describe an expectation - test whether {actual} value
+ matches with {expected} value, in a sense of
+ {matcher}.
+
+ {actual} and {expected} is an arbitrary Vim script
+ |expression| with the following limitation:
+
+ - Comparing operators, such as ==, !~, etc, cannot be
+ used in {actual} and {expected}. See |expr4| for
+ the list of comparing operators in Vim script.
+
+ {matcher} is a comparing operator, such as ==, !~,
+ etc, which is described in |expr4|.
+
+ You have to insert one or more spaces between
+ {actual}, {matcher} and {expected}.
+
+ Examples:
+>
+ :Should 'abc' =~# 'A'
+ " ==> good
+ :Should 'abc' =~? 'A'
+ " ==> bad
+
+ :Should {} == {}
+ " ==> good
+ :Should {} isnot {}
+ " ==> bad
+<
+ *vspec-custom-matcher*
+ If {matcher} is "be", :Should acts in another mode.
+ {expected} is treated as an alias of a function which
+ is called "custom matcher". The custom matcher
+ corresponding to {expected} is called with {actual}
+ value. It must return true if {actual} value is
+ valid, otherwise it must return false. See also
+ |vspec#customize_matcher()|.
+
+ Examples:
+>
+ function! True(actual_value)
+ return (type(a:actual_value) == type(0)
+ \ ? a:actual_value
+ \ : !!0)
+ endfunction
+ call vspec#customize_matcher('true',
+ \ function('True'))
+
+ :Should 123 be true
+ " ===> good
+ :Should [123] be true
+ " ===> bad
+<
+ *vspec-predefined-custom-matchers*
+ The following custom matcheres are predefined:
+
+ "true"
+ Return true if {actual} value is true.
+ "false"
+ Return true if {actual} value is false.
+
+
+------------------------------------------------------------------------------
+FUNCTIONS *vspec-functions*
+
+Call(...) *Call()*
+ Alias of |vspec#call()|.
+
+Ref(...) *Ref()*
+ Alias of |vspec#ref()|.
+
+Set(...) *Set()*
+ Alias of |vspec#set()|.
+
+vspec#call({funcname}, [{arg}, ...]) *vspec#call()*
+ Like |call()|, but vspec#call() can call
+ a script-local function defined in a script to be
+ tested.
+
+ {funcname} is a string which represents the name of
+ a function. If {funcname} starts with 's:', it calls
+ a script-local function defined in a script to be
+ tested. To use this feature, you have to tell
+ "sid" hint to vspec with |vspec#hint()|.
+
+
+ {arg} is an arbitrary value which is given to the
+ function corresponding to o{funcname}.
+
+vspec#customize_matcher({alias}, {function}) *vspec#customize_matcher()*
+ Register {function} as a |vspec-custom-matcher| which
+ alias is {alias}.
+
+vspec#hint({info}) *vspec#hint()*
+ Tell vspec "hint" information to use useful API to
+ test a Vim script.
+
+ {info} is a dictionary. Each key is a string. The
+ detail of this dictionary is as follows:
+
+ "sid" (optional)
+ A string which is evaluated to <SID> of
+ a script to be tested.
+
+ If this value is given, you can use
+ |vspec#call()|.
+
+ "scope" (optional)
+ A string which is evaluated to the dictionary
+ corresponding to s: (= the scope of
+ script-local variables) for a script.
+
+ If this value is given, you can use
+ |vspec#ref()| and |vspec#set()|.
+
+vspec#ref({varname}) *vspec#ref()*
+ Return the value of a variable.
+
+ {varname} is a string which represents the name of
+ a script-local variable defined in a script to be
+ tested. The name must start with 's:'. To use this
+ feature, you have to tell vspec to "scope" hint with
+ |vspec#hint()|.
+
+vspec#set({varname}, {value}) *vspec#set()*
+ Assign {value} to a variable. See |vspec#ref()| for
+ the details of {varname}.
+
+vspec#test({specfile}) *vspec#test()*
+ |:source| {specfile}, test expectations described in
+ {specfile}, then output a result of the test.
+
+
+
+
+==============================================================================
+EXAMPLES *vspec-examples*
+
+See the content in "test" directory.
+
+
+
+
+==============================================================================
+BUGS *vspec-bugs*
+
+KNOWN ISSUES ~
+
+- Currently there is no known issue.
+
+
+PLANNED FEATURES ~
+
+- Currently there is no planned feature.
+
+
+ETC ~
+
+- Welcome your feedback.
+
+
+
+
+==============================================================================
+CHANGELOG *vspec-changelog*
+
+0.0.3 2010-03-12T21:43:12+09:00 *vspec-changelog-0.0.3*
+ - Add test driver |bin/vspec|.
+
+0.0.2 2010-02-20T23:11:03+09:00 *vspec-changelog-0.0.2*
+ - Add |vspec-custom-matcher|.
+ - Fix typos in the document.
+
+0.0.1 2009-11-18T20:44:13+09:00 *vspec-changelog-0.0.1*
+ - Test driver: Fix not to read/write viminfo file for reproducibility
+ and to avoid overwrite user's viminfo unexpectedly.
+
+0.0.0 2009-10-12T10:51:26+09:00 *vspec-changelog-0.0.0*
+ - Initial version.
+
+
+
+
+==============================================================================
+vim:tw=78:ts=8:ft=help:norl:fen:fdl=0:fdm=marker:
423 mduem/Makefile
@@ -0,0 +1,423 @@
+# mduem - Little utility for little software development
+#
+# This is a library Makefile to maintain software development, especially for
+# Vim script. Note that this Makefile requires GNU make to use.
+# Coding Rules #{{{1
+#
+# - Use non-empty string as true and empty string as false.
+#
+#
+# Naming Rules:
+#
+# - Use UPPER_CASE variables to be configured by user.
+#
+# - Use lower_case variables for internal use of mduem.
+#
+# - Use suffix "_p" to indicate that a boolean value is resulted from
+# a variable.
+# Example: vim_script_repos_p, SHOULD_INSTALL_ASIS_P
+#
+# - Use noun for ordinary variables.
+# Example: repos_name, TARGETS_GENERATED
+#
+# - Use verb for variables as functions.
+# Example: resolve_dep_uri, RENAME_TARGET
+#
+# - Use prefix "generate_rule_" for variables to generate make rules.
+# Example: generate_rule_to_install_a_target
+#
+# - Use abbreviations for words which names are too long to code.
+# Example: dependency => dep, directory => dir, repository => repos
+#
+# - Use lower-case names for phony targets.
+#
+# - Use verb for phony targets.
+# Example: clean, install, pack, ...
+#
+# - Use hyphens to join words in names of phony targets.
+# Example: clean-junks, fetch-deps
+#
+# - Use prefix "," for names of files which are automatically generated by
+# mduem and they are temporary ones.
+# Example: test/,good-case.output
+#
+# - Use directory ".mduem" to contain stuffs for internal use.
+# Example: .mduem/cache/
+#
+# - All rules may be violated if there is a strong custom from old times.
+# Example: all (phony target)
+
+
+
+
+
+
+
+
+# Common #{{{1
+
+all: # Ensure that this is the default target.
+
+SHELL := /bin/bash
+this_makefile := $(lastword $(MAKEFILE_LIST))
+cache_makefile := .mduem/cache/Makefile.variables
+user_makefiles := $(filter-out \
+ $(this_makefile) $(cache_makefile), \
+ $(MAKEFILE_LIST))
+
+not = $(if $(1),,t)
+toplevel_dir := $(shell git rev-parse --show-toplevel 2>/dev/null)
+inner_dir := $(shell git rev-parse --show-prefix 2>/dev/null)
+git_controlled_p := $(toplevel_dir)
+toplevel_dir_p := $(and $(git_controlled_p),$(call not,$(inner_dir)))
+
+ifneq '$(git_controlled_p)' ''
+$(cache_makefile): \
+ $(toplevel_dir)/.git/config \
+ $(toplevel_dir)/.git/index \
+ $(this_makefile)
+ @echo 'GENERATE $@'
+ @mkdir -p '$(dir $@)'
+ @{ \
+ current_branch="$$(git symbolic-ref -q HEAD \
+ | sed -e 's|^refs/heads/||')"; \
+ _origin_name="$$(git config "branch.$$current_branch.remote")"; \
+ origin_name="$${_origin_name:-origin}"; \
+ _origin_uri="$$(git config "remote.$$origin_name.url")"; \
+ origin_uri="$${_origin_uri:-../.}"; \
+ \
+ echo "all_files_in_repos := \
+ $(filter-out .gitmodules \
+ $(shell cd $(toplevel_dir) && \
+ git submodule foreach 'echo "$$path"'),\
+ $(shell git ls-files))"; \
+ echo "current_branch := $${current_branch}"; \
+ echo "origin_name := $${origin_name}"; \
+ echo "origin_uri := $${origin_uri}"; \
+ echo 'repos_name := $(notdir $(shell pwd))'; \
+ echo 'version := $(shell git describe --tags --always --dirty)'; \
+ } >'$@'
+endif
+include $(cache_makefile)
+
+vim_script_repos_p := $(filter vim-%,$(repos_name))
+
+
+
+
+
+
+
+
+# all #{{{1
+
+.PHONY: all
+all: build
+
+
+
+
+
+
+
+
+# build #{{{1
+
+TARGETS_ARCHIVED ?= $(all_files_in_repos)
+TARGETS_GENERATED ?=# Empty
+TARGETS_STATIC ?=# Empty
+
+targets_all_installed := $(TARGETS_GENERATED) $(TARGETS_STATIC)
+targets_all_archived := $(sort \
+ $(TARGETS_ARCHIVED) \
+ $(targets_all_installed) \
+ $(cache_makefile) \
+ )
+
+
+
+
+.PHONY: build
+build: $(targets_all_installed)
+
+
+
+
+
+
+
+
+# clean #{{{1
+
+.PHONY: clean
+clean: clean-generated clean-junks
+
+.PHONY: clean-generated
+clean-generated:
+ @echo 'CLEAN-GENERATED'
+ @rm -rf $(TARGETS_GENERATED)
+ @find -name '.mduem' | xargs rm -rf
+
+.PHONY: clean-junks
+clean-junks:
+ @echo 'CLEAN-JUNKS'
+ @find -name '*~' -or -name ',*' | xargs rm -rf
+
+
+
+
+
+
+
+
+# fetch-deps #{{{1
+
+DEPS ?=# Empty
+vim_script_deps := $(if $(vim_script_repos_p),vim-vspec vimup,)
+all_deps := $(vim_script_deps) $(DEPS)
+
+DEP_vim_vspec_URI ?= ../vim-vspec
+DEP_vim_vspec_VERSION ?= 0.0.3a1
+
+DEP_vimup_URI ?= ../vimup
+DEP_vimup_VERSION ?= 0.0.0a1
+
+
+ # BUGS: This resolves "../" just once, but it's enough for usual cases.
+resolve_dep_uri = $(strip $(if $(filter ../%,$(1)), \
+ $(dir $(origin_uri))$(1:../%=%), \
+ $(1)))
+normalize_dep_name = $(subst -,_,$(1))
+get_dep_raw_uri = $(DEP_$(call normalize_dep_name,$(1))_URI)
+get_dep_dir_name = $(patsubst %.git,%,$(notdir $(call get_dep_uri,$(1))))
+
+get_dep_uri = $(call resolve_dep_uri,$(call get_dep_raw_uri,$(1)))
+get_dep_version = $(DEP_$(call normalize_dep_name,$(1))_VERSION)
+get_dep_dir = .mduem/deps/$(call get_dep_dir_name,$(1))
+
+
+
+
+.PHONY: fetch-deps
+fetch-deps: $(all_deps:%=.mduem/deps/,%)
+
+# FIXME: Update for changes on only DEPS and other values.
+.mduem/deps/,%: $(user_makefiles)
+ @echo 'FETCH-DEP $*'
+ @mkdir -p '$(dir $@)'
+ @ ( \
+ if [ -d '$(call get_dep_dir,$*)' ] \
+ ; then \
+ cd './$(call get_dep_dir,$*)' \
+ && git fetch \
+ && git checkout -f mduem-master \
+ ; else \
+ git clone '$(call get_dep_uri,$*)' '$(call get_dep_dir,$*)'\
+ && cd './$(call get_dep_dir,$*)' \
+ && git checkout -b mduem-master \
+ ; fi \
+ && git reset --hard '$(call get_dep_version,$*)' \
+ ; ) &>'$@.log' \
+ || { cat '$@.log'; false; }
+ @touch '$@'
+
+
+
+
+
+
+
+
+# install #{{{1
+# Core #{{{2
+
+INSTALLATION_DIR ?= $(error Please set INSTALLATION_DIR)
+
+RENAME_TARGET ?= $(patsubst %,$(INSTALLATION_DIR)/%,$(1))
+SHOULD_INSTALL_ASIS_P ?=# All files are version-filtered by default.
+
+
+
+
+.PHONY: install
+install: build
+
+
+define generate_rule_to_install_a_target # (build_target, install_target)
+install: $(2)
+$(2): $(1)
+ @echo 'INSTALL $(1)'
+ @mkdir -p '$(dir $(2))'
+ifneq '$(call SHOULD_INSTALL_ASIS_P,$(1))' ''
+ @cp '$(1)' '$(2)'
+else
+ @sed -e 's/0.0.3/$(version)/' '$(1)' >'$(2)'
+endif
+
+endef
+$(eval \
+ $(foreach t, \
+ $(targets_all_installed), \
+ $(call generate_rule_to_install_a_target,$(t),$(call RENAME_TARGET,$(t)))))
+
+
+# This should be placed at the last to ensure that post-install is executed
+# after any other rules to install.
+install: post-install
+
+
+
+
+# post-install #{{{2
+
+TARGETS_POST_INSTALL ?=# Empty
+targets_post_install_builtin :=# Empty
+
+
+ifneq '$(vim_script_repos_p)' ''
+target_vim_helptags := $(call RENAME_TARGET,doc/tags)
+$(target_vim_helptags): $(filter doc/%.txt,$(targets_all_installed))
+ @echo 'POST-INSTALL vim helptags'
+ @vim -n -N -u NONE -U NONE -e -c 'helptags $(dir $@) | qall!'
+
+targets_post_install_builtin += $(target_vim_helptags)
+endif
+
+
+.PHONY: post-install
+post-install: $(targets_post_install_builtin) $(TARGETS_POST_INSTALL)
+
+
+
+
+
+
+
+
+# pack #{{{1
+
+archive_basename = $(repos_name)-$(version)
+archive_name = $(archive_basename).zip
+
+
+.PHONY: pack
+pack: $(archive_name)
+
+$(archive_name): $(cache_makefile)
+ rm -rf '$(archive_basename)' '$(archive_name)'
+ $(MAKE) \
+ 'INSTALLATION_DIR=$(archive_basename)' \
+ 'targets_all_installed=$(targets_all_archived)' \
+ install
+ zip -r $(archive_name) $(archive_basename)/
+ rm -rf '$(archive_basename)'
+
+
+
+
+
+
+
+
+# release #{{{1
+
+.PHONY: release
+release: $(if $(vim_script_repos_p),release-vim-script,release-default)
+
+
+.PHONY: release-default
+release-default:
+ @echo 'Rules to release are not defined.'
+
+
+.PHONY: release-vim-script
+release-vim-script: fetch-deps $(repos_name).vimup pack
+ ./.mduem/deps/vimup/vimup update-script $(repos_name)
+ rm $(repos_name).vimup
+
+.PHONY: release-new-vim-script
+release-new-vim-script: fetch-deps $(repos_name).vimup pack
+ ./.mduem/deps/vimup/vimup new-script $(repos_name)
+ rm $(repos_name).vimup
+
+$(repos_name).vimup: $(firstword $(sort $(filter doc/%.txt, \
+ $(all_files_in_repos))))
+ ./.mduem/deps/vimup/vimup-info-generator \
+ <$< \
+ >$(repos_name).vimup
+
+
+
+
+
+
+
+
+# test #{{{1
+
+test_cases := $(patsubst test/%.expected,%, \
+ $(filter test/%.expected,$(all_files_in_repos)))
+
+
+default_test_rule_deps := $(MAKEFILE_LIST)
+define default_test_rule
+ @source './$<' &>'$@' || { cat '$@'; false; }
+endef
+
+ifneq '$(vim_script_repos_p)' ''
+all_vim_scripts := $(filter %.vim,$(all_files_in_repos))
+vim_script_test_rule_deps := .mduem/deps/vim-vspec/bin/vspec $(all_vim_scripts)
+define vim_script_test_rule
+ @./$(call get_dep_dir,vim-vspec)/bin/vspec \
+ $< \
+ "$$PWD" \
+ $(foreach d,$(all_deps),$(call get_dep_dir,$(d))) \
+ &>$@
+endef
+endif
+
+TEST_RULE ?= $(if $(vim_script_repos_p), \
+ $(vim_script_test_rule), \
+ $(default_test_rule))
+TEST_RULE_DEPS ?= $(if $(vim_script_repos_p), \
+ $(vim_script_test_rule_deps), \
+ $(default_test_rule_deps))
+
+
+
+
+.PHONY: test
+test: fetch-deps test/,ok
+
+test/,ok: $(test_cases:%=test/,%.ok)
+ @echo 'ALL TESTS ARE PASSED.'
+ @touch $@
+
+test/,%.ok: test/%.input $(TEST_RULE_DEPS)
+ @echo -n 'TEST $* ... '
+ @$(MAKE) --silent '$(@:.ok=.diff)'
+ @if ! [ -s $(@:.ok=.diff) ]; then \
+ echo 'OK'; \
+ else \
+ echo 'FAILED'; \
+ cat $(@:.ok=.diff); \
+ echo 'END'; \
+ false; \
+ fi
+ @touch $@
+
+test/,%.diff: test/%.expected test/,%.output
+ @diff -u $^ >$@; true
+
+test/,%.output: test/%.input $(TEST_RULE_DEPS)
+ $(TEST_RULE)
+
+
+
+
+
+
+
+
+# __END__ #{{{1
+# vim: foldmethod=marker
18 test/context.expected
@@ -0,0 +1,18 @@
+==== ResetContext
+---- It should reset to the state when vspec#hint() is called
+...
+---- It should not touch new items which are set after vspec#hint()
+..
+
+==== SaveContext
+---- It should reset to the state when :SaveContext is executed
+..
+---- It should not touch new items which are set after :SaveContext
+..
+
+
+
+**** Result ****
+
+
+9 examples, 0 failures
65 test/context.input
@@ -0,0 +1,65 @@
+function! s:describe__ResetContext() "{{{1
+ let DUMMY_SCOPE_CONTENT = {'misaka': 'mikoto', 'shirai': 'kuroko'}
+ let g:dummy_scope = deepcopy(DUMMY_SCOPE_CONTENT)
+ let old_reference_of_dummy_scope = g:dummy_scope
+
+ It should reset to the state when vspec#hint() is called
+
+ call vspec#hint({'scope': 'g:dummy_scope'})
+
+ Should g:dummy_scope == DUMMY_SCOPE_CONTENT
+
+ let g:dummy_scope['misaka'] = 'electromaster'
+ let g:dummy_scope['shirai'] = 'teleporter'
+
+ ResetContext
+
+ Should g:dummy_scope == DUMMY_SCOPE_CONTENT
+ Should g:dummy_scope is old_reference_of_dummy_scope
+
+ It should not touch new items which are set after vspec#hint()
+
+ let g:dummy_scope['level'] = 5
+
+ ResetContext
+
+ Should g:dummy_scope == {'misaka': 'mikoto', 'shirai': 'kuroko', 'level': 5}
+ Should g:dummy_scope is old_reference_of_dummy_scope
+endfunction
+
+
+
+
+function! s:describe__SaveContext() "{{{1
+ let DUMMY_SCOPE_CONTENT = {'misaka': 'mikoto', 'shirai': 'kuroko'}
+ let g:dummy_scope = deepcopy(DUMMY_SCOPE_CONTENT)
+ let old_reference_of_dummy_scope = g:dummy_scope
+ call vspec#hint({'scope': 'g:dummy_scope'})
+
+ It should reset to the state when :SaveContext is executed
+
+ let g:dummy_scope['misaka'] = 'electromaster'
+ let g:dummy_scope['shirai'] = 'teleporter'
+ SaveContext
+
+ ResetContext
+
+ Should g:dummy_scope == {'misaka': 'electromaster', 'shirai': 'teleporter'}
+ Should g:dummy_scope is old_reference_of_dummy_scope
+
+ It should not touch new items which are set after :SaveContext
+
+ let g:dummy_scope['level'] = 5
+
+ ResetContext
+
+ Should g:dummy_scope
+ \ == {'misaka': 'electromaster', 'shirai': 'teleporter', 'level': 5}
+ Should g:dummy_scope is old_reference_of_dummy_scope
+endfunction
+
+
+
+
+" __END__ "{{{1
+" vim: filetype=vim foldmethod=marker
30 test/custom-matcher.expected
@@ -0,0 +1,30 @@
+==== Should be false
+---- It should work
+.......
+
+==== Should be true
+---- It should work
+........
+
+==== Should with custom matcher
+---- It should accept custom matcher
+..
+---- It sould fail with unknown custom matcher
+.
+
+==== s_valid_matcher_custom_p
+---- It should return true for "be"
+.
+---- It should return false for other value
+...
+
+==== vspec_customize_matcher
+---- It should succeed
+..
+
+
+
+**** Result ****
+
+
+24 examples, 0 failures
99 test/custom-matcher.input
@@ -0,0 +1,99 @@
+call vspec#hint({'scope': 'vspec#_scope()', 'sid': 'vspec#_sid()'})
+function! s:describe__s_valid_matcher_custom_p() "{{{1
+ It should return true for "be"
+
+ Should Call('s:valid_matcher_custom_p', 'be') == !0
+
+ It should return false for other value
+
+ Should Call('s:valid_matcher_custom_p', 'foo') == !!0
+ Should Call('s:valid_matcher_custom_p', 'being') == !!0
+ Should Call('s:valid_matcher_custom_p', 'describe') == !!0
+endfunction
+
+
+
+
+function! s:describe__vspec_customize_matcher() "{{{1
+ function! True(value)
+ return type(a:value) == type(0) ? !!(a:value) : !!0
+ endfunction
+ function! False(value)
+ return type(a:value) == type(0) ? !(a:value) : !!0
+ endfunction
+
+ It should succeed
+
+ call vspec#customize_matcher('foo', function('True'))
+ Should Ref('s:custom_matchers')['foo'] ==# function('True')
+
+ call vspec#customize_matcher('foo', function('False'))
+ Should Ref('s:custom_matchers')['foo'] ==# function('False')
+endfunction
+
+
+
+
+function! s:describe__Should__with_custom_matcher() "{{{1
+ function! True(value)
+ return type(a:value) == type(0) ? !!(a:value) : !!0
+ endfunction
+ function! False(value)
+ return type(a:value) == type(0) ? !(a:value) : !!0
+ endfunction
+
+ It should accept custom matcher
+
+ call vspec#customize_matcher('my true', function('True'))
+ Should 123 be my true
+
+ call vspec#customize_matcher('my false', function('False'))
+ Should 0 be my false
+
+ It sould fail with unknown custom matcher
+
+ let v:errmsg = ''
+ silent! call Call('s:matches_p', 'foo', 'be', 'my unknown')
+ Should v:errmsg =~# 'Unknown custom matcher'
+endfunction
+
+
+
+
+function! s:describe__Should__be_false() "{{{1
+ It should work
+
+ Should vspec#_matcher_false(!!0) == !0
+ Should vspec#_matcher_false(123) == !!0
+
+ Should vspec#_matcher_false('') == !!0
+ Should vspec#_matcher_false('123') == !!0
+ Should vspec#_matcher_false([]) == !!0
+ Should vspec#_matcher_false(['123']) == !!0
+
+ Should 0 be false
+endfunction
+
+
+
+
+function! s:describe__Should__be_true() "{{{1
+ It should work
+
+ Should vspec#_matcher_true(!0) == !0
+ Should vspec#_matcher_true(123) == !0
+
+ Should vspec#_matcher_true(!!0) == !!0
+ Should vspec#_matcher_true('') == !!0
+ Should vspec#_matcher_true('123') == !!0
+ Should vspec#_matcher_true([]) == !!0
+ Should vspec#_matcher_true(['123']) == !!0
+
+ Should 1 be true
+endfunction
+
+
+
+
+" __END__ "{{{1
+" vim: filetype=vim foldmethod=marker
7 test/no-test.expected
@@ -0,0 +1,7 @@
+
+
+
+**** Result ****
+
+
+0 examples, 0 failures
2 test/no-test.input
@@ -0,0 +1,2 @@
+" Empty content, nothing is tested.
+" vim: filetype=vim
20 test/tools.expected
@@ -0,0 +1,20 @@
+==== Call
+---- It should succeed with script-local functions
+..
+---- It should succeed with not a script-local function
+..
+
+==== Ref
+---- It should succeed
+...
+
+==== Set
+---- It should succeed
+...
+
+
+
+**** Result ****
+
+
+10 examples, 0 failures
46 test/tools.input
@@ -0,0 +1,46 @@
+call vspec#hint({'scope': 'vspec#_scope()', 'sid': 'vspec#_sid()'})
+function! s:describe__Ref() "{{{1
+ It should succeed
+
+ Should Ref('s:EXPR_HINT_SCOPE') ==# 'vspec#_scope()'
+ Should Ref('s:EXPR_HINT_SID') ==# 'vspec#_sid()'
+ Should eval(Ref('s:EXPR_HINT_SID')) =~# '<SNR>\d\+_'
+endfunction
+
+
+
+
+function! s:describe__Set() "{{{1
+ It should succeed
+
+ let original_value = Ref('s:EXPR_HINT_SID')
+ Should Ref('s:EXPR_HINT_SID') ==# 'vspec#_sid()'
+
+ let l = []
+ call Set('s:EXPR_HINT_SID', l)
+ Should Ref('s:EXPR_HINT_SID') is l
+
+ call Set('s:EXPR_HINT_SID', original_value)
+ Should Ref('s:EXPR_HINT_SID') ==# 'vspec#_sid()'
+endfunction
+
+
+
+
+function! s:describe__Call() "{{{1
+ It should succeed with script-local functions
+
+ Should Call('s:valid_matcher_p', '==') == 1
+ Should Call('s:valid_matcher_p', '=?') == 0
+
+ It should succeed with not a script-local function
+
+ Should Call('function', 'type') == function('type')
+ Should Call('getcwd') == fnamemodify('./xxx', ':p:h')
+endfunction
+
+
+
+
+" __END__ "{{{1
+" vim: filetype=vim foldmethod=marker
193 test/typical-content.expected
@@ -0,0 +1,193 @@
+==== matchers with literals
+---- It should succeed
+.......................
+---- It should fail
+xxxxxxxxxxxxxxxxxxxxxxxxx
+
+==== matchers with variables
+---- It should succeed
+....
+
+==== matchers with wrong types
+---- It should succeed
+...
+---- It should fail
+xxxxxxxx
+
+
+
+**** Result ****
+
+
+In matchers with literals
+
+It should fail
+FAILED: 0 != 0
+ expected: 0
+ got: 0
+
+It should fail
+FAILED: 0 !~ '0'
+ lhs: 0
+ rhs: '0'
+
+It should fail
+FAILED: 0 < 0
+ lhs: 0
+ rhs: 0
+
+It should fail
+FAILED: 0 < -1
+ lhs: 0
+ rhs: -1
+
+It should fail
+FAILED: 0 <= -1
+ lhs: 0
+ rhs: -1
+
+It should fail
+FAILED: 0 == 1
+ expected: 1
+ got: 0
+
+It should fail
+FAILED: 0 =~ '1'
+ lhs: 0
+ rhs: '1'
+
+It should fail
+FAILED: 0 > 0
+ lhs: 0
+ rhs: 0
+
+It should fail
+FAILED: 0 > 1
+ lhs: 0
+ rhs: 1
+
+It should fail
+FAILED: 0 >= 1
+ lhs: 0
+ rhs: 1
+
+It should fail
+FAILED: 0 is 1
+ expected: 1
+ got: 0
+
+It should fail
+FAILED: 0 is '0'
+ expected: '0'
+ got: 0
+
+It should fail
+FAILED: 0 isnot 0
+ expected: 0
+ got: 0
+
+It should fail
+FAILED: 'a' ==# 'b'
+ expected: 'b'
+ got: 'a'
+
+It should fail
+FAILED: 'a' ==# 'A'
+ expected: 'A'
+ got: 'a'
+
+It should fail
+FAILED: 'a' !=# 'a'
+ expected: 'a'
+ got: 'a'
+
+It should fail
+FAILED: 'a' ==? 'b'
+ expected: 'b'
+ got: 'a'
+
+It should fail
+FAILED: 'a' !=? 'A'
+ expected: 'A'
+ got: 'a'
+
+It should fail
+FAILED: 'a' !=? 'a'
+ expected: 'a'
+ got: 'a'
+
+It should fail
+FAILED: [] == [0]
+ expected: [0]
+ got: []
+
+It should fail
+FAILED: [] is []
+ expected: []
+ got: []
+
+It should fail
+FAILED: {} == {'0': 0}
+ expected: {'0': 0}
+ got: {}
+
+It should fail
+FAILED: {} is {}
+ expected: {}
+ got: {}
+
+It should fail
+FAILED: function('function') == function('type')
+ expected: function('type')
+ got: function('function')
+
+It should fail
+FAILED: function('function') != function('function')
+ expected: function('function')
+ got: function('function')
+
+
+In matchers with wrong types
+
+It should fail
+FAILED: 0 < '1'
+ lhs: 0
+ rhs: '1'
+
+It should fail
+FAILED: [] < []
+ lhs: []
+ rhs: []
+
+It should fail
+FAILED: {} < {}
+ lhs: {}
+ rhs: {}
+
+It should fail
+FAILED: function('type') < function('type')
+ lhs: function('type')
+ rhs: function('type')
+
+It should fail
+FAILED: 0 =~ '0'
+ lhs: 0
+ rhs: '0'
+
+It should fail
+FAILED: [] =~ '[]'
+ lhs: []
+ rhs: '[]'
+
+It should fail
+FAILED: {} =~ '{}'
+ lhs: {}
+ rhs: '{}'
+
+It should fail
+FAILED: function('type') =~ function('type')
+ lhs: function('type')
+ rhs: function('type')
+
+
+63 examples, 33 failures
109 test/typical-content.input
@@ -0,0 +1,109 @@
+function! s:describe__matchers__with_literals() "{{{1
+ It should succeed
+
+ Should 0 != 1
+ "Should 0 !~ '1'
+ Should 0 < 1
+ Should 0 <= 0
+ Should 0 <= 1
+ Should 0 == 0
+ "Should 0 =~ '0'
+ Should 0 > -1
+ Should 0 >= 0
+ Should 0 >= -1
+ Should 0 is 0
+ Should 0 isnot 1
+ Should 0 isnot '0'
+
+ Should 'a' ==# 'a'
+ Should 'a' !=# 'A'
+ Should 'a' !=# 'B'
+ Should 'a' ==? 'A'
+ Should 'a' ==? 'A'
+ Should 'a' !=? 'B'
+
+ Should [] == []
+ Should [] isnot []
+
+ Should {} == {}
+ Should {} isnot {}
+
+ Should function('function') == function('function')
+ Should function('function') != function('type')
+
+ It should fail
+
+ Should 0 != 0
+ Should 0 !~ '0'
+ Should 0 < 0
+ Should 0 < -1
+ Should 0 <= -1
+ Should 0 == 1
+ Should 0 =~ '1'
+ Should 0 > 0
+ Should 0 > 1
+ Should 0 >= 1
+ Should 0 is 1
+ Should 0 is '0'
+ Should 0 isnot 0
+
+ Should 'a' ==# 'b'
+ Should 'a' ==# 'A'
+ Should 'a' !=# 'a'
+ Should 'a' ==? 'b'
+ Should 'a' !=? 'A'
+ Should 'a' !=? 'a'
+
+ Should [] == [0]
+ Should [] is []
+
+ Should {} == {'0': 0}
+ Should {} is {}
+
+ Should function('function') == function('type')
+ Should function('function') != function('function')
+endfunction
+
+
+
+
+function! s:describe__matchers__with_variables() "{{{1
+ It should succeed
+
+ let s = 'A'
+ Should s ==# 'A'
+ Should s !=# 'a'
+
+ let l = []
+ Should l == []
+ Should l is l
+endfunction
+
+
+
+
+function! s:describe__matchers__with_wrong_types() "{{{1
+ It should succeed
+
+ Should 0 == 0
+ Should 0 != '0'
+ Should 0 != []
+
+ It should fail
+
+ Should 0 < '1'
+ Should [] < []
+ Should {} < {}
+ Should function('type') < function('type')
+
+ Should 0 =~ '0'
+ Should [] =~ '[]'
+ Should {} =~ '{}'
+ Should function('type') =~ function('type')
+endfunction
+
+
+
+
+" __END__ "{{{1
+" vim: filetype=vim foldmethod=marker

0 comments on commit e241eaa

Please sign in to comment.