mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-13 01:16:52 -04:00
feat(new-tool): ipv4 address converter
This commit is contained in:
parent
8930e139b2
commit
28145e0ffe
5 changed files with 152 additions and 1 deletions
|
@ -0,0 +1,36 @@
|
|||
import { expect, describe, it } from 'vitest';
|
||||
import { isValidIpv4, ipv4ToInt } from './ipv4-address-converter.service';
|
||||
|
||||
describe('ipv4-address-converter', () => {
|
||||
describe('ipv4ToInt', () => {
|
||||
it('should convert an IPv4 address to an integer', () => {
|
||||
expect(ipv4ToInt({ ip: '192.168.0.1' })).toBe(3232235521);
|
||||
expect(ipv4ToInt({ ip: '10.0.0.1' })).toBe(167772161);
|
||||
expect(ipv4ToInt({ ip: '255.255.255.255' })).toBe(4294967295);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isValidIpv4', () => {
|
||||
it('should return true for a valid IP address', () => {
|
||||
expect(isValidIpv4({ ip: '192.168.0.1' })).to.equal(true);
|
||||
expect(isValidIpv4({ ip: '10.0.0.1' })).to.equal(true);
|
||||
});
|
||||
|
||||
it('should return false for an invalid IP address', () => {
|
||||
expect(isValidIpv4({ ip: '256.168.0.1' })).to.equal(false);
|
||||
expect(isValidIpv4({ ip: '192.168.0' })).to.equal(false);
|
||||
expect(isValidIpv4({ ip: '192.168.0.1.2' })).to.equal(false);
|
||||
expect(isValidIpv4({ ip: '192.168.0.1.' })).to.equal(false);
|
||||
expect(isValidIpv4({ ip: '.192.168.0.1' })).to.equal(false);
|
||||
expect(isValidIpv4({ ip: '192.168.0.a' })).to.equal(false);
|
||||
});
|
||||
|
||||
it('should return false for crap as input', () => {
|
||||
expect(isValidIpv4({ ip: '' })).to.equal(false);
|
||||
expect(isValidIpv4({ ip: ' ' })).to.equal(false);
|
||||
expect(isValidIpv4({ ip: 'foo' })).to.equal(false);
|
||||
expect(isValidIpv4({ ip: '-1' })).to.equal(false);
|
||||
expect(isValidIpv4({ ip: '0' })).to.equal(false);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue