view src/testdir/test_sort.vim @ 8234:dc72f4a463e4 v7.4.1410

commit https://github.com/vim/vim/commit/42dd7aee41ffcc5afdbf9bb83d70e7123261cada Author: Bram Moolenaar <Bram@vim.org> Date: Tue Feb 23 22:50:12 2016 +0100 patch 7.4.1410 Problem: Leaking memory in cscope interface. Solution: Free memory when no tab is found. (Christian Brabandt)
author Christian Brabandt <cb@256bit.org>
date Tue, 23 Feb 2016 23:00:05 +0100
parents c11aaa31a0ed
children 2aa24f702b8d
line wrap: on
line source

" Test sort()

:func Compare1(a, b) abort
    call sort(range(3), 'Compare2')
    return a:a - a:b
:endfunc

:func Compare2(a, b) abort
    return a:a - a:b
:endfunc

func Test_sort_strings()
  " numbers compared as strings
  call assert_equal([1, 2, 3], sort([3, 2, 1]))
  call assert_equal([13, 28, 3], sort([3, 28, 13]))
endfunc

func Test_sort_numeric()
  call assert_equal([1, 2, 3], sort([3, 2, 1], 'n'))
  call assert_equal([3, 13, 28], sort([13, 28, 3], 'n'))
  " strings are not sorted
  call assert_equal(['13', '28', '3'], sort(['13', '28', '3'], 'n'))
endfunc

func Test_sort_numbers()
  call assert_equal([3, 13, 28], sort([13, 28, 3], 'N'))
  call assert_equal(['3', '13', '28'], sort(['13', '28', '3'], 'N'))
endfunc

func Test_sort_float()
  call assert_equal([0.28, 3, 13.5], sort([13.5, 0.28, 3], 'f'))
endfunc

func Test_sort_nested()
  " test ability to call sort() from a compare function
  call assert_equal([1, 3, 5], sort([3, 1, 5], 'Compare1'))
endfunc