|  | 
| 1 | 1 | import { assert, expect, test } from 'vitest'; | 
| 2 |  | -import { exec, parse_route_id, resolve_entry } from './routing.js'; | 
|  | 2 | +import { exec, parse_route_id } from './routing.js'; | 
| 3 | 3 | 
 | 
| 4 | 4 | const tests = { | 
| 5 | 5 | 	'/': { | 
| @@ -221,55 +221,3 @@ test('parse_route_id errors on bad param name', () => { | 
| 221 | 221 | 	assert.throws(() => parse_route_id('abc/[b-c]'), /Invalid param: b-c/); | 
| 222 | 222 | 	assert.throws(() => parse_route_id('abc/[bc=d-e]'), /Invalid param: bc=d-e/); | 
| 223 | 223 | }); | 
| 224 |  | - | 
| 225 |  | -const from_entry_tests = [ | 
| 226 |  | -	{ | 
| 227 |  | -		route: '/blog/[one]/[two]', | 
| 228 |  | -		entry: { one: 'one', two: 'two' }, | 
| 229 |  | -		expected: '/blog/one/two' | 
| 230 |  | -	}, | 
| 231 |  | -	{ | 
| 232 |  | -		route: '/blog/[one=matcher]/[...two]', | 
| 233 |  | -		entry: { one: 'one', two: 'two/three' }, | 
| 234 |  | -		expected: '/blog/one/two/three' | 
| 235 |  | -	}, | 
| 236 |  | -	{ | 
| 237 |  | -		route: '/blog/[one=matcher]/[[two]]', | 
| 238 |  | -		entry: { one: 'one' }, | 
| 239 |  | -		expected: '/blog/one' | 
| 240 |  | -	}, | 
| 241 |  | -	{ | 
| 242 |  | -		route: '/blog/[one]/[two]-and-[three]', | 
| 243 |  | -		entry: { one: 'one', two: '2', three: '3' }, | 
| 244 |  | -		expected: '/blog/one/2-and-3' | 
| 245 |  | -	}, | 
| 246 |  | -	{ | 
| 247 |  | -		route: '/blog/[one]/[...two]-not-three', | 
| 248 |  | -		entry: { one: 'one', two: 'two/2' }, | 
| 249 |  | -		expected: '/blog/one/two/2-not-three' | 
| 250 |  | -	} | 
| 251 |  | -]; | 
| 252 |  | - | 
| 253 |  | -for (const { route, entry, expected } of from_entry_tests) { | 
| 254 |  | -	test(`resolve_entry generates correct path for ${route}`, () => { | 
| 255 |  | -		const result = resolve_entry(route, entry); | 
| 256 |  | -		assert.equal(result, expected); | 
| 257 |  | -	}); | 
| 258 |  | -} | 
| 259 |  | - | 
| 260 |  | -test('resolve_entry errors on missing entry for required param', () => { | 
| 261 |  | -	expect(() => resolve_entry('/blog/[one]/[two]', { one: 'one' })).toThrow( | 
| 262 |  | -		"Missing parameter 'two' in route /blog/[one]/[two]" | 
| 263 |  | -	); | 
| 264 |  | -}); | 
| 265 |  | - | 
| 266 |  | -test('resolve_entry errors on entry values starting or ending with slashes', () => { | 
| 267 |  | -	assert.throws( | 
| 268 |  | -		() => resolve_entry('/blog/[one]/[two]', { one: 'one', two: '/two' }), | 
| 269 |  | -		"Parameter 'two' in route /blog/[one]/[two] cannot start or end with a slash -- this would cause an invalid route like foo//bar" | 
| 270 |  | -	); | 
| 271 |  | -	assert.throws( | 
| 272 |  | -		() => resolve_entry('/blog/[one]/[two]', { one: 'one', two: 'two/' }), | 
| 273 |  | -		"Parameter 'two' in route /blog/[one]/[two] cannot start or end with a slash -- this would cause an invalid route like foo//bar" | 
| 274 |  | -	); | 
| 275 |  | -}); | 
0 commit comments