1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-25 09:10:03 +08:00
SpaceVim/test/api/data/string.vader
Wang Shidong eede4cfbe3
Improve data#string api (#2515)
- add fill_left and fill_middle function
- fix string api doc
- add string api cn doc
2019-01-28 17:50:20 +08:00

44 lines
2.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Execute ( SpaceVim api: data#string ):
let str = SpaceVim#api#import('data#string')
Log 'test trim()'
AssertEqual str.trim(' s b '), 's b'
Log 'test fill()'
AssertEqual str.fill('s b', 10), 's b '
Log 'test fill() len < strlen'
AssertEqual str.fill('s b', 2), 's '
Log 'test fill() with char'
AssertEqual str.fill('s b', 10, '*'), 's b*******'
Log 'test fill_left()'
AssertEqual str.fill_left('s b', 10, '*'), '*******s b'
Log 'test fill_left() len = strlen'
AssertEqual str.fill_left('s b', 3, '*'), 's b'
Log 'test fill_left() len < strlen'
AssertEqual str.fill_left('s b', 2, '*'), ' b'
Log 'test fill_middle()'
AssertEqual str.fill_middle('s b', 9, '*'), '***s b***'
Log 'test fill_middle() fill number % 2 = 1'
AssertEqual str.fill_middle('s b', 10, '*'), '***s b****'
Log 'test fill_middle() len = strlen'
AssertEqual str.fill_middle('s b', 3, '*'), 's b'
Log 'test fill_middle() len < strlen'
AssertEqual str.fill_middle('s b', 2, '*'), ' b'
AssertEqual str.fill_middle('s b', 1, '*'), ' '
Log 'test split()'
AssertEqual str.split(' 20 281 23 -invalid-', '', 0, 4)[2], '23'
Log 'test trim_start()'
AssertEqual str.trim_start(' s b '), 's b '
Log 'test string2chars()'
AssertEqual str.string2chars(' a b '), [' ', 'a', ' ', 'b', ' ']
AssertEqual str.string2chars('你好'), ['你', '好']
Log 'test strQ2B()'
AssertEqual str.strQ2B(''), '%'
Log 'test strB2Q()'
AssertEqual str.strB2Q('%'), ''
AssertEqual str.trim_end(' s b '), ' s b'
AssertEqual str.fill_middle('s b', 10), ' s b '
AssertEqual str.strAllIndex('hello spacevim hello', 'hello', 0), [[0, 5], [15, 20]]
AssertEqual str.strAllIndex('hello spacevim hello', 'he.*', 1), [[0, 20]]
AssertEqual str.strAllIndex('hello spacevim hello', 'he[^ ]*', 1), [[0, 5], [15, 20]]
AssertEqual str.strAllIndex('let s:cursor_stack[i].end = s:cursor_stack[i].cursor . s:cursor_stack[i].end', 's.cursor[^_]*', 1), [[4, 12], [28, 36], [55, 63]]
unlet str