aboutsummaryrefslogtreecommitdiff
path: root/scripts/migrate_ref_tests.rb
blob: b6c89bfec6e83b986c31c47b7a47a4ddc5217ce5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env ruby

require 'json'

Dir.glob('./tests/ref/**/grid.json').each do |path|
  # Read contents
  s = File.open(path) { |f| f.read }

  # Parse
  grid = JSON.parse(s)

  # Check if it's already migrated / make this migration idempotent
  next if grid['raw'][0][0].is_a? Array

  # Transform
  grid['raw'].reverse!
  grid['raw'] = [grid['raw'], 0, grid['lines'] - 1]

  # Write updated grid
  File.open(path, 'w') { |f| f << JSON.generate(grid) }
end