From b5b63fa9d1126de1bf6e5c5dbc9f2b0011a91298 Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Fri, 19 Jan 2024 09:58:43 +0100 Subject: [PATCH] test(parser): ensure identifier can be escaped --- tests/parser.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/parser.spec.ts b/tests/parser.spec.ts index 6f5cc88..953e15a 100644 --- a/tests/parser.spec.ts +++ b/tests/parser.spec.ts @@ -95,6 +95,25 @@ test.group('Env Parser', () => { }) }) + test('allows to escape the identifier', async ({ assert, cleanup, expectTypeOf }) => { + cleanup(() => { + EnvParser.removeIdentifier('file') + }) + + EnvParser.identifier('file', (_value: string) => { + return '3000' + }) + + const envString = ['ENV_USER=file\\:///root/app/user.js'].join('\n') + const parser = new EnvParser(envString) + const parsed = await parser.parse() + + expectTypeOf(parsed).toEqualTypeOf() + assert.deepEqual(parsed, { + ENV_USER: 'file:///root/app/user.js', + }) + }) + test('throw when identifier is already defined', async ({ assert, cleanup }) => { cleanup(() => { EnvParser.removeIdentifier('file')