addon-sdk/source/test/test-uuid.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/test-uuid.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,27 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +const { uuid } = require('sdk/util/uuid');
    1.11 +
    1.12 +exports['test generate uuid'] = function(assert) {
    1.13 +  let signature = /{[0-9a-f\-]+}/
    1.14 +  let first = String(uuid());
    1.15 +  let second = String(uuid());
    1.16 +
    1.17 +  assert.ok(signature.test(first), 'first guid has a correct signature');
    1.18 +  assert.ok(signature.test(second), 'second guid has a correct signature');
    1.19 +  assert.notEqual(first, second, 'guid generates new guid on each call');
    1.20 +};
    1.21 +
    1.22 +exports['test parse uuid'] = function(assert) {
    1.23 +  let firefoxUUID = '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}';
    1.24 +  let actual = uuid(firefoxUUID);
    1.25 +
    1.26 +  assert.equal(actual.number, firefoxUUID, 'uuid parsed given string');
    1.27 +  assert.equal(String(actual), firefoxUUID, 'serializes to the same value');
    1.28 +};
    1.29 +
    1.30 +require('test').run(exports);

mercurial