literal.json 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. [
  2. {
  3. "given": {
  4. "foo": [{"name": "a"}, {"name": "b"}],
  5. "bar": {"baz": "qux"}
  6. },
  7. "cases": [
  8. {
  9. "expression": "`\"foo\"`",
  10. "result": "foo"
  11. },
  12. {
  13. "comment": "Interpret escaped unicode.",
  14. "expression": "`\"\\u03a6\"`",
  15. "result": "Φ"
  16. },
  17. {
  18. "expression": "`\"✓\"`",
  19. "result": "✓"
  20. },
  21. {
  22. "expression": "`[1, 2, 3]`",
  23. "result": [1, 2, 3]
  24. },
  25. {
  26. "expression": "`{\"a\": \"b\"}`",
  27. "result": {"a": "b"}
  28. },
  29. {
  30. "expression": "`true`",
  31. "result": true
  32. },
  33. {
  34. "expression": "`false`",
  35. "result": false
  36. },
  37. {
  38. "expression": "`null`",
  39. "result": null
  40. },
  41. {
  42. "expression": "`0`",
  43. "result": 0
  44. },
  45. {
  46. "expression": "`1`",
  47. "result": 1
  48. },
  49. {
  50. "expression": "`2`",
  51. "result": 2
  52. },
  53. {
  54. "expression": "`3`",
  55. "result": 3
  56. },
  57. {
  58. "expression": "`4`",
  59. "result": 4
  60. },
  61. {
  62. "expression": "`5`",
  63. "result": 5
  64. },
  65. {
  66. "expression": "`6`",
  67. "result": 6
  68. },
  69. {
  70. "expression": "`7`",
  71. "result": 7
  72. },
  73. {
  74. "expression": "`8`",
  75. "result": 8
  76. },
  77. {
  78. "expression": "`9`",
  79. "result": 9
  80. },
  81. {
  82. "comment": "Escaping a backtick in quotes",
  83. "expression": "`\"foo\\`bar\"`",
  84. "result": "foo`bar"
  85. },
  86. {
  87. "comment": "Double quote in literal",
  88. "expression": "`\"foo\\\"bar\"`",
  89. "result": "foo\"bar"
  90. },
  91. {
  92. "expression": "`\"1\\`\"`",
  93. "result": "1`"
  94. },
  95. {
  96. "comment": "Multiple literal expressions with escapes",
  97. "expression": "`\"\\\\\"`.{a:`\"b\"`}",
  98. "result": {"a": "b"}
  99. },
  100. {
  101. "comment": "literal . identifier",
  102. "expression": "`{\"a\": \"b\"}`.a",
  103. "result": "b"
  104. },
  105. {
  106. "comment": "literal . identifier . identifier",
  107. "expression": "`{\"a\": {\"b\": \"c\"}}`.a.b",
  108. "result": "c"
  109. },
  110. {
  111. "comment": "literal . identifier bracket-expr",
  112. "expression": "`[0, 1, 2]`[1]",
  113. "result": 1
  114. }
  115. ]
  116. },
  117. {
  118. "comment": "Literals",
  119. "given": {"type": "object"},
  120. "cases": [
  121. {
  122. "comment": "Literal with leading whitespace",
  123. "expression": "` {\"foo\": true}`",
  124. "result": {"foo": true}
  125. },
  126. {
  127. "comment": "Literal with trailing whitespace",
  128. "expression": "`{\"foo\": true} `",
  129. "result": {"foo": true}
  130. },
  131. {
  132. "comment": "Literal on RHS of subexpr not allowed",
  133. "expression": "foo.`\"bar\"`",
  134. "error": "syntax"
  135. }
  136. ]
  137. },
  138. {
  139. "comment": "Raw String Literals",
  140. "given": {},
  141. "cases": [
  142. {
  143. "expression": "'foo'",
  144. "result": "foo"
  145. },
  146. {
  147. "expression": "' foo '",
  148. "result": " foo "
  149. },
  150. {
  151. "expression": "'0'",
  152. "result": "0"
  153. },
  154. {
  155. "expression": "'newline\n'",
  156. "result": "newline\n"
  157. },
  158. {
  159. "expression": "'\n'",
  160. "result": "\n"
  161. },
  162. {
  163. "expression": "'✓'",
  164. "result": "✓"
  165. },
  166. {
  167. "expression": "'𝄞'",
  168. "result": "𝄞"
  169. },
  170. {
  171. "expression": "' [foo] '",
  172. "result": " [foo] "
  173. },
  174. {
  175. "expression": "'[foo]'",
  176. "result": "[foo]"
  177. },
  178. {
  179. "comment": "Do not interpret escaped unicode.",
  180. "expression": "'\\u03a6'",
  181. "result": "\\u03a6"
  182. },
  183. {
  184. "comment": "Can escape the single quote",
  185. "expression": "'foo\\'bar'",
  186. "result": "foo'bar"
  187. },
  188. {
  189. "comment": "Backslash not followed by single quote is treated as any other character",
  190. "expression": "'\\z'",
  191. "result": "\\z"
  192. },
  193. {
  194. "comment": "Backslash not followed by single quote is treated as any other character",
  195. "expression": "'\\\\'",
  196. "result": "\\\\"
  197. }
  198. ]
  199. }
  200. ]