UNPKG

tap-parser

Version:

parse the test anything protocol

35 lines 1.11 kB
import { OPEN_BRACE_EOL } from './brace-patterns.js'; /** * Parse a "directive", the bit that follows the `#` character * on a TestPoint line. */ export const parseDirective = (line) => { if (!line.trim()) return false; line = line .replace(OPEN_BRACE_EOL, '') .trim() .replace(/^duration_ms ([0-9.]+)$/, 'time=$1ms'); const time = line.match(/^time=((?:[1-9][0-9]*|0)(?:\.[0-9]+)?)(ms|s)$/i); const t = time?.[1]; const s = time?.[2]; if (typeof t === 'string') { let n = +t; if (s === 's') { // JS does weird things with floats. Round it off a bit. n *= 1000000; n = Math.round(n); n /= 1000; } return ['time', n]; } const ts = line.match(/^(todo|skip)(?:\S*)\b(.*)$/i); const type = ts?.[1]?.toLowerCase(); const msg = ts?.[2]?.trim(); if (!type) return false; // we know at this point it must be either 'todo' or 'skip', // in unknown upper/lower case return [type, msg || true]; }; //# sourceMappingURL=parse-directive.js.map