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