about summary refs log tree commit diff stats
path: root/build
Commit message (Expand)AuthorAgeFilesLines
* 5650 - support a second OS: sosoKartik Agaram2019-09-141-8/+10
* 5649Kartik Agaram2019-09-141-4/+4
* 5647 - experimental support for swapping OSKartik Agaram2019-09-111-4/+4
* 5594 - rename 'desugar' to 'sigils'Kartik Agaram2019-08-311-1/+1
* Merge branch 'master' into desugarKartik Agaram2019-08-251-0/+3
|\
| * 5512 - don't rebuild apps by defaultKartik Agaram2019-08-141-1/+4
* | skip building apps when running a single testKartik Agaram2019-08-251-1/+1
* | .Kartik Agaram2019-08-131-0/+8
|/
* 5485 - promote SubX to top-levelKartik Agaram2019-07-271-0/+141
* 4216 - include simpler alternative to build scriptKartik K. Agaram2018-03-121-149/+0
* 4204Kartik K. Agaram2018-02-151-2/+2
* 3967Kartik K. Agaram2017-07-101-2/+3
* 3846Kartik K. Agaram2017-05-061-1/+1
* 3835Kartik K. Agaram2017-04-181-9/+3
* 3834Kartik K. Agaram2017-04-181-0/+2
* 3815Kartik K. Agaram2017-04-061-1/+1
* 3807Kartik K. Agaram2017-03-311-3/+3
* 3712Kartik K. Agaram2016-12-261-15/+15
* 3680Kartik K. Agaram2016-11-171-16/+13
* 3551Kartik K. Agaram2016-10-221-1/+4
* 3548Kartik K. Agaram2016-10-221-1/+4
* 3546Kartik K. Agaram2016-10-221-0/+4
* 3540Kartik K. Agaram2016-10-211-2/+2
* 3538Kartik K. Agaram2016-10-201-1/+6
* 3534Kartik K. Agaram2016-10-201-33/+22
* 3533Kartik K. Agaram2016-10-201-13/+35
* 3512Kartik K. Agaram2016-10-171-1/+1
* 3509Kartik K. Agaram2016-10-161-2/+3
* 3493Kartik K. Agaram2016-10-101-1/+1
* 3488 -Kartik K. Agaram2016-10-081-1/+1
* 3487Kartik K. Agaram2016-10-081-1/+1
* 3475Kartik K. Agaram2016-10-071-22/+20
* 3474Kartik K. Agaram2016-10-071-20/+27
* 3459Kartik K. Agaram2016-10-071-2/+2
* 3452Kartik K. Agaram2016-10-061-21/+23
* 3450Kartik K. Agaram2016-10-061-2/+6
* 3447 - drop dependence on GNU makeKartik K. Agaram2016-10-061-0/+117
* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
## clicking on sandbox results to 'fix' them and turn sandboxes into tests

scenario sandbox-click-on-result-toggles-color-to-green [
  local-scope
  trace-until 100/app  # trace too long
  assume-screen 50/width, 20/height
  # basic recipe
  assume-resources [
    [lesson/recipes.mu] <- [
      |recipe foo [|
      |  reply 4|
      |]|
    ]
  ]
  env:&:environment <- new-programming-environment resources, screen, [foo]
  render-all screen, env, render
  # run it
  assume-console [
    press F4
  ]
  event-loop screen, console, env, resources
  screen-should-contain [
    .                               run (F4)           .
    .                                                  .
    .──────────────────────────────────────────────────.
    .0   edit           copy           delete          .
    .foo                                               .
    .4                                                 .
    .──────────────────────────────────────────────────.
    .                                                  .
  ]
  # click on the '4' in the result
  $clear-trace
  assume-console [
    left-click 5, 21
  ]
  run [
    event-loop screen, console, env, resources
  ]
  # color toggles to green
  screen-should-contain-in-color 2/green, [
    .                                                  .
    .                                                  .
    .                                                  .
    .                                                  .
    .                                                  .
    .4                                                 .
    .                                                  .
  ]
  # don't render entire sandbox side
  check-trace-count-for-label-lesser-than 250, [print-character]  # say 5 sandbox lines
  # cursor should remain unmoved
  run [
    cursor:char <- copy 9251/    print screen, cursor
  ]
  screen-should-contain [
    .                               run (F4)           .
    .                                                 .
    .──────────────────────────────────────────────────.
    .0   edit           copy           delete          .
    .foo                                               .
    .4                                                 .
    .──────────────────────────────────────────────────.
    .                                                  .
  ]
  # now change the result
  assume-resources [
    [lesson/recipes.mu] <- [
      |recipe foo [|
      |  reply 3|
      |]|
    ]
  ]
  # then rerun
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env, resources
  ]
  # result turns red
  screen-should-contain-in-color 1/red, [
    .                                                  .
    .                                                  .
    .                                                  .
    .                                                  .
    .                                                  .
    .3                                                 .
    .                                                  .
  ]
]

# this requires tracking a couple more things
container sandbox [
  response-starting-row-on-screen:num
  expected-response:text
]

# include expected response when saving or restoring a sandbox
before <end-save-sandbox> [
  {
    expected-response:text <- get *sandbox, expected-response:offset
    break-unless expected-response
    filename <- append filename, [.out]
    resources <- dump resources, filename, expected-response
  }
]

before <end-restore-sandbox> [
  {
    filename <- append filename, [.out]
    contents <- slurp resources, filename
    break-unless contents
    *curr <- put *curr, expected-response:offset, contents
  }
]

# clicks on sandbox responses save it as 'expected'
after <global-touch> [
  # check if it's inside the output of any sandbox
  {
    sandbox-left-margin:num <- get *current-sandbox, left:offset
    click-column:num <- get t, column:offset
    on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin
    break-unless on-sandbox-side?
    first-sandbox:&:sandbox <- get *env, sandbox:offset
    break-unless first-sandbox
    first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset
    click-row:num <- get t, row:offset
    below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins
    break-unless below-sandbox-editor?
    # identify the sandbox whose output is being clicked on
    sandbox:&:sandbox, sandbox-index:num <- find-click-in-sandbox-output env, click-row
    break-unless sandbox
    # update it
    sandbox <- toggle-expected-response sandbox
    # minimal update to disk
    save-sandbox resources, sandbox, sandbox-index
    # minimal update to screen
    sandbox-right-margin:num <- get *current-sandbox, right:offset
    row:num <- render-sandbox-response screen, sandbox, sandbox-left-margin, sandbox-right-margin
    {
      height:num <- screen-height screen
      at-bottom?:bool <- greater-or-equal row, height
      break-if at-bottom?
      draw-horizontal screen, row, sandbox-left-margin, sandbox-right-margin
    }
    screen <- update-cursor screen, current-sandbox, env
    loop +next-event
  }
]

def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox, sandbox-index:num [
  local-scope
  load-inputs
  # assert click-row >= sandbox.starting-row-on-screen
  sandbox:&:sandbox <- get *env, sandbox:offset
  start:num <- get *sandbox, starting-row-on-screen:offset
  clicked-on-sandboxes?:bool <- greater-or-equal click-row, start
  assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor]
  # while click-row < sandbox.next-sandbox.starting-row-on-screen
  sandbox-index <- copy 0
  {
    next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset
    break-unless next-sandbox
    next-start:num <- get *next-sandbox, starting-row-on-screen:offset
    found?:bool <- lesser-than click-row, next-start
    break-if found?
    sandbox <- copy next-sandbox
    sandbox-index <- add sandbox-index, 1
    loop
  }
  # return sandbox if click is in its output region
  response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset
  return-unless response-starting-row, null/no-click-in-sandbox-output, 0/sandbox-index
  click-in-response?:bool <- greater-or-equal click-row, response-starting-row
  return-unless click-in-response?, null/no-click-in-sandbox-output, 0/sandbox-index
  return sandbox, sandbox-index
]

def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [
  local-scope
  load-inputs
  expected-response:text <- get *sandbox, expected-response:offset
  {
    # if expected-response is set, reset
    break-unless expected-response
    *sandbox <- put *sandbox, expected-response:offset, null
  }
  {
    # if not, set expected response to the current response
    break-if expected-response
    response:text <- get *sandbox, response:offset
    *sandbox <- put *sandbox, expected-response:offset, response
  }
]

# when rendering a sandbox, color it in red/green if expected response exists
after <render-sandbox-response> [
  {
    break-unless sandbox-response
    *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row
    row <- render-sandbox-response screen, sandbox, left, right
    jump +render-sandbox-end
  }
]

def render-sandbox-response screen:&:screen, sandbox:&:sandbox, left:num, right:num -> row:num, screen:&:screen [
  local-scope
  load-inputs
  sandbox-response:text <- get *sandbox, response:offset
  expected-response:text <- get *sandbox, expected-response:offset
  row:num <- get *sandbox response-starting-row-on-screen:offset
  {
    break-if expected-response
    row <- render-text screen, sandbox-response, left, right, 245/grey, row
    return
  }
  response-is-expected?:bool <- equal expected-response, sandbox-response
  {
    break-if response-is-expected?
    row <- render-text screen, sandbox-response, left, right, 1/red, row
  }
  {
    break-unless response-is-expected?:bool
    row <- render-text screen, sandbox-response, left, right, 2/green, row
  }
]

before <end-render-sandbox-reset-hidden> [
  *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0
]