Skip to content

Commit

Permalink
Version 1.1.0
Browse files Browse the repository at this point in the history
- |:Expect-not|:  - Show proper messages for failed expectations.- |vspec-custom-matcher|:  - Change the naming guideline.    - Use snake_case instead of camelCase.    - Add new aliases for predefined custom matcheres.    - Old aliases are still supported, but deprecated.  - Support custom failure message.    - See |vspec#customize_matcher()| for the details.    - It was not possible to show meaningful messages for failed expectations using custom mathcers with old versions.    - Change the syntax to register new matcher.    - Old syntax is still supported, but deprecated.  - Fix to properly support custom matchers with 2 or more arguments.
  • Loading branch information
Kana Natsuno authored and vim-scripts committed Nov 30, 2012
1 parent 76a0e21 commit e8deaae
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .mduem/cache/Makefile.variables
@@ -1,6 +1,6 @@
all_files_in_repos := Makefile after/indent/vim.vim after/syntax/vim/vspec.vim autoload/vspec.vim bin/vspec doc/vspec.txt t/after.vim t/before.vim t/builtin-matchers.vim t/check-vspec-result t/context.vim t/custom-matchers.vim t/error-in-describe.t t/error-in-it.t t/error-in-should-evaluating.t t/error-in-should-parsing.t t/error-in-source.t t/expect.vim t/indent.vim t/no-hint.vim t/no-test.vim t/runtimepath.vim t/skip.t t/syntax.vim t/todo.t t/tools.vim
all_files_in_repos := Makefile after/indent/vim.vim after/syntax/vim/vspec.vim autoload/vspec.vim bin/vspec doc/vspec.txt t/after.vim t/before.vim t/builtin-matchers.vim t/check-vspec-result t/context.vim t/custom-failure-message.t t/custom-matchers.vim t/error-in-describe.t t/error-in-it.t t/error-in-should-evaluating.t t/error-in-should-parsing.t t/error-in-source.t t/expect.vim t/indent.vim t/no-hint.vim t/no-test.vim t/runtimepath.vim t/skip.t t/syntax.vim t/todo.t t/tools.vim
current_branch := master
origin_name := origin
origin_uri := ../.
repos_name := vim-vspec
version := 1.0.2
version := 1.1.0
2 changes: 1 addition & 1 deletion after/indent/vim.vim
@@ -1,5 +1,5 @@
" Vim additional indent settings: vim/vspec - indent vspec commands
" Version: 1.0.2
" Version: 1.1.0
" Copyright (C) 2012 Kana Natsuno <http://whileimautomaton.net/>
" License: So-called MIT/X license {{{
" Permission is hereby granted, free of charge, to any person obtaining
Expand Down
2 changes: 1 addition & 1 deletion after/syntax/vim/vspec.vim
@@ -1,5 +1,5 @@
" Vim additional syntax: vim/vspec - highlight vspec commands
" Version: 1.0.2
" Version: 1.1.0
" Copyright (C) 2010-2012 Kana Natsuno <http://whileimautomaton.net/>
" License: So-called MIT/X license {{{
" Permission is hereby granted, free of charge, to any person obtaining
Expand Down
94 changes: 78 additions & 16 deletions autoload/vspec.vim
@@ -1,5 +1,5 @@
" vspec - Testing framework for Vim script
" Version: 1.0.2
" Version: 1.1.0
" Copyright (C) 2009-2012 Kana Natsuno <http://whileimautomaton.net/>
" License: So-called MIT/X license {{{
" Permission is hereby granted, free of charge, to any person obtaining
Expand Down Expand Up @@ -49,7 +49,7 @@ let s:current_suites = [] "{{{2


let s:custom_matchers = {} "{{{2
" :: MatcherNameString -> Funcref
" :: MatcherNameString -> Matcher



Expand Down Expand Up @@ -149,8 +149,13 @@ endfunction



function! vspec#customize_matcher(matcher_name, funcref) "{{{2
let s:custom_matchers[a:matcher_name] = a:funcref
function! vspec#customize_matcher(matcher_name, maybe_matcher) "{{{2
if type(a:maybe_matcher) == type({})
let matcher = a:maybe_matcher
else
let matcher = {'match': a:maybe_matcher}
endif
let s:custom_matchers[a:matcher_name] = matcher
endfunction


Expand Down Expand Up @@ -235,11 +240,15 @@ function! vspec#test(specfile_path) "{{{2
\ suite.subject,
\ example
\ )
echo '# Expected' i.expr_actual i.expr_matcher i.expr_expected
echo '# Actual value:' string(i.value_actual)
if !s:is_custom_matcher(i.expr_matcher)
echo '# Expected value:' string(i.value_expected)
endif
echo '# Expected' join(filter([
\ i.expr_actual,
\ i.expr_not,
\ i.expr_matcher,
\ i.expr_expected,
\ ], 'v:val != ""'))
for line in s:generate_failure_message(i)
echo '# ' . line
endfor
elseif type ==# 'TODO'
echo printf(
\ '%s %d - # TODO %s %s',
Expand Down Expand Up @@ -301,19 +310,21 @@ endfunction



" Predefined custom matchers - toBeFalse "{{{2
" Predefined custom matchers - to_be_false "{{{2
function! vspec#_matcher_false(value)
return type(a:value) == type(0) ? !(a:value) : s:FALSE
endfunction
call vspec#customize_matcher('to_be_false', function('vspec#_matcher_false'))
call vspec#customize_matcher('toBeFalse', function('vspec#_matcher_false'))




" Predefined custom matchers - toBeTrue "{{{2
" Predefined custom matchers - to_be_true "{{{2
function! vspec#_matcher_true(value)
return type(a:value) == type(0) ? !!(a:value) : s:FALSE
endfunction
call vspec#customize_matcher('to_be_true', function('vspec#_matcher_true'))
call vspec#customize_matcher('toBeTrue', function('vspec#_matcher_true'))


Expand Down Expand Up @@ -516,7 +527,7 @@ function! s:parse_should_arguments(s, mode) "{{{2
let matcher = string(_matcher)
endif
if s:is_custom_matcher(_matcher)
let expected = string(_expected)
let expected = '[' . _expected . ']'
endif
let not = string(_not)
endif
Expand Down Expand Up @@ -589,14 +600,22 @@ let s:VALID_MATCHERS = (s:VALID_MATCHERS_EQUALITY
function! s:are_matched(value_actual, expr_matcher, value_expected) "{{{2
if s:is_custom_matcher(a:expr_matcher)
let custom_matcher_name = a:expr_matcher
if !has_key(s:custom_matchers, custom_matcher_name)
let matcher = get(s:custom_matchers, custom_matcher_name, 0)
if matcher is 0
throw
\ 'vspec:InvalidOperation:Unknown custom matcher - '
\ . string(custom_matcher_name)
endif
let Match = get(matcher, 'match', 0)
if Match is 0
throw
\ 'vspec:InvalidOperation:Custom matcher does not have match function - '
\ . string(custom_matcher_name)
endif
return !!call(
\ s:custom_matchers[custom_matcher_name],
\ [a:value_actual] + eval(printf('[%s]', a:value_expected))
\ Match,
\ [a:value_actual] + a:value_expected,
\ matcher
\ )
elseif s:is_equality_matcher(a:expr_matcher)
let type_equality = type(a:value_actual) == type(a:value_expected)
Expand Down Expand Up @@ -625,6 +644,49 @@ endfunction



function! s:generate_default_failure_message(i) "{{{2
return [
\ ' Actual value: ' . string(a:i.value_actual),
\ 'Expected value: ' . string(a:i.value_expected),
\ ]
endfunction




function! s:generate_failure_message(i) "{{{2
let matcher = get(s:custom_matchers, a:i.value_matcher, 0)
if matcher is 0
return s:generate_default_failure_message(a:i)
else
let method_name =
\ a:i.value_not == ''
\ ? 'failure_message_for_should'
\ : 'failure_message_for_should_not'
let Generate = get(
\ matcher,
\ method_name,
\ 0
\ )
if Generate is 0
return s:generate_default_failure_message(a:i)
else
let values = [a:i.value_actual]
if a:i.expr_expected != ''
call extend(values, a:i.value_expected)
endif
let maybe_message = call(Generate, values, matcher)
return
\ type(maybe_message) == type('')
\ ? [maybe_message]
\ : maybe_message
endif
endif
endfunction




function! s:is_custom_matcher(expr_matcher) "{{{2
return a:expr_matcher =~# '^to'
endfunction
Expand Down Expand Up @@ -683,7 +745,7 @@ endfunction

let s:RE_SPLIT_AT_MATCHER =
\ printf(
\ '\C\v^(.{-})\s+%%((not)\s+)?(%%(%%(%s)[#?]?)|to\w+>)(.*)$',
\ '\C\v^(.{-})\s+%%((not)\s+)?(%%(%%(%s)[#?]?)|to\w+>)\s*(.*)$',
\ join(
\ map(
\ reverse(sort(copy(s:VALID_MATCHERS))),
Expand Down
2 changes: 1 addition & 1 deletion bin/vspec
@@ -1,6 +1,6 @@
#!/bin/bash
# bin/vspec - Driver script to test Vim script
# Version: 1.0.2
# Version: 1.1.0
# Copyright (C) 2009-2012 Kana Natsuno <http://whileimautomaton.net/>
# License: So-called MIT/X license {{{
# Permission is hereby granted, free of charge, to any person obtaining
Expand Down
2 changes: 2 additions & 0 deletions doc/tags
Expand Up @@ -15,6 +15,7 @@ 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#customize_matcher()-old vspec.txt /*vspec#customize_matcher()-old*
vspec#hint() vspec.txt /*vspec#hint()*
vspec#ref() vspec.txt /*vspec#ref()*
vspec#set() vspec.txt /*vspec#set()*
Expand All @@ -29,6 +30,7 @@ vspec-changelog-0.0.4 vspec.txt /*vspec-changelog-0.0.4*
vspec-changelog-1.0.0 vspec.txt /*vspec-changelog-1.0.0*
vspec-changelog-1.0.1 vspec.txt /*vspec-changelog-1.0.1*
vspec-changelog-1.0.2 vspec.txt /*vspec-changelog-1.0.2*
vspec-changelog-1.1.0 vspec.txt /*vspec-changelog-1.1.0*
vspec-commands vspec.txt /*vspec-commands*
vspec-contents vspec.txt /*vspec-contents*
vspec-custom-matcher vspec.txt /*vspec-custom-matcher*
Expand Down
72 changes: 61 additions & 11 deletions doc/vspec.txt
@@ -1,6 +1,6 @@
*vspec.txt* Testing framework for Vim script

Version 1.0.2
Version 1.1.0
Script ID: 3012
Copyright (C) 2009-2012 Kana Natsuno <http://whileimautomaton.net/>
License: So-called MIT/X license {{{
Expand Down Expand Up @@ -143,26 +143,32 @@ COMMANDS *vspec-commands*

Examples:
>
function! True(actual_value)
function! ToBeTrue(actual_value)
return (type(a:actual_value) == type(0)
\ ? a:actual_value
\ : !!0)
endfunction
call vspec#customize_matcher('toBeTrue',
\ function('True'))
call vspec#customize_matcher(
\ 'to_be_true',
\ function('ToBeTrue')
\ )
:Expect 123 toBeTrue
:Expect 123 to_be_true
" ===> good
:Expect [123] toBeTrue
:Expect [123] to_be_true
" ===> bad
<
*vspec-predefined-custom-matchers*
The following custom matcheres are predefined:

"toBeTrue"
"to_be_true"
Return true if {actual} value is true.
"toBeFalse"
"to_be_false"
Return true if {actual} value is false.
"toBeTrue"
Same as "to_be_true". Deprecated.
"toBeFalse"
Same as "to_be_false". Deprecated.

:Expect {actual} not {matcher} {expected} *:Expect-not*
:Expect {actual} not {custom-matcher} [{arg}, ...]
Expand Down Expand Up @@ -240,9 +246,37 @@ vspec#call({funcname}, [{arg}, ...]) *vspec#call()*
{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#customize_matcher({alias}, {matcher}) *vspec#customize_matcher()*
Register {matcher} as a |vspec-custom-matcher| with
a given {alias}. {alias} should be snake_case.

{matcher} is a dictionary with the following items:

"match" (required)
A |Funcref| to determine whether {actual}
value matches to {expected} value. It takes
1 or more arguments. The first argument is
{actual} value given to |:Expect|, and the
rest of arguments are arbitrary {expected}
values. It returns true if {actual} value is
matched to {expected} value, or false
otherwise.

"failure_message_for_should" (optional)
A |Funcref| to generate user friendly message
for failed match with |:Expect|. It takes
arguments the same as "match", and it returns
a string or a list of strings to describe
a failure.

"failure_message_for_should_not" (optional)
Like "failure_message_for_should", but it is
used to generate failure message for
|:Expect-not|.

vspec#customize_matcher({alias}, {function}) *vspec#customize_matcher()-old*
Deprecated. Use |vspec#customize_matcher()| instead.
This style is remiained for backward compatibility.

vspec#hint({info}) *vspec#hint()*
Tell vspec "hint" information to use useful API to
Expand Down Expand Up @@ -321,6 +355,22 @@ ETC ~
==============================================================================
CHANGELOG *vspec-changelog*

1.1.0 2012-10-29T22:19:45+09:00 *vspec-changelog-1.1.0*
- |:Expect-not|:
- Show proper messages for failed expectations.
- |vspec-custom-matcher|:
- Change the naming guideline.
- Use snake_case instead of camelCase.
- Add new aliases for predefined custom matcheres.
- Old aliases are still supported, but deprecated.
- Support custom failure message.
- See |vspec#customize_matcher()| for the details.
- It was not possible to show meaningful messages for failed
expectations using custom mathcers with old versions.
- Change the syntax to register new matcher.
- Old syntax is still supported, but deprecated.
- Fix to properly support custom matchers with 2 or more arguments.

1.0.2 2012-02-12T21:02:50+09:00 *vspec-changelog-1.0.2*
- |bin/vspec|:
- Remove user's |after-directory| from 'runtimepath' to avoid
Expand Down
2 changes: 1 addition & 1 deletion mduem/Makefile
Expand Up @@ -258,7 +258,7 @@ $(2): $(1)
@mkdir -p '$(dir $(2))'
@cp '--preserve=mode,ownership' '$(1)' '$(2)'
ifeq '$(call SHOULD_INSTALL_ASIS_P,$(1))' ''
@sed -i -e 's/1.0.2/$(version)/' '$(2)'
@sed -i -e 's/1.1.0/$(version)/' '$(2)'
endif

endef
Expand Down
14 changes: 12 additions & 2 deletions t/builtin-matchers.vim
Expand Up @@ -844,15 +844,25 @@ describe 'isnot?'
end
end

describe 'be false'
describe 'to_be_false'
it 'should succeed if a given value is false'
Expect 0 to_be_false
Expect 1 not to_be_false
end

it 'is still available as old style alias'
Expect 0 toBeFalse
Expect 1 not toBeFalse
end
end

describe 'be true'
describe 'to_be_true'
it 'should succeed if a given value is true'
Expect 0 not to_be_true
Expect 1 to_be_true
end

it 'is still available as old style alias'
Expect 0 not toBeTrue
Expect 1 toBeTrue
end
Expand Down

0 comments on commit e8deaae

Please sign in to comment.