Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 76 additions & 25 deletions packages/regex/src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
absoluteLinuxPath,
alpha,
alphaLower,
alphanum,
alphanumLowercase,
alphanumSpacesDotsUnderscoreDash,
Expand All @@ -15,6 +16,7 @@ import {
alphanumdots,
ascii,
backupKey,
basicDomain,
cron,
digits,
email,
Expand All @@ -33,6 +35,9 @@ const asciiLetters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
const asciiLowercase = 'abcdefghijklmnopqrstuvwxyz'
const asciiUppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
const backupKeyTest = '123456789ABCEDFGHIJIKLMNOPQRSTUV'
const domain = 'another-example.com'
const subDomain = 'sub.another-example.com'
const longTldDomain = 'sub.another-example.verylongtld'
const cronTest = '0/15*-'
const digitsTest = '0123456789'
const emailTest = 'test@scaleway.com'
Expand Down Expand Up @@ -77,11 +82,32 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alpha.test(string)).toBe(expected)
})
})

describe('alphaLower', () => {
test.each([
[alphanumdashText, false],
[alphanumdashdotsText, false],
[asciiLetters, false],
[asciiLowercase, true],
[asciiUppercase, false],
[digitsTest, false],
[emailTest, false],
[octdigits, false],
[hexdigits, false],
[printable, false],
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s', (string, expected) => {
expect(alphaLower.test(string)).toBe(expected)
})
})

describe('alphanum', () => {
test.each([
[alphanumdashText, false],
Expand All @@ -98,7 +124,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanum.test(string)).toBe(expected)
})
})
Expand All @@ -119,7 +145,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanumdash.test(string)).toBe(expected)
})
})
Expand All @@ -140,7 +166,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanumdashdots.test(string)).toBe(expected)
})
})
Expand All @@ -161,7 +187,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanumdashdotsorempty.test(string)).toBe(expected)
})
})
Expand All @@ -182,7 +208,7 @@ describe('@regex', () => {
[whitespace, true],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanumdashdotsspaces.test(string)).toBe(expected)
})
})
Expand All @@ -203,7 +229,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanumdashorempty.test(string)).toBe(expected)
})
})
Expand All @@ -224,7 +250,7 @@ describe('@regex', () => {
[whitespace, true],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanumdashspaces.test(string)).toBe(expected)
})
})
Expand All @@ -245,7 +271,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanumdots.test(string)).toBe(expected)
})
})
Expand All @@ -264,7 +290,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanumLowercase.test(string)).toBe(expected)
})
})
Expand All @@ -283,7 +309,7 @@ describe('@regex', () => {
[whitespace, true],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanumSpacesDotsUnderscoreDash.test(string)).toBe(expected)
})
})
Expand All @@ -302,7 +328,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanumUnderscoreDash.test(string)).toBe(expected)
})
})
Expand All @@ -321,7 +347,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(alphanumUnderscoreDollarDash.test(string)).toBe(expected)
})
})
Expand Down Expand Up @@ -352,7 +378,7 @@ describe('@regex', () => {
[punctuation, true],
[whitespace, true],
[cronTest, true],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(ascii.test(string)).toBe(expected)
})
})
Expand All @@ -372,10 +398,35 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(backupKey.test(string)).toBe(expected)
})
})
describe('basicDomain', () => {
test.each([
[asciiLetters, false],
[asciiLowercase, false],
[asciiUppercase, false],
[backupKeyTest, false],
[domain, true],
[subDomain, true],
[longTldDomain, true],
[digitsTest, false],
[emailTest, false],
[octdigits, false],
[hexdigits, false],
[printable, false],
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
[url1, false],
[url2, false],
])('should match regex %s to be %s', (string, expected) => {
expect(basicDomain.test(string)).toBe(expected)
})
})


describe('cron', () => {
test.each([
Expand All @@ -390,7 +441,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, true],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(cron.test(string)).toBe(expected)
})
})
Expand All @@ -409,7 +460,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(digits.test(string)).toBe(expected)
})
})
Expand All @@ -428,7 +479,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(email.test(string)).toBe(expected)
})
})
Expand All @@ -448,7 +499,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(fourDigitsCode.test(string)).toBe(expected)
})
})
Expand All @@ -468,7 +519,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, true],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(macAddress.test(string)).toBe(expected)
})
})
Expand All @@ -489,7 +540,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(phone.test(string)).toBe(expected)
})
})
Expand All @@ -510,7 +561,7 @@ describe('@regex', () => {
[whitespace, true],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(spaces.test(string)).toBe(expected)
})
})
Expand All @@ -532,7 +583,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(sixDigitsCode.test(string)).toBe(expected)
})
})
Expand All @@ -556,7 +607,7 @@ describe('@regex', () => {
[macAddress1, false],
[url1, true],
[url2, true],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(url.test(string)).toBe(expected)
})
})
Expand All @@ -577,7 +628,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[hexdigits, true],
])('should match regex %s to be %s)', (string, expected) => {
])('should match regex %s to be %s', (string, expected) => {
expect(hexadecimal.test(string)).toBe(expected)
})
})
Expand Down
2 changes: 2 additions & 0 deletions packages/regex/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const alpha = /^[a-zA-Z]*$/
export const alphaLower = /^[a-z]+$/
export const alphanum = /^[a-zA-Z0-9]*$/
export const alphanumdash = /^[a-zA-Z0-9-]*$/
export const alphanumdashdots = /^[a-zA-Z0-9-.]*$/
Expand All @@ -16,6 +17,7 @@ export const absoluteLinuxPath = /(^\/$|^(\/[a-zA-Z0-9_]+)*$)/
// eslint-disable-next-line no-control-regex
export const ascii = /^[\x00-\x7F]+$/
export const backupKey = /^[A-Z0-9]{32}$/
export const basicDomain = /^[a-z0-9-]+(\.[a-z0-9-]{1,63})+$/
export const cron = /^[0-9,/*-]+$/
export const digits = /^[0-9]*$/
export const macAddress =
Expand Down