Skip to content

Commit

Permalink
Add type check for regexp matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
kana committed Mar 1, 2010
1 parent fd80f6a commit fdb5bb0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
12 changes: 12 additions & 0 deletions autoload/vspec.vim
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ function! s:matches_p(value_actual, expr_matcher, value_expected) "{{{2
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
Expand Down Expand Up @@ -408,6 +413,13 @@ endfunction



function! s:valid_matcher_regexp_p(expr_matcher) "{{{2
return 0 <= index(s:VALID_MATCHERS_REGEXP, a:expr_matcher)
endfunction







Expand Down
26 changes: 23 additions & 3 deletions test/typical-content.expected
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
==== matchers with literals
---- It should succeed
.........................
.......................
---- It should fail
xxxxxxxxxxxxxxxxxxxxxxxxx

Expand All @@ -12,7 +12,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxx
---- It should succeed
...
---- It should fail
xxxx
xxxxxxxx



Expand Down Expand Up @@ -169,5 +169,25 @@ 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')


61 examples, 29 failures
63 examples, 33 failures
9 changes: 7 additions & 2 deletions test/typical-content.input
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ function! s:describe__matchers__with_literals() "{{{1
It should succeed

Should 0 != 1
Should 0 !~ '1'
"Should 0 !~ '1'
Should 0 < 1
Should 0 <= 0
Should 0 <= 1
Should 0 == 0
Should 0 =~ '0'
"Should 0 =~ '0'
Should 0 > -1
Should 0 >= 0
Should 0 >= -1
Expand Down Expand Up @@ -95,6 +95,11 @@ function! s:describe__matchers__with_wrong_types() "{{{1
Should [] < []
Should {} < {}
Should function('type') < function('type')

Should 0 =~ '0'
Should [] =~ '[]'
Should {} =~ '{}'
Should function('type') =~ function('type')
endfunction


Expand Down

0 comments on commit fdb5bb0

Please sign in to comment.