From e5780cd69ab8a81cad3b3a62d0230ae7c0c36923 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Thu, 20 May 2021 15:12:06 +0500 Subject: [PATCH] fix(parseMacro): updated to have macros with parameters + options --- src/utils/parseMacros.spec.ts | 70 +++++++++++++++++++++++++++++++++++ src/utils/parseMacros.ts | 1 + 2 files changed, 71 insertions(+) diff --git a/src/utils/parseMacros.spec.ts b/src/utils/parseMacros.spec.ts index 8a90525..ce33f37 100644 --- a/src/utils/parseMacros.spec.ts +++ b/src/utils/parseMacros.spec.ts @@ -25,6 +25,76 @@ describe('parseMacros', () => { }) }) + it('should return an array with a single macro having parameters', () => { + const text = `%macro test(var,sum); + %put 'hello'; +%mend` + + const macros = parseMacros(text, new LintConfig()) + + expect(macros.length).toEqual(1) + expect(macros).toContainEqual({ + name: 'test', + declarationLine: '%macro test(var,sum);', + terminationLine: '%mend', + declaration: '%macro test(var,sum)', + termination: '%mend', + startLineNumber: 1, + endLineNumber: 3, + parentMacro: '', + hasMacroNameInMend: false, + hasParentheses: false, + mismatchedMendMacroName: '' + }) + }) + + it('should return an array with a single macro having PARMBUFF option', () => { + const text = `%macro test/parmbuff; + %put 'hello'; +%mend` + + const macros = parseMacros(text, new LintConfig()) + + expect(macros.length).toEqual(1) + expect(macros).toContainEqual({ + name: 'test', + declarationLine: '%macro test/parmbuff;', + terminationLine: '%mend', + declaration: '%macro test/parmbuff', + termination: '%mend', + startLineNumber: 1, + endLineNumber: 3, + parentMacro: '', + hasMacroNameInMend: false, + hasParentheses: false, + mismatchedMendMacroName: '' + }) + }) + + it('should return an array with a single macro having paramerter & SOURCE option', () => { + const text = `/* commentary */ %macro foobar(arg) /store source + des="This macro does not do much"; + %put 'hello'; +%mend` + + const macros = parseMacros(text, new LintConfig()) + + expect(macros.length).toEqual(1) + expect(macros).toContainEqual({ + name: 'foobar', + declarationLine: '/* commentary */ %macro foobar(arg) /store source', + terminationLine: '%mend', + declaration: '%macro foobar(arg) /store source', + termination: '%mend', + startLineNumber: 1, + endLineNumber: 4, + parentMacro: '', + hasMacroNameInMend: false, + hasParentheses: false, + mismatchedMendMacroName: '' + }) + }) + it('should return an array with multiple macros', () => { const text = `%macro foo; %put 'foo'; diff --git a/src/utils/parseMacros.ts b/src/utils/parseMacros.ts index 6ee838a..656dc41 100644 --- a/src/utils/parseMacros.ts +++ b/src/utils/parseMacros.ts @@ -43,6 +43,7 @@ export const parseMacros = (text: string, config?: LintConfig): Macro[] => { const name = trimmedStatement .slice(7, trimmedStatement.length) .trim() + .split('/')[0] .split('(')[0] macroStack.push({ name,