diff src/testdir/test_profile.vim @ 16720:9c90cf08cfa8 v8.1.1362

patch 8.1.1362: code and data in tests can be hard to read commit https://github.com/vim/vim/commit/c79745a82faeb5a6058e915ca49a4c69fa60ea01 Author: Bram Moolenaar <Bram@vim.org> Date: Mon May 20 22:12:34 2019 +0200 patch 8.1.1362: code and data in tests can be hard to read Problem: Code and data in tests can be hard to read. Solution: Use the new heredoc style. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/4400)
author Bram Moolenaar <Bram@vim.org>
date Mon, 20 May 2019 22:15:06 +0200
parents 2dcaa860e3fc
children f38fcbf343ce
line wrap: on
line diff
--- a/src/testdir/test_profile.vim
+++ b/src/testdir/test_profile.vim
@@ -4,34 +4,34 @@ if !has('profile')
 endif
 
 func Test_profile_func()
-  let lines = [
-    \ 'profile start Xprofile_func.log',
-    \ 'profile func Foo*"',
-    \ "func! Foo1()",
-    \ "endfunc",
-    \ "func! Foo2()",
-    \ "  let l:count = 100",
-    \ "  while l:count > 0",
-    \ "    let l:count = l:count - 1",
-    \ "  endwhile",
-    \ "endfunc",
-    \ "func! Foo3()",
-    \ "endfunc",
-    \ "func! Bar()",
-    \ "endfunc",
-    \ "call Foo1()",
-    \ "call Foo1()",
-    \ "profile pause",
-    \ "call Foo1()",
-    \ "profile continue",
-    \ "call Foo2()",
-    \ "call Foo3()",
-    \ "call Bar()",
-    \ "if !v:profiling",
-    \ "  delfunc Foo2",
-    \ "endif",
-    \ "delfunc Foo3",
-    \ ]
+  let lines =<< trim [CODE]
+    profile start Xprofile_func.log
+    profile func Foo*
+    func! Foo1()
+    endfunc
+    func! Foo2()
+      let l:count = 100
+      while l:count > 0
+        let l:count = l:count - 1
+      endwhile
+    endfunc
+    func! Foo3()
+    endfunc
+    func! Bar()
+    endfunc
+    call Foo1()
+    call Foo1()
+    profile pause
+    call Foo1()
+    profile continue
+    call Foo2()
+    call Foo3()
+    call Bar()
+    if !v:profiling
+      delfunc Foo2
+    endif
+    delfunc Foo3
+  [CODE]
 
   call writefile(lines, 'Xprofile_func.vim')
   call system(v:progpath
@@ -86,38 +86,38 @@ func Test_profile_func()
 endfunc
 
 func Test_profile_func_with_ifelse()
-  let lines = [
-    \ "func! Foo1()",
-    \ "  if 1",
-    \ "    let x = 0",
-    \ "  elseif 1",
-    \ "    let x = 1",
-    \ "  else",
-    \ "    let x = 2",
-    \ "  endif",
-    \ "endfunc",
-    \ "func! Foo2()",
-    \ "  if 0",
-    \ "    let x = 0",
-    \ "  elseif 1",
-    \ "    let x = 1",
-    \ "  else",
-    \ "    let x = 2",
-    \ "  endif",
-    \ "endfunc",
-    \ "func! Foo3()",
-    \ "  if 0",
-    \ "    let x = 0",
-    \ "  elseif 0",
-    \ "    let x = 1",
-    \ "  else",
-    \ "    let x = 2",
-    \ "  endif",
-    \ "endfunc",
-    \ "call Foo1()",
-    \ "call Foo2()",
-    \ "call Foo3()",
-    \ ]
+  let lines =<< trim [CODE]
+    func! Foo1()
+      if 1
+        let x = 0
+      elseif 1
+        let x = 1
+      else
+        let x = 2
+      endif
+    endfunc
+    func! Foo2()
+      if 0
+        let x = 0
+      elseif 1
+        let x = 1
+      else
+        let x = 2
+      endif
+    endfunc
+    func! Foo3()
+      if 0
+        let x = 0
+      elseif 0
+        let x = 1
+      else
+        let x = 2
+      endif
+    endfunc
+    call Foo1()
+    call Foo2()
+    call Foo3()
+  [CODE]
 
   call writefile(lines, 'Xprofile_func.vim')
   call system(v:progpath
@@ -196,41 +196,41 @@ func Test_profile_func_with_ifelse()
 endfunc
 
 func Test_profile_func_with_trycatch()
-  let lines = [
-    \ "func! Foo1()",
-    \ "  try",
-    \ "    let x = 0",
-    \ "  catch",
-    \ "    let x = 1",
-    \ "  finally",
-    \ "    let x = 2",
-    \ "  endtry",
-    \ "endfunc",
-    \ "func! Foo2()",
-    \ "  try",
-    \ "    throw 0",
-    \ "  catch",
-    \ "    let x = 1",
-    \ "  finally",
-    \ "    let x = 2",
-    \ "  endtry",
-    \ "endfunc",
-    \ "func! Foo3()",
-    \ "  try",
-    \ "    throw 0",
-    \ "  catch",
-    \ "    throw 1",
-    \ "  finally",
-    \ "    let x = 2",
-    \ "  endtry",
-    \ "endfunc",
-    \ "call Foo1()",
-    \ "call Foo2()",
-    \ "try",
-    \ "  call Foo3()",
-    \ "catch",
-    \ "endtry",
-    \ ]
+  let lines =<< trim [CODE]
+    func! Foo1()
+      try
+        let x = 0
+      catch
+        let x = 1
+      finally
+        let x = 2
+      endtry
+    endfunc
+    func! Foo2()
+      try
+        throw 0
+      catch
+        let x = 1
+      finally
+        let x = 2
+      endtry
+    endfunc
+    func! Foo3()
+      try
+        throw 0
+      catch
+        throw 1
+      finally
+        let x = 2
+      endtry
+    endfunc
+    call Foo1()
+    call Foo2()
+    try
+      call Foo3()
+    catch
+    endtry
+  [CODE]
 
   call writefile(lines, 'Xprofile_func.vim')
   call system(v:progpath
@@ -309,15 +309,15 @@ func Test_profile_func_with_trycatch()
 endfunc
 
 func Test_profile_file()
-  let lines = [
-    \ 'func! Foo()',
-    \ 'endfunc',
-    \ 'for i in range(10)',
-    \ '  " a comment',
-    \ '  call Foo()',
-    \ 'endfor',
-    \ 'call Foo()',
-    \ ]
+  let lines =<< trim [CODE]
+  func! Foo()
+  endfunc
+  for i in range(10)
+    " a comment
+    call Foo()
+  endfor
+  call Foo()
+  [CODE]
 
   call writefile(lines, 'Xprofile_file.vim')
   call system(v:progpath
@@ -448,26 +448,27 @@ func Test_profile_truncate_mbyte()
 endfunc
 
 func Test_profdel_func()
-  let lines = [
-    \  'profile start Xprofile_file.log',
-    \  'func! Foo1()',
-    \  'endfunc',
-    \  'func! Foo2()',
-    \  'endfunc',
-    \  'func! Foo3()',
-    \  'endfunc',
-    \  '',
-    \  'profile func Foo1',
-    \  'profile func Foo2',
-    \  'call Foo1()',
-    \  'call Foo2()',
-    \  '',
-    \  'profile func Foo3',
-    \  'profdel func Foo2',
-    \  'profdel func Foo3',
-    \  'call Foo1()',
-    \  'call Foo2()',
-    \  'call Foo3()' ]
+  let lines =<< trim [CODE]
+    profile start Xprofile_file.log
+    func! Foo1()
+    endfunc
+    func! Foo2()
+    endfunc
+    func! Foo3()
+    endfunc
+
+    profile func Foo1
+    profile func Foo2
+    call Foo1()
+    call Foo2()
+
+    profile func Foo3
+    profdel func Foo2
+    profdel func Foo3
+    call Foo1()
+    call Foo2()
+    call Foo3()
+  [CODE]
   call writefile(lines, 'Xprofile_file.vim')
   call system(v:progpath . ' -es --clean -c "so Xprofile_file.vim" -c q')
   call assert_equal(0, v:shell_error)
@@ -494,14 +495,15 @@ endfunc
 func Test_profdel_star()
   " Foo() is invoked once before and once after 'profdel *'.
   " So profiling should report it only once.
-  let lines = [
-    \  'profile start Xprofile_file.log',
-    \  'func! Foo()',
-    \  'endfunc',
-    \  'profile func Foo',
-    \  'call Foo()',
-    \  'profdel *',
-    \  'call Foo()' ]
+  let lines =<< trim [CODE]
+    profile start Xprofile_file.log
+    func! Foo()
+    endfunc
+    profile func Foo
+    call Foo()
+    profdel *
+    call Foo()
+  [CODE]
   call writefile(lines, 'Xprofile_file.vim')
   call system(v:progpath . ' -es --clean -c "so Xprofile_file.vim" -c q')
   call assert_equal(0, v:shell_error)