All files / shared/utils sketch-validation.ts

100% Statements 11/11
87.5% Branches 7/8
100% Functions 1/1
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2427x           238x 238x   238x 455x 231x 224x 224x     455x 223x       238x    
const ENTRYPOINT_REGEX = /\bvoid\s+(setup|loop)\s*\(\s*\)/g;
 
export function detectSketchEntrypoints(code: string): {
  hasSetup: boolean;
  hasLoop: boolean;
} {
  let hasSetup = false;
  let hasLoop = false;
 
  for (const match of code.matchAll(ENTRYPOINT_REGEX)) {
    if (match[1] === "setup") {
      hasSetup = true;
    E} else if (match[1] === "loop") {
      hasLoop = true;
    }
 
    if (hasSetup && hasLoop) {
      break;
    }
  }
 
  return { hasSetup, hasLoop };
}