shell.test.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. 'use strict';
  6. import { testTokenization } from '../test/testRunner';
  7. testTokenization('shell', [
  8. // Keywords
  9. [{
  10. line: 'if while',
  11. tokens: [
  12. { startIndex: 0, type: 'keyword.shell' },
  13. { startIndex: 2, type: 'white.shell' },
  14. { startIndex: 3, type: 'keyword.shell' }
  15. ]
  16. }],
  17. // Predefined & attribute
  18. [{
  19. line: 'ps -aux | grep code',
  20. tokens: [
  21. { startIndex: 0, type: 'type.identifier.shell' },
  22. { startIndex: 2, type: 'white.shell' },
  23. { startIndex: 3, type: 'attribute.name.shell' },
  24. { startIndex: 7, type: 'white.shell' },
  25. { startIndex: 8, type: 'delimiter.shell' },
  26. { startIndex: 9, type: 'white.shell' },
  27. { startIndex: 10, type: 'type.identifier.shell' },
  28. { startIndex: 14, type: 'white.shell' },
  29. { startIndex: 15, type: '' },
  30. ]
  31. }],
  32. [{
  33. line: '# comment',
  34. tokens: [
  35. { startIndex: 0, type: 'comment.shell' }
  36. ]
  37. }, {
  38. line: 'cd tree',
  39. tokens: [
  40. { startIndex: 0, type: 'type.identifier.shell' },
  41. { startIndex: 2, type: 'white.shell' },
  42. { startIndex: 3, type: '' }
  43. ]
  44. }],
  45. // Shebang
  46. [{
  47. line: '#!/bin/env bash',
  48. tokens: [
  49. { startIndex: 0, type: 'metatag.shell' }
  50. ]
  51. }],
  52. // Comments
  53. [{
  54. line: '#',
  55. tokens: [
  56. { startIndex: 0, type: 'comment.shell' }
  57. ]
  58. }],
  59. [{
  60. line: '# a comment',
  61. tokens: [
  62. { startIndex: 0, type: 'comment.shell' }
  63. ]
  64. }],
  65. [{
  66. line: ' # a comment',
  67. tokens: [
  68. { startIndex: 0, type: 'white.shell' },
  69. { startIndex: 4, type: 'comment.shell' }
  70. ]
  71. }],
  72. // numbers
  73. [{
  74. line: '0',
  75. tokens: [
  76. { startIndex: 0, type: 'number.shell' }
  77. ]
  78. }],
  79. [{
  80. line: '0.0',
  81. tokens: [
  82. { startIndex: 0, type: 'number.float.shell' }
  83. ]
  84. }],
  85. [{
  86. line: '0x123',
  87. tokens: [
  88. { startIndex: 0, type: 'number.hex.shell' }
  89. ]
  90. }],
  91. [{
  92. line: '23.5',
  93. tokens: [
  94. { startIndex: 0, type: 'number.float.shell' }
  95. ]
  96. }],
  97. [{
  98. line: '23.5e3',
  99. tokens: [
  100. { startIndex: 0, type: 'number.float.shell' }
  101. ]
  102. }],
  103. [{
  104. line: '23.5E3',
  105. tokens: [
  106. { startIndex: 0, type: 'number.float.shell' }
  107. ]
  108. }],
  109. [{
  110. line: '1.72e-3',
  111. tokens: [
  112. { startIndex: 0, type: 'number.float.shell' }
  113. ]
  114. }],
  115. [{
  116. line: '0+0',
  117. tokens: [
  118. { startIndex: 0, type: 'number.shell' },
  119. { startIndex: 1, type: 'delimiter.shell' },
  120. { startIndex: 2, type: 'number.shell' }
  121. ]
  122. }],
  123. [{
  124. line: '100+10',
  125. tokens: [
  126. { startIndex: 0, type: 'number.shell' },
  127. { startIndex: 3, type: 'delimiter.shell' },
  128. { startIndex: 4, type: 'number.shell' }
  129. ]
  130. }],
  131. [{
  132. line: '0 + 0',
  133. tokens: [
  134. { startIndex: 0, type: 'number.shell' },
  135. { startIndex: 1, type: 'white.shell' },
  136. { startIndex: 2, type: 'delimiter.shell' },
  137. { startIndex: 3, type: 'white.shell' },
  138. { startIndex: 4, type: 'number.shell' }
  139. ]
  140. }],
  141. // Strings
  142. [{
  143. line: "'test string'",
  144. tokens: [
  145. { startIndex: 0, type: 'string.shell' }
  146. ]
  147. }],
  148. [{
  149. line: '"test string"',
  150. tokens: [
  151. { startIndex: 0, type: 'string.shell' }
  152. ]
  153. }],
  154. [{
  155. line: "'test",
  156. tokens: [
  157. { startIndex: 0, type: 'string.shell' }
  158. ],
  159. }, {
  160. line: '',
  161. tokens: [
  162. ]
  163. }, {
  164. line: "string'",
  165. tokens: [
  166. { startIndex: 0, type: 'string.shell' }
  167. ]
  168. }],
  169. [{
  170. line: '"test',
  171. tokens: [
  172. { startIndex: 0, type: 'string.shell' }
  173. ],
  174. }, {
  175. line: '',
  176. tokens: [
  177. ]
  178. }, {
  179. line: 'string"',
  180. tokens: [
  181. { startIndex: 0, type: 'string.shell' }
  182. ]
  183. }],
  184. // Parameters
  185. [{
  186. line: '$1',
  187. tokens: [
  188. { startIndex: 0, type: 'variable.predefined.shell' }
  189. ]
  190. }],
  191. [{
  192. line: '$a',
  193. tokens: [
  194. { startIndex: 0, type: 'variable.shell' }
  195. ]
  196. }],
  197. [{
  198. line: '${string:position}',
  199. tokens: [
  200. { startIndex: 0, type: 'variable.shell' },
  201. { startIndex: 8, type: 'delimiter.shell' },
  202. { startIndex: 9, type: 'variable.shell' }
  203. ]
  204. }],
  205. [{
  206. line: '$(pwd)',
  207. tokens: [
  208. { startIndex: 0, type: 'variable.shell' },
  209. ]
  210. }],
  211. [{
  212. line: 'echo $hello | less',
  213. tokens: [
  214. { startIndex: 0, type: 'type.identifier.shell' },
  215. { startIndex: 4, type: 'white.shell' },
  216. { startIndex: 5, type: 'variable.shell' },
  217. { startIndex: 11, type: 'white.shell' },
  218. { startIndex: 12, type: 'delimiter.shell' },
  219. { startIndex: 13, type: 'white.shell' },
  220. { startIndex: 14, type: '' }
  221. ]
  222. }],
  223. // HereDoc
  224. [{
  225. line: '<< word',
  226. tokens: [
  227. { startIndex: 0, type: 'constants.shell' },
  228. { startIndex: 2, type: 'white.shell' },
  229. { startIndex: 3, type: 'string.heredoc.shell' }
  230. ]
  231. }],
  232. [{
  233. line: '<<- "word"',
  234. tokens: [
  235. { startIndex: 0, type: 'constants.shell' },
  236. { startIndex: 3, type: 'white.shell' },
  237. { startIndex: 4, type: 'string.heredoc.delimiter.shell' },
  238. { startIndex: 5, type: 'string.heredoc.shell' },
  239. { startIndex: 9, type: 'string.heredoc.delimiter.shell' },
  240. ]
  241. }],
  242. [{
  243. line: '<<< word',
  244. tokens: [
  245. { startIndex: 0, type: 'constants.shell' },
  246. { startIndex: 3, type: 'white.shell' },
  247. { startIndex: 4, type: 'string.heredoc.shell' }
  248. ]
  249. }],
  250. ])