Repository: cordova-lib Updated Branches: refs/heads/master cbb04ac8c -> 996556a10
CB-8067 externalized valid-identifier it is it's own module Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/996556a1 Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/996556a1 Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/996556a1 Branch: refs/heads/master Commit: 996556a109c3463c8994dcc4c5cdd640a3c5cadc Parents: cbb04ac Author: Jesse MacFadyen <[email protected]> Authored: Wed Nov 26 14:37:40 2014 -0800 Committer: Jesse MacFadyen <[email protected]> Committed: Wed Nov 26 14:37:40 2014 -0800 ---------------------------------------------------------------------- cordova-lib/package.json | 3 +- cordova-lib/spec-cordova/create.spec.js | 19 +++++ .../spec-cordova/valid-identifiers-spec.js | 76 -------------------- cordova-lib/src/cordova/create.js | 2 +- cordova-lib/src/util/valid-identifier.js | 47 ------------ 5 files changed, 22 insertions(+), 125 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/996556a1/cordova-lib/package.json ---------------------------------------------------------------------- diff --git a/cordova-lib/package.json b/cordova-lib/package.json index 7ac3bc8..32ff1b8 100644 --- a/cordova-lib/package.json +++ b/cordova-lib/package.json @@ -37,7 +37,8 @@ "xcode": "0.6.7", "cordova-js": "3.7.2", "d8": "0.4.4", - "unorm": "1.3.3" + "unorm": "1.3.3", + "valid-identifier": "0.0.1" }, "devDependencies": { "jshint": "2.5.8", http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/996556a1/cordova-lib/spec-cordova/create.spec.js ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-cordova/create.spec.js b/cordova-lib/spec-cordova/create.spec.js index a7e5c08..5e58494 100644 --- a/cordova-lib/spec-cordova/create.spec.js +++ b/cordova-lib/spec-cordova/create.spec.js @@ -65,6 +65,25 @@ var configSymlink = { } }; +describe('cordova create checks for valid-identifier', function(done) { + + it('should reject reserved words from start of id', function(done) { + cordova.raw.create("projectPath", "int.bob", "appName") + .fail(function(err) { + expect(err.message).toBe("App id contains a reserved word, or is not a valid identifier."); + }) + .fin(done); + }); + + it('should reject reserved words from end of id', function(done) { + cordova.raw.create("projectPath", "bob.class", "appName") + .fail(function(err) { + expect(err.message).toBe("App id contains a reserved word, or is not a valid identifier."); + }) + .fin(done); + }); +}); + describe('create end-to-end', function() { http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/996556a1/cordova-lib/spec-cordova/valid-identifiers-spec.js ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-cordova/valid-identifiers-spec.js b/cordova-lib/spec-cordova/valid-identifiers-spec.js deleted file mode 100644 index 3c8dd2f..0000000 --- a/cordova-lib/spec-cordova/valid-identifiers-spec.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var Q = require('q'), - validateIdentifier = require('../src/util/valid-identifier'), - cordova = require('../src/cordova/cordova'); - -describe('valid-identifier',function(done){ - - it('should allow valid identifiers', function(done) { - expect(validateIdentifier("LeadingCap")).toBe(true); - expect(validateIdentifier("camelCase")).toBe(true); - expect(validateIdentifier("ALLCAPS")).toBe(true); - expect(validateIdentifier("x")).toBe(true); - expect(validateIdentifier("_underscore")).toBe(true); - expect(validateIdentifier("$dollarSign")).toBe(true); - expect(validateIdentifier("_8bit")).toBe(true); - expect(validateIdentifier("LeadingCap.camelCase.ALLCAPS._underscore.$dollarSign")).toBe(true); - done(); - }); - - it('should not allow invalid identifiers', function(done) { - expect(validateIdentifier("3numberstart")).toBe(false); - expect(validateIdentifier("has space")).toBe(false); - expect(validateIdentifier("x + y")).toBe(false); - expect(validateIdentifier("O'Mega")).toBe(false); - expect(validateIdentifier("amp&ersand")).toBe(false); - done(); - }); - - it('should not allow reserved words', function(done) { - expect(validateIdentifier("foreach")).toBe(false); - expect(validateIdentifier("valid.foreach")).toBe(false); - expect(validateIdentifier("win.in.g")).toBe(false); - expect(validateIdentifier("ends.with.")).toBe(false); - expect(validateIdentifier(".starts.with")).toBe(false); - expect(validateIdentifier("double..dot")).toBe(false); - done(); - }); - -}); - -describe('cordova create checks valid-identifier', function(done) { - - it('should reject reserved words from start of id', function(done) { - cordova.raw.create("projectPath", "int.bob", "appName") - .fail(function(err) { - expect(err.message).toBe("App id contains a reserved word, or is not a valid identifier."); - }) - .fin(done); - }); - - it('should reject reserved words from end of id', function(done) { - cordova.raw.create("projectPath", "bob.class", "appName") - .fail(function(err) { - expect(err.message).toBe("App id contains a reserved word, or is not a valid identifier."); - }) - .fin(done); - }); -}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/996556a1/cordova-lib/src/cordova/create.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/cordova/create.js b/cordova-lib/src/cordova/create.js index e6f9135..262cc2f 100644 --- a/cordova-lib/src/cordova/create.js +++ b/cordova-lib/src/cordova/create.js @@ -31,7 +31,7 @@ var path = require('path'), CordovaError = require('../CordovaError'), ConfigParser = require('../configparser/ConfigParser'), cordova_util = require('./util'), - validateIdentifier = require('../util/valid-identifier'); + validateIdentifier = require('valid-identifier'); var DEFAULT_NAME = 'HelloCordova', DEFAULT_ID = 'io.cordova.hellocordova'; http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/996556a1/cordova-lib/src/util/valid-identifier.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/util/valid-identifier.js b/cordova-lib/src/util/valid-identifier.js deleted file mode 100644 index 1b5b0bc..0000000 --- a/cordova-lib/src/util/valid-identifier.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var reserved = [ - "abstract","as","base","bool ","break","byte","case","catch","char", - "checked","class","const","continue","decimal","default","delegate", - "do","double","else","enum","event","explicit","extern","false","finally", - "fixed","float","for","foreach","goto","if","implicit","in","int", - "interface","internal","is","lock","long","namespace","new","null", - "object","operator","out","override","params","private","protected", - "public","readonly","ref","return","sbyte","sealed","short","sizeof", - "stackalloc","static","string","struct","switch","this","throw","true", - "try","typeof","uint","ulong","unchecked","unsafe","ushort","using", - "virtual","void","volatile","while","assert","package","synchronized", - "boolean","implements","import"]; - -var regX = /([a-zA-Z_$][a-zA-Z\d_$]*\.)*[a-zA-Z_$][a-zA-Z\d_$]*/; - -module.exports = function (nsPackage) { - var match = nsPackage.match(regX); - var isValid = match ? match[0] == nsPackage : false; - if(isValid) { - nsPackage.split(".").every(function(val){ - if(reserved.indexOf(val) > -1) { - isValid = false; - } - return isValid; - }); - } - return isValid; -}; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
