From ef6116cbaf9368e490bfdec1c6404396ac161026 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 13 May 2017 12:50:07 -0700 Subject: 3855 --- html/edit/009-sandbox-test.mu.html | 152 +++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 75 deletions(-) (limited to 'html/edit/009-sandbox-test.mu.html') diff --git a/html/edit/009-sandbox-test.mu.html b/html/edit/009-sandbox-test.mu.html index baa7c1ba..80242905 100644 --- a/html/edit/009-sandbox-test.mu.html +++ b/html/edit/009-sandbox-test.mu.html @@ -174,7 +174,7 @@ if ('onhashchange' in window) { 111 ] 112 113 # clicks on sandbox responses save it as 'expected' -114 after <global-touch> [ +114 after <global-touch> [ 115 # check if it's inside the output of any sandbox 116 { 117 ¦ sandbox-left-margin:num <- get *current-sandbox, left:offset @@ -188,83 +188,85 @@ if ('onhashchange' in window) { 125 ¦ below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins 126 ¦ break-unless below-sandbox-editor? 127 ¦ # identify the sandbox whose output is being clicked on -128 ¦ sandbox:&:sandbox <- find-click-in-sandbox-output env, click-row +128 ¦ sandbox:&:sandbox <- find-click-in-sandbox-output env, click-row 129 ¦ break-unless sandbox 130 ¦ # toggle its expected-response, and save session -131 ¦ sandbox <- toggle-expected-response sandbox +131 ¦ sandbox <- toggle-expected-response sandbox 132 ¦ save-sandboxes env, resources -133 ¦ screen <- render-sandbox-side screen, env, render -134 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env -135 ¦ loop +next-event -136 } -137 ] -138 -139 def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox [ -140 local-scope -141 load-ingredients -142 # assert click-row >= sandbox.starting-row-on-screen -143 sandbox:&:sandbox <- get *env, sandbox:offset -144 start:num <- get *sandbox, starting-row-on-screen:offset -145 clicked-on-sandboxes?:bool <- greater-or-equal click-row, start -146 assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] -147 # while click-row < sandbox.next-sandbox.starting-row-on-screen -148 { -149 ¦ next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset -150 ¦ break-unless next-sandbox -151 ¦ next-start:num <- get *next-sandbox, starting-row-on-screen:offset -152 ¦ found?:bool <- lesser-than click-row, next-start -153 ¦ break-if found? -154 ¦ sandbox <- copy next-sandbox -155 ¦ loop -156 } -157 # return sandbox if click is in its output region -158 response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset -159 return-unless response-starting-row, 0/no-click-in-sandbox-output -160 click-in-response?:bool <- greater-or-equal click-row, response-starting-row -161 return-unless click-in-response?, 0/no-click-in-sandbox-output -162 return sandbox -163 ] -164 -165 def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [ -166 local-scope -167 load-ingredients -168 expected-response:text <- get *sandbox, expected-response:offset -169 { -170 ¦ # if expected-response is set, reset -171 ¦ break-unless expected-response -172 ¦ *sandbox <- put *sandbox, expected-response:offset, 0 -173 } -174 { -175 ¦ # if not, set expected response to the current response -176 ¦ break-if expected-response -177 ¦ response:text <- get *sandbox, response:offset -178 ¦ *sandbox <- put *sandbox, expected-response:offset, response -179 } -180 ] -181 -182 # when rendering a sandbox, color it in red/green if expected response exists -183 after <render-sandbox-response> [ -184 { -185 ¦ break-unless sandbox-response -186 ¦ *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row -187 ¦ expected-response:text <- get *sandbox, expected-response:offset -188 ¦ break-unless expected-response # fall-through to print in grey -189 ¦ response-is-expected?:bool <- equal expected-response, sandbox-response -190 ¦ { -191 ¦ ¦ break-if response-is-expected?:bool -192 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 1/red, row -193 ¦ } -194 ¦ { -195 ¦ ¦ break-unless response-is-expected?:bool -196 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 2/green, row -197 ¦ } -198 ¦ jump +render-sandbox-end -199 } -200 ] -201 -202 before <end-render-sandbox-reset-hidden> [ -203 *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 -204 ] +133 ¦ hide-screen screen +134 ¦ screen <- render-sandbox-side screen, env, render +135 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env +136 ¦ show-screen screen +137 ¦ loop +next-event +138 } +139 ] +140 +141 def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox [ +142 local-scope +143 load-ingredients +144 # assert click-row >= sandbox.starting-row-on-screen +145 sandbox:&:sandbox <- get *env, sandbox:offset +146 start:num <- get *sandbox, starting-row-on-screen:offset +147 clicked-on-sandboxes?:bool <- greater-or-equal click-row, start +148 assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] +149 # while click-row < sandbox.next-sandbox.starting-row-on-screen +150 { +151 ¦ next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset +152 ¦ break-unless next-sandbox +153 ¦ next-start:num <- get *next-sandbox, starting-row-on-screen:offset +154 ¦ found?:bool <- lesser-than click-row, next-start +155 ¦ break-if found? +156 ¦ sandbox <- copy next-sandbox +157 ¦ loop +158 } +159 # return sandbox if click is in its output region +160 response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset +161 return-unless response-starting-row, 0/no-click-in-sandbox-output +162 click-in-response?:bool <- greater-or-equal click-row, response-starting-row +163 return-unless click-in-response?, 0/no-click-in-sandbox-output +164 return sandbox +165 ] +166 +167 def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [ +168 local-scope +169 load-ingredients +170 expected-response:text <- get *sandbox, expected-response:offset +171 { +172 ¦ # if expected-response is set, reset +173 ¦ break-unless expected-response +174 ¦ *sandbox <- put *sandbox, expected-response:offset, 0 +175 } +176 { +177 ¦ # if not, set expected response to the current response +178 ¦ break-if expected-response +179 ¦ response:text <- get *sandbox, response:offset +180 ¦ *sandbox <- put *sandbox, expected-response:offset, response +181 } +182 ] +183 +184 # when rendering a sandbox, color it in red/green if expected response exists +185 after <render-sandbox-response> [ +186 { +187 ¦ break-unless sandbox-response +188 ¦ *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row +189 ¦ expected-response:text <- get *sandbox, expected-response:offset +190 ¦ break-unless expected-response # fall-through to print in grey +191 ¦ response-is-expected?:bool <- equal expected-response, sandbox-response +192 ¦ { +193 ¦ ¦ break-if response-is-expected?:bool +194 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 1/red, row +195 ¦ } +196 ¦ { +197 ¦ ¦ break-unless response-is-expected?:bool +198 ¦ ¦ row, screen <- render-text screen, sandbox-response, left, right, 2/green, row +199 ¦ } +200 ¦ jump +render-sandbox-end +201 } +202 ] +203 +204 before <end-render-sandbox-reset-hidden> [ +205 *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0 +206 ] -- cgit 1.4.1-2-gfad0