| 1 |
from graphql.language.print_string import print_string |
| 2 |
|
| 3 |
|
| 4 |
def describe_print_string(): |
| 5 |
def prints_a_simple_string(): |
| 6 |
assert print_string("hello world") == '"hello world"' |
| 7 |
|
| 8 |
def escapes_quotes(): |
| 9 |
assert print_string('"hello world"') == '"\\"hello world\\""' |
| 10 |
|
| 11 |
def escapes_backslashes(): |
| 12 |
assert print_string("escape: \\") == '"escape: \\\\"' |
| 13 |
|
| 14 |
def escapes_well_known_control_chars(): |
| 15 |
assert print_string("\b\f\n\r\t") == '"\\b\\f\\n\\r\\t"' |
| 16 |
|
| 17 |
def escapes_zero_byte(): |
| 18 |
assert print_string("\x00") == '"\\u0000"' |
| 19 |
|
| 20 |
def does_not_escape_space(): |
| 21 |
assert print_string(" ") == '" "' |
| 22 |
|
| 23 |
def does_not_escape_non_ascii_character(): |
| 24 |
assert print_string("\u21bb") == '"\u21bb"' |
| 25 |
|
| 26 |
def does_not_escape_supplementary_character(): |
| 27 |
assert print_string("\U0001f600") == '"\U0001f600"' |
| 28 |
|
| 29 |
def escapes_all_control_chars(): |
| 30 |
assert print_string( |
| 31 |
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" |
| 32 |
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" |
| 33 |
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f" |
| 34 |
"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f" |
| 35 |
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f" |
| 36 |
"\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f" |
| 37 |
"\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f" |
| 38 |
"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f" |
| 39 |
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" |
| 40 |
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" |
| 41 |
) == ( |
| 42 |
'"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007' |
| 43 |
"\\b\\t\\n\\u000B\\f\\r\\u000E\\u000F" |
| 44 |
"\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017" |
| 45 |
"\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F" |
| 46 |
" !\\\"#$%&'()*+,-./0123456789:;<=>?" |
| 47 |
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_" |
| 48 |
"`abcdefghijklmnopqrstuvwxyz{|}~\\u007F" |
| 49 |
"\\u0080\\u0081\\u0082\\u0083\\u0084\\u0085\\u0086\\u0087" |
| 50 |
"\\u0088\\u0089\\u008A\\u008B\\u008C\\u008D\\u008E\\u008F" |
| 51 |
"\\u0090\\u0091\\u0092\\u0093\\u0094\\u0095\\u0096\\u0097" |
| 52 |
'\\u0098\\u0099\\u009A\\u009B\\u009C\\u009D\\u009E\\u009F"' |
| 53 |
) |