test-uuid.js 968 B

123456789101112131415161718192021222324252627
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const { uuid } = require('sdk/util/uuid');
  6. exports['test generate uuid'] = function(assert) {
  7. let signature = /{[0-9a-f\-]+}/
  8. let first = String(uuid());
  9. let second = String(uuid());
  10. assert.ok(signature.test(first), 'first guid has a correct signature');
  11. assert.ok(signature.test(second), 'second guid has a correct signature');
  12. assert.notEqual(first, second, 'guid generates new guid on each call');
  13. };
  14. exports['test parse uuid'] = function(assert) {
  15. let firefoxUUID = '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}';
  16. let actual = uuid(firefoxUUID);
  17. assert.equal(actual.number, firefoxUUID, 'uuid parsed given string');
  18. assert.equal(String(actual), firefoxUUID, 'serializes to the same value');
  19. };
  20. require('test').run(exports);