(selective-load "mu.arc" section-level) (test-only-settings) (add-code:readfile "trace.mu") (ero "running tests in trace.arc.t (takes ~10 mins)") (freeze function*) (load-system-functions) (reset2) (new-trace "print-trace") (run-code main (default-space:space-address <- new space:literal 30:literal/capacity) (x:string-address <- new "schedule: main run: main 0: (((1 integer)) <- ((copy)) ((1 literal))) run: main 0: 1 => ((1 integer)) mem: ((1 integer)): 1 <= 1 run: main 1: (((2 integer)) <- ((copy)) ((3 literal))) run: main 1: 3 => ((2 integer)) mem: ((2 integer)): 2 <= 3 run: main 2: (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) mem: ((1 integer)) => 1 mem: ((2 integer)) => 3 run: main 2: 4 => ((3 integer)) mem: ((3 integer)): 3 <= 4 schedule: done with routine") (s:stream-address <- init-stream x:string-address) (traces:instruction-trace-address-array-address <- parse-traces s:stream-address) (screen:terminal-address <- init-fake-terminal 70:literal 15:literal) (browser-state:space-address <- browser-state traces:instruction-trace-address-array-address 30:literal/screen-height) (print-traces-collapsed browser-state:space-address screen:terminal-address) (1:string-address/raw <- get screen:terminal-address/deref data:offset) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) ;? (prn memory*.1) (when (~screen-contains memory*.1 70 (+ "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal))) " "+ main/ 0 : 1 => ((1 integer)) " "+ main/ 1 : (((2 integer)) <- ((copy)) ((3 literal))) " "+ main/ 1 : 3 => ((2 integer)) " "+ main/ 2 : (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) " "+ main/ 2 : 4 => ((3 integer)) ")) (prn "F - print-traces-collapsed works")) ;? (quit) ;? 1 (reset2) (new-trace "print-trace-from-middle-of-screen") (run-code main (default-space:space-address <- new space:literal 30:literal/capacity) (x:string-address <- new "schedule: main run: main 0: (((1 integer)) <- ((copy)) ((1 literal))) run: main 0: 1 => ((1 integer)) mem: ((1 integer)): 1 <= 1 run: main 1: (((2 integer)) <- ((copy)) ((3 literal))) run: main 1: 3 => ((2 integer)) mem: ((2 integer)): 2 <= 3 run: main 2: (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) mem: ((1 integer)) => 1 mem: ((2 integer)) => 3 run: main 2: 4 => ((3 integer)) mem: ((3 integer)): 3 <= 4 schedule: done with routine") (s:stream-address <- init-stream x:string-address) (traces:instruction-trace-address-array-address <- parse-traces s:stream-address) (1:terminal-address/raw <- init-fake-terminal 70:literal 15:literal) ; position the cursor away from top of screen (cursor-down 1:terminal-address/raw) (cursor-down 1:terminal-address/raw) (browser-state:space-address <- browser-state traces:instruction-trace-address-array-address 30:literal/screen-height) (print-traces-collapsed browser-state:space-address 1:terminal-address/raw traces:instruction-trace-address-array-address) (2:string-address/raw <- get 1:terminal-address/raw/deref data:offset) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.2 70 (+ " " " " "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal))) " "+ main/ 0 : 1 => ((1 integer)) " "+ main/ 1 : (((2 integer)) <- ((copy)) ((3 literal))) " "+ main/ 1 : 3 => ((2 integer)) " "+ main/ 2 : (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) " "+ main/ 2 : 4 => ((3 integer)) ")) (prn "F - print-traces-collapsed works anywhere on the screen")) (run-code main2 (print-character 1:terminal-address/raw ((#\* literal)))) (when (~screen-contains memory*.2 70 (+ " " " " "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal))) " "+ main/ 0 : 1 => ((1 integer)) " "+ main/ 1 : (((2 integer)) <- ((copy)) ((3 literal))) " "+ main/ 1 : 3 => ((2 integer)) " "+ main/ 2 : (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) " "+ main/ 2 : 4 => ((3 integer)) " "* ")) (prn "F - print-traces-collapsed leaves cursor at next line")) (reset2) (new-trace "process-key-move-up-down") (run-code main (default-space:space-address <- new space:literal 30:literal/capacity) (x:string-address <- new "schedule: main run: main 0: (((1 integer)) <- ((copy)) ((1 literal))) run: main 0: 1 => ((1 integer)) mem: ((1 integer)): 1 <= 1 run: main 1: (((2 integer)) <- ((copy)) ((3 literal))) run: main 1: 3 => ((2 integer)) mem: ((2 integer)): 2 <= 3 run: main 2: (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) mem: ((1 integer)) => 1 mem: ((2 integer)) => 3 run: main 2: 4 => ((3 integer)) mem: ((3 integer)): 3 <= 4 schedule: done with routine") (s:stream-address <- init-stream x:string-address) (1:instruction-trace-address-array-address/raw <- parse-traces s:stream-address) (2:terminal-address/raw <- init-fake-terminal 70:literal 15:literal) ; position the cursor away from top of screen (cursor-down 2:terminal-address/raw) (cursor-down 2:terminal-address/raw) (3:space-address/raw <- browser-state 1:instruction-trace-address-array-address/raw 30:literal/screen-height) ; draw trace (print-traces-collapsed 3:space-address/raw/browser-state 2:terminal-address/raw 1:instruction-trace-address-array-address/raw) ; move cursor up ; we have no way yet to test special keys like up-arrow (s:string-address <- new "k") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ; draw cursor (replace-character 2:terminal-address/raw ((#\* literal))) (4:string-address/raw <- get 2:terminal-address/raw/deref data:offset) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 70 (+ " " " " "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal))) " "+ main/ 0 : 1 => ((1 integer)) " "+ main/ 1 : (((2 integer)) <- ((copy)) ((3 literal))) " "+ main/ 1 : 3 => ((2 integer)) " "+ main/ 2 : (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) " "* main/ 2 : 4 => ((3 integer)) ")) ;^cursor (prn "F - process-key can move up the cursor")) (run-code main2 (default-space:space-address <- new space:literal 30:literal/capacity) ; reset previous cursor (replace-character 2:terminal-address/raw ((#\+ literal))) ; move cursor up 3 more lines (s:string-address <- new "kkk") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (replace-character 2:terminal-address/raw ((#\* literal))) ) ; cursor is now at line 3 (when (~screen-contains memory*.4 70 (+ " " " " "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal))) " "+ main/ 0 : 1 => ((1 integer)) " "* main/ 1 : (((2 integer)) <- ((copy)) ((3 literal))) " ;^cursor "+ main/ 1 : 3 => ((2 integer)) " "+ main/ 2 : (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) " "+ main/ 2 : 4 => ((3 integer)) ")) (prn "F - process-key can move up multiple times")) ; try to move cursor up thrice more (run-code main3 (default-space:space-address <- new space:literal 30:literal/capacity) (replace-character 2:terminal-address/raw ((#\+ literal))) (s:string-address <- new "kkk") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (replace-character 2:terminal-address/raw ((#\* literal))) ) ; cursor doesn't go beyond the first line printed ; stuff on screen before browser-state was initialized is inviolate (when (~screen-contains memory*.4 70 (+ " " " " "* main/ 0 : (((1 integer)) <- ((copy)) ((1 literal))) " ;^cursor "+ main/ 0 : 1 => ((1 integer)) " "+ main/ 1 : (((2 integer)) <- ((copy)) ((3 literal))) " "+ main/ 1 : 3 => ((2 integer)) " "+ main/ 2 : (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) " "+ main/ 2 : 4 => ((3 integer)) ")) (prn "F - process-key doesn't move above bounds")) ; now move cursor down 4 times (run-code main4 (default-space:space-address <- new space:literal 30:literal/capacity) (replace-character 2:terminal-address/raw ((#\+ literal))) (s:string-address <- new "jjjj") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (replace-character 2:terminal-address/raw ((#\* literal))) ) (when (~screen-contains memory*.4 70 (+ " " " " "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal))) " "+ main/ 0 : 1 => ((1 integer)) " "+ main/ 1 : (((2 integer)) <- ((copy)) ((3 literal))) " "+ main/ 1 : 3 => ((2 integer)) " "* main/ 2 : (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) " ;^cursor "+ main/ 2 : 4 => ((3 integer)) ")) (prn "F - process-key can move down multiple times")) ; try to move cursor down 4 more times (run-code main5 (default-space:space-address <- new space:literal 30:literal/capacity) (replace-character 2:terminal-address/raw ((#\+ literal))) (s:string-address <- new "jjjj") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (replace-character 2:terminal-address/raw ((#\* literal))) ) (when (~screen-contains memory*.4 70 (+ " " " " "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal))) " "+ main/ 0 : 1 => ((1 integer)) " "+ main/ 1 : (((2 integer)) <- ((copy)) ((3 literal))) " "+ main/ 1 : 3 => ((2 integer)) " "+ main/ 2 : (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) " "+ main/ 2 : 4 => ((3 integer)) " "* ")) (prn "F - process-key doesn't move below bounds")) (reset2) (new-trace "process-key-expand") (run-code main (default-space:space-address <- new space:literal 30:literal/capacity) (x:string-address <- new "schedule: main run: main 0: (((1 integer)) <- ((copy)) ((1 literal))) run: main 0: 1 => ((1 integer)) mem: ((1 integer)): 1 <= 1 run: main 1: (((2 integer)) <- ((copy)) ((3 literal))) run: main 1: 3 => ((2 integer)) mem: ((2 integer)): 2 <= 3 run: main 2: (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) mem: ((1 integer)) => 1 mem: ((2 integer)) => 3 run: main 2: 4 => ((3 integer)) mem: ((3 integer)): 3 <= 4 schedule: done with routine") (s:stream-address <- init-stream x:string-address) (1:instruction-trace-address-array-address/raw <- parse-traces s:stream-address) (2:terminal-address/raw <- init-fake-terminal 70:literal 15:literal) ; position the cursor away from top of screen (cursor-down 2:terminal-address/raw) (cursor-down 2:terminal-address/raw) (3:space-address/raw <- browser-state 1:instruction-trace-address-array-address/raw 30:literal/screen-height) ; draw trace (print-traces-collapsed 3:space-address/raw/browser-state 2:terminal-address/raw 1:instruction-trace-address-array-address/raw) (4:string-address/raw <- get 2:terminal-address/raw/deref data:offset) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 70 (+ " " " " "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal))) " "+ main/ 0 : 1 => ((1 integer)) " "+ main/ 1 : (((2 integer)) <- ((copy)) ((3 literal))) " "+ main/ 1 : 3 => ((2 integer)) " "+ main/ 2 : (((3 integer)) <- ((add)) ((1 integer)) ((2 integer))) " "+ main/ 2 : 4 => ((3 integer)) ")) (prn "F - process-key: before expand")) (run-code main2 (default-space:space-address <- new space:literal 30:literal/capacity) ; move cursor to final line and expand (s:st
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

if __name__ == '__main__': from __init__ import init; init()
import unittest
from collections import deque

from ranger.ext.iter_tools import *

class TestCases(unittest.TestCase):
	def test_flatten(self):
		def f(x):
			return list(flatten(x))

		self.assertEqual(
			[1,2,3,4,5],
			f([1,2,3,4,5]))
		self.assertEqual(
			[1,2,3,4,5],
			f([1,[2,3],4,5]))
		self.assertEqual(
			[1,2,3,4,5],
			f([[1,[2,3]],4,5]))
		self.assertEqual(
			[],
			f([[[[]]]]))
		self.assertEqual(
			['a', 'b', 'fskldfjl'],
			f(['a', ('b', 'fskldfjl')]))
		self.assertEqual(
			['a', 'b', 'fskldfjl'],
			f(['a', deque(['b', 'fskldfjl'])]))
		self.assertEqual(
			set([3.5, 4.3, 5.2, 6.0]),
			set(f([6.0, set((3.5, 4.3)), (5.2, )])))

	def test_unique(self):
		def u(x):
			return list(unique(x))

		self.assertEqual(
			[1,2,3],
			u([1,2,3]))
		self.assertEqual(
			[1,2,3],
			u([1,2,3,2,1]))
		self.assertEqual(
			[1,2,3],
			u([1,2,3,1,2,3,2,2,3,1,2,3,1,2,3,2,3,2,1]))
		self.assertEqual(
			[1,[2,3]],
			u([1,[2,3],1,[2,3],[2,3],1,[2,3],1,[2,3],[2,3],1]))

	def test_unique_keeps_type(self):
		def u(x):
			return unique(x)

		self.assertEqual(
			[1,2,3],
			u([1,2,3,1]))
		self.assertEqual(
			(1,2,3),
			u((1,2,3,1)))
		self.assertEqual(
			set((1,2,3)),
			u(set((1,2,3,1))))
		self.assertEqual(
			deque((1,2,3)),
			u(deque((1,2,3,1))))

	def test_mount_path(self):
		# assuming ismount() is used

		def my_ismount(path):
			depth = path.count('/')
			if path.startswith('/media'):
				return depth == 0 or depth == 2
			return depth <= 1

		from ranger.ext import mount_path
		original_ismount = mount_path.ismount
		mount_path.ismount = my_ismount
		try:
			mp = mount_path.mount_path

			self.assertEqual('/home', mp('/home/hut/porn/bondage'))
			self.assertEqual('/', mp('/'))
			self.assertEqual('/media/sdb1', mp('/media/sdb1/foo/bar'))
			self.assertEqual('/media/sdc2', mp('/media/sdc2/a/b/c/d/e'))
		finally:
			mount_path.ismount = original_ismount

		# TODO: links are not tested but I don't see how its possible
		# without messing around with mounts.
		# self.assertEqual('/media/foo',
		#     mount_path('/media/bar/some_link_to_a_foo_subdirectory'))

	def test_openstruct(self):
		from ranger.ext.openstruct import OpenStruct
		from random import randint, choice
		from string import ascii_letters

		os = OpenStruct(a='a')
		self.assertEqual(os.a, 'a')
		self.assertRaises(AttributeError, getattr, os, 'b')

		dictionary = {'foo': 'bar', 'zoo': 'zar'}
		os = OpenStruct(dictionary)
		self.assertEqual(os.foo, 'bar')
		self.assertEqual(os.zoo, 'zar')
		self.assertRaises(AttributeError, getattr, os, 'sdklfj')

		for i in range(100):
			attr_name = ''.join(choice(ascii_letters) \
				for x in range(randint(3,9)))
			value = randint(100,999)
			if not attr_name in os:
				self.assertRaises(AttributeError, getattr, os, attr_name)
			setattr(os, attr_name, value)
			value2 = randint(100,999)
			setattr(os, attr_name, value2)
			self.assertEqual(value2, getattr(os, attr_name))

	def test_shell_escape(self):
		from ranger.ext.shell_escape import shell_escape, shell_quote
		self.assertEqual(r"'luigi'\''s pizza'", shell_quote("luigi's pizza"))
		self.assertEqual(r"luigi\'s\ pizza", shell_escape("luigi's pizza"))
		self.assertEqual(r"\$lol/foo\\xyz\|\>\<\]\[",
				shell_escape(r"$lol/foo\xyz|><]["))


if __name__ == '__main__':
	unittest.main()
er/space:1 <- copy 2:literal) (last-index-on-page:integer/space:1 <- copy 1:literal) (last-subindex-on-page:integer/space:1 <- copy 4:literal) (expanded-index:integer/space:1 <- copy 1:literal) (expanded-children:integer/space:1 <- copy 5:literal) (s:string-address <- new "K") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "- main/ 1 : d e f" " mem : 1 a " " mem : 1 b " " " " ")) (prn "F - page-up 4")) ; page-up scenario 5 ; + run: main 0: a b c ; mem: 0 a ; - run: main 1: d e f ; mem: 1 a <- top of page ; mem: 1 b ; mem: 1 c <- bottom of page ; mem: 1 d ; mem: 1 e ; + run: main 2: g hi ; + run: main 3: j ; mem: 3 a ; + run: main 4: k ; + run: main 5: l ; + run: main 6: m ; + run: main 7: n (run-code main16pre (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 1:literal) (first-subindex-on-page:integer/space:1 <- copy 0:literal) (last-index-on-page:integer/space:1 <- copy 1:literal) (last-subindex-on-page:integer/space:1 <- copy 2:literal) (expanded-index:integer/space:1 <- copy 1:literal) (expanded-children:integer/space:1 <- copy 5:literal) ;? ($print cursor-row:integer/space:1) ;? 1 (to-top 0:space-address/browser-state 2:terminal-address/raw) ;? ($print cursor-row:integer/space:1) ;? 1 (print-page 0:space-address/browser-state 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ " mem : 1 a " " mem : 1 b " " mem : 1 c " " " " ")) (prn "F - page-up 5: initial print-page state")) (run-code main16 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 1:literal) (first-subindex-on-page:integer/space:1 <- copy 0:literal) (last-index-on-page:integer/space:1 <- copy 1:literal) (last-subindex-on-page:integer/space:1 <- copy 2:literal) (expanded-index:integer/space:1 <- copy 1:literal) (expanded-children:integer/space:1 <- copy 5:literal) (s:string-address <- new "K") (k:keyboard-address <- init-keyboard s:string-address) ;? ($dump-browser-state 3:space-address/raw/browser-state) ;? 1 (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "+ main/ 0 : a b c" "- main/ 1 : d e f" " mem : 1 a " " " " ")) (prn "F - page-up 5")) ; page-up scenario 6 ; + run: main 0: a b c ; mem: 0 a ; - run: main 1: d e f ; mem: 1 a ; mem: 1 b <- top of page ; mem: 1 c ; mem: 1 d <- bottom of page ; mem: 1 e ; + run: main 2: g hi ; + run: main 3: j ; mem: 3 a ; + run: main 4: k ; + run: main 5: l ; + run: main 6: m ; + run: main 7: n (run-code main17 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 1:literal) (first-subindex-on-page:integer/space:1 <- copy 1:literal) (last-index-on-page:integer/space:1 <- copy 1:literal) (last-subindex-on-page:integer/space:1 <- copy 3:literal) (expanded-index:integer/space:1 <- copy 1:literal) (expanded-children:integer/space:1 <- copy 5:literal) (s:string-address <- new "K") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "+ main/ 0 : a b c" "- main/ 1 : d e f" " mem : 1 a " " " " ")) (prn "F - page-up 6")) ; page-up scenario 7 ; + run: main 0: a b c ; mem: 0 a ; + run: main 1: d e f <- top of page ; mem: 1 a ; mem: 1 b ; mem: 1 c ; mem: 1 d ; mem: 1 e ; + run: main 2: g hi ; - run: main 3: j <- bottom of page ; mem: 3 a ; + run: main 4: k ; + run: main 5: l ; + run: main 6: m ; + run: main 7: n (run-code main18 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 1:literal) (first-subindex-on-page:integer/space:1 <- copy -2:literal) (last-index-on-page:integer/space:1 <- copy 3:literal) (last-subindex-on-page:integer/space:1 <- copy -1:literal) (expanded-index:integer/space:1 <- copy 3:literal) (expanded-children:integer/space:1 <- copy 1:literal) (s:string-address <- new "K") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "+ main/ 0 : a b c" "+ main/ 1 : d e f" "+ main/ 2 : g hi " " ")) (prn "F - page-up 7 - expanded index starts below bottom")) ;? (quit) ;? 1 ; page-up scenario 8 ; + run: main 0: a b c ; mem: 0 a ; + run: main 1: d e f <- top of page ; mem: 1 a ; mem: 1 b ; mem: 1 c ; mem: 1 d ; mem: 1 e ; + run: main 2: g hi ; + run: main 3: j <- bottom of page ; mem: 3 a ; - run: main 4: k ; + run: main 5: l ; + run: main 6: m ; + run: main 7: n (run-code main19 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 1:literal) (first-subindex-on-page:integer/space:1 <- copy -2:literal) (last-index-on-page:integer/space:1 <- copy 3:literal) (last-subindex-on-page:integer/space:1 <- copy -1:literal) (expanded-index:integer/space:1 <- copy 4:literal) (expanded-children:integer/space:1 <- copy 0:literal) (s:string-address <- new "K") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "+ main/ 0 : a b c" "+ main/ 1 : d e f" "+ main/ 2 : g hi " " ")) (prn "F - page-up 8 - expanded index starts below top - 2")) ; page-up scenario 9 ; - run: main 0: a b c ; mem: 0 a ; + run: main 1: d e f ; mem: 1 a ; mem: 1 b ; mem: 1 c ; mem: 1 d ; mem: 1 e ; + run: main 2: g hi ; + run: main 3: j <- top of page ; mem: 3 a ; + run: main 4: k ; + run: main 5: l <- bottom of page ; + run: main 6: m ; + run: main 7: n (run-code main20 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 3:literal) (first-subindex-on-page:integer/space:1 <- copy -2:literal) (last-index-on-page:integer/space:1 <- copy 5:literal) (last-subindex-on-page:integer/space:1 <- copy -2:literal) (expanded-index:integer/space:1 <- copy 0:literal) (expanded-children:integer/space:1 <- copy 1:literal) (s:string-address <- new "K") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ " mem : 0 a " "+ main/ 1 : d e f" "+ main/ 2 : g hi " " ")) (prn "F - page-up 9 - expanded index overlaps target page")) ; page-up scenario 10 ; - run: main 0: a b c ; mem: 0 a ; + run: main 1: d e f ; mem: 1 a ; mem: 1 b ; mem: 1 c ; mem: 1 d ; mem: 1 e ; + run: main 2: g hi <- top of page ; + run: main 3: j ; mem: 3 a ; + run: main 4: k <- bottom of page ; + run: main 5: l ; + run: main 6: m ; + run: main 7: n (run-code main21pre (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 2:literal) (first-subindex-on-page:integer/space:1 <- copy -2:literal) (last-index-on-page:integer/space:1 <- copy 4:literal) (last-subindex-on-page:integer/space:1 <- copy -2:literal) (expanded-index:integer/space:1 <- copy 0:literal) (expanded-children:integer/space:1 <- copy 1:literal) (to-top 0:space-address/browser-state 2:terminal-address/raw) ;? ($start-tracing) ;? 2 (print-page 0:space-address/browser-state 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "+ main/ 2 : g hi " "+ main/ 3 : j " "+ main/ 4 : k " " " " ")) (prn "F - page-up 10: initial print-page state")) ;? (quit) ;? 1 (run-code main21 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 2:literal) (first-subindex-on-page:integer/space:1 <- copy -2:literal) (last-index-on-page:integer/space:1 <- copy 4:literal) (last-subindex-on-page:integer/space:1 <- copy -2:literal) (expanded-index:integer/space:1 <- copy 0:literal) (expanded-children:integer/space:1 <- copy 1:literal) (s:string-address <- new "K") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "- main/ 0 : a b c" " mem : 0 a " "+ main/ 1 : d e f" " " " ")) (prn "F - page-up 10 - expanded index overlaps target page - 2")) ;? (quit) ;? 2 (reset2) (new-trace "trace-paginate2") ; page-up scenario 11 ; + run: main 0: a b c ; mem: 0 a ; + run: main 1: d e f ; - run: main 2: g hi ; mem: 2 a ; + run: main 3: j <- top of page ; mem: 3 a ; + run: main 4: k ; + run: main 5: l <- bottom of page ; + run: main 6: m ; + run: main 7: n (run-code main22 (default-space:space-address <- new space:literal 30:literal/capacity) (x:string-address <- new "run: main 0: a b c mem: 0 a run: main 1: d e f run: main 2: g hi mem: 2 a run: main 3: j mem: 3 a run: main 4: k run: main 5: l run: main 6: m run: main 7: n") (s:stream-address <- init-stream x:string-address) (traces:instruction-trace-address-array-address <- parse-traces s:stream-address) (2:terminal-address/raw <- init-fake-terminal 17:literal 15:literal) (3:space-address/raw/browser-state <- browser-state traces:instruction-trace-address-array-address 3:literal/screen-height) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (4:string-address/raw <- get 2:terminal-address/raw/deref data:offset) (first-index-on-page:integer/space:1 <- copy 3:literal) (first-subindex-on-page:integer/space:1 <- copy -2:literal) (last-index-on-page:integer/space:1 <- copy 5:literal) (last-subindex-on-page:integer/space:1 <- copy -2:literal) (expanded-index:integer/space:1 <- copy 2:literal) (expanded-children:integer/space:1 <- copy 1:literal) (s:string-address <- new "K") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "+ main/ 1 : d e f" "- main/ 2 : g hi " " mem : 2 a " " " " ")) (prn "F - page-up 11 - expanded index overlaps target page - 3")) ; page-up scenario 12 ; + run: main 0: a b c ; mem: 0 a ; + run: main 1: d e f ; - run: main 2: g hi ; mem: 2 a ; + run: main 3: j ; mem: 3 a ; + run: main 4: k <- top of page ; + run: main 5: l ; + run: main 6: m <- bottom of page ; + run: main 7: n (run-code main23 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 4:literal) (first-subindex-on-page:integer/space:1 <- copy -2:literal) (last-index-on-page:integer/space:1 <- copy 6:literal) (last-subindex-on-page:integer/space:1 <- copy -2:literal) (expanded-index:integer/space:1 <- copy 2:literal) (expanded-children:integer/space:1 <- copy 1:literal) (s:string-address <- new "K") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "- main/ 2 : g hi " " mem : 2 a " "+ main/ 3 : j " " ")) (prn "F - page-up 12 - expanded index overlaps target page - 4")) ; page-up scenario 13 ; + run: main 0: a b c ; mem: 0 a ; + run: main 1: d e f ; - run: main 2: g hi ; mem: 2 a ; + run: main 3: j ; mem: 3 a ; + run: main 4: k ; + run: main 5: l ; + run: main 6: m <- top of page ; + run: main 7: n <- bottom of page (run-code main24 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 6:literal) (first-subindex-on-page:integer/space:1 <- copy -2:literal) (last-index-on-page:integer/space:1 <- copy 7:literal) (last-subindex-on-page:integer/space:1 <- copy -2:literal) (expanded-index:integer/space:1 <- copy 2:literal) (expanded-children:integer/space:1 <- copy 1:literal) (s:string-address <- new "K") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "+ main/ 3 : j " "+ main/ 4 : k " "+ main/ 5 : l " " ")) (prn "F - page-up 13 - expanded index far above target page")) (run-code main25 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (s:string-address <- new "kk\n") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "+ main/ 3 : j " "- main/ 4 : k " "+ main/ 5 : l " " ")) (prn "F - process-key expands a trace index on any page")) (run-code main26 (replace-character 2:terminal-address/raw ((#\* literal))) ) (when (~screen-contains memory*.4 17 (+ "+ main/ 3 : j " "* main/ 4 : k " "+ main/ 5 : l " " ")) (prn "F - process-key resets the cursor after expand")) ;? (quit) ;? 1 (run-code main27 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) ; reset previous cursor (replace-character 2:terminal-address/raw ((#\- literal))) (s:string-address <- new "j\n") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "+ main/ 3 : j " "+ main/ 4 : k " "- main/ 5 : l " " ")) (prn "F - process-key expands a trace index on any page when there's an expanded trace index above it on the same page")) ; expand scenario ; + run: main 0: a b c ; mem: 0 a ; + run: main 1: d e f ; - run: main 2: g hi ; mem: 2 a <- top of page ; + run: main 3: j ; mem: 3 a ; + run: main 4: k <- bottom of page ; + run: main 5: l ; + run: main 6: m ; + run: main 7: n (run-code main28 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 2:literal) (first-subindex-on-page:integer/space:1 <- copy 0:literal) (last-index-on-page:integer/space:1 <- copy 4:literal) (last-subindex-on-page:integer/space:1 <- copy -2:literal) (expanded-index:integer/space:1 <- copy 2:literal) (expanded-children:integer/space:1 <- copy 1:literal) (to-top 0:space-address/browser-state 2:terminal-address/raw) (print-page 0:space-address/browser-state 2:terminal-address/raw) (s:string-address <- new "kk\n") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ;? (replace-character 2:terminal-address/raw ((#\* literal))) ;? 2 ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 ;? (+ " mem : 2 a " ; after print-page ;? "+ main/ 3 : j " ;? "+ main/ 4 : k " ;? " ")) (+ "+ main/ 2 : g hi " "- main/ 3 : j " " mem : 3 a " " ")) ;? (+ "- main/ 3 : j " ; alternative interpretation in case the above isn't intuitive ;? " mem : 3 a " ;? (+ "- main/ 4 : k " ;? " ")) (prn "F - process-key expands trace index on a page that starts with a partial expanded trace")) (reset2) (new-trace "trace-paginate3") ; expand scenario ; + run: main 0: a b c ; mem: 0 a ; + run: main 1: d e f ; mem: 1 a ; mem: 1 b <- top of page ; mem: 1 c ; + run: main 2: g hi <- bottom of page ; mem: 2 a ; + run: main 3: j ; + run: main 4: k ; + run: main 5: l (run-code main29 (default-space:space-address <- new space:literal 30:literal/capacity) (x:string-address <- new "run: main 0: a b c mem: 0 a run: main 1: d e f mem: 1 a mem: 1 b mem: 1 c run: main 2: g hi mem: 2 a run: main 3: j run: main 4: k run: main 5: l") (s:stream-address <- init-stream x:string-address) (traces:instruction-trace-address-array-address <- parse-traces s:stream-address) (2:terminal-address/raw <- init-fake-terminal 17:literal 15:literal) (3:space-address/raw/browser-state <- browser-state traces:instruction-trace-address-array-address 3:literal/screen-height) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (4:string-address/raw <- get 2:terminal-address/raw/deref data:offset) (first-index-on-page:integer/space:1 <- copy 1:literal) (first-subindex-on-page:integer/space:1 <- copy 1:literal) (last-index-on-page:integer/space:1 <- copy 3:literal) (last-subindex-on-page:integer/space:1 <- copy -2:literal) (expanded-index:integer/space:1 <- copy 1:literal) (expanded-children:integer/space:1 <- copy 3:literal) (to-top 0:space-address/browser-state 2:terminal-address/raw) (print-page 0:space-address/browser-state 2:terminal-address/raw) ;? (replace-character 2:terminal-address/raw ((#\* literal))) ;? 1 (s:string-address <- new "k\n") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 ;? (+ " mem : 1 b " ; after print-page ;? " mem : 1 c " ;? "+ main/ 2 : g hi " ;? "* " ;? " ")) (+ "+ main/ 1 : d e f" "- main/ 2 : g hi " " mem : 2 a " " " " ")) (prn "F - process-key expands trace index on a page that starts with a partial expanded trace - 2")) ; expand scenario ; + run: main 0: a b c ; mem: 0 a ; + run: main 1: d e f ; mem: 1 a <- top of page ; mem: 1 b ; mem: 1 c <- bottom of page ; + run: main 2: g hi ; mem: 2 a ; + run: main 3: j ; + run: main 4: k ; + run: main 5: l (run-code main30 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) (first-index-on-page:integer/space:1 <- copy 1:literal) (first-subindex-on-page:integer/space:1 <- copy 0:literal) (last-index-on-page:integer/space:1 <- copy 1:literal) (last-subindex-on-page:integer/space:1 <- copy 2:literal) (expanded-index:integer/space:1 <- copy 1:literal) (expanded-children:integer/space:1 <- copy 3:literal) (to-top 0:space-address/browser-state 2:terminal-address/raw) (print-page 0:space-address/browser-state 2:terminal-address/raw) (s:string-address <- new "k\n") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ;? (replace-character 2:terminal-address/raw ((#\* literal))) ;? 1 ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 ;? (+ " mem : 1 a " ; after print-page ;? " mem : 1 b " ;? " mem : 1 c " ;? "* ")) (+ "+ main/ 1 : d e f" "+ main/ 2 : g hi " "+ main/ 3 : j ")) (prn "F - process-key expands trace index on a page with only subindex lines")) (run-code main31 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) ; reinitialize (first-index-on-page:integer/space:1 <- copy 0:literal) (first-subindex-on-page:integer/space:1 <- copy -2:literal) (last-index-on-page:integer/space:1 <- copy 2:literal) (last-subindex-on-page:integer/space:1 <- copy -2:literal) (expanded-index:integer/space:1 <- copy -1:literal) (expanded-children:integer/space:1 <- copy -1:literal) (to-top 0:space-address/browser-state 2:terminal-address/raw) (print-page 0:space-address/browser-state 2:terminal-address/raw) ;? (replace-character 2:terminal-address/raw ((#\* literal))) ;? 1 (s:string-address <- new "Jjj\n") (k:keyboard-address <- init-keyboard s:string-address) ;? ($print (("test: first subindex " literal))) ;? 1 ;? ($print first-subindex-on-page:integer/space:1) ;? 1 ;? ($print (("\n" literal))) ;? 1 (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ;? ($print (("test: first subindex 2 " literal))) ;? 1 ;? ($print first-subindex-on-page:integer/space:1) ;? 1 ;? ($print (("\n" literal))) ;? 1 (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ;? ($print (("test: first subindex 3 " literal))) ;? 1 ;? ($print first-subindex-on-page:integer/space:1) ;? 1 ;? ($print (("\n" literal))) ;? 1 (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ;? ($print (("test: first subindex 4 " literal))) ;? 1 ;? ($print first-subindex-on-page:integer/space:1) ;? 1 ;? ($print (("\n" literal))) ;? 1 (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) (when (~screen-contains memory*.4 17 (+ "+ main/ 3 : j " "+ main/ 4 : k " "- main/ 5 : l " " " " ")) (prn "F - process-key expands final index of trace at bottom of page")) (run-code main32 (default-space:space-address <- new space:literal 30:literal/capacity) (0:space-address/names:browser-state <- copy 3:space-address/raw/browser-state) ; reinitialize (first-index-on-page:integer/space:1 <- copy 0:literal) (first-subindex-on-page:integer/space:1 <- copy -2:literal) (last-index-on-page:integer/space:1 <- copy 2:literal) (last-subindex-on-page:integer/space:1 <- copy -2:literal) (expanded-index:integer/space:1 <- copy -1:literal) (expanded-children:integer/space:1 <- copy -1:literal) (to-top 0:space-address/browser-state 2:terminal-address/raw) (print-page 0:space-address/browser-state 2:terminal-address/raw) ;? (replace-character 2:terminal-address/raw ((#\* literal))) ;? 1 (s:string-address <- new "kk\nJjj") (k:keyboard-address <- init-keyboard s:string-address) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (process-key 3:space-address/raw/browser-state k:keyboard-address 2:terminal-address/raw) (5:integer-address/raw <- get-address 2:terminal-address/raw/deref cursor-row:offset) ) (each routine completed-routines* (awhen rep.routine!error (prn "error - " it))) ;? (prn (memory* memory*.5)) ;? 1 (when (~is 3 (memory* memory*.5)) (prn "F - key movement stays within screen bounds, even when no next trace on page")) (reset2) ;? (print-times) ;? 3