Path: blob/trunk/javascript/selenium-webdriver/test/net/index_test.js
2885 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617'use strict'1819const assert = require('node:assert')20const net = require('selenium-webdriver/net')2122describe('net.splitHostAndPort', function () {23it('hostname with no port', function () {24assert.deepStrictEqual(net.splitHostAndPort('www.example.com'), {25host: 'www.example.com',26port: null,27})28})2930it('hostname with port', function () {31assert.deepStrictEqual(net.splitHostAndPort('www.example.com:80'), {32host: 'www.example.com',33port: 80,34})35})3637it('IPv4 with no port', function () {38assert.deepStrictEqual(net.splitHostAndPort('127.0.0.1'), {39host: '127.0.0.1',40port: null,41})42})4344it('IPv4 with port', function () {45assert.deepStrictEqual(net.splitHostAndPort('127.0.0.1:1234'), {46host: '127.0.0.1',47port: 1234,48})49})5051it('IPv6 with no port', function () {52assert.deepStrictEqual(net.splitHostAndPort('1234:0:1000:5768:1234:5678:90'), {53host: '1234:0:1000:5768:1234:5678:90',54port: null,55})56})5758it('IPv6 with port', function () {59assert.deepStrictEqual(net.splitHostAndPort('[1234:0:1000:5768:1234:5678:90]:1234'), {60host: '1234:0:1000:5768:1234:5678:90',61port: 1234,62})63})64})656667