2010-12-29 00:48:54 -05:00
|
|
|
# String Literals
|
|
|
|
# ---------------
|
|
|
|
|
|
|
|
# TODO: refactor string literal tests
|
2011-01-03 04:17:00 -05:00
|
|
|
# TODO: add indexing and method invocation tests: "string"["toString"] is String::toString, "string".toString() is "string"
|
2010-12-29 00:48:54 -05:00
|
|
|
|
2011-01-03 04:28:47 -05:00
|
|
|
# * Strings
|
|
|
|
# * Heredocs
|
|
|
|
|
2010-12-30 22:48:31 -05:00
|
|
|
test "backslash escapes", ->
|
|
|
|
eq "\\/\\\\", /\/\\/.source
|
|
|
|
|
2010-12-29 00:48:54 -05:00
|
|
|
eq '(((dollars)))', '\(\(\(dollars\)\)\)'
|
|
|
|
eq 'one two three', "one
|
|
|
|
two
|
|
|
|
three"
|
|
|
|
eq "four five", 'four
|
|
|
|
|
|
|
|
five'
|
|
|
|
|
2013-11-18 19:04:17 -05:00
|
|
|
test "#3229, multiline strings", ->
|
|
|
|
# Separate lines by default by a single space in literal strings.
|
2013-11-17 23:32:15 -05:00
|
|
|
eq 'one
|
|
|
|
two', 'one two'
|
|
|
|
eq "one
|
|
|
|
two", 'one two'
|
2013-11-18 19:04:17 -05:00
|
|
|
eq '
|
|
|
|
a
|
|
|
|
b
|
|
|
|
', 'a b'
|
|
|
|
eq "
|
|
|
|
a
|
|
|
|
b
|
|
|
|
", 'a b'
|
|
|
|
eq 'one
|
|
|
|
|
|
|
|
two', 'one two'
|
|
|
|
eq "one
|
|
|
|
|
|
|
|
two", 'one two'
|
|
|
|
eq '
|
|
|
|
indentation
|
|
|
|
doesn\'t
|
|
|
|
matter', 'indentation doesn\'t matter'
|
2013-11-24 13:37:11 -05:00
|
|
|
eq 'trailing ws
|
|
|
|
doesn\'t matter', 'trailing ws doesn\'t matter'
|
2013-11-18 19:04:17 -05:00
|
|
|
|
|
|
|
# Use backslashes at the end of a line to specify whitespace between lines.
|
2013-11-17 23:32:15 -05:00
|
|
|
eq 'a \
|
|
|
|
b\
|
|
|
|
c \
|
|
|
|
d', 'a bc d'
|
|
|
|
eq "a \
|
|
|
|
b\
|
|
|
|
c \
|
|
|
|
d", 'a bc d'
|
2013-11-18 19:04:17 -05:00
|
|
|
eq 'ignore \
|
|
|
|
trailing whitespace', 'ignore trailing whitespace'
|
2013-11-17 23:32:15 -05:00
|
|
|
|
2013-11-18 19:04:17 -05:00
|
|
|
# Backslash at the beginning of a literal string.
|
|
|
|
eq '\
|
|
|
|
ok', 'ok'
|
|
|
|
eq ' \
|
|
|
|
ok', ' ok'
|
2013-11-17 23:32:15 -05:00
|
|
|
|
2013-11-18 19:04:17 -05:00
|
|
|
# Same behavior in interpolated strings.
|
2013-11-17 23:32:15 -05:00
|
|
|
eq "interpolation #{1}
|
|
|
|
follows #{2} \
|
|
|
|
too #{3}\
|
|
|
|
!", 'interpolation 1 follows 2 too 3!'
|
2013-11-18 10:25:11 -05:00
|
|
|
eq "a #{
|
|
|
|
'string ' + "inside
|
|
|
|
interpolation"
|
|
|
|
}", "a string inside interpolation"
|
2013-11-18 19:04:17 -05:00
|
|
|
|
|
|
|
# Handle escaped backslashes correctly.
|
2013-11-24 13:37:11 -05:00
|
|
|
eq '\\', `'\\'`
|
2013-11-18 19:04:17 -05:00
|
|
|
eq 'escaped backslash at EOL\\
|
|
|
|
next line', 'escaped backslash at EOL\\ next line'
|
|
|
|
eq '\\
|
|
|
|
next line', '\\ next line'
|
|
|
|
eq "#{1}\\
|
|
|
|
after interpolation", '1\\ after interpolation'
|
|
|
|
eq 'escaped backslash before slash\\ \
|
|
|
|
next line', 'escaped backslash before slash\\ next line'
|
|
|
|
eq 'triple backslash\\\
|
|
|
|
next line', 'triple backslash\\next line'
|
2013-11-19 18:41:43 -05:00
|
|
|
eq 'several escaped backslashes\\\\\\
|
|
|
|
ok', 'several escaped backslashes\\\\\\ ok'
|
2013-11-24 13:37:11 -05:00
|
|
|
eq 'several escaped backslashes slash\\\\\\\
|
|
|
|
ok', 'several escaped backslashes slash\\\\\\ok'
|
|
|
|
eq 'several escaped backslashes with trailing ws \\\\\\
|
|
|
|
ok', 'several escaped backslashes with trailing ws \\\\\\ ok'
|
2013-11-18 19:04:17 -05:00
|
|
|
|
2013-11-19 18:41:43 -05:00
|
|
|
# Backslashes at beginning of lines.
|
2013-11-18 19:04:17 -05:00
|
|
|
eq 'first line
|
|
|
|
\ backslash at BOL', 'first line \ backslash at BOL'
|
|
|
|
eq 'first line\
|
|
|
|
\ backslash at BOL', 'first line\ backslash at BOL'
|
|
|
|
|
|
|
|
# Edge case.
|
|
|
|
eq 'lone
|
|
|
|
|
|
|
|
\
|
|
|
|
|
|
|
|
backslash', 'lone backslash'
|
|
|
|
|
2013-11-24 13:37:11 -05:00
|
|
|
test "#3249, escape newlines in heredocs with backslashes", ->
|
|
|
|
# Ignore escaped newlines
|
|
|
|
eq '''
|
|
|
|
Set whitespace \
|
|
|
|
<- this is ignored\
|
|
|
|
none
|
|
|
|
normal indentation
|
|
|
|
''', 'Set whitespace <- this is ignorednone\n normal indentation'
|
|
|
|
eq """
|
|
|
|
Set whitespace \
|
|
|
|
<- this is ignored\
|
|
|
|
none
|
|
|
|
normal indentation
|
|
|
|
""", 'Set whitespace <- this is ignorednone\n normal indentation'
|
|
|
|
|
|
|
|
# Changed from #647
|
|
|
|
eq '''
|
|
|
|
Hello, World\
|
|
|
|
|
|
|
|
''', 'Hello, World'
|
|
|
|
|
|
|
|
# Backslash at the beginning of a literal string.
|
|
|
|
eq '''\
|
|
|
|
ok''', 'ok'
|
|
|
|
eq ''' \
|
|
|
|
ok''', ' ok'
|
|
|
|
|
|
|
|
# Same behavior in interpolated strings.
|
|
|
|
eq """
|
|
|
|
interpolation #{1}
|
|
|
|
follows #{2} \
|
|
|
|
too #{3}\
|
|
|
|
!
|
|
|
|
""", 'interpolation 1\n follows 2 too 3!'
|
|
|
|
|
|
|
|
# TODO: uncomment when #2388 is fixed
|
|
|
|
# eq """a heredoc #{
|
|
|
|
# "inside \
|
|
|
|
# interpolation"
|
|
|
|
# }""", "a heredoc inside interpolation"
|
|
|
|
|
|
|
|
# Handle escaped backslashes correctly.
|
|
|
|
eq '''
|
|
|
|
escaped backslash at EOL\\
|
|
|
|
next line
|
|
|
|
''', 'escaped backslash at EOL\\\n next line'
|
|
|
|
|
|
|
|
# Backslashes at beginning of lines.
|
|
|
|
eq '''first line
|
|
|
|
\ backslash at BOL''', 'first line\n\ backslash at BOL'
|
|
|
|
eq """first line\
|
|
|
|
\ backslash at BOL""", 'first line\ backslash at BOL'
|
|
|
|
|
|
|
|
# Edge case.
|
|
|
|
eq '''lone
|
|
|
|
|
|
|
|
\
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backslash''', 'lone\n\n backslash'
|
2013-11-17 23:32:15 -05:00
|
|
|
|
2010-12-29 00:48:54 -05:00
|
|
|
#647
|
|
|
|
eq "''Hello, World\\''", '''
|
|
|
|
'\'Hello, World\\\''
|
|
|
|
'''
|
|
|
|
eq '""Hello, World\\""', """
|
|
|
|
"\"Hello, World\\\""
|
|
|
|
"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
basic heredoc
|
|
|
|
on two lines
|
|
|
|
"""
|
|
|
|
ok a is "basic heredoc\non two lines"
|
|
|
|
|
|
|
|
a = '''
|
|
|
|
a
|
|
|
|
"b
|
|
|
|
c
|
|
|
|
'''
|
|
|
|
ok a is "a\n \"b\nc"
|
|
|
|
|
|
|
|
a = """
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
"""
|
|
|
|
ok a is "a\n b\n c"
|
|
|
|
|
|
|
|
a = '''one-liner'''
|
|
|
|
ok a is 'one-liner'
|
|
|
|
|
|
|
|
a = """
|
|
|
|
out
|
|
|
|
here
|
|
|
|
"""
|
|
|
|
ok a is "out\nhere"
|
|
|
|
|
|
|
|
a = '''
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
'''
|
|
|
|
ok a is " a\n b\nc"
|
|
|
|
|
|
|
|
a = '''
|
|
|
|
a
|
|
|
|
|
|
|
|
|
|
|
|
b c
|
|
|
|
'''
|
|
|
|
ok a is "a\n\n\nb c"
|
|
|
|
|
|
|
|
a = '''more"than"one"quote'''
|
|
|
|
ok a is 'more"than"one"quote'
|
|
|
|
|
|
|
|
a = '''here's an apostrophe'''
|
|
|
|
ok a is "here's an apostrophe"
|
|
|
|
|
|
|
|
# The indentation detector ignores blank lines without trailing whitespace
|
|
|
|
a = """
|
|
|
|
one
|
|
|
|
two
|
|
|
|
|
|
|
|
"""
|
|
|
|
ok a is "one\ntwo\n"
|
|
|
|
|
|
|
|
eq ''' line 0
|
|
|
|
should not be relevant
|
|
|
|
to the indent level
|
2013-11-18 11:26:48 -05:00
|
|
|
''', ' line 0\nshould not be relevant\n to the indent level'
|
2010-12-29 00:48:54 -05:00
|
|
|
|
|
|
|
eq ''' '\\\' ''', " '\\' "
|
|
|
|
eq """ "\\\" """, ' "\\" '
|
|
|
|
|
|
|
|
eq ''' <- keep these spaces -> ''', ' <- keep these spaces -> '
|
2011-01-15 10:57:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
test "#1046, empty string interpolations", ->
|
|
|
|
eq "#{ }", ''
|