comparison src/testdir/test_vim9_assign.vim @ 28560:060fc3b69697 v8.2.4804

patch 8.2.4804: expression in heredoc doesn't work for compiled function Commit: https://github.com/vim/vim/commit/1fc6ea9bf3548b578676331f5eac1f7e0611c268 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Thu Apr 21 23:30:15 2022 +0100 patch 8.2.4804: expression in heredoc doesn't work for compiled function Problem: Expression in heredoc doesn't work for compiled function. Solution: Implement compiling the heredoc expressions. (Yegappan Lakshmanan, closes #10232)
author Bram Moolenaar <Bram@vim.org>
date Fri, 22 Apr 2022 00:45:04 +0200
parents 769599ee9f06
children 723c7d940cba
comparison
equal deleted inserted replaced
28559:a9388feb437d 28560:060fc3b69697
1819 END 1819 END
1820 v9.CheckDefAndScriptFailure(lines, 'E1051:') 1820 v9.CheckDefAndScriptFailure(lines, 'E1051:')
1821 enddef 1821 enddef
1822 1822
1823 def Test_heredoc() 1823 def Test_heredoc()
1824 var lines =<< trim END # comment 1824 # simple heredoc
1825 text 1825 var lines =<< trim END
1826 END 1826 var text =<< trim TEXT # comment
1827 assert_equal(['text'], lines) 1827 abc
1828 TEXT
1829 assert_equal(['abc'], text)
1830 END
1831 v9.CheckDefAndScriptSuccess(lines)
1832
1833 # empty heredoc
1834 lines =<< trim END
1835 var text =<< trim TEXT
1836 TEXT
1837 assert_equal([], text)
1838 END
1839 v9.CheckDefAndScriptSuccess(lines)
1840
1841 # heredoc with a single empty line
1842 lines =<< trim END
1843 var text =<< trim TEXT
1844
1845 TEXT
1846 assert_equal([''], text)
1847 END
1848 v9.CheckDefAndScriptSuccess(lines)
1828 1849
1829 v9.CheckDefFailure(['var lines =<< trim END X', 'END'], 'E488:') 1850 v9.CheckDefFailure(['var lines =<< trim END X', 'END'], 'E488:')
1830 v9.CheckDefFailure(['var lines =<< trim END " comment', 'END'], 'E488:') 1851 v9.CheckDefFailure(['var lines =<< trim END " comment', 'END'], 'E488:')
1831 1852
1832 lines =<< trim [END] 1853 lines =<< trim [END]
2640 let g:someVar = 'X' 2661 let g:someVar = 'X'
2641 2662
2642 " Test for heredoc with Vim expressions. 2663 " Test for heredoc with Vim expressions.
2643 " This messes up highlighting, keep it near the end. 2664 " This messes up highlighting, keep it near the end.
2644 def Test_heredoc_expr() 2665 def Test_heredoc_expr()
2645 var code =<< trim eval END 2666 var lines =<< trim CODE
2646 var a = `=5 + 10` 2667 var s = "local"
2647 var b = `=min([10, 6])` + `=max([4, 6])` 2668 var a1 = "1"
2648 END 2669 var a2 = "2"
2649 assert_equal(['var a = 15', 'var b = 6 + 6'], code) 2670 var a3 = "3"
2650 2671 var a4 = ""
2651 code =<< eval trim END 2672 var code =<< trim eval END
2652 var s = "`=$SOME_ENV_VAR`" 2673 var a = `=5 + 10`
2653 END 2674 var b = `=min([10, 6])` + `=max([4, 6])`
2654 assert_equal(['var s = "somemore"'], code) 2675 var c = "`=s`"
2655 2676 var d = x`=a1`x`=a2`x`=a3`x`=a4`
2656 code =<< eval END 2677 END
2657 var s = "`=$SOME_ENV_VAR`" 2678 assert_equal(['var a = 15', 'var b = 6 + 6', 'var c = "local"', 'var d = x1x2x3x'], code)
2658 END 2679 CODE
2659 assert_equal([' var s = "somemore"'], code) 2680 v9.CheckDefAndScriptSuccess(lines)
2660 2681
2661 code =<< eval trim END 2682 lines =<< trim CODE
2662 let a = `abc` 2683 var code =<< eval trim END
2663 let b = `=g:someVar` 2684 var s = "`=$SOME_ENV_VAR`"
2664 let c = ` 2685 END
2665 END 2686 assert_equal(['var s = "somemore"'], code)
2666 assert_equal(['let a = `abc`', 'let b = X', 'let c = `'], code) 2687 CODE
2667 2688 v9.CheckDefAndScriptSuccess(lines)
2668 var lines =<< trim LINES 2689
2690 lines =<< trim CODE
2691 var code =<< eval END
2692 var s = "`=$SOME_ENV_VAR`"
2693 END
2694 assert_equal([' var s = "somemore"'], code)
2695 CODE
2696 v9.CheckDefAndScriptSuccess(lines)
2697
2698 lines =<< trim CODE
2699 var code =<< eval trim END
2700 let a = `abc`
2701 let b = `=g:someVar`
2702 let c = `
2703 END
2704 assert_equal(['let a = `abc`', 'let b = X', 'let c = `'], code)
2705 CODE
2706 v9.CheckDefAndScriptSuccess(lines)
2707
2708 lines =<< trim LINES
2669 var text =<< eval trim END 2709 var text =<< eval trim END
2670 let b = `= 2710 let b = `=
2671 END 2711 END
2672 LINES 2712 LINES
2673 v9.CheckDefAndScriptFailure(lines, 'E1083:') 2713 v9.CheckDefAndScriptFailure(lines, ['E1143: Empty expression: ""', 'E1083: Missing backtick'])
2674 2714
2675 lines =<< trim LINES 2715 lines =<< trim LINES
2676 var text =<< eval trim END 2716 var text =<< eval trim END
2677 let b = `=abc 2717 let b = `=abc
2678 END 2718 END
2679 LINES 2719 LINES
2680 v9.CheckDefAndScriptFailure(lines, 'E1083:') 2720 v9.CheckDefAndScriptFailure(lines, ['E1001: Variable not found: abc', 'E1083: Missing backtick'])
2681 2721
2682 lines =<< trim LINES 2722 lines =<< trim LINES
2683 var text =<< eval trim END 2723 var text =<< eval trim END
2684 let b = `=` 2724 let b = `=`
2685 END 2725 END
2686 LINES 2726 LINES
2687 v9.CheckDefAndScriptFailure(lines, 'E15:') 2727 v9.CheckDefAndScriptFailure(lines, ['E1015: Name expected: `', 'E15: Invalid expression: "`"'])
2688 enddef 2728 enddef
2689
2690
2691 2729
2692 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker 2730 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker