All files / web/scripts validateTypstRefactoring.ts

0% Statements 0/98
0% Branches 0/1
0% Functions 0/1
0% Lines 0/98

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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99                                                                                                                                                                                                     
#!/usr/bin/env tsx
/**
 * Validation script for typstHelpers refactoring
 *
 * Generates sample worksheets and verifies that the refactored code
 * produces identical Typst output to ensure no regressions.
 */

import { generateSubtractionProblemStackFunction } from '../src/app/create/worksheets/typstHelpers'
import { generateTypstHelpers } from '../src/app/create/worksheets/typstHelpers'
import { generatePlaceValueColors } from '../src/app/create/worksheets/typstHelpers'

console.log('šŸ” Validating typstHelpers refactoring...\n')

// Test 1: Check that functions are exported and callable
console.log('āœ“ Test 1: Functions are exported')
console.log(
  `  - generateSubtractionProblemStackFunction: ${typeof generateSubtractionProblemStackFunction}`
)
console.log(`  - generateTypstHelpers: ${typeof generateTypstHelpers}`)
console.log(`  - generatePlaceValueColors: ${typeof generatePlaceValueColors}`)

if (typeof generateSubtractionProblemStackFunction !== 'function') {
  console.error('āŒ generateSubtractionProblemStackFunction is not a function!')
  process.exit(1)
}

// Test 2: Generate sample Typst code
console.log('\nāœ“ Test 2: Generate sample Typst code')
const cellSize = 0.55
const maxDigits = 3

const helpers = generateTypstHelpers(cellSize)
console.log(`  - Helper functions: ${helpers.length} characters`)

const colors = generatePlaceValueColors()
console.log(`  - Color definitions: ${colors.length} characters`)

const problemStack = generateSubtractionProblemStackFunction(cellSize, maxDigits)
console.log(`  - Problem stack function: ${problemStack.length} characters`)

// Test 3: Verify key features are present
console.log('\nāœ“ Test 3: Verify key features in generated Typst')

const checks = [
  { name: 'Borrow boxes row', pattern: /Borrow boxes row/ },
  { name: 'Minuend row', pattern: /Minuend row/ },
  { name: 'Subtrahend row', pattern: /Subtrahend row/ },
  { name: 'Answer boxes', pattern: /Answer boxes/ },
  { name: 'Ten-frames', pattern: /Ten-frames row/ },
  { name: 'Borrowing hints', pattern: /show-borrowing-hints/ },
  { name: 'Arrow rendering', pattern: /path\(/ },
  { name: 'Place value colors', pattern: /place-colors/ },
  { name: 'Scratch work boxes', pattern: /dotted.*paint: gray/ },
]

let allPassed = true
for (const check of checks) {
  const found = check.pattern.test(problemStack)
  if (found) {
    console.log(`  āœ“ ${check.name}`)
  } else {
    console.log(`  āŒ ${check.name} - NOT FOUND`)
    allPassed = false
  }
}

// Test 4: Verify structure
console.log('\nāœ“ Test 4: Verify Typst structure')
const structureChecks = [
  { name: 'Function definition', pattern: /#let subtraction-problem-stack\(/ },
  { name: 'Grid structure', pattern: /grid\(/ },
  { name: 'Stack structure', pattern: /stack\(/ },
  { name: 'Problem number display', pattern: /problem-number-display/ },
]

for (const check of structureChecks) {
  const found = check.pattern.test(problemStack)
  if (found) {
    console.log(`  āœ“ ${check.name}`)
  } else {
    console.log(`  āŒ ${check.name} - NOT FOUND`)
    allPassed = false
  }
}

// Summary
console.log('\n' + '='.repeat(60))
if (allPassed) {
  console.log('āœ… All validation checks passed!')
  console.log('\nThe refactored code generates valid Typst output with all')
  console.log('expected features present.')
  process.exit(0)
} else {
  console.log('āŒ Some validation checks failed!')
  console.log('\nPlease review the output above for details.')
  process.exit(1)
}