Mercurial > vim
comparison src/testdir/test_vim9_builtin.vim @ 25288:ddc38de331ff v8.2.3181
patch 8.2.3181: Vim9: builtin function test fails without channel feature
Commit: https://github.com/vim/vim/commit/9ff9c7b9741b216d3dc75603e50654088dc5f55b
Author: Dominique Pelle <dominique.pelle@gmail.com>
Date: Sun Jul 18 21:44:37 2021 +0200
patch 8.2.3181: Vim9: builtin function test fails without channel feature
Problem: Vim9: builtin function test fails without channel feature.
Solution: Add feature checks. (Dominique Pell?, closes https://github.com/vim/vim/issues/8586) Make feature
checks more consistent.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 18 Jul 2021 21:45:04 +0200 |
parents | 712e867f9721 |
children | 8b7ea875afed |
comparison
equal
deleted
inserted
replaced
25287:8c572a349cff | 25288:ddc38de331ff |
---|---|
396 endif | 396 endif |
397 CheckDefFailure(['ch_close_in(true)'], 'E1013: Argument 1: type mismatch, expected channel but got bool') | 397 CheckDefFailure(['ch_close_in(true)'], 'E1013: Argument 1: type mismatch, expected channel but got bool') |
398 enddef | 398 enddef |
399 | 399 |
400 def Test_ch_getjob() | 400 def Test_ch_getjob() |
401 CheckDefAndScriptFailure2(['ch_getjob(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument:') | 401 if !has('channel') |
402 CheckDefAndScriptFailure2(['ch_getjob({"a": 10})'], 'E1013: Argument 1: type mismatch, expected channel but got dict<number>', 'E731: Using a Dictionary as a String') | 402 CheckFeature channel |
403 assert_equal(0, ch_getjob(test_null_channel())) | 403 else |
404 CheckDefAndScriptFailure2(['ch_getjob(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument:') | |
405 CheckDefAndScriptFailure2(['ch_getjob({"a": 10})'], 'E1013: Argument 1: type mismatch, expected channel but got dict<number>', 'E731: Using a Dictionary as a String') | |
406 assert_equal(0, ch_getjob(test_null_channel())) | |
407 endif | |
404 enddef | 408 enddef |
405 | 409 |
406 def Test_ch_info() | 410 def Test_ch_info() |
407 if !has('channel') | 411 if !has('channel') |
408 CheckFeature channel | 412 CheckFeature channel |
1423 assert_equal([['a', 10], ['b', 20]], {'a': 10, 'b': 20}->items()) | 1427 assert_equal([['a', 10], ['b', 20]], {'a': 10, 'b': 20}->items()) |
1424 assert_equal([], {}->items()) | 1428 assert_equal([], {}->items()) |
1425 enddef | 1429 enddef |
1426 | 1430 |
1427 def Test_job_getchannel() | 1431 def Test_job_getchannel() |
1428 CheckDefAndScriptFailure2(['job_getchannel("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument') | 1432 if !has('job') |
1429 assert_fails('job_getchannel(test_null_job())', 'E916: not a valid job') | 1433 CheckFeature job |
1434 else | |
1435 CheckDefAndScriptFailure2(['job_getchannel("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument') | |
1436 assert_fails('job_getchannel(test_null_job())', 'E916: not a valid job') | |
1437 endif | |
1430 enddef | 1438 enddef |
1431 | 1439 |
1432 def Test_job_info() | 1440 def Test_job_info() |
1433 CheckDefAndScriptFailure2(['job_info("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument') | 1441 if !has('job') |
1434 assert_fails('job_info(test_null_job())', 'E916: not a valid job') | 1442 CheckFeature job |
1443 else | |
1444 CheckDefAndScriptFailure2(['job_info("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument') | |
1445 assert_fails('job_info(test_null_job())', 'E916: not a valid job') | |
1446 endif | |
1435 enddef | 1447 enddef |
1436 | 1448 |
1437 def Test_job_info_return_type() | 1449 def Test_job_info_return_type() |
1438 if has('job') | 1450 if !has('job') |
1451 CheckFeature job | |
1452 else | |
1439 job_start(&shell) | 1453 job_start(&shell) |
1440 var jobs = job_info() | 1454 var jobs = job_info() |
1441 assert_equal('list<job>', typename(jobs)) | 1455 assert_equal('list<job>', typename(jobs)) |
1442 assert_equal('dict<any>', typename(job_info(jobs[0]))) | 1456 assert_equal('dict<any>', typename(job_info(jobs[0]))) |
1443 job_stop(jobs[0]) | 1457 job_stop(jobs[0]) |
1444 endif | 1458 endif |
1445 enddef | 1459 enddef |
1446 | 1460 |
1447 def Test_job_status() | 1461 def Test_job_status() |
1448 CheckDefAndScriptFailure2(['job_status("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument') | 1462 if !has('job') |
1449 assert_equal('fail', job_status(test_null_job())) | 1463 CheckFeature job |
1464 else | |
1465 CheckDefAndScriptFailure2(['job_status("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument') | |
1466 assert_equal('fail', job_status(test_null_job())) | |
1467 endif | |
1450 enddef | 1468 enddef |
1451 | 1469 |
1452 def Test_js_decode() | 1470 def Test_js_decode() |
1453 CheckDefFailure(['js_decode(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') | 1471 CheckDefFailure(['js_decode(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
1454 assert_equal([1, 2], js_decode('[1,2]')) | 1472 assert_equal([1, 2], js_decode('[1,2]')) |
1875 CheckDefFailure(['prevnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') | 1893 CheckDefFailure(['prevnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
1876 assert_equal(0, prevnonblank(1)) | 1894 assert_equal(0, prevnonblank(1)) |
1877 enddef | 1895 enddef |
1878 | 1896 |
1879 def Test_prompt_getprompt() | 1897 def Test_prompt_getprompt() |
1880 if has('channel') | 1898 if !has('channel') |
1899 CheckFeature channel | |
1900 else | |
1881 CheckDefFailure(['prompt_getprompt([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') | 1901 CheckDefFailure(['prompt_getprompt([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
1882 assert_equal('', prompt_getprompt('NonExistingBuf')) | 1902 assert_equal('', prompt_getprompt('NonExistingBuf')) |
1883 endif | 1903 endif |
1884 enddef | 1904 enddef |
1885 | 1905 |
2437 assert_equal(0z, slice(0z001122334455, 1, -6)) | 2457 assert_equal(0z, slice(0z001122334455, 1, -6)) |
2438 enddef | 2458 enddef |
2439 | 2459 |
2440 def Test_spellsuggest() | 2460 def Test_spellsuggest() |
2441 if !has('spell') | 2461 if !has('spell') |
2442 MissingFeature 'spell' | 2462 CheckFeature spell |
2443 else | 2463 else |
2444 spellsuggest('marrch', 1, true)->assert_equal(['March']) | 2464 spellsuggest('marrch', 1, true)->assert_equal(['March']) |
2445 endif | 2465 endif |
2446 enddef | 2466 enddef |
2447 | 2467 |
2494 assert_equal('', state('a')) | 2514 assert_equal('', state('a')) |
2495 enddef | 2515 enddef |
2496 | 2516 |
2497 def Run_str2float() | 2517 def Run_str2float() |
2498 if !has('float') | 2518 if !has('float') |
2499 MissingFeature 'float' | 2519 CheckFeature float |
2500 endif | 2520 endif |
2501 str2float("1.00")->assert_equal(1.00) | 2521 str2float("1.00")->assert_equal(1.00) |
2502 str2float("2e-2")->assert_equal(0.02) | 2522 str2float("2e-2")->assert_equal(0.02) |
2503 | 2523 |
2504 CheckDefFailure(['str2float(123)'], 'E1013:') | 2524 CheckDefFailure(['str2float(123)'], 'E1013:') |
2719 CheckDefAndScriptFailure2(['term_gettitle(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number') | 2739 CheckDefAndScriptFailure2(['term_gettitle(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number') |
2720 enddef | 2740 enddef |
2721 | 2741 |
2722 def Test_term_gettty() | 2742 def Test_term_gettty() |
2723 if !has('terminal') | 2743 if !has('terminal') |
2724 MissingFeature 'terminal' | 2744 CheckFeature terminal |
2725 else | 2745 else |
2726 var buf = Run_shell_in_terminal({}) | 2746 var buf = Run_shell_in_terminal({}) |
2727 term_gettty(buf, true)->assert_notequal('') | 2747 term_gettty(buf, true)->assert_notequal('') |
2728 StopShellInTerminal(buf) | 2748 StopShellInTerminal(buf) |
2729 endif | 2749 endif |
2752 CheckDefAndScriptFailure2(['term_setrestore([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') | 2772 CheckDefAndScriptFailure2(['term_setrestore([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') |
2753 CheckDefAndScriptFailure2(['term_setrestore(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2') | 2773 CheckDefAndScriptFailure2(['term_setrestore(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2') |
2754 enddef | 2774 enddef |
2755 def Test_term_start() | 2775 def Test_term_start() |
2756 if !has('terminal') | 2776 if !has('terminal') |
2757 MissingFeature 'terminal' | 2777 CheckFeature terminal |
2758 else | 2778 else |
2759 botright new | 2779 botright new |
2760 var winnr = winnr() | 2780 var winnr = winnr() |
2761 term_start(&shell, {curwin: true}) | 2781 term_start(&shell, {curwin: true}) |
2762 winnr()->assert_equal(winnr) | 2782 winnr()->assert_equal(winnr) |