prettier/tests/quotes/strings.js

70 lines
1.1 KiB
JavaScript
Raw Normal View History

// Every string will be changed to double quotes, unless we end up with fewer
// escaped quotes by using single quotes. (Vice versa if the "singleQuote"
// option is true).
//
// Note that even if a string already has the correct enclosing quotes, it is
// still processed in order to remove unnecessarily escaped quotes within it,
// for consistency.
// Simple strings.
2017-01-13 09:30:35 +03:00
"abc"
'abc'
// Escape.
'\0'
// Emoji.
'🐶'
2017-01-13 09:30:35 +03:00
// Empty string.
""
''
// Single double quote.
"\""
2017-01-13 09:30:35 +03:00
'"'
// Single single quote.
2017-01-13 09:30:35 +03:00
"'"
'\''
// Unnecessary escapes.
2017-01-13 09:30:35 +03:00
"\'"
'\"'
// One of each.
"\"'"
'"\''
// One of each with unnecessary escapes.
"\"\'"
'\"\''
// More double quotes than single quotes.
"\"'\""
'"\'"'
// More single quotes than double quotes.
"\"''"
'"\'\''
2017-01-13 09:30:35 +03:00
// Two of each.
"\"\"''"
'""\'\''
2017-01-13 09:30:35 +03:00
// Single backslash.
2017-01-13 09:30:35 +03:00
'\\'
"\\"
// Backslases.
"\"\\\"\\\\\" '\'\\'\\\'\\\\'"
'\'\\\'\\\\\' "\"\\"\\\"\\\\"'
// Somewhat more real-word example.
"He's sayin': \"How's it goin'?\" Don't ask me why."
'He\'s sayin\': "How\'s it goin\'?" Don\'t ask me why.'
// Somewhat more real-word example 2.
"var backslash = \"\\\", doubleQuote = '\"';"
'var backslash = "\\", doubleQuote = \'"\';'