silverwolf-x's picture
download
raw
1.71 kB
import { PrefixPathnameNormalizer } from './prefix'
describe('PrefixPathnameNormalizer', () => {
describe('match', () => {
it('should return false if the pathname does not start with the prefix', () => {
const normalizer = new PrefixPathnameNormalizer('/foo')
const pathnames = ['/bar', '/bar/foo', '/fooo/bar']
for (const pathname of pathnames) {
expect(normalizer.match(pathname)).toBe(false)
}
})
it('should return true if the pathname starts with the prefix', () => {
const normalizer = new PrefixPathnameNormalizer('/foo')
const pathnames = ['/foo', '/foo/bar', '/foo/bar/baz']
for (const pathname of pathnames) {
expect(normalizer.match(pathname)).toBe(true)
}
})
})
it('should throw if the prefix ends with a slash', () => {
expect(() => new PrefixPathnameNormalizer('/foo/')).toThrow()
expect(() => new PrefixPathnameNormalizer('/')).toThrow()
})
describe('normalize', () => {
it('should return the same pathname if we are not matched and the pathname does not start with the prefix', () => {
const normalizer = new PrefixPathnameNormalizer('/foo')
let pathnames = ['/bar', '/bar/foo', '/fooo/bar']
for (const pathname of pathnames) {
expect(normalizer.normalize(pathname)).toBe(pathname)
}
})
it('should strip the prefix from the pathname when it matches', () => {
const normalizer = new PrefixPathnameNormalizer('/foo')
const pathnames = ['/foo', '/foo/bar', '/foo/bar/baz']
for (const pathname of pathnames) {
expect(normalizer.normalize(pathname)).toBe(
pathname.substring(4) || '/'
)
}
})
})
})

Xet Storage Details

Size:
1.71 kB
·
Xet hash:
57aa299114cd26f6b8d8ed97ecd264de26f060c7c8e27c4e8add2eff7d558279

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.