mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
string: separate strip_margin tests into different functions
This commit is contained in:
parent
f73b38a0d8
commit
e2eb0f17d7
@ -696,78 +696,115 @@ fn test_split_into_lines() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_strip_margins() {
|
fn test_strip_margins_no_tabs() {
|
||||||
no_tabs := 'Hello there
|
no_tabs := ['Hello there',
|
||||||
This is a string
|
'This is a string',
|
||||||
With multiple lines'
|
'With multiple lines',
|
||||||
|
].join('\n')
|
||||||
no_tabs_stripped := 'Hello there
|
no_tabs_stripped := 'Hello there
|
||||||
|This is a string
|
|This is a string
|
||||||
|With multiple lines'.strip_margin()
|
|With multiple lines'.strip_margin()
|
||||||
assert no_tabs == no_tabs_stripped
|
assert no_tabs == no_tabs_stripped
|
||||||
|
}
|
||||||
|
|
||||||
text_before := 'There is text
|
fn test_strip_margins_text_before() {
|
||||||
before the delimiter
|
text_before := ['There is text',
|
||||||
that should be removed as well'
|
'before the delimiter',
|
||||||
|
'that should be removed as well',
|
||||||
|
].join('\n')
|
||||||
text_before_stripped := 'There is text
|
text_before_stripped := 'There is text
|
||||||
f lasj asldfj j lksjdf |before the delimiter
|
f lasj asldfj j lksjdf |before the delimiter
|
||||||
Which is removed hello |that should be removed as well'.strip_margin()
|
Which is removed hello |that should be removed as well'.strip_margin()
|
||||||
assert text_before_stripped == text_before
|
assert text_before_stripped == text_before
|
||||||
|
}
|
||||||
|
|
||||||
tabs := ' Tab
|
fn test_strip_margins_white_space_after_delim() {
|
||||||
spaces
|
tabs := [' Tab',
|
||||||
another tab'
|
' spaces',
|
||||||
|
' another tab',
|
||||||
|
].join('\n')
|
||||||
tabs_stripped := ' Tab
|
tabs_stripped := ' Tab
|
||||||
| spaces
|
| spaces
|
||||||
| another tab'.strip_margin()
|
| another tab'.strip_margin()
|
||||||
assert tabs == tabs_stripped
|
assert tabs == tabs_stripped
|
||||||
|
}
|
||||||
|
|
||||||
alternate_delimiter := 'This has a different delim,
|
fn test_strip_margins_alternate_delim() {
|
||||||
but that is ok
|
alternate_delimiter := ['This has a different delim,',
|
||||||
because everything works'
|
'but that is ok',
|
||||||
|
'because everything works',
|
||||||
|
].join('\n')
|
||||||
alternate_delimiter_stripped := 'This has a different delim,
|
alternate_delimiter_stripped := 'This has a different delim,
|
||||||
#but that is ok
|
#but that is ok
|
||||||
# because everything works'.strip_margin(`#`)
|
#because everything works'.strip_margin(`#`)
|
||||||
assert alternate_delimiter_stripped == alternate_delimiter
|
assert alternate_delimiter_stripped == alternate_delimiter
|
||||||
|
}
|
||||||
|
|
||||||
delim_after_first_instance := 'The delimiter used
|
fn test_strip_margins_multiple_delims_after_first() {
|
||||||
only matters the |||| First time it is seen
|
delim_after_first_instance := ['The delimiter used',
|
||||||
not any | other | times'
|
'only matters the |||| First time it is seen',
|
||||||
|
'not any | other | times',
|
||||||
|
].join('\n')
|
||||||
delim_after_first_instance_stripped := 'The delimiter used
|
delim_after_first_instance_stripped := 'The delimiter used
|
||||||
|only matters the |||| First time it is seen
|
|only matters the |||| First time it is seen
|
||||||
|not any | other | times'.strip_margin()
|
|not any | other | times'.strip_margin()
|
||||||
assert delim_after_first_instance_stripped == delim_after_first_instance
|
assert delim_after_first_instance_stripped == delim_after_first_instance
|
||||||
|
}
|
||||||
|
|
||||||
uneven_delims := 'It doesn\'t matter if the delims are uneven,
|
fn test_strip_margins_uneven_delims() {
|
||||||
The text will still be delimited correctly.
|
uneven_delims := ['It doesn\'t matter if the delims are uneven,',
|
||||||
Maybe not everything needs 3 lines?
|
'The text will still be delimited correctly.',
|
||||||
Let us go for 4 then'
|
'Maybe not everything needs 3 lines?',
|
||||||
|
'Let us go for 4 then',
|
||||||
|
].join('\n')
|
||||||
uneven_delims_stripped := 'It doesn\'t matter if the delims are uneven,
|
uneven_delims_stripped := 'It doesn\'t matter if the delims are uneven,
|
||||||
|The text will still be delimited correctly.
|
|The text will still be delimited correctly.
|
||||||
|Maybe not everything needs 3 lines?
|
|Maybe not everything needs 3 lines?
|
||||||
|Let us go for 4 then'.strip_margin()
|
|Let us go for 4 then'.strip_margin()
|
||||||
assert uneven_delims_stripped == uneven_delims
|
assert uneven_delims_stripped == uneven_delims
|
||||||
|
}
|
||||||
|
|
||||||
multi_blank_lines := 'Multiple blank lines will be removed.
|
fn test_strip_margins_multiple_blank_lines() {
|
||||||
I actually consider this a feature.'
|
multi_blank_lines := ['Multiple blank lines will be removed.',
|
||||||
|
' I actually consider this a feature.',
|
||||||
|
].join('\n')
|
||||||
multi_blank_lines_stripped := 'Multiple blank lines will be removed.
|
multi_blank_lines_stripped := 'Multiple blank lines will be removed.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| I actually consider this a feature.'.strip_margin()
|
| I actually consider this a feature.'.strip_margin()
|
||||||
assert multi_blank_lines == multi_blank_lines_stripped
|
assert multi_blank_lines == multi_blank_lines_stripped
|
||||||
|
}
|
||||||
|
|
||||||
end_with_newline := 'This line will end with a newline
|
fn test_strip_margins_end_newline() {
|
||||||
Something cool or something.
|
end_with_newline := ['This line will end with a newline',
|
||||||
'
|
'Something cool or something.',
|
||||||
|
'',
|
||||||
|
].join('\n')
|
||||||
end_with_newline_stripped := 'This line will end with a newline
|
end_with_newline_stripped := 'This line will end with a newline
|
||||||
|Something cool or something.
|
|Something cool or something.
|
||||||
|
|
||||||
'.strip_margin()
|
'.strip_margin()
|
||||||
assert end_with_newline_stripped == end_with_newline
|
assert end_with_newline_stripped == end_with_newline
|
||||||
|
}
|
||||||
|
|
||||||
space_delimiter := 'Using a white-space char will
|
fn test_strip_margins_space_delimiter() {
|
||||||
revert back to default behavior.'
|
space_delimiter := ['Using a white-space char will',
|
||||||
|
'revert back to default behavior.',
|
||||||
|
].join('\n')
|
||||||
space_delimiter_stripped := 'Using a white-space char will
|
space_delimiter_stripped := 'Using a white-space char will
|
||||||
|revert back to default behavior.'.strip_margin(`\n`)
|
|revert back to default behavior.'.strip_margin(`\n`)
|
||||||
assert space_delimiter == space_delimiter_stripped
|
assert space_delimiter == space_delimiter_stripped
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_strip_margins_crlf() {
|
||||||
|
crlf := ['This string\'s line endings have CR as well as LFs.',
|
||||||
|
'This should pass',
|
||||||
|
'Definitely',
|
||||||
|
].join('\r\n')
|
||||||
|
crlf_stripped := 'This string\'s line endings have CR as well as LFs.\r
|
||||||
|
|This should pass\r
|
||||||
|
|Definitely'.strip_margin()
|
||||||
|
|
||||||
|
assert crlf == crlf_stripped
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user