fast-check
Version:
Property based testing framework for JavaScript (like QuickCheck)
27 lines (26 loc) • 1.29 kB
JavaScript
import { array } from './ArrayArbitrary.js';
import { buildAlphaNumericPercentArb, buildLowerAlphaArb, buildLowerAlphaNumericArb, } from './helpers/SpecificCharacterRange.js';
import { option } from './OptionArbitrary.js';
import { stringOf } from './StringArbitrary.js';
import { tuple } from './TupleArbitrary.js';
function subdomain() {
const alphaNumericArb = buildLowerAlphaNumericArb([]);
const alphaNumericHyphenArb = buildLowerAlphaNumericArb(['-']);
return tuple(alphaNumericArb, option(tuple(stringOf(alphaNumericHyphenArb), alphaNumericArb)))
.map(([f, d]) => (d === null ? f : `${f}${d[0]}${d[1]}`))
.filter((d) => d.length <= 63)
.filter((d) => {
return d.length < 4 || d[0] !== 'x' || d[1] !== 'n' || d[2] !== '-' || d[3] !== '-';
});
}
export function domain() {
const alphaNumericArb = buildLowerAlphaArb([]);
const extensionArb = stringOf(alphaNumericArb, 2, 10);
return tuple(array(subdomain(), 1, 5), extensionArb)
.map(([mid, ext]) => `${mid.join('.')}.${ext}`)
.filter((d) => d.length <= 255);
}
export function hostUserInfo() {
const others = ['-', '.', '_', '~', '!', '$', '&', "'", '(', ')', '*', '+', ',', ';', '=', ':'];
return stringOf(buildAlphaNumericPercentArb(others));
}