Skip to content
This repository
Browse code

Moved specs to vimtlib

  • Loading branch information...
commit de31d5c97fb569d2e425b61a5ffc1fbe04b7f8ff 1 parent a37f877
Tom Link authored September 18, 2010
4  spec/spec/rewrite.vim
@@ -2,7 +2,7 @@
2 2
 " @Website:     http://www.vim.org/account/profile.php?user_id=4037
3 3
 " @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
4 4
 " @Created:     2009-03-07.
5  
-" @Last Change: 2009-03-07.
  5
+" @Last Change: 2010-09-17.
6 6
 
7 7
 let s:save_cpo = &cpo
8 8
 set cpo&vim
@@ -12,6 +12,8 @@ call spec#RewriteRule('^!\?\zsfoo \(\d\+\) bar \(\d\+\).*', '(\1 == \2)')
12 12
 SpecBegin 'title': 'Spec: Rewrite rules'
13 13
 
14 14
 
  15
+Should be equal spec#__Rewrite('throw exception "tlib#date#Parse(''2000-14-2'')"'), 'should#throw#Exception("tlib#date#Parse(''2000-14-2'')")'
  16
+
15 17
 Should be equal spec#__Rewrite('foo 1 bar 1'), '(1 == 1)'
16 18
 Should be equal spec#__Rewrite('not foo 1 bar 1'), '!(1 == 1)'
17 19
 
89  spec/spec/should_be.vim
... ...
@@ -0,0 +1,89 @@
  1
+" @Author:      Tom Link (mailto:micathom AT gmail com?subject=[vim])
  2
+" @Website:     http://www.vim.org/account/profile.php?user_id=4037
  3
+" @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
  4
+" @Created:     2009-03-06.
  5
+" @Last Change: 2009-03-06.
  6
+
  7
+let s:save_cpo = &cpo
  8
+set cpo&vim
  9
+
  10
+
  11
+SpecBegin 'title': 'Should be', 'sfile': 'autoload/should/be.vim'
  12
+
  13
+It should test if the argument is a number.
  14
+Should be#Number(1)
  15
+Should not be#Number("foo")
  16
+
  17
+It should test if the argument is a string.
  18
+Should be#String("foo")
  19
+Should not be#String(1)
  20
+
  21
+It should test if the argument is a funcref.
  22
+Should be#Funcref(function('should#be#Funcref'))
  23
+Should not be#Funcref(1)
  24
+
  25
+It should test if the argument is a list.
  26
+Should be#List([1,2,3])
  27
+Should not be#List(1)
  28
+
  29
+It should test if the argument is a dictionary.
  30
+Should be#Dictionary({1:2})
  31
+Should not be#Dictionary([1,2,3])
  32
+
  33
+It should test if the argument is of a specified type.
  34
+Should be#A(1, 'number')
  35
+Should be a {"foo": "bar"}, 'dictionary'
  36
+Should not be a {"foo": "bar"}, 'list'
  37
+
  38
+It should test for multiple types.
  39
+Should be a {"foo": "bar"}, ['list', 'dictionary']
  40
+Should not be a {"foo": "bar"}, ['number', 'string']
  41
+
  42
+It should test for class equivalence.
  43
+Should be a {"foo": "bar"}, {"foo": 0}
  44
+Should be a {"foo": "bar"}, {"foo": 1}
  45
+Should be a {"foo": "bar"}, {"x": 0}
  46
+Should not be a {"foo": "bar"}, {"x": 1}
  47
+
  48
+It should test for equality.
  49
+Should be#Equal(1, 1)
  50
+Should be#Equal({1:2}, {1:2})
  51
+Should not be#Equal(1, 2)
  52
+Should not be#Equal(1, "1")
  53
+Should not be#Equal({1:2}, {1:3})
  54
+
  55
+It should test for inequality.
  56
+Should be#Unequal(1, 2)
  57
+Should be#Unequal(1, "2")
  58
+Should be#Unequal(1, "1")
  59
+Should not be#Unequal(1, 1)
  60
+
  61
+It should test for <, <=, >, >=.
  62
+Should be#Greater(2, 1)
  63
+Should not be#Greater(2, 2)
  64
+
  65
+Should be#GreaterEqual(1, 1)
  66
+Should be#GreaterEqual(2, 1)
  67
+Should not be#GreaterEqual(2, 3)
  68
+
  69
+Should be#Less(1, 2)
  70
+Should not be#Less(3, 2)
  71
+
  72
+Should be#LessEqual(1, 1)
  73
+Should be#LessEqual(1, 2)
  74
+Should not be#LessEqual(3, 2)
  75
+
  76
+It should match strings.
  77
+Should be like "foo", '^f'
  78
+Should not be like "foo", '^x'
  79
+Should be unlike "foo", '^x'
  80
+Should be like "foo", '^f', '#'
  81
+Should be unlike "foo", '^F', '#'
  82
+Should be unlike "Foo", '^f', '#'
  83
+Should be like "Foo", '^F', '#'
  84
+Should be like "foo", '^F', '?'
  85
+Should be like "Foo", '^f', '?'
  86
+
  87
+
  88
+let &cpo = s:save_cpo
  89
+unlet s:save_cpo
36  spec/spec/should_finish.vim
... ...
@@ -0,0 +1,36 @@
  1
+" @Author:      Tom Link (mailto:micathom AT gmail com?subject=[vim])
  2
+" @Website:     http://www.vim.org/account/profile.php?user_id=4037
  3
+" @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
  4
+" @Created:     2009-03-06.
  5
+" @Last Change: 2009-03-07.
  6
+
  7
+let s:save_cpo = &cpo
  8
+set cpo&vim
  9
+
  10
+
  11
+SpecBegin 'title': 'Should finish',
  12
+            \ 'sfile': 'autoload/should/finish.vim',
  13
+            \ 'cleanup': ['TakeTime()']
  14
+
  15
+function! TakeTime(n) "{{{3
  16
+    for i in range(a:n)
  17
+    endfor
  18
+endf
  19
+
  20
+echo "Spec 'finish': The following test could take up to 5 seconds."
  21
+It should measure execution time in seconds.
  22
+Should finish#InSecs(':2sleep', 3)
  23
+Should not finish#InSecs(':2sleep', 1)
  24
+
  25
+
  26
+if exists('g:loaded_tlib')
  27
+
  28
+    It should measure in microseconds but this depends on your OS so it probably doesn't.
  29
+    Should finish#InMicroSecs('TakeTime(10)', 40)
  30
+    Should not finish#InMicroSecs('TakeTime(100000)', 20)
  31
+
  32
+endif
  33
+
  34
+
  35
+let &cpo = s:save_cpo
  36
+unlet s:save_cpo
23  spec/spec/should_throw.vim
... ...
@@ -0,0 +1,23 @@
  1
+" @Author:      Tom Link (mailto:micathom AT gmail com?subject=[vim])
  2
+" @Website:     http://www.vim.org/account/profile.php?user_id=4037
  3
+" @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
  4
+" @Created:     2009-03-06.
  5
+" @Last Change: 2009-03-06.
  6
+
  7
+let s:save_cpo = &cpo
  8
+set cpo&vim
  9
+
  10
+
  11
+SpecBegin 'title': 'Should throw', 'sfile': 'autoload/should/throw.vim'
  12
+
  13
+It should test for exceptions.
  14
+Should throw#Something('1 + [2]')
  15
+Should not throw#Something('1 + 2')
  16
+
  17
+It should test for specific exceptions.
  18
+Should throw#Exception('1 + [2]', ':E745:')
  19
+Should not throw#Exception('1 + [2]', ':E746:')
  20
+
  21
+
  22
+let &cpo = s:save_cpo
  23
+unlet s:save_cpo
25  spec/spec/should_yield.vim
... ...
@@ -0,0 +1,25 @@
  1
+" @Author:      Tom Link (mailto:micathom AT gmail com?subject=[vim])
  2
+" @Website:     http://www.vim.org/account/profile.php?user_id=4037
  3
+" @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
  4
+" @Created:     2009-03-06.
  5
+" @Last Change: 2009-03-06.
  6
+
  7
+let s:save_cpo = &cpo
  8
+set cpo&vim
  9
+
  10
+
  11
+let g:test_file = expand('<sfile>:p:h') .'/'
  12
+SpecBegin 'title': 'Should yield', 'sfile': 'autoload/should/yield.vim',
  13
+            \ 'scratch': [g:test_file . "test_yield.txt"]
  14
+
  15
+It should test buffer content.
  16
+Should yield#Buffer(':silent 1,3delete', g:test_file.'test_yield1.txt')
  17
+Should not yield#Buffer(':silent 1,3delete', g:test_file.'should_yield.vim')
  18
+
  19
+It should test squeezed buffer content.
  20
+Should yield#SqueezedBuffer(':silent 1,3delete', g:test_file.'test_yield2.txt')
  21
+Should not yield#SqueezedBuffer(':silent 1,3delete', g:test_file.'should_yield.vim')
  22
+
  23
+
  24
+let &cpo = s:save_cpo
  25
+unlet s:save_cpo
91  spec/spec/spec.vim
... ...
@@ -0,0 +1,91 @@
  1
+" @Author:      Thomas Link (micathom AT gmail com?subject=[vim])
  2
+" @Website:     http://www.vim.org/account/profile.php?user_id=4037
  3
+" @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
  4
+" @Created:     2009-02-22.
  5
+" @Last Change: 2009-03-06.
  6
+
  7
+let s:save_cpo = &cpo
  8
+set cpo&vim
  9
+
  10
+let s:vars = len(g:)
  11
+
  12
+let g:spec_bar = 1
  13
+
  14
+
  15
+SpecBegin 'title': 'Self-test',
  16
+            \ 'scratch': '%',
  17
+            \ 'sfile': 'autoload/spec.vim',
  18
+            \ 'before': 'let g:spec_bar = 2',
  19
+            \ 'after': 'let g:spec_bar = 1'
  20
+
  21
+
  22
+It should initialize the environment.
  23
+Should be#Equal(spec#Val('s:spec_vars'), keys(g:))
  24
+Should be#Equal(spec#Val('s:spec_msg'), 'Self-test')
  25
+
  26
+Should be#Equal(spec#Val('s:should_counts['. string(<SID>CurrentFile()) .']'), 3)
  27
+
  28
+Should be#Dictionary(spec#Val('s:spec_args'))
  29
+Should be#NotEmpty(spec#Val('s:spec_args'))
  30
+
  31
+Should be#List(spec#Val('s:scripts'))
  32
+Should be#NotEmpty(spec#Val('s:scripts'))
  33
+
  34
+
  35
+It should execute before & after ex commands.
  36
+Should be#Equal(g:spec_bar, 2)
  37
+if g:spec_bar != 1
  38
+    throw 'Teardown failed'
  39
+endif
  40
+
  41
+
  42
+It should remember comments.
  43
+Should be#Equal(spec#Val('s:spec_comment'), 'It should remember comments.')
  44
+Should !be#Equal(spec#Val('s:spec_comment'), 'Foo')
  45
+Should be#NotEmpty(spec#Val('s:spec_comment'))
  46
+
  47
+
  48
+It should rewrite expressions.
  49
+Should be#Equal(spec#__Rewrite('not be#Equal'), '!should#be#Equal')
  50
+Should be#Equal(spec#__Rewrite('finish in 1 second "Fun2()"'), 'should#finish#InSecs("Fun2()", 1)')
  51
+Should be#Equal(spec#__Rewrite('not finish in 2 seconds "Fun2()"'), '!should#finish#InSecs("Fun2()", 2)')
  52
+Should be#Equal(spec#__Rewrite("throw something '1 + [1]'"), "should#throw#Something('1 + [1]')")
  53
+Should be#Equal(spec#__Rewrite("not exists('*SpecFoo')"), "!exists('*SpecFoo')")
  54
+
  55
+" Should be#Equal(spec#__Rewrite('not be equal'), '!should#be#Equal')
  56
+Should not be#Equal(spec#__Rewrite('not be#Equal'), 'foo')
  57
+Should not be equal(spec#__Rewrite('not be#Equal'), 'foo')
  58
+Should not be Equal spec#__Rewrite('not be#Equal'), 'foo'
  59
+Should not be equal spec#__Rewrite('not be#Equal'), 'foo'
  60
+
  61
+
  62
+It should be able to access script-local functions.
  63
+Should be#Equal(<SID>CanonicalFilename('a:\foo/bar'), 'A:/foo/bar')
  64
+
  65
+
  66
+let g:spec_qfl_len = len(getqflist())
  67
+It should fail. Please ignore the entry below unless there is no descriptive explanation.
  68
+Should be#Equal("fail", "should")
  69
+It should integrate with the quickfix list.
  70
+Should be#Equal(len(getqflist()), g:spec_qfl_len + 2)
  71
+
  72
+
  73
+It! should always add this message to the quickfix list.
  74
+Should be#Equal(len(getqflist()), g:spec_qfl_len + 3)
  75
+
  76
+
  77
+It should replay key sequences.
  78
+Replay :let g:spec_char1 = getchar()\n\<f11>
  79
+Should be#Equal g:spec_char1, "€F1"
  80
+
  81
+
  82
+It should replay macros.
  83
+call spec#Replay(':let g:spec_char2 = getchar()
€F1')
  84
+Should be#Equal g:spec_char2, "€F1"
  85
+unlet g:spec_char2
  86
+Replay! :let g:spec_char2 = getchar()
€F1
  87
+Should be#Equal g:spec_char2, "€F1"
  88
+
  89
+
  90
+let &cpo = s:save_cpo
  91
+unlet s:save_cpo
37  spec/spec/speckiller.vim
... ...
@@ -0,0 +1,37 @@
  1
+" @Author:      Tom Link (mailto:micathom AT gmail com?subject=[vim])
  2
+" @Website:     http://www.vim.org/account/profile.php?user_id=4037
  3
+" @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
  4
+" @Created:     2009-03-06.
  5
+" @Last Change: 2009-03-14.
  6
+
  7
+let s:save_cpo = &cpo
  8
+set cpo&vim
  9
+
  10
+
  11
+if !exists('g:spec_foo')
  12
+    let g:spec_foo = "foo"
  13
+endif
  14
+
  15
+SpecBegin 'title': 'Option sets',
  16
+            \ 'sfile': 'autoload/spec.vim',
  17
+            \ 'options': [
  18
+            \ {'&l:hidden': 1, '&acd': 0, 'g:spec_foo': 'bar'},
  19
+            \ {'&l:hidden': 0, '&acd': 1, 'g:spec_foo': 'bar'},
  20
+            \ ]
  21
+
  22
+" echom "Round ". spec#Val('s:spec_perm')
  23
+
  24
+if spec#Val('s:spec_perm') >= 0
  25
+    It should test the spec against option sets (:SpecBegin).
  26
+    Should &hidden || &acd
  27
+    Should not (&hidden && &acd)
  28
+    Should be equal &hidden + &acd, 1
  29
+
  30
+    Should be equal g:spec_foo, 'bar'
  31
+else
  32
+    Should be equal g:spec_foo, 'foo'
  33
+endif
  34
+
  35
+
  36
+let &cpo = s:save_cpo
  37
+unlet s:save_cpo
7  spec/spec/test_yield.txt
... ...
@@ -0,0 +1,7 @@
  1
+        1          1                1
  2
+            2          2
  3
+        3
  4
+            4         4
  5
+    5   5
  6
+    6 6
  7
+    77
4  spec/spec/test_yield1.txt
... ...
@@ -0,0 +1,4 @@
  1
+            4         4
  2
+    5   5
  3
+    6 6
  4
+    77
4  spec/spec/test_yield2.txt
... ...
@@ -0,0 +1,4 @@
  1
+4 4
  2
+5   5
  3
+6 6
  4
+77
40  spec/tlib/date.vim
... ...
@@ -0,0 +1,40 @@
  1
+" @Author:      Tom Link (micathom AT gmail com?subject=[vim])
  2
+" @Website:     http://www.vim.org/account/profile.php?user_id=4037
  3
+" @GIT:         http://github.com/tomtom/vimtlib/
  4
+" @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
  5
+" @Created:     2010-09-17.
  6
+" @Last Change: 2010-09-17.
  7
+" @Revision:    16
  8
+
  9
+SpecBegin 'title': 'tlib#date'
  10
+
  11
+Should be equal tlib#date#Parse('2000-1-0', 1), [2000, 1, 0]
  12
+Should be equal tlib#date#Parse('2000-1-2'), [2000, 1, 2]
  13
+Should be equal tlib#date#Parse('2000-01-02'), [2000, 1, 2]
  14
+Should be equal tlib#date#Parse('2000-10-20'), [2000, 10, 20]
  15
+
  16
+Should be equal tlib#date#Parse('00-1-0', 1), [2000, 1, 0]
  17
+Should be equal tlib#date#Parse('00-1-2'), [2000, 1, 2]
  18
+Should be equal tlib#date#Parse('00-01-02'), [2000, 1, 2]
  19
+Should be equal tlib#date#Parse('00-10-20'), [2000, 10, 20]
  20
+
  21
+Should be equal tlib#date#Parse('2000/2/1'), [2000, 1, 2]
  22
+Should be equal tlib#date#Parse('2000/02/01'), [2000, 1, 2]
  23
+Should be equal tlib#date#Parse('2000/20/10'), [2000, 10, 20]
  24
+
  25
+Should be equal tlib#date#Parse('00/2/1'), [2000, 1, 2]
  26
+Should be equal tlib#date#Parse('00/02/01'), [2000, 1, 2]
  27
+Should be equal tlib#date#Parse('00/20/10'), [2000, 10, 20]
  28
+
  29
+Should be equal tlib#date#Parse('2.1.2000'), [2000, 1, 2]
  30
+Should be equal tlib#date#Parse('2. 1. 2000'), [2000, 1, 2]
  31
+Should be equal tlib#date#Parse('02.01.2000'), [2000, 1, 2]
  32
+Should be equal tlib#date#Parse('02. 01. 2000'), [2000, 1, 2]
  33
+Should be equal tlib#date#Parse('20.10.2000'), [2000, 10, 20]
  34
+Should be equal tlib#date#Parse('20. 10. 2000'), [2000, 10, 20]
  35
+
  36
+Should throw exception "tlib#date#Parse('2000-14-2')", 'TLib: Invalid date'
  37
+Should throw exception "tlib#date#Parse('2000-011-02')", 'TLib: Invalid date'
  38
+Should throw exception "tlib#date#Parse('2000-10-40')", 'TLib: Invalid date'
  39
+Should throw exception "tlib#date#Parse('2000-10-0')", 'TLib: Invalid date'
  40
+

0 notes on commit de31d5c

Please sign in to comment.
Something went wrong with that request. Please try again.