react / wstein / node_modules / browserify / node_modules / insert-module-globals / node_modules / combine-source-map / node_modules / source-map / test / source-map / test-util.js
80559 views/* -*- Mode: js; js-indent-level: 2; -*- */1/*2* Copyright 2014 Mozilla Foundation and contributors3* Licensed under the New BSD license. See LICENSE or:4* http://opensource.org/licenses/BSD-3-Clause5*/6if (typeof define !== 'function') {7var define = require('amdefine')(module, require);8}9define(function (require, exports, module) {1011var libUtil = require('../../lib/source-map/util');1213exports['test urls'] = function (assert, util) {14var assertUrl = function (url) {15assert.equal(url, libUtil.urlGenerate(libUtil.urlParse(url)));16};17assertUrl('http://');18assertUrl('http://www.example.com');19assertUrl('http://user:[email protected]');20assertUrl('http://www.example.com:80');21assertUrl('http://www.example.com/');22assertUrl('http://www.example.com/foo/bar');23assertUrl('http://www.example.com/foo/bar/');24assertUrl('http://user:[email protected]:80/foo/bar/');2526assertUrl('//');27assertUrl('//www.example.com');28assertUrl('file:///www.example.com');2930assert.equal(libUtil.urlParse(''), null);31assert.equal(libUtil.urlParse('.'), null);32assert.equal(libUtil.urlParse('..'), null);33assert.equal(libUtil.urlParse('a'), null);34assert.equal(libUtil.urlParse('a/b'), null);35assert.equal(libUtil.urlParse('a//b'), null);36assert.equal(libUtil.urlParse('/a'), null);37assert.equal(libUtil.urlParse('data:foo,bar'), null);38};3940exports['test normalize()'] = function (assert, util) {41assert.equal(libUtil.normalize('/..'), '/');42assert.equal(libUtil.normalize('/../'), '/');43assert.equal(libUtil.normalize('/../../../..'), '/');44assert.equal(libUtil.normalize('/../../../../a/b/c'), '/a/b/c');45assert.equal(libUtil.normalize('/a/b/c/../../../d/../../e'), '/e');4647assert.equal(libUtil.normalize('..'), '..');48assert.equal(libUtil.normalize('../'), '../');49assert.equal(libUtil.normalize('../../a/'), '../../a/');50assert.equal(libUtil.normalize('a/..'), '.');51assert.equal(libUtil.normalize('a/../../..'), '../..');5253assert.equal(libUtil.normalize('/.'), '/');54assert.equal(libUtil.normalize('/./'), '/');55assert.equal(libUtil.normalize('/./././.'), '/');56assert.equal(libUtil.normalize('/././././a/b/c'), '/a/b/c');57assert.equal(libUtil.normalize('/a/b/c/./././d/././e'), '/a/b/c/d/e');5859assert.equal(libUtil.normalize(''), '.');60assert.equal(libUtil.normalize('.'), '.');61assert.equal(libUtil.normalize('./'), '.');62assert.equal(libUtil.normalize('././a'), 'a');63assert.equal(libUtil.normalize('a/./'), 'a/');64assert.equal(libUtil.normalize('a/././.'), 'a');6566assert.equal(libUtil.normalize('/a/b//c////d/////'), '/a/b/c/d/');67assert.equal(libUtil.normalize('///a/b//c////d/////'), '///a/b/c/d/');68assert.equal(libUtil.normalize('a/b//c////d'), 'a/b/c/d');6970assert.equal(libUtil.normalize('.///.././../a/b//./..'), '../../a')7172assert.equal(libUtil.normalize('http://www.example.com'), 'http://www.example.com');73assert.equal(libUtil.normalize('http://www.example.com/'), 'http://www.example.com/');74assert.equal(libUtil.normalize('http://www.example.com/./..//a/b/c/.././d//'), 'http://www.example.com/a/b/d/');75};7677exports['test join()'] = function (assert, util) {78assert.equal(libUtil.join('a', 'b'), 'a/b');79assert.equal(libUtil.join('a/', 'b'), 'a/b');80assert.equal(libUtil.join('a//', 'b'), 'a/b');81assert.equal(libUtil.join('a', 'b/'), 'a/b/');82assert.equal(libUtil.join('a', 'b//'), 'a/b/');83assert.equal(libUtil.join('a/', '/b'), '/b');84assert.equal(libUtil.join('a//', '//b'), '//b');8586assert.equal(libUtil.join('a', '..'), '.');87assert.equal(libUtil.join('a', '../b'), 'b');88assert.equal(libUtil.join('a/b', '../c'), 'a/c');8990assert.equal(libUtil.join('a', '.'), 'a');91assert.equal(libUtil.join('a', './b'), 'a/b');92assert.equal(libUtil.join('a/b', './c'), 'a/b/c');9394assert.equal(libUtil.join('a', 'http://www.example.com'), 'http://www.example.com');95assert.equal(libUtil.join('a', 'data:foo,bar'), 'data:foo,bar');969798assert.equal(libUtil.join('', 'b'), 'b');99assert.equal(libUtil.join('.', 'b'), 'b');100assert.equal(libUtil.join('', 'b/'), 'b/');101assert.equal(libUtil.join('.', 'b/'), 'b/');102assert.equal(libUtil.join('', 'b//'), 'b/');103assert.equal(libUtil.join('.', 'b//'), 'b/');104105assert.equal(libUtil.join('', '..'), '..');106assert.equal(libUtil.join('.', '..'), '..');107assert.equal(libUtil.join('', '../b'), '../b');108assert.equal(libUtil.join('.', '../b'), '../b');109110assert.equal(libUtil.join('', '.'), '.');111assert.equal(libUtil.join('.', '.'), '.');112assert.equal(libUtil.join('', './b'), 'b');113assert.equal(libUtil.join('.', './b'), 'b');114115assert.equal(libUtil.join('', 'http://www.example.com'), 'http://www.example.com');116assert.equal(libUtil.join('.', 'http://www.example.com'), 'http://www.example.com');117assert.equal(libUtil.join('', 'data:foo,bar'), 'data:foo,bar');118assert.equal(libUtil.join('.', 'data:foo,bar'), 'data:foo,bar');119120121assert.equal(libUtil.join('..', 'b'), '../b');122assert.equal(libUtil.join('..', 'b/'), '../b/');123assert.equal(libUtil.join('..', 'b//'), '../b/');124125assert.equal(libUtil.join('..', '..'), '../..');126assert.equal(libUtil.join('..', '../b'), '../../b');127128assert.equal(libUtil.join('..', '.'), '..');129assert.equal(libUtil.join('..', './b'), '../b');130131assert.equal(libUtil.join('..', 'http://www.example.com'), 'http://www.example.com');132assert.equal(libUtil.join('..', 'data:foo,bar'), 'data:foo,bar');133134135assert.equal(libUtil.join('a', ''), 'a');136assert.equal(libUtil.join('a', '.'), 'a');137assert.equal(libUtil.join('a/', ''), 'a');138assert.equal(libUtil.join('a/', '.'), 'a');139assert.equal(libUtil.join('a//', ''), 'a');140assert.equal(libUtil.join('a//', '.'), 'a');141assert.equal(libUtil.join('/a', ''), '/a');142assert.equal(libUtil.join('/a', '.'), '/a');143assert.equal(libUtil.join('', ''), '.');144assert.equal(libUtil.join('.', ''), '.');145assert.equal(libUtil.join('.', ''), '.');146assert.equal(libUtil.join('.', '.'), '.');147assert.equal(libUtil.join('..', ''), '..');148assert.equal(libUtil.join('..', '.'), '..');149assert.equal(libUtil.join('http://foo.org/a', ''), 'http://foo.org/a');150assert.equal(libUtil.join('http://foo.org/a', '.'), 'http://foo.org/a');151assert.equal(libUtil.join('http://foo.org/a/', ''), 'http://foo.org/a');152assert.equal(libUtil.join('http://foo.org/a/', '.'), 'http://foo.org/a');153assert.equal(libUtil.join('http://foo.org/a//', ''), 'http://foo.org/a');154assert.equal(libUtil.join('http://foo.org/a//', '.'), 'http://foo.org/a');155assert.equal(libUtil.join('http://foo.org', ''), 'http://foo.org/');156assert.equal(libUtil.join('http://foo.org', '.'), 'http://foo.org/');157assert.equal(libUtil.join('http://foo.org/', ''), 'http://foo.org/');158assert.equal(libUtil.join('http://foo.org/', '.'), 'http://foo.org/');159assert.equal(libUtil.join('http://foo.org//', ''), 'http://foo.org/');160assert.equal(libUtil.join('http://foo.org//', '.'), 'http://foo.org/');161assert.equal(libUtil.join('//www.example.com', ''), '//www.example.com/');162assert.equal(libUtil.join('//www.example.com', '.'), '//www.example.com/');163164165assert.equal(libUtil.join('http://foo.org/a', 'b'), 'http://foo.org/a/b');166assert.equal(libUtil.join('http://foo.org/a/', 'b'), 'http://foo.org/a/b');167assert.equal(libUtil.join('http://foo.org/a//', 'b'), 'http://foo.org/a/b');168assert.equal(libUtil.join('http://foo.org/a', 'b/'), 'http://foo.org/a/b/');169assert.equal(libUtil.join('http://foo.org/a', 'b//'), 'http://foo.org/a/b/');170assert.equal(libUtil.join('http://foo.org/a/', '/b'), 'http://foo.org/b');171assert.equal(libUtil.join('http://foo.org/a//', '//b'), 'http://b');172173assert.equal(libUtil.join('http://foo.org/a', '..'), 'http://foo.org/');174assert.equal(libUtil.join('http://foo.org/a', '../b'), 'http://foo.org/b');175assert.equal(libUtil.join('http://foo.org/a/b', '../c'), 'http://foo.org/a/c');176177assert.equal(libUtil.join('http://foo.org/a', '.'), 'http://foo.org/a');178assert.equal(libUtil.join('http://foo.org/a', './b'), 'http://foo.org/a/b');179assert.equal(libUtil.join('http://foo.org/a/b', './c'), 'http://foo.org/a/b/c');180181assert.equal(libUtil.join('http://foo.org/a', 'http://www.example.com'), 'http://www.example.com');182assert.equal(libUtil.join('http://foo.org/a', 'data:foo,bar'), 'data:foo,bar');183184185assert.equal(libUtil.join('http://foo.org', 'a'), 'http://foo.org/a');186assert.equal(libUtil.join('http://foo.org/', 'a'), 'http://foo.org/a');187assert.equal(libUtil.join('http://foo.org//', 'a'), 'http://foo.org/a');188assert.equal(libUtil.join('http://foo.org', '/a'), 'http://foo.org/a');189assert.equal(libUtil.join('http://foo.org/', '/a'), 'http://foo.org/a');190assert.equal(libUtil.join('http://foo.org//', '/a'), 'http://foo.org/a');191192193assert.equal(libUtil.join('http://', 'www.example.com'), 'http://www.example.com');194assert.equal(libUtil.join('file:///', 'www.example.com'), 'file:///www.example.com');195assert.equal(libUtil.join('http://', 'ftp://example.com'), 'ftp://example.com');196197assert.equal(libUtil.join('http://www.example.com', '//foo.org/bar'), 'http://foo.org/bar');198assert.equal(libUtil.join('//www.example.com', '//foo.org/bar'), '//foo.org/bar');199};200201// TODO Issue #128: Define and test this function properly.202exports['test relative()'] = function (assert, util) {203assert.equal(libUtil.relative('/the/root', '/the/root/one.js'), 'one.js');204assert.equal(libUtil.relative('/the/root', '/the/rootone.js'), '/the/rootone.js');205206assert.equal(libUtil.relative('', '/the/root/one.js'), '/the/root/one.js');207assert.equal(libUtil.relative('.', '/the/root/one.js'), '/the/root/one.js');208assert.equal(libUtil.relative('', 'the/root/one.js'), 'the/root/one.js');209assert.equal(libUtil.relative('.', 'the/root/one.js'), 'the/root/one.js');210211assert.equal(libUtil.relative('/', '/the/root/one.js'), 'the/root/one.js');212assert.equal(libUtil.relative('/', 'the/root/one.js'), 'the/root/one.js');213};214215});216217218