comparison src/testdir/test_listdict.vim @ 25595:c4e29355cd8b v8.2.3334

patch 8.2.3334: Vim9: not enough tests run with Vim9 Commit: https://github.com/vim/vim/commit/bd77aa92744d79f3ba69aee713739ec17da474f6 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Aug 12 17:06:05 2021 +0200 patch 8.2.3334: Vim9: not enough tests run with Vim9 Problem: Vim9: not enough tests run with Vim9. Solution: Run a few more tests in Vim9 script and :def function. Fix islocked(). Fix error for locking local variable.
author Bram Moolenaar <Bram@vim.org>
date Thu, 12 Aug 2021 17:15:04 +0200
parents c6277019b8c1
children 0fdacd8f0cf3
comparison
equal deleted inserted replaced
25594:174cf06af294 25595:c4e29355cd8b
480 call assert_equal('6', trim(execute('echo 2 *{blue: 3}.blue'))) 480 call assert_equal('6', trim(execute('echo 2 *{blue: 3}.blue')))
481 endfunc 481 endfunc
482 482
483 " Nasty: deepcopy() dict that refers to itself (fails when noref used) 483 " Nasty: deepcopy() dict that refers to itself (fails when noref used)
484 func Test_dict_deepcopy() 484 func Test_dict_deepcopy()
485 let d = {1:1, 2:2} 485 let lines =<< trim END
486 let l = [4, d, 6] 486 VAR d = {1: 1, 2: '2'}
487 let d[3] = l 487 VAR l = [4, d, 6]
488 let dc = deepcopy(d) 488 LET d[3] = l
489 call assert_fails('call deepcopy(d, 1)', 'E698:') 489 VAR dc = deepcopy(d)
490 let l2 = [0, l, l, 3] 490 call deepcopy(d, 1)
491 let l[1] = l2 491 END
492 let l3 = deepcopy(l2) 492 call CheckLegacyAndVim9Failure(lines, 'E698:')
493 call assert_true(l3[1] is l3[2]) 493
494 let lines =<< trim END
495 VAR d = {1: 1, 2: '2'}
496 VAR l = [4, d, 6]
497 LET d[3] = l
498 VAR l2 = [0, l, l, 3]
499 LET l[1] = l2
500 VAR l3 = deepcopy(l2)
501 call assert_true(l3[1] is l3[2])
502 END
503 call CheckLegacyAndVim9Success(lines)
504
494 call assert_fails("call deepcopy([1, 2], 2)", 'E1023:') 505 call assert_fails("call deepcopy([1, 2], 2)", 'E1023:')
495 endfunc 506 endfunc
496 507
497 " Locked variables 508 " Locked variables
498 func Test_list_locked_var() 509 func Test_list_locked_var()
499 let expected = [ 510 " Not tested with :def function, local vars cannot be locked.
500 \ [['1000-000', 'ppppppF'], 511 let lines =<< trim END
501 \ ['0000-000', 'ppppppp'], 512 VAR expected = [
502 \ ['0000-000', 'ppppppp']], 513 \ [['1000-000', 'ppppppF'],
503 \ [['1000-000', 'ppppppF'], 514 \ ['0000-000', 'ppppppp'],
504 \ ['0000-000', 'ppppppp'], 515 \ ['0000-000', 'ppppppp']],
505 \ ['0000-000', 'ppppppp']], 516 \ [['1000-000', 'ppppppF'],
506 \ [['1100-100', 'ppFppFF'], 517 \ ['0000-000', 'ppppppp'],
507 \ ['0000-000', 'ppppppp'], 518 \ ['0000-000', 'ppppppp']],
508 \ ['0000-000', 'ppppppp']], 519 \ [['1100-100', 'ppFppFF'],
509 \ [['1110-110', 'pFFpFFF'], 520 \ ['0000-000', 'ppppppp'],
510 \ ['0010-010', 'pFppFpp'], 521 \ ['0000-000', 'ppppppp']],
511 \ ['0000-000', 'ppppppp']], 522 \ [['1110-110', 'pFFpFFF'],
512 \ [['1111-111', 'FFFFFFF'], 523 \ ['0010-010', 'pFppFpp'],
513 \ ['0011-011', 'FFpFFpp'], 524 \ ['0000-000', 'ppppppp']],
514 \ ['0000-000', 'ppppppp']] 525 \ [['1111-111', 'FFFFFFF'],
515 \ ] 526 \ ['0011-011', 'FFpFFpp'],
516 for depth in range(5) 527 \ ['0000-000', 'ppppppp']]
517 for u in range(3) 528 \ ]
518 unlet! l 529 for depth in range(5)
519 let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] 530 for u in range(3)
520 exe "lockvar " . depth . " l" 531 VAR l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]
521 if u == 1 532 exe "lockvar " .. depth .. " l"
522 exe "unlockvar l" 533 if u == 1
523 elseif u == 2 534 exe "unlockvar l"
524 exe "unlockvar " . depth . " l" 535 elseif u == 2
525 endif 536 exe "unlockvar " .. depth .. " l"
526 let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]") 537 endif
527 call assert_equal(expected[depth][u][0], ps, 'depth: ' .. depth) 538 VAR ps = islocked("l") .. islocked("l[1]") .. islocked("l[1][1]") .. islocked("l[1][1][0]") .. '-' .. islocked("l[2]") .. islocked("l[2]['6']") .. islocked("l[2]['6'][7]")
528 let ps = '' 539 call assert_equal(expected[depth][u][0], ps, 'depth: ' .. depth)
529 try 540 LET ps = ''
530 let l[1][1][0] = 99 541 try
531 let ps .= 'p' 542 LET l[1][1][0] = 99
532 catch 543 LET ps ..= 'p'
533 let ps .= 'F' 544 catch
534 endtry 545 LET ps ..= 'F'
535 try 546 endtry
536 let l[1][1] = [99] 547 try
537 let ps .= 'p' 548 LET l[1][1] = [99]
538 catch 549 LET ps ..= 'p'
539 let ps .= 'F' 550 catch
540 endtry 551 LET ps ..= 'F'
541 try 552 endtry
542 let l[1] = [99] 553 try
543 let ps .= 'p' 554 LET l[1] = [99]
544 catch 555 LET ps ..= 'p'
545 let ps .= 'F' 556 catch
546 endtry 557 LET ps ..= 'F'
547 try 558 endtry
548 let l[2]['6'][7] = 99 559 try
549 let ps .= 'p' 560 LET l[2]['6'][7] = 99
550 catch 561 LET ps ..= 'p'
551 let ps .= 'F' 562 catch
552 endtry 563 LET ps ..= 'F'
553 try 564 endtry
554 let l[2][6] = {99: 99} 565 try
555 let ps .= 'p' 566 LET l[2][6] = {99: 99}
556 catch 567 LET ps ..= 'p'
557 let ps .= 'F' 568 catch
558 endtry 569 LET ps ..= 'F'
559 try 570 endtry
560 let l[2] = {99: 99} 571 try
561 let ps .= 'p' 572 LET l[2] = {99: 99}
562 catch 573 LET ps ..= 'p'
563 let ps .= 'F' 574 catch
564 endtry 575 LET ps ..= 'F'
565 try 576 endtry
566 let l = [99] 577 try
567 let ps .= 'p' 578 LET l = [99]
568 catch 579 LET ps ..= 'p'
569 let ps .= 'F' 580 catch
570 endtry 581 LET ps ..= 'F'
571 call assert_equal(expected[depth][u][1], ps, 'depth: ' .. depth) 582 endtry
572 endfor 583 call assert_equal(expected[depth][u][1], ps, 'depth: ' .. depth)
573 endfor 584 unlock! l
585 endfor
586 endfor
587 END
588 call CheckTransLegacySuccess(lines)
589 call CheckTransVim9Success(lines)
590
574 call assert_fails("let x=islocked('a b')", 'E488:') 591 call assert_fails("let x=islocked('a b')", 'E488:')
575 let mylist = [1, 2, 3] 592 let mylist = [1, 2, 3]
576 call assert_fails("let x = islocked('mylist[1:2]')", 'E786:') 593 call assert_fails("let x = islocked('mylist[1:2]')", 'E786:')
577 let mydict = {'k' : 'v'} 594 let mydict = {'k' : 'v'}
578 call assert_fails("let x = islocked('mydict.a')", 'E716:') 595 call assert_fails("let x = islocked('mydict.a')", 'E716:')
579 endfunc 596 endfunc
580 597
581 " Unletting locked variables 598 " Unletting locked variables
582 func Test_list_locked_var_unlet() 599 func Test_list_locked_var_unlet()
600 " Not tested with Vim9: script and local variables cannot be unlocked
583 let expected = [ 601 let expected = [
584 \ [['1000-000', 'ppppppp'], 602 \ [['1000-000', 'ppppppp'],
585 \ ['0000-000', 'ppppppp'], 603 \ ['0000-000', 'ppppppp'],
586 \ ['0000-000', 'ppppppp']], 604 \ ['0000-000', 'ppppppp']],
587 \ [['1000-000', 'ppFppFp'], 605 \ [['1000-000', 'ppFppFp'],
672 call assert_fails('unlet d.a', 'E741:') 690 call assert_fails('unlet d.a', 'E741:')
673 endfunc 691 endfunc
674 692
675 " unlet after lock on dict item 693 " unlet after lock on dict item
676 func Test_dict_item_lock_unlet() 694 func Test_dict_item_lock_unlet()
677 let d = {'a': 99, 'b': 100} 695 let lines =<< trim END
678 lockvar d.a 696 VAR d = {'a': 99, 'b': 100}
679 unlet d.a 697 lockvar d.a
680 call assert_equal({'b' : 100}, d) 698 unlet d.a
699 call assert_equal({'b': 100}, d)
700 END
701 " TODO: make this work in a :def function
702 "call CheckLegacyAndVim9Success(lines)
703 call CheckTransLegacySuccess(lines)
704 call CheckTransVim9Success(lines)
681 endfunc 705 endfunc
682 706
683 " filter() after lock on dict item 707 " filter() after lock on dict item
684 func Test_dict_lock_filter() 708 func Test_dict_lock_filter()
685 let d = {'a': 99, 'b': 100} 709 let lines =<< trim END
686 lockvar d.a 710 VAR d = {'a': 99, 'b': 100}
687 call filter(d, 'v:key != "a"') 711 lockvar d.a
688 call assert_equal({'b' : 100}, d) 712 call filter(d, 'v:key != "a"')
713 call assert_equal({'b': 100}, d)
714 END
715 " TODO: make this work in a :def function
716 "call CheckLegacyAndVim9Success(lines)
717 call CheckTransLegacySuccess(lines)
718 call CheckTransVim9Success(lines)
689 endfunc 719 endfunc
690 720
691 " map() after lock on dict 721 " map() after lock on dict
692 func Test_dict_lock_map() 722 func Test_dict_lock_map()
693 let d = {'a': 99, 'b': 100} 723 let lines =<< trim END
694 lockvar 1 d 724 VAR d = {'a': 99, 'b': 100}
695 call map(d, 'v:val + 200') 725 lockvar 1 d
696 call assert_equal({'a' : 299, 'b' : 300}, d) 726 call map(d, 'v:val + 200')
727 call assert_equal({'a': 299, 'b': 300}, d)
728 END
729 " This won't work in a :def function
730 call CheckTransLegacySuccess(lines)
731 call CheckTransVim9Success(lines)
697 endfunc 732 endfunc
698 733
699 " No extend() after lock on dict item 734 " No extend() after lock on dict item
700 func Test_dict_lock_extend() 735 func Test_dict_lock_extend()
701 let d = {'a': 99, 'b': 100} 736 let d = {'a': 99, 'b': 100}