annotate src/testdir/test_assert.vim @ 8749:65a5a18d3acf v7.4.1663

commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 27 15:13:38 2016 +0200 patch 7.4.1663 Problem: In tests it's often useful to check if a pattern matches. Solution: Add assert_match().
author Christian Brabandt <cb@256bit.org>
date Sun, 27 Mar 2016 15:15:06 +0200
parents 7d3548ae729d
children 6f41d68aa68e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test that the methods used for testing work.
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
3 func Test_assert_false()
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
4 call assert_false(0)
7951
03e716299680 commit https://github.com/vim/vim/commit/3712792637516aea7acf76a11533be1066952820
Christian Brabandt <cb@256bit.org>
parents: 7852
diff changeset
5 call assert_false(v:false)
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 endfunc
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
8 func Test_assert_true()
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
9 call assert_true(1)
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
10 call assert_true(123)
7951
03e716299680 commit https://github.com/vim/vim/commit/3712792637516aea7acf76a11533be1066952820
Christian Brabandt <cb@256bit.org>
parents: 7852
diff changeset
11 call assert_true(v:true)
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 endfunc
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
14 func Test_assert_equal()
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 let s = 'foo'
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
16 call assert_equal('foo', s)
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 let n = 4
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
18 call assert_equal(4, n)
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 let l = [1, 2, 3]
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
20 call assert_equal([1, 2, 3], l)
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 endfunc
7412
bc5de65e499a commit https://github.com/vim/vim/commit/2d820808cda15b3ad9fe674393d1f1e997453d9e
Christian Brabandt <cb@256bit.org>
parents: 7279
diff changeset
22
7675
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
23 func Test_assert_exception()
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
24 try
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
25 nocommand
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
26 catch
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
27 call assert_exception('E492:')
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
28 endtry
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
29
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
30 try
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
31 nocommand
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
32 catch
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
33 try
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
34 " illegal argument, get NULL for error
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
35 call assert_exception([])
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
36 catch
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
37 call assert_exception('E730:')
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
38 endtry
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
39 endtry
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
40 endfunc
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
41
7852
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
42 func Test_wrong_error_type()
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
43 let save_verrors = v:errors
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
44 let v:['errors'] = {'foo': 3}
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
45 call assert_equal('yes', 'no')
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
46 let verrors = v:errors
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
47 let v:errors = save_verrors
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
48 call assert_equal(type([]), type(verrors))
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
49 endfunc
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
50
8550
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
51 func Test_compare_fail()
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
52 let s:v = {}
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
53 let s:x = {"a": s:v}
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
54 let s:v["b"] = s:x
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
55 let s:w = {"c": s:x, "d": ''}
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
56 try
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
57 call assert_equal(s:w, '')
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
58 catch
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
59 call assert_exception('E724:')
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
60 call assert_match("Expected NULL but got ''", v:errors[0])
8550
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
61 call remove(v:errors, 0)
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
62 endtry
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
63 endfunc
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
64
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
65 func Test_match()
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
66 call assert_match('^f.*b.*r$', 'foobar')
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
67
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
68 call assert_match('bar.*foo', 'foobar')
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
69 call assert_match("Pattern 'bar.*foo' does not match 'foobar'", v:errors[0])
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
70 call remove(v:errors, 0)
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
71
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
72 call assert_match('bar.*foo', 'foobar', 'wrong')
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
73 call assert_match('wrong', v:errors[0])
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
74 call remove(v:errors, 0)
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
75 endfunc
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
76
8554
7d3548ae729d commit https://github.com/vim/vim/commit/1abb502635c7f317e05a0cf3ea067101f9d684f5
Christian Brabandt <cb@256bit.org>
parents: 8550
diff changeset
77 func Test_assert_fail_fails()
7d3548ae729d commit https://github.com/vim/vim/commit/1abb502635c7f317e05a0cf3ea067101f9d684f5
Christian Brabandt <cb@256bit.org>
parents: 8550
diff changeset
78 call assert_fails('xxx', {})
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8554
diff changeset
79 call assert_match("Expected {} but got 'E731:", v:errors[0])
8554
7d3548ae729d commit https://github.com/vim/vim/commit/1abb502635c7f317e05a0cf3ea067101f9d684f5
Christian Brabandt <cb@256bit.org>
parents: 8550
diff changeset
80 call remove(v:errors, 0)
7d3548ae729d commit https://github.com/vim/vim/commit/1abb502635c7f317e05a0cf3ea067101f9d684f5
Christian Brabandt <cb@256bit.org>
parents: 8550
diff changeset
81 endfunc
7d3548ae729d commit https://github.com/vim/vim/commit/1abb502635c7f317e05a0cf3ea067101f9d684f5
Christian Brabandt <cb@256bit.org>
parents: 8550
diff changeset
82
8550
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
83
7412
bc5de65e499a commit https://github.com/vim/vim/commit/2d820808cda15b3ad9fe674393d1f1e997453d9e
Christian Brabandt <cb@256bit.org>
parents: 7279
diff changeset
84 func Test_user_is_happy()
bc5de65e499a commit https://github.com/vim/vim/commit/2d820808cda15b3ad9fe674393d1f1e997453d9e
Christian Brabandt <cb@256bit.org>
parents: 7279
diff changeset
85 smile
bc5de65e499a commit https://github.com/vim/vim/commit/2d820808cda15b3ad9fe674393d1f1e997453d9e
Christian Brabandt <cb@256bit.org>
parents: 7279
diff changeset
86 sleep 300m
bc5de65e499a commit https://github.com/vim/vim/commit/2d820808cda15b3ad9fe674393d1f1e997453d9e
Christian Brabandt <cb@256bit.org>
parents: 7279
diff changeset
87 endfunc