File: util.vim

package info (click to toggle)
vim-youcompleteme 0%2B20230109%2Bgit7620d87%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,404 kB
  • sloc: python: 10,569; sh: 203; cpp: 121; makefile: 24; f90: 5; xml: 1
file content (79 lines) | stat: -rw-r--r-- 3,075 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function! CheckCurrentLine( expected_value )
  return assert_equal( a:expected_value, getline( '.' ) )
endfunction

function! AssertDictHasEntries( actual, expected, name = 'expected dict' )
  let l:errs = 0
  for key in keys( a:expected )
    if !has_key( a:actual, key )
      let l:errs += assert_report( 'Key '
                                 \ . key
                                 \ . ' of '
                                 \ . a:name
                                 \ . ' was not found' )
    elseif type( a:expected[ key ] ) == v:t_dict
      if type( a:actual[ key ] ) != v:t_dict
        let l:errs += assert_report( 'Key '
                                   \ . key
                                   \ . ' of '
                                   \ . a:name
                                   \ . ' was expected to be a dict, but was '
                                   \ . string( a:actual[ key ] ) )
      else
        let l:errs += AssertDictHasEntries( a:actual[ key ],
                                          \ a:expected[ key ],
                                          \ 'entry ' . key . ' in ' . a:name )
      endif
    else
      let l:errs += assert_equal( a:expected[ key ],
                                \ a:actual[ key ],
                                \ 'Key '
                                \ . key
                                \ . ' of '
                                \ . a:name
                                \ . ' did not match' )
    endif
  endfor
  return l:errs
endfunction

function! CheckListOfDicts( actual_list, expected_list )
  let l:errs = 0
  let l:idx = 0
  if len( a:actual_list ) != len( a:expected_list )
    let l:errs += assert_report( 'Expected list to contain '
                               \ . len( a:actual_list )
                               \ . ' entries, but found '
                               \ . len( a:expected_list )
                               \ . ': Expected '
                               \ . string( a:expected_list )
                               \ . ' but found '
                               \ . string( a:actual_list ) )
  endif

  while l:idx < len( a:expected_list )
    let l:expected = a:expected_list[ l:idx ]
    if l:idx >= len( a:actual_list )
      let l:errs += assert_report( 'The item at index '
                                 \ . l:idx
                                 \ . ' was not found: '
                                 \ . string( l:expected ) )
    else
      let l:actual = a:actual_list[ l:idx ]
      let l:errs += AssertDictHasEntries( l:actual,
                                        \ l:expected,
                                        \ 'item at index ' . l:idx )
    endif
    let l:idx = l:idx + 1
  endwhile

  while idx < len( a:actual_list )
    let l:actual = a:actual_list[ idx ]
    let l:errs +=  assert_report( 'The following additional property '
                                \ . 'was found: '
                                \ . string( l:actual ) )
    let l:idx = l:idx + 1
  endwhile

  return l:errs > 0 ? 1 : 0
endfunction