Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2012, Mozilla Foundation and contributors |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | 'use strict'; |
michael@0 | 18 | // <INJECTED SOURCE:START> |
michael@0 | 19 | |
michael@0 | 20 | // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT |
michael@0 | 21 | // DO NOT EDIT IT DIRECTLY |
michael@0 | 22 | |
michael@0 | 23 | var exports = {}; |
michael@0 | 24 | |
michael@0 | 25 | var TEST_URI = "data:text/html;charset=utf-8,<p id='gcli-input'>gcli-testTokenize.js</p>"; |
michael@0 | 26 | |
michael@0 | 27 | function test() { |
michael@0 | 28 | return Task.spawn(function() { |
michael@0 | 29 | let options = yield helpers.openTab(TEST_URI); |
michael@0 | 30 | yield helpers.openToolbar(options); |
michael@0 | 31 | gcli.addItems(mockCommands.items); |
michael@0 | 32 | |
michael@0 | 33 | yield helpers.runTests(options, exports); |
michael@0 | 34 | |
michael@0 | 35 | gcli.removeItems(mockCommands.items); |
michael@0 | 36 | yield helpers.closeToolbar(options); |
michael@0 | 37 | yield helpers.closeTab(options); |
michael@0 | 38 | }).then(finish, helpers.handleError); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | // <INJECTED SOURCE:END> |
michael@0 | 42 | |
michael@0 | 43 | // var assert = require('../testharness/assert'); |
michael@0 | 44 | var cli = require('gcli/cli'); |
michael@0 | 45 | |
michael@0 | 46 | exports.testBlanks = function(options) { |
michael@0 | 47 | var args; |
michael@0 | 48 | |
michael@0 | 49 | args = cli.tokenize(''); |
michael@0 | 50 | assert.is(args.length, 1); |
michael@0 | 51 | assert.is(args[0].text, ''); |
michael@0 | 52 | assert.is(args[0].prefix, ''); |
michael@0 | 53 | assert.is(args[0].suffix, ''); |
michael@0 | 54 | |
michael@0 | 55 | args = cli.tokenize(' '); |
michael@0 | 56 | assert.is(args.length, 1); |
michael@0 | 57 | assert.is(args[0].text, ''); |
michael@0 | 58 | assert.is(args[0].prefix, ' '); |
michael@0 | 59 | assert.is(args[0].suffix, ''); |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | exports.testTokSimple = function(options) { |
michael@0 | 63 | var args; |
michael@0 | 64 | |
michael@0 | 65 | args = cli.tokenize('s'); |
michael@0 | 66 | assert.is(args.length, 1); |
michael@0 | 67 | assert.is(args[0].text, 's'); |
michael@0 | 68 | assert.is(args[0].prefix, ''); |
michael@0 | 69 | assert.is(args[0].suffix, ''); |
michael@0 | 70 | assert.is(args[0].type, 'Argument'); |
michael@0 | 71 | |
michael@0 | 72 | args = cli.tokenize('s s'); |
michael@0 | 73 | assert.is(args.length, 2); |
michael@0 | 74 | assert.is(args[0].text, 's'); |
michael@0 | 75 | assert.is(args[0].prefix, ''); |
michael@0 | 76 | assert.is(args[0].suffix, ''); |
michael@0 | 77 | assert.is(args[0].type, 'Argument'); |
michael@0 | 78 | assert.is(args[1].text, 's'); |
michael@0 | 79 | assert.is(args[1].prefix, ' '); |
michael@0 | 80 | assert.is(args[1].suffix, ''); |
michael@0 | 81 | assert.is(args[1].type, 'Argument'); |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | exports.testJavascript = function(options) { |
michael@0 | 85 | var args; |
michael@0 | 86 | |
michael@0 | 87 | args = cli.tokenize('{x}'); |
michael@0 | 88 | assert.is(args.length, 1); |
michael@0 | 89 | assert.is(args[0].text, 'x'); |
michael@0 | 90 | assert.is(args[0].prefix, '{'); |
michael@0 | 91 | assert.is(args[0].suffix, '}'); |
michael@0 | 92 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 93 | |
michael@0 | 94 | args = cli.tokenize('{ x }'); |
michael@0 | 95 | assert.is(args.length, 1); |
michael@0 | 96 | assert.is(args[0].text, 'x'); |
michael@0 | 97 | assert.is(args[0].prefix, '{ '); |
michael@0 | 98 | assert.is(args[0].suffix, ' }'); |
michael@0 | 99 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 100 | |
michael@0 | 101 | args = cli.tokenize('{x} {y}'); |
michael@0 | 102 | assert.is(args.length, 2); |
michael@0 | 103 | assert.is(args[0].text, 'x'); |
michael@0 | 104 | assert.is(args[0].prefix, '{'); |
michael@0 | 105 | assert.is(args[0].suffix, '}'); |
michael@0 | 106 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 107 | assert.is(args[1].text, 'y'); |
michael@0 | 108 | assert.is(args[1].prefix, ' {'); |
michael@0 | 109 | assert.is(args[1].suffix, '}'); |
michael@0 | 110 | assert.is(args[1].type, 'ScriptArgument'); |
michael@0 | 111 | |
michael@0 | 112 | args = cli.tokenize('{x}{y}'); |
michael@0 | 113 | assert.is(args.length, 2); |
michael@0 | 114 | assert.is(args[0].text, 'x'); |
michael@0 | 115 | assert.is(args[0].prefix, '{'); |
michael@0 | 116 | assert.is(args[0].suffix, '}'); |
michael@0 | 117 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 118 | assert.is(args[1].text, 'y'); |
michael@0 | 119 | assert.is(args[1].prefix, '{'); |
michael@0 | 120 | assert.is(args[1].suffix, '}'); |
michael@0 | 121 | assert.is(args[1].type, 'ScriptArgument'); |
michael@0 | 122 | |
michael@0 | 123 | args = cli.tokenize('{'); |
michael@0 | 124 | assert.is(args.length, 1); |
michael@0 | 125 | assert.is(args[0].text, ''); |
michael@0 | 126 | assert.is(args[0].prefix, '{'); |
michael@0 | 127 | assert.is(args[0].suffix, ''); |
michael@0 | 128 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 129 | |
michael@0 | 130 | args = cli.tokenize('{ '); |
michael@0 | 131 | assert.is(args.length, 1); |
michael@0 | 132 | assert.is(args[0].text, ''); |
michael@0 | 133 | assert.is(args[0].prefix, '{ '); |
michael@0 | 134 | assert.is(args[0].suffix, ''); |
michael@0 | 135 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 136 | |
michael@0 | 137 | args = cli.tokenize('{x'); |
michael@0 | 138 | assert.is(args.length, 1); |
michael@0 | 139 | assert.is(args[0].text, 'x'); |
michael@0 | 140 | assert.is(args[0].prefix, '{'); |
michael@0 | 141 | assert.is(args[0].suffix, ''); |
michael@0 | 142 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 143 | }; |
michael@0 | 144 | |
michael@0 | 145 | exports.testRegularNesting = function(options) { |
michael@0 | 146 | var args; |
michael@0 | 147 | |
michael@0 | 148 | args = cli.tokenize('{"x"}'); |
michael@0 | 149 | assert.is(args.length, 1); |
michael@0 | 150 | assert.is(args[0].text, '"x"'); |
michael@0 | 151 | assert.is(args[0].prefix, '{'); |
michael@0 | 152 | assert.is(args[0].suffix, '}'); |
michael@0 | 153 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 154 | |
michael@0 | 155 | args = cli.tokenize('{\'x\'}'); |
michael@0 | 156 | assert.is(args.length, 1); |
michael@0 | 157 | assert.is(args[0].text, '\'x\''); |
michael@0 | 158 | assert.is(args[0].prefix, '{'); |
michael@0 | 159 | assert.is(args[0].suffix, '}'); |
michael@0 | 160 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 161 | |
michael@0 | 162 | args = cli.tokenize('"{x}"'); |
michael@0 | 163 | assert.is(args.length, 1); |
michael@0 | 164 | assert.is(args[0].text, '{x}'); |
michael@0 | 165 | assert.is(args[0].prefix, '"'); |
michael@0 | 166 | assert.is(args[0].suffix, '"'); |
michael@0 | 167 | assert.is(args[0].type, 'Argument'); |
michael@0 | 168 | |
michael@0 | 169 | args = cli.tokenize('\'{x}\''); |
michael@0 | 170 | assert.is(args.length, 1); |
michael@0 | 171 | assert.is(args[0].text, '{x}'); |
michael@0 | 172 | assert.is(args[0].prefix, '\''); |
michael@0 | 173 | assert.is(args[0].suffix, '\''); |
michael@0 | 174 | assert.is(args[0].type, 'Argument'); |
michael@0 | 175 | }; |
michael@0 | 176 | |
michael@0 | 177 | exports.testDeepNesting = function(options) { |
michael@0 | 178 | var args; |
michael@0 | 179 | |
michael@0 | 180 | args = cli.tokenize('{{}}'); |
michael@0 | 181 | assert.is(args.length, 1); |
michael@0 | 182 | assert.is(args[0].text, '{}'); |
michael@0 | 183 | assert.is(args[0].prefix, '{'); |
michael@0 | 184 | assert.is(args[0].suffix, '}'); |
michael@0 | 185 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 186 | |
michael@0 | 187 | args = cli.tokenize('{{x} {y}}'); |
michael@0 | 188 | assert.is(args.length, 1); |
michael@0 | 189 | assert.is(args[0].text, '{x} {y}'); |
michael@0 | 190 | assert.is(args[0].prefix, '{'); |
michael@0 | 191 | assert.is(args[0].suffix, '}'); |
michael@0 | 192 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 193 | |
michael@0 | 194 | args = cli.tokenize('{{w} {{{x}}}} {y} {{{z}}}'); |
michael@0 | 195 | |
michael@0 | 196 | assert.is(args.length, 3); |
michael@0 | 197 | |
michael@0 | 198 | assert.is(args[0].text, '{w} {{{x}}}'); |
michael@0 | 199 | assert.is(args[0].prefix, '{'); |
michael@0 | 200 | assert.is(args[0].suffix, '}'); |
michael@0 | 201 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 202 | |
michael@0 | 203 | assert.is(args[1].text, 'y'); |
michael@0 | 204 | assert.is(args[1].prefix, ' {'); |
michael@0 | 205 | assert.is(args[1].suffix, '}'); |
michael@0 | 206 | assert.is(args[1].type, 'ScriptArgument'); |
michael@0 | 207 | |
michael@0 | 208 | assert.is(args[2].text, '{{z}}'); |
michael@0 | 209 | assert.is(args[2].prefix, ' {'); |
michael@0 | 210 | assert.is(args[2].suffix, '}'); |
michael@0 | 211 | assert.is(args[2].type, 'ScriptArgument'); |
michael@0 | 212 | |
michael@0 | 213 | args = cli.tokenize('{{w} {{{x}}} {y} {{{z}}}'); |
michael@0 | 214 | |
michael@0 | 215 | assert.is(args.length, 1); |
michael@0 | 216 | |
michael@0 | 217 | assert.is(args[0].text, '{w} {{{x}}} {y} {{{z}}}'); |
michael@0 | 218 | assert.is(args[0].prefix, '{'); |
michael@0 | 219 | assert.is(args[0].suffix, ''); |
michael@0 | 220 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 221 | }; |
michael@0 | 222 | |
michael@0 | 223 | exports.testStrangeNesting = function(options) { |
michael@0 | 224 | var args; |
michael@0 | 225 | |
michael@0 | 226 | // Note: When we get real JS parsing this should break |
michael@0 | 227 | args = cli.tokenize('{"x}"}'); |
michael@0 | 228 | |
michael@0 | 229 | assert.is(args.length, 2); |
michael@0 | 230 | |
michael@0 | 231 | assert.is(args[0].text, '"x'); |
michael@0 | 232 | assert.is(args[0].prefix, '{'); |
michael@0 | 233 | assert.is(args[0].suffix, '}'); |
michael@0 | 234 | assert.is(args[0].type, 'ScriptArgument'); |
michael@0 | 235 | |
michael@0 | 236 | assert.is(args[1].text, '}'); |
michael@0 | 237 | assert.is(args[1].prefix, '"'); |
michael@0 | 238 | assert.is(args[1].suffix, ''); |
michael@0 | 239 | assert.is(args[1].type, 'Argument'); |
michael@0 | 240 | }; |
michael@0 | 241 | |
michael@0 | 242 | exports.testComplex = function(options) { |
michael@0 | 243 | var args; |
michael@0 | 244 | |
michael@0 | 245 | args = cli.tokenize(' 1234 \'12 34\''); |
michael@0 | 246 | |
michael@0 | 247 | assert.is(args.length, 2); |
michael@0 | 248 | |
michael@0 | 249 | assert.is(args[0].text, '1234'); |
michael@0 | 250 | assert.is(args[0].prefix, ' '); |
michael@0 | 251 | assert.is(args[0].suffix, ''); |
michael@0 | 252 | assert.is(args[0].type, 'Argument'); |
michael@0 | 253 | |
michael@0 | 254 | assert.is(args[1].text, '12 34'); |
michael@0 | 255 | assert.is(args[1].prefix, ' \''); |
michael@0 | 256 | assert.is(args[1].suffix, '\''); |
michael@0 | 257 | assert.is(args[1].type, 'Argument'); |
michael@0 | 258 | |
michael@0 | 259 | args = cli.tokenize('12\'34 "12 34" \\'); // 12'34 "12 34" \ |
michael@0 | 260 | |
michael@0 | 261 | assert.is(args.length, 3); |
michael@0 | 262 | |
michael@0 | 263 | assert.is(args[0].text, '12\'34'); |
michael@0 | 264 | assert.is(args[0].prefix, ''); |
michael@0 | 265 | assert.is(args[0].suffix, ''); |
michael@0 | 266 | assert.is(args[0].type, 'Argument'); |
michael@0 | 267 | |
michael@0 | 268 | assert.is(args[1].text, '12 34'); |
michael@0 | 269 | assert.is(args[1].prefix, ' "'); |
michael@0 | 270 | assert.is(args[1].suffix, '"'); |
michael@0 | 271 | assert.is(args[1].type, 'Argument'); |
michael@0 | 272 | |
michael@0 | 273 | assert.is(args[2].text, '\\'); |
michael@0 | 274 | assert.is(args[2].prefix, ' '); |
michael@0 | 275 | assert.is(args[2].suffix, ''); |
michael@0 | 276 | assert.is(args[2].type, 'Argument'); |
michael@0 | 277 | }; |
michael@0 | 278 | |
michael@0 | 279 | exports.testPathological = function(options) { |
michael@0 | 280 | var args; |
michael@0 | 281 | |
michael@0 | 282 | args = cli.tokenize('a\\ b \\t\\n\\r \\\'x\\\" \'d'); // a_b \t\n\r \'x\" 'd |
michael@0 | 283 | |
michael@0 | 284 | assert.is(args.length, 4); |
michael@0 | 285 | |
michael@0 | 286 | assert.is(args[0].text, 'a\\ b'); |
michael@0 | 287 | assert.is(args[0].prefix, ''); |
michael@0 | 288 | assert.is(args[0].suffix, ''); |
michael@0 | 289 | assert.is(args[0].type, 'Argument'); |
michael@0 | 290 | |
michael@0 | 291 | assert.is(args[1].text, '\\t\\n\\r'); |
michael@0 | 292 | assert.is(args[1].prefix, ' '); |
michael@0 | 293 | assert.is(args[1].suffix, ''); |
michael@0 | 294 | assert.is(args[1].type, 'Argument'); |
michael@0 | 295 | |
michael@0 | 296 | assert.is(args[2].text, '\\\'x\\"'); |
michael@0 | 297 | assert.is(args[2].prefix, ' '); |
michael@0 | 298 | assert.is(args[2].suffix, ''); |
michael@0 | 299 | assert.is(args[2].type, 'Argument'); |
michael@0 | 300 | |
michael@0 | 301 | assert.is(args[3].text, 'd'); |
michael@0 | 302 | assert.is(args[3].prefix, ' \''); |
michael@0 | 303 | assert.is(args[3].suffix, ''); |
michael@0 | 304 | assert.is(args[3].type, 'Argument'); |
michael@0 | 305 | }; |