mirror of
https://github.com/sasjs/lint.git
synced 2026-01-05 03:30:06 +00:00
feat(*): add line endings rule, add automatic formatting for fixable violations
This commit is contained in:
95
src/utils/parseMacros.spec.ts
Normal file
95
src/utils/parseMacros.spec.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import { LintConfig } from '../types'
|
||||
import { parseMacros } from './parseMacros'
|
||||
|
||||
describe('parseMacros', () => {
|
||||
it('should return an array with a single macro', () => {
|
||||
const text = `%macro test;
|
||||
%put 'hello';
|
||||
%mend`
|
||||
|
||||
const macros = parseMacros(text, new LintConfig())
|
||||
|
||||
expect(macros.length).toEqual(1)
|
||||
expect(macros).toContainEqual({
|
||||
name: 'test',
|
||||
declaration: '%macro test;',
|
||||
termination: '%mend',
|
||||
startLineNumber: 1,
|
||||
endLineNumber: 3,
|
||||
parentMacro: '',
|
||||
hasMacroNameInMend: false,
|
||||
hasParentheses: false,
|
||||
mismatchedMendMacroName: ''
|
||||
})
|
||||
})
|
||||
|
||||
it('should return an array with multiple macros', () => {
|
||||
const text = `%macro foo;
|
||||
%put 'foo';
|
||||
%mend;
|
||||
%macro bar();
|
||||
%put 'bar';
|
||||
%mend bar;`
|
||||
|
||||
const macros = parseMacros(text, new LintConfig())
|
||||
|
||||
expect(macros.length).toEqual(2)
|
||||
expect(macros).toContainEqual({
|
||||
name: 'foo',
|
||||
declaration: '%macro foo;',
|
||||
termination: '%mend;',
|
||||
startLineNumber: 1,
|
||||
endLineNumber: 3,
|
||||
parentMacro: '',
|
||||
hasMacroNameInMend: false,
|
||||
hasParentheses: false,
|
||||
mismatchedMendMacroName: ''
|
||||
})
|
||||
expect(macros).toContainEqual({
|
||||
name: 'bar',
|
||||
declaration: '%macro bar();',
|
||||
termination: '%mend bar;',
|
||||
startLineNumber: 4,
|
||||
endLineNumber: 6,
|
||||
parentMacro: '',
|
||||
hasMacroNameInMend: true,
|
||||
hasParentheses: true,
|
||||
mismatchedMendMacroName: ''
|
||||
})
|
||||
})
|
||||
|
||||
it('should detect nested macro definitions', () => {
|
||||
const text = `%macro test()
|
||||
%put 'hello';
|
||||
%macro test2
|
||||
%put 'world;
|
||||
%mend
|
||||
%mend test`
|
||||
|
||||
const macros = parseMacros(text, new LintConfig())
|
||||
|
||||
expect(macros.length).toEqual(2)
|
||||
expect(macros).toContainEqual({
|
||||
name: 'test',
|
||||
declaration: '%macro test()',
|
||||
termination: '%mend test',
|
||||
startLineNumber: 1,
|
||||
endLineNumber: 6,
|
||||
parentMacro: '',
|
||||
hasMacroNameInMend: true,
|
||||
hasParentheses: true,
|
||||
mismatchedMendMacroName: ''
|
||||
})
|
||||
expect(macros).toContainEqual({
|
||||
name: 'test2',
|
||||
declaration: ' %macro test2',
|
||||
termination: ' %mend',
|
||||
startLineNumber: 3,
|
||||
endLineNumber: 5,
|
||||
parentMacro: 'test',
|
||||
hasMacroNameInMend: false,
|
||||
hasParentheses: false,
|
||||
mismatchedMendMacroName: ''
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user