From b0f655ac85ab6d86e9e482cbb9035200c6f08d40 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Fri, 9 Mar 2018 13:49:47 -0800 Subject: Make tests compile again Some tests are still not passing, though. A migration script was added to migrate serialized grids from pre-scrollback to the current format. The script is included with this commit for completeness, posterity, and as an example to be used in the future. A few tests in grid/tests.rs were removed due to becoming irrelevant. --- scripts/migrate_ref_tests.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 scripts/migrate_ref_tests.rb (limited to 'scripts/migrate_ref_tests.rb') diff --git a/scripts/migrate_ref_tests.rb b/scripts/migrate_ref_tests.rb new file mode 100755 index 00000000..b6c89bfe --- /dev/null +++ b/scripts/migrate_ref_tests.rb @@ -0,0 +1,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 -- cgit From c61a912f6221a320ec4787cd883527b0e7f26a8e Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Sat, 19 May 2018 11:18:37 -0700 Subject: Optimize Row::reset Now, only cells that have been used are cleared. This is achieved by using a "occupied" memo on the Row itself. The value, `occ`, is updated wherever the Row is accessed mutably, and it's cleared to zero in Row::reset. The tests for grid scroll_up and scroll_down were updated to include a test on the value `occ` and slightly refactored, but are otherwise equivalent to the previous implementation of those tests. Because of the change to the `Row` struct, the ref tests were updated so Deserialization keeps working as expected. --- scripts/migrate_ref_tests.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'scripts/migrate_ref_tests.rb') diff --git a/scripts/migrate_ref_tests.rb b/scripts/migrate_ref_tests.rb index b6c89bfe..5ed02893 100755 --- a/scripts/migrate_ref_tests.rb +++ b/scripts/migrate_ref_tests.rb @@ -3,18 +3,31 @@ require 'json' Dir.glob('./tests/ref/**/grid.json').each do |path| + puts "Migrating #{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 + # Normalize Storage serialization + if grid['raw'].is_a? Array + grid['raw'] = { + 'inner' => grid['raw'][0], + 'zero' => grid['raw'][1], + 'visible_lines' => grid['raw'][2] + } + end - # Transform - grid['raw'].reverse! - grid['raw'] = [grid['raw'], 0, grid['lines'] - 1] + # Migrate Row serialization + grid['raw']['inner'].map! do |row| + if row.is_a? Hash + row + else + { inner: row, occ: row.length } + end + end # Write updated grid File.open(path, 'w') { |f| f << JSON.generate(grid) } -- cgit