Created
March 28, 2017 10:15
-
-
Save zbraniecki/5a2060a6d91d7085fa12e990c6e9d62e to your computer and use it in GitHub Desktop.
Preprocessor for fluent tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//--// | |
const ppStart = '^\/\/--\/\/ '; | |
const ppLineRE = new RegExp(`${ppStart}(.*)[\n$]`, 'gm'); | |
function parseDirective(dir) { | |
const result = { | |
pos: null, | |
code: null | |
}; | |
const fields = dir.split(',').map(field => field.trim()); | |
fields.forEach(field => { | |
let [key, value] = field.split(':').map(tok => tok.trim()); | |
result[key] = value; | |
}); | |
return result; | |
} | |
function preprocess(source) { | |
let match; | |
while ((match = ppLineRE.exec(source)) !== null) { | |
console.log(parseDirective(match[1])); | |
} | |
return source.replace(ppLineRE, ''); | |
} | |
let tests = [ | |
[ | |
` | |
key = Value | |
//--// pos: 23, code: E0234 | |
//--// pos: 32, code: E213 | |
key2 = Value 2 | |
` | |
] | |
]; | |
console.log(preprocess(tests[0][0])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment