diff options
| author | cainus <[email protected]> | 2013-03-27 23:48:04 -0700 |
|---|---|---|
| committer | cainus <[email protected]> | 2013-03-27 23:48:04 -0700 |
| commit | 112119e43cb048cfa0dbd98d6e03833b8ca4b619 (patch) | |
| tree | 1bdb90068b87229dfa04a7a217e907d856ed0981 /fixtures | |
| parent | 86f733351d4e920a44e9682f105034628f6b0b4d (diff) | |
| download | node-coveralls-112119e43cb048cfa0dbd98d6e03833b8ca4b619.tar.xz node-coveralls-112119e43cb048cfa0dbd98d6e03833b8ca4b619.zip | |
changed to use lcov input format only.
Diffstat (limited to 'fixtures')
| -rw-r--r-- | fixtures/lib/index.js | 224 | ||||
| -rw-r--r-- | fixtures/onefile.lcov | 116 |
2 files changed, 340 insertions, 0 deletions
diff --git a/fixtures/lib/index.js b/fixtures/lib/index.js new file mode 100644 index 0000000..4a22c7a --- /dev/null +++ b/fixtures/lib/index.js @@ -0,0 +1,224 @@ +var nodeUrl = require('url'); +var querystring = require('querystring'); +var _ = require('underscore'); + +var UrlGrey = function(url){ + this.url = url; + this._parsed = null; +}; + +UrlGrey.prototype.parsed = function(){ + if (!this._parsed){ + this._parsed = nodeUrl.parse(this.url); + var p = this._parsed; + if (p.protocol){ + p.protocol = p.protocol.slice(0,-1); + } else { + p.protocol = 'http'; + } + if (p.hash){ + p.hash = p.hash.substring(1); + } + p.username = ''; + p.password = ''; + if (!p.hostname){ + p.hostname = 'localhost'; + } + if (!p.port){ + p.port = 80; + } else { + p.port = parseInt(p.port, 10); + } + if (p.auth){ + var auth = p.auth.split(':'); + p.username = auth[0]; + p.password = auth[1]; + } + } + return this._parsed; +}; + +UrlGrey.prototype.query = function(mergeObject){ + var path; + if (mergeObject === false){ + // clear the query entirely if the input === false + return this.queryString(''); + } + + var url = this.url; + if (!mergeObject){ + var parsed = nodeUrl.parse(url); + if (!!parsed.search){ + var qstr = parsed.search.substring(1); + return querystring.parse(qstr); + } + return {}; + } else { + // read the object out + var oldQuery = querystring.parse(this.queryString()); + _.each(mergeObject, function(v, k){ + if (v === null){ + delete oldQuery[k]; + } else { + oldQuery[k] = v; + } + }); + var newString = querystring.stringify(oldQuery, '&', '='); + return this.queryString(newString); + } +}; + + +addPropertyGetterSetter('protocol'); +addPropertyGetterSetter('port'); +addPropertyGetterSetter('username'); +addPropertyGetterSetter('password'); +addPropertyGetterSetter('hostname'); +addPropertyGetterSetter('hash'); +// add a method called queryString that manipulates 'query' +addPropertyGetterSetter('query', 'queryString'); +addPropertyGetterSetter('pathname', 'path'); + +UrlGrey.prototype.path = function(){ + var args = _.toArray(arguments); + if (args.length !== 0){ + var obj = new UrlGrey(this.toString()); + var str = _.flatten(args).join('/'); + str = str.replace(/\/+/g, '/'); // remove double slashes + str = str.replace(/\/$/, ''); // remove all trailing slashes + if (str[0] !== '/'){ str = '/' + str; } + obj.parsed().pathname = str; + return obj; + } + return this.parsed().pathname; +}; + + +UrlGrey.prototype.encode = function(str){ + return querystring.escape(str); +}; + +UrlGrey.prototype.decode = function(str){ + return querystring.unescape(str); +}; + +UrlGrey.prototype.parent = function(){ + // read-only. (can't SET parent) + var pieces = this.path().split("/"); + var popped = pieces.pop(); + if (popped === ''){ // ignore trailing slash + pieces.pop(); + } + return this.path(pieces.join("/")); +}; + +UrlGrey.prototype.child = function(suffix){ + if (suffix){ + suffix = encodeURIComponent(suffix); + return this.path(this.path(), suffix); + } else { + // if no suffix, return the child + var pieces = this.path().split("/"); + var last = _.last(pieces); + if ((pieces.length > 1) && (last === '')){ + // ignore trailing slashes + pieces.pop(); + last = _.last(pieces); + } + return last; + } +}; + +UrlGrey.prototype.toJSON = function(){ + return this.toString(); +}; + +UrlGrey.prototype.toString = function(){ + var p = this.parsed(); + var userinfo = p.username + ':' + p.password; + var retval = this.protocol() + '://'; + if (userinfo != ':'){ + retval += userinfo + '@'; + } + retval += p.hostname; + if (this.port() !== 80){ + retval += ':' + this.port(); + } + retval += this.path() === '/' ? '' : this.path(); + var qs = this.queryString(); + if (qs){ + retval += '?' + qs; + } + if (p.hash){ + retval += '#' + p.hash; + } + return retval; +}; + +/* +UrlGrey.prototype.absolute = function(path){ + if (path[0] == '/'){ + path = path.substring(1); + } + var parsed = nodeUrl.parse(path); + if (!!parsed.protocol){ // if it's already absolute, just return it + return path; + } + return this._protocol + "://" + this._host + '/' + path; +}; + +// TODO make this interpolate vars into the url. both sinatra style and url-tempates +// TODO name this: +UrlGrey.prototype.get = function(nameOrPath, varDict){ + if (!!nameOrPath){ + if (!!varDict){ + return this.absolute(this._router.getUrl(nameOrPath, varDict)); + } + return this.absolute(this._router.getUrl(nameOrPath)); + } + return this.url; +};*/ + +/* +// TODO needs to take a template as an input +UrlGrey.prototype.param = function(key, defaultValue){ + var value = this.params()[key]; + if (!!value) { + return value; + } + return defaultValue; +}; + +// TODO extract params, given a template? +// TODO needs to take a template as an input +UrlGrey.prototype.params = function(inUrl){ + if (!!inUrl){ + return this._router.pathVariables(inUrl); + } + if (!!this._params){ + return this._params; + } + return this._router.pathVariables(this.url); +}; +*/ + +// TODO relative() // takes an absolutepath and returns a relative one +// TODO absolute() // takes a relative path and returns an absolute one. + + + +module.exports = function(url){ return new UrlGrey(url); }; + +function addPropertyGetterSetter(propertyName, methodName){ + if (!methodName){ + methodName = propertyName; + } + UrlGrey.prototype[methodName] = function(str){ + if (!!str || str === ''){ + var obj = new UrlGrey(this.toString()); + obj.parsed()[propertyName] = str; + return obj; + } + return this.parsed()[propertyName]; + }; +} diff --git a/fixtures/onefile.lcov b/fixtures/onefile.lcov new file mode 100644 index 0000000..bc24682 --- /dev/null +++ b/fixtures/onefile.lcov @@ -0,0 +1,116 @@ +make[1]: Entering directory `/home/cainus/urlgrey' +SF:index.js +DA:1,1 +DA:2,1 +DA:3,1 +DA:5,1 +DA:6,66 +DA:7,66 +DA:10,1 +DA:11,323 +DA:12,63 +DA:13,63 +DA:14,63 +DA:15,60 +DA:17,3 +DA:19,63 +DA:20,32 +DA:22,63 +DA:23,63 +DA:24,63 +DA:25,3 +DA:27,63 +DA:28,60 +DA:30,3 +DA:32,63 +DA:33,27 +DA:34,27 +DA:35,27 +DA:38,323 +DA:41,1 +DA:42,5 +DA:43,5 +DA:45,2 +DA:48,3 +DA:49,3 +DA:50,1 +DA:51,1 +DA:52,1 +DA:53,1 +DA:55,0 +DA:58,2 +DA:59,2 +DA:60,2 +DA:61,0 +DA:63,2 +DA:66,2 +DA:67,2 +DA:72,1 +DA:73,1 +DA:74,1 +DA:75,1 +DA:76,1 +DA:77,1 +DA:79,1 +DA:80,1 +DA:82,1 +DA:83,87 +DA:84,87 +DA:85,6 +DA:86,6 +DA:87,6 +DA:88,6 +DA:89,9 +DA:90,6 +DA:91,6 +DA:93,81 +DA:97,1 +DA:98,1 +DA:101,1 +DA:102,1 +DA:105,1 +DA:107,2 +DA:108,2 +DA:109,2 +DA:110,1 +DA:112,2 +DA:115,1 +DA:116,3 +DA:117,1 +DA:118,1 +DA:121,2 +DA:122,2 +DA:123,2 +DA:125,1 +DA:126,1 +DA:128,2 +DA:132,1 +DA:133,1 +DA:136,1 +DA:137,50 +DA:138,50 +DA:139,50 +DA:140,50 +DA:141,20 +DA:143,50 +DA:144,50 +DA:145,2 +DA:147,50 +DA:148,50 +DA:149,50 +DA:150,31 +DA:152,50 +DA:153,24 +DA:155,50 +DA:210,40 +DA:212,1 +DA:213,8 +DA:214,6 +DA:216,8 +DA:217,186 +DA:218,21 +DA:219,21 +DA:220,21 +DA:222,165 +end_of_record +make[1]: Leaving directory `/home/cainus/urlgrey' |
