about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-06-22 10:29:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-06-22 10:29:38 -0700
commite80fd05f4e02c930d5709068267ea4a58e54229d (patch)
tree460e1d39607651296226e4429787a7fadccb0096
parentfb942da8a9ffc2e52f5e838a5f57decae67bcabb (diff)
downloadmu-e80fd05f4e02c930d5709068267ea4a58e54229d.tar.gz
3937
Fix screen-checking functions to handle fake screen after scrolling.
I can't believe I forgot about this during commit 3882.
-rw-r--r--082scenario_screen.cc12
-rw-r--r--083scenario_screen_test.mu15
2 files changed, 23 insertions, 4 deletions
diff --git a/082scenario_screen.cc b/082scenario_screen.cc
index 7121776e..4ee62e06 100644
--- a/082scenario_screen.cc
+++ b/082scenario_screen.cc
@@ -261,8 +261,9 @@ void check_screen(const string& expected_contents, const int color) {
   int screen_height = get_or_insert(Memory, screen_location+height_offset);
   raw_string_stream cursor(expected_contents);
   // todo: too-long expected_contents should fail
-  int addr = screen_data_start+/*skip length*/1;
-  for (int row = 0;  row < screen_height;  ++row) {
+  int top_index_offset = find_element_name(get(Type_ordinal, "screen"), "top-idx", "");
+  int top_index = get_or_insert(Memory, screen_location+top_index_offset);
+  for (int i=0, row=top_index/screen_width;  i < screen_height;  ++i, row=(row+1)%screen_height) {
     cursor.skip_whitespace_and_comments();
     if (cursor.at_end()) break;
     if (cursor.get() != '.') {
@@ -270,6 +271,7 @@ void check_screen(const string& expected_contents, const int color) {
       if (!Scenario_testing_scenario) Passed = false;
       return;
     }
+    int addr = screen_data_start+/*length*/1+row*screen_width* /*size of screen-cell*/2;
     for (int column = 0;  column < screen_width;  ++column, addr+= /*size of screen-cell*/2) {
       const int cell_color_offset = 1;
       uint32_t curr = cursor.get();
@@ -393,9 +395,11 @@ void dump_screen() {
   int screen_data_location = screen_location+data_offset;  // type: address:array:character
   int screen_data_start = get_or_insert(Memory, screen_data_location) + /*skip refcount*/1;  // type: array:character
   assert(get_or_insert(Memory, screen_data_start) == screen_width*screen_height);
-  int curr = screen_data_start+1;  // skip length
-  for (int row = 0;  row < screen_height;  ++row) {
+  int top_index_offset = find_element_name(get(Type_ordinal, "screen"), "top-idx", "");
+  int top_index = get_or_insert(Memory, screen_location+top_index_offset);
+  for (int i=0, row=top_index/screen_width;  i < screen_height;  ++i, row=(row+1)%screen_height) {
     cerr << '.';
+    int curr = screen_data_start+/*length*/1+row*screen_width* /*size of screen-cell*/2;
     for (int col = 0;  col < screen_width;  ++col) {
       if (get_or_insert(Memory, curr))
         cerr << to_unicode(static_cast<uint32_t>(get_or_insert(Memory, curr)));
diff --git a/083scenario_screen_test.mu b/083scenario_screen_test.mu
index b6f0cb95..b4ac6e5e 100644
--- a/083scenario_screen_test.mu
+++ b/083scenario_screen_test.mu
@@ -30,3 +30,18 @@ scenario clear-line-erases-printed-characters-2 [
     .     .
   ]
 ]
+
+scenario scroll-screen [
+  local-scope
+  assume-screen 3/width, 2/height
+  run [
+    a:char <- copy 97/a
+    move-cursor screen, 1/row, 2/column
+    screen <- print screen, a
+    screen <- print screen, a
+  ]
+  screen-should-contain [
+    .  a.
+    .a  .
+  ]
+]