comparison src/testdir/test_vimscript.vim @ 15790:05d836c8f1c4 v8.1.0902

patch 8.1.0902: incomplete set of assignment operators commit https://github.com/vim/vim/commit/ff697e6cef8ced7717a21fd525ab3200b2f1724f Author: Bram Moolenaar <Bram@vim.org> Date: Tue Feb 12 22:28:33 2019 +0100 patch 8.1.0902: incomplete set of assignment operators Problem: Incomplete set of assignment operators. Solution: Add /=, *= and %=. (Ozaki Kiichi, closes https://github.com/vim/vim/issues/3931)
author Bram Moolenaar <Bram@vim.org>
date Tue, 12 Feb 2019 22:30:08 +0100
parents 63b02fcf1361
children 9cc42db77a54
comparison
equal deleted inserted replaced
15789:9b7a86acea77 15790:05d836c8f1c4
1439 call assert_equal('nothing line', getline(2)) 1439 call assert_equal('nothing line', getline(2))
1440 call assert_equal('last line', getline(3)) 1440 call assert_equal('last line', getline(3))
1441 enew! | close 1441 enew! | close
1442 endfunc 1442 endfunc
1443 1443
1444 func Test_compound_assignment_operators()
1445 " Test for number
1446 let x = 1
1447 let x += 10
1448 call assert_equal(11, x)
1449 let x -= 5
1450 call assert_equal(6, x)
1451 let x *= 4
1452 call assert_equal(24, x)
1453 let x /= 3
1454 call assert_equal(8, x)
1455 let x %= 3
1456 call assert_equal(2, x)
1457 let x .= 'n'
1458 call assert_equal('2n', x)
1459
1460 " Test for string
1461 let x = 'str'
1462 let x .= 'ing'
1463 call assert_equal('string', x)
1464 let x += 1
1465 call assert_equal(1, x)
1466 let x -= 1.5
1467 call assert_equal(-0.5, x)
1468
1469 if has('float')
1470 " Test for float
1471 let x = 0.5
1472 let x += 4.5
1473 call assert_equal(5.0, x)
1474 let x -= 1.5
1475 call assert_equal(3.5, x)
1476 let x *= 3.0
1477 call assert_equal(10.5, x)
1478 let x /= 2.5
1479 call assert_equal(4.2, x)
1480 call assert_fails('let x %= 0.5', 'E734')
1481 call assert_fails('let x .= "f"', 'E734')
1482 endif
1483
1484 " Test for environment variable
1485 let $FOO = 1
1486 call assert_fails('let $FOO += 1', 'E734')
1487 call assert_fails('let $FOO -= 1', 'E734')
1488 call assert_fails('let $FOO *= 1', 'E734')
1489 call assert_fails('let $FOO /= 1', 'E734')
1490 call assert_fails('let $FOO %= 1', 'E734')
1491 let $FOO .= 's'
1492 call assert_equal('1s', $FOO)
1493 unlet $FOO
1494
1495 " Test for option variable (type: number)
1496 let &scrolljump = 1
1497 let &scrolljump += 5
1498 call assert_equal(6, &scrolljump)
1499 let &scrolljump -= 2
1500 call assert_equal(4, &scrolljump)
1501 let &scrolljump *= 3
1502 call assert_equal(12, &scrolljump)
1503 let &scrolljump /= 2
1504 call assert_equal(6, &scrolljump)
1505 let &scrolljump %= 5
1506 call assert_equal(1, &scrolljump)
1507 call assert_fails('let &scrolljump .= "j"', 'E734')
1508 set scrolljump&vim
1509
1510 " Test for register
1511 let @/ = 1
1512 call assert_fails('let @/ += 1', 'E734')
1513 call assert_fails('let @/ -= 1', 'E734')
1514 call assert_fails('let @/ *= 1', 'E734')
1515 call assert_fails('let @/ /= 1', 'E734')
1516 call assert_fails('let @/ %= 1', 'E734')
1517 let @/ .= 's'
1518 call assert_equal('1s', @/)
1519 let @/ = ''
1520 endfunc
1521
1444 "------------------------------------------------------------------------------- 1522 "-------------------------------------------------------------------------------
1445 " Modelines {{{1 1523 " Modelines {{{1
1446 " vim: ts=8 sw=4 tw=80 fdm=marker 1524 " vim: ts=8 sw=4 tw=80 fdm=marker
1447 " vim: fdt=substitute(substitute(foldtext(),\ '\\%(^+--\\)\\@<=\\(\\s*\\)\\(.\\{-}\\)\:\ \\%(\"\ \\)\\=\\(Test\ \\d*\\)\:\\s*',\ '\\3\ (\\2)\:\ \\1',\ \"\"),\ '\\(Test\\s*\\)\\(\\d\\)\\D\\@=',\ '\\1\ \\2',\ "") 1525 " vim: fdt=substitute(substitute(foldtext(),\ '\\%(^+--\\)\\@<=\\(\\s*\\)\\(.\\{-}\\)\:\ \\%(\"\ \\)\\=\\(Test\ \\d*\\)\:\\s*',\ '\\3\ (\\2)\:\ \\1',\ \"\"),\ '\\(Test\\s*\\)\\(\\d\\)\\D\\@=',\ '\\1\ \\2',\ "")
1448 "------------------------------------------------------------------------------- 1526 "-------------------------------------------------------------------------------