From 24482d08ce16ecf8ff8bdb16bea0669526baccd8 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Thu, 1 Dec 2016 11:23:46 -0600 Subject: [PATCH] url: add inspect function to TupleOrigin This adds a simple inspect function the the TupleOrigin class. This adds tests for the newly added inspect function in the TupleOrigin class. PR-URL: https://github.com/nodejs/node/pull/10039 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock --- lib/internal/url.js | 9 +++++ .../test-util-inspect-tuple-origin.js | 37 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/parallel/test-util-inspect-tuple-origin.js diff --git a/lib/internal/url.js b/lib/internal/url.js index e97fb3931607f2..ba54aa8c233354 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -74,6 +74,15 @@ class TupleOrigin { result += `:${this.port}`; return result; } + + inspect() { + return `TupleOrigin { + scheme: ${this.scheme}, + host: ${this.host}, + port: ${this.port}, + domain: ${this.domain} + }`; + } } class URL { diff --git a/test/parallel/test-util-inspect-tuple-origin.js b/test/parallel/test-util-inspect-tuple-origin.js new file mode 100644 index 00000000000000..7529273756afe9 --- /dev/null +++ b/test/parallel/test-util-inspect-tuple-origin.js @@ -0,0 +1,37 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const inspect = require('util').inspect; +const URL = require('url').URL; + +assert.strictEqual( + inspect(URL.originFor('http://test.com:8000')), + `TupleOrigin { + scheme: http, + host: test.com, + port: 8000, + domain: null + }` + ); + +assert.strictEqual( + inspect(URL.originFor('http://test.com')), + `TupleOrigin { + scheme: http, + host: test.com, + port: undefined, + domain: null + }` + ); + + +assert.strictEqual( + inspect(URL.originFor('https://test.com')), + `TupleOrigin { + scheme: https, + host: test.com, + port: undefined, + domain: null + }` + );