Skip to content

Instantly share code, notes, and snippets.

@zbraniecki
Created March 28, 2017 10:15
Show Gist options
  • Save zbraniecki/5a2060a6d91d7085fa12e990c6e9d62e to your computer and use it in GitHub Desktop.
Save zbraniecki/5a2060a6d91d7085fa12e990c6e9d62e to your computer and use it in GitHub Desktop.
Preprocessor for fluent tests
//--//
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