index_test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Licensed to the Software Freedom Conservancy (SFC) under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The SFC licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. 'use strict';
  18. var assert = require('assert');
  19. var net = require('../../net');
  20. describe('net.splitHostAndPort', function() {
  21. it('hostname with no port', function() {
  22. assert.deepEqual(
  23. net.splitHostAndPort('www.example.com'),
  24. {host: 'www.example.com', port: null});
  25. });
  26. it('hostname with port', function() {
  27. assert.deepEqual(
  28. net.splitHostAndPort('www.example.com:80'),
  29. {host: 'www.example.com', port: 80});
  30. });
  31. it('IPv4 with no port', function() {
  32. assert.deepEqual(
  33. net.splitHostAndPort('127.0.0.1'),
  34. {host: '127.0.0.1', port: null});
  35. });
  36. it('IPv4 with port', function() {
  37. assert.deepEqual(
  38. net.splitHostAndPort('127.0.0.1:1234'),
  39. {host: '127.0.0.1', port: 1234});
  40. });
  41. it('IPv6 with no port', function() {
  42. assert.deepEqual(
  43. net.splitHostAndPort('1234:0:1000:5768:1234:5678:90'),
  44. {host: '1234:0:1000:5768:1234:5678:90', port: null});
  45. });
  46. it('IPv6 with port', function() {
  47. assert.deepEqual(
  48. net.splitHostAndPort('[1234:0:1000:5768:1234:5678:90]:1234'),
  49. {host: '1234:0:1000:5768:1234:5678:90', port: 1234});
  50. });
  51. });