about summary refs log tree commit diff stats
path: root/html/edit/011-errors.mu.html
blob: 91e48c57e86277fe597ed65f9a2d5fede437f057 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
generated by cgit-pink 1.4.1-2-gfad0 (git 2.36.2.497.gbbea4dcf42) at 2024-08-06 03:12:51 +0000
 


>
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - edit/011-errors.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="none">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 12pt; font-size: 1em; }
.muData { color: #ffff00; }
.muControl { color: #c0a020; }
.Special { color: #c00000; }
.Delimiter { color: #800080; }
.Comment { color: #9090ff; }
.Constant { color: #00a0a0; }
.SalientComment { color: #00ffff; }
.muRecipe { color: #ff8700; }
.muScenario { color: #00af00; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="SalientComment">## handling malformed programs</span>

<span class="muData">container</span> environment [
  recipe-errors:text
]

<span class="Comment"># copy code from recipe editor, persist to disk, load, save any errors</span>
<span class="muRecipe">def!</span> update-recipes env:&amp;:environment, screen:&amp;:screen<span class="muRecipe"> -&gt; </span>errors-found?:bool, env:&amp;:environment, screen:&amp;:screen [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  recipes:&amp;:editor <span class="Special">&lt;-</span> get *env, <span class="Constant">recipes:offset</span>
  in:text <span class="Special">&lt;-</span> editor-contents recipes
  save <span class="Constant">[recipes.mu]</span>, in
  recipe-errors:text <span class="Special">&lt;-</span> reload in
  *env <span class="Special">&lt;-</span> put *env, <span class="Constant">recipe-errors:offset</span>, recipe-errors
  <span class="Comment"># if recipe editor has errors, stop</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> recipe-errors
    update-status screen, <span class="Constant">[errors found     ]</span>, <span class="Constant">1/red</span>
    errors-found? <span class="Special">&lt;-</span> copy <span class="Constant">1/true</span>
    <span class="muControl">return</span>
  <span class="Delimiter">}</span>
  errors-found? <span class="Special">&lt;-</span> copy <span class="Constant">0/false</span>
]

<span class="muRecipe">before</span> <span class="Constant">&lt;render-components-end&gt;</span> [
  trace<span class="Constant"> 11</span>, <span class="Constant">[app]</span>, <span class="Constant">[render status]</span>
  recipe-errors:text <span class="Special">&lt;-</span> get *env, <span class="Constant">recipe-errors:offset</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> recipe-errors
    update-status screen, <span class="Constant">[errors found     ]</span>, <span class="Constant">1/red</span>
  <span class="Delimiter">}</span>
]

<span class="muRecipe">before</span> <span class="Constant">&lt;render-recipe-components-end&gt;</span> [
  <span class="Delimiter">{</span>
    recipe-errors:text <span class="Special">&lt;-</span> get *env, <span class="Constant">recipe-errors:offset</span>
    <span class="muControl">break-unless</span> recipe-errors
    row, screen <span class="Special">&lt;-</span> render-text screen, recipe-errors, left, right, <span class="Constant">1/red</span>, row
  <span class="Delimiter">}</span>
]

<span class="muData">container</span> environment [
  error-index:num  <span class="Comment"># index of first sandbox with an error (or -1 if none)</span>
]

<span class="muRecipe">after</span> <span class="Constant">&lt;programming-environment-initialization&gt;</span> [
  *result <span class="Special">&lt;-</span> put *result, <span class="Constant">error-index:offset</span>,<span class="Constant"> -1</span>
]

<span class="muRecipe">after</span> <span class="Constant">&lt;run-sandboxes-begin&gt;</span> [
  *env <span class="Special">&lt;-</span> put *env, <span class="Constant">error-index:offset</span>,<span class="Constant"> -1</span>
]

<span class="muRecipe">before</span> <span class="Constant">&lt;run-sandboxes-end&gt;</span> [
  <span class="Delimiter">{</span>
    error-index:num <span class="Special">&lt;-</span> get *env, <span class="Constant">error-index:offset</span>
    sandboxes-completed-successfully?:bool <span class="Special">&lt;-</span> equal error-index,<span class="Constant"> -1</span>
    <span class="muControl">break-if</span> sandboxes-completed-successfully?
    errors-found? <span class="Special">&lt;-</span> copy <span class="Constant">1/true</span>
  <span class="Delimiter">}</span>
]

<span class="muRecipe">before</span> <span class="Constant">&lt;render-components-end&gt;</span> [
  <span class="Delimiter">{</span>
    <span class="muControl">break-if</span> recipe-errors
    error-index:num <span class="Special">&lt;-</span> get *env, <span class="Constant">error-index:offset</span>
    sandboxes-completed-successfully?:bool <span class="Special">&lt;-</span> equal error-index,<span class="Constant"> -1</span>
    <span class="muControl">break-if</span> sandboxes-completed-successfully?
    error-index-text:text <span class="Special">&lt;-</span> to-text error-index
    status:text <span class="Special">&lt;-</span> interpolate <span class="Constant">[errors found (_)    ]</span>, error-index-text
    update-status screen, status, <span class="Constant">1/red</span>
  <span class="Delimiter">}</span>
]

<span class="muData">container</span> sandbox [
  errors:text
]

<span class="muRecipe">def!</span> update-sandbox sandbox:&amp;:sandbox, env:&amp;:environment, idx:num<span class="muRecipe"> -&gt; </span>sandbox:&amp;:sandbox, env:&amp;:environment [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  data:text <span class="Special">&lt;-</span> get *sandbox, <span class="Constant">data:offset</span>
  response:text, errors:text, fake-screen:&amp;:screen, trace:text, completed?:bool <span class="Special">&lt;-</span> run-sandboxed data
  *sandbox <span class="Special">&lt;-</span> put *sandbox, <span class="Constant">response:offset</span>, response
  *sandbox <span class="Special">&lt;-</span> put *sandbox, <span class="Constant">errors:offset</span>, errors
  *sandbox <span class="Special">&lt;-</span> put *sandbox, <span class="Constant">screen:offset</span>, fake-screen
  *sandbox <span class="Special">&lt;-</span> put *sandbox, <span class="Constant">trace:offset</span>, trace
  <span class="Delimiter">{</span>
    <span class="muControl">break-if</span> errors
    <span class="muControl">break-if</span> completed?:bool
    errors <span class="Special">&lt;-</span> new <span class="Constant">[took too long!</span>
<span class="Constant">]</span>
    *sandbox <span class="Special">&lt;-</span> put *sandbox, <span class="Constant">errors:offset</span>, errors
  <span class="Delimiter">}</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> errors
    error-index:num <span class="Special">&lt;-</span> get *env, <span class="Constant">error-index:offset</span>
    error-not-set?:bool <span class="Special">&lt;-</span> equal error-index,<span class="Constant"> -1</span>
    <span class="muControl">break-unless</span> error-not-set?
    *env <span class="Special">&lt;-</span> put *env, <span class="Constant">error-index:offset</span>, idx
  <span class="Delimiter">}</span>
]

<span class="Comment"># make sure we render any trace</span>
<span class="muRecipe">after</span> <span class="Constant">&lt;render-sandbox-trace-done&gt;</span> [
  <span class="Delimiter">{</span>
    sandbox-errors:text <span class="Special">&lt;-</span> get *sandbox, <span class="Constant">errors:offset</span>
    <span class="muControl">break-unless</span> sandbox-errors
    *sandbox <span class="Special">&lt;-</span> put *sandbox, <span class="Constant">response-starting-row-on-screen:offset</span>,<span class="Constant"> 0</span>  <span class="Comment"># no response</span>
    row, screen <span class="Special">&lt;-</span> render-text screen, sandbox-errors, left, right, <span class="Constant">1/red</span>, row
    <span class="Comment"># don't try to print anything more for this sandbox</span>
    <span class="muControl">jump</span> <span class="Constant">+render-sandbox-end</span>
  <span class="Delimiter">}</span>
]

<span class="muScenario">scenario</span> run-shows-errors-in-get [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span>
  recipes:text <span class="Special">&lt;-</span> new <span class="Constant">[ </span>
<span class="Constant">recipe foo [</span>
<span class="Constant">  get 123:num, foo:offset</span>
<span class="Constant">]</span>]
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span>
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  screen-should-contain [
   <span class="Constant"> .  errors found                                                                   run (F4)           .</span>
   <span class="Constant"> .                                                  ╎foo                                              .</span>
   <span class="Constant"> .recipe foo [                                      ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .  get 123:num, foo:offset                         ╎                                                 .</span>
   <span class="Constant"> .]                                                 ╎                                                 .</span>
   <span class="Constant"> .foo: unknown element 'foo' in container 'number'  ╎                                                 .</span>
   <span class="Constant"> .foo: first ingredient of 'get' should be a contai↩╎                                                 .</span>
   <span class="Constant"> .ner, but got '123:num'                            ╎                                                 .</span>
   <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎                                                 .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
  screen-should-contain-in-color <span class="Constant">1/red</span>, [
   <span class="Constant"> .  errors found                                                                                      .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .foo: unknown element 'foo' in container 'number'                                                    .</span>
   <span class="Constant"> .foo: first ingredient of 'get' should be a contai                                                   .</span>
   <span class="Constant"> .ner, but got '123:num'                                                                              .</span>
   <span class="Constant"> .                                                                                                    .</span>
  ]
]

<span class="muScenario">scenario</span> run-updates-status-with-first-erroneous-sandbox [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span>
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span>
  assume-console [
    left-click<span class="Constant"> 3</span>,<span class="Constant"> 80</span>
    <span class="Comment"># create invalid sandbox 1</span>
    type <span class="Constant">[get foo, x:offset]</span>
    press F4
    <span class="Comment"># create invalid sandbox 0</span>
    type <span class="Constant">[get foo, x:offset]</span>
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  <span class="Comment"># status line shows that error is in first sandbox</span>
  screen-should-contain [
   <span class="Constant"> .  errors found (0)                                                               run (F4)           .</span>
  ]
]

<span class="muScenario">scenario</span> run-updates-status-with-first-erroneous-sandbox-2 [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span>
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[]</span>
  assume-console [
    left-click<span class="Constant"> 3</span>,<span class="Constant"> 80</span>
    <span class="Comment"># create invalid sandbox 2</span>
    type <span class="Constant">[get foo, x:offset]</span>
    press F4
    <span class="Comment"># create invalid sandbox 1</span>
    type <span class="Constant">[get foo, x:offset]</span>
    press F4
    <span class="Comment"># create valid sandbox 0</span>
    type <span class="Constant">[add 2, 2]</span>
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  <span class="Comment"># status line shows that error is in second sandbox</span>
  screen-should-contain [
   <span class="Constant"> .  errors found (1)                                                               run (F4)           .</span>
  ]
]

<span class="muScenario">scenario</span> run-hides-errors-from-past-sandboxes [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span>
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, <span class="Constant">[]</span>, <span class="Constant">[get foo, x:offset]</span>  <span class="Comment"># invalid</span>
  assume-console [
    press F4  <span class="Comment"># generate error</span>
  ]
  run [
    event-loop screen, console, env
  ]
  assume-console [
    left-click<span class="Constant"> 3</span>,<span class="Constant"> 58</span>
    press ctrl-k
    type <span class="Constant">[add 2, 2]</span>  <span class="Comment"># valid code</span>
    press F4  <span class="Comment"># update sandbox</span>
  ]
  run [
    event-loop screen, console, env
  ]
  <span class="Comment"># error should disappear</span>
  screen-should-contain [
   <span class="Constant"> .                                                                                 run (F4)           .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
<span class="Constant">    .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .                                                  ╎0   edit          copy            delete         .</span>
   <span class="Constant"> .                                                  ╎add 2, 2                                         .</span>
   <span class="Constant"> .                                                  ╎4                                                .</span>
   <span class="Constant"> .                                                  ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
]

<span class="muScenario">scenario</span> run-updates-errors-for-shape-shifting-recipes [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span>
  <span class="Comment"># define a shape-shifting recipe with an error</span>
  recipes:text <span class="Special">&lt;-</span> new <span class="Constant">[recipe foo x:_elem -&gt; z:_elem [</span>
<span class="Constant">local-scope</span>
<span class="Constant">load-ingredients</span>
<span class="Constant">y:&amp;:num &lt;- copy 0</span>
<span class="Constant">z &lt;- add x, y</span>
<span class="Constant">]</span>]
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, recipes, <span class="Constant">[foo 2]</span>
  assume-console [
    press F4
  ]
  event-loop screen, console, env
  screen-should-contain [
   <span class="Constant"> .  errors found (0)                                                               run (F4)           .</span>
   <span class="Constant"> .recipe foo x:_elem -&gt; z:_elem [                   ╎                                                 .</span>
   <span class="Constant"> .local-scope                                       ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .load-ingredients                                  ╎0   edit          copy            delete         .</span>
   <span class="Constant"> .y:&amp;:num &lt;- copy 0                                 ╎foo 2                                            .</span>
   <span class="Constant"> .z &lt;- add x, y                                     ╎foo_2: 'add' requires number ingredients, but go↩.</span>
   <span class="Constant"> .]                                                 ╎t 'y'                                            .</span>
<span class="Constant">    .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
  <span class="Comment"># now rerun everything</span>
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  <span class="Comment"># error should remain unchanged</span>
  screen-should-contain [
   <span class="Constant"> .  errors found (0)                                                               run (F4)           .</span>
   <span class="Constant"> .recipe foo x:_elem -&gt; z:_elem [                   ╎                                                 .</span>
   <span class="Constant"> .local-scope                                       ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .load-ingredients                                  ╎0   edit          copy            delete         .</span>
   <span class="Constant"> .y:&amp;:num &lt;- copy 0                                 ╎foo 2                                            .</span>
   <span class="Constant"> .z &lt;- add x, y                                     ╎foo_3: 'add' requires number ingredients, but go↩.</span>
   <span class="Constant"> .]                                                 ╎t 'y'                                            .</span>
<span class="Constant">    .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
]

<span class="muScenario">scenario</span> run-avoids-spurious-errors-on-reloading-shape-shifting-recipes [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span>
  <span class="Comment"># overload a well-known shape-shifting recipe</span>
  recipes:text <span class="Special">&lt;-</span> new <span class="Constant">[recipe length l:&amp;:list:_elem -&gt; n:num [</span>
<span class="Constant">]</span>]
  <span class="Comment"># call code that uses other variants of it, but not it itself</span>
  sandbox:text <span class="Special">&lt;-</span> new <span class="Constant">[x:&amp;:list:num &lt;- copy 0</span>
<span class="Constant">to-text x]</span>
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, recipes, sandbox
  <span class="Comment"># run it once</span>
  assume-console [
    press F4
  ]
  event-loop screen, console, env
  <span class="Comment"># no errors anywhere on screen (can't check anything else, since to-text will return an address)</span>
  screen-should-contain-in-color <span class="Constant">1/red</span>, [
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                &lt;-                                  .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
  ]
  <span class="Comment"># rerun everything</span>
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  <span class="Comment"># still no errors</span>
  screen-should-contain-in-color <span class="Constant">1/red</span>, [
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                &lt;-                                  .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
  ]
]

<span class="muScenario">scenario</span> run-shows-missing-type-errors [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span>
  recipes:text <span class="Special">&lt;-</span> new <span class="Constant">[ </span>
<span class="Constant">recipe foo [</span>
<span class="Constant">  x &lt;- copy 0</span>
<span class="Constant">]</span>]
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span>
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  screen-should-contain [
   <span class="Constant"> .  errors found                                                                   run (F4)           .</span>
   <span class="Constant"> .                                                  ╎foo                                              .</span>
   <span class="Constant"> .recipe foo [                                      ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .  x &lt;- copy 0                                     ╎                                                 .</span>
   <span class="Constant"> .]                                                 ╎                                                 .</span>
   <span class="Constant"> .foo: missing type for 'x' in 'x &lt;- copy 0'        ╎                                                 .</span>
  ]
]

<span class="muScenario">scenario</span> run-shows-unbalanced-bracket-errors [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span>
  <span class="Comment"># recipe is incomplete (unbalanced '[')</span>
  recipes:text <span class="Special">&lt;-</span> new <span class="Constant">[ </span>
<span class="Constant">recipe foo \\[</span>
<span class="Constant">  x &lt;- copy 0</span>
<span class="Constant">]</span>
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span>
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  screen-should-contain [
   <span class="Constant"> .  errors found                                                                   run (F4)           .</span>
   <span class="Constant"> .                                                  ╎foo                                              .</span>
   <span class="Constant"> .recipe foo \\[                                      ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .  x &lt;- copy 0                                     ╎                                                 .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
   <span class="Constant"> .9: unbalanced '\\[' for recipe                      ╎                                                 .</span>
   <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎                                                 .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
]

<span class="muScenario">scenario</span> run-shows-get-on-non-container-errors [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span>
  recipes:text <span class="Special">&lt;-</span> new <span class="Constant">[ </span>
<span class="Constant">recipe foo [</span>
<span class="Constant">  local-scope</span>
<span class="Constant">  x:&amp;:point &lt;- new point:type</span>
<span class="Constant">  get x:&amp;:point, 1:offset</span>
<span class="Constant">]</span>]
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span>
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  screen-should-contain [
   <span class="Constant"> .  errors found                                                                   run (F4)           .</span>
   <span class="Constant"> .                                                  ╎foo                                              .</span>
   <span class="Constant"> .recipe foo [                                      ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .  local-scope                                     ╎                                                 .</span>
   <span class="Constant"> .  x:&amp;:point &lt;- new point:type                     ╎                                                 .</span>
   <span class="Constant"> .  get x:&amp;:point, 1:offset                         ╎                                                 .</span>
   <span class="Constant"> .]                                                 ╎                                                 .</span>
   <span class="Constant"> .foo: first ingredient of 'get' should be a contai↩╎                                                 .</span>
   <span class="Constant"> .ner, but got 'x:&amp;:point'                          ╎                                                 .</span>
   <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎                                                 .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
]

<span class="muScenario">scenario</span> run-shows-non-literal-get-argument-errors [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span>
  recipes:text <span class="Special">&lt;-</span> new <span class="Constant">[ </span>
<span class="Constant">recipe foo [</span>
<span class="Constant">  local-scope</span>
<span class="Constant">  x:num &lt;- copy 0</span>
<span class="Constant">  y:&amp;:point &lt;- new point:type</span>
<span class="Constant">  get *y:&amp;:point, x:num</span>
<span class="Constant">]</span>]
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span>
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  screen-should-contain [
   <span class="Constant"> .  errors found                                                                   run (F4)           .</span>
   <span class="Constant"> .                                                  ╎foo                                              .</span>
   <span class="Constant"> .recipe foo [                                      ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .  local-scope                                     ╎                                                 .</span>
   <span class="Constant"> .  x:num &lt;- copy 0                                 ╎                                                 .</span>
   <span class="Constant"> .  y:&amp;:point &lt;- new point:type                     ╎                                                 .</span>
   <span class="Constant"> .  get *y:&amp;:point, x:num                           ╎                                                 .</span>
   <span class="Constant"> .]                                                 ╎                                                 .</span>
   <span class="Constant"> .foo: second ingredient of 'get' should have type ↩╎                                                 .</span>
   <span class="Constant"> .'offset', but got 'x:num'                         ╎                                                 .</span>
   <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎                                                 .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
]

<span class="muScenario">scenario</span> run-shows-errors-everytime [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  <span class="Comment"># try to run a file with an error</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">15/height</span>
  recipes:text <span class="Special">&lt;-</span> new <span class="Constant">[ </span>
<span class="Constant">recipe foo [</span>
<span class="Constant">  local-scope</span>
<span class="Constant">  x:num &lt;- copy y:num</span>
<span class="Constant">]</span>]
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span>
  assume-console [
    press F4
  ]
  event-loop screen, console, env
  screen-should-contain [
   <span class="Constant"> .  errors found                                                                   run (F4)           .</span>
   <span class="Constant"> .                                                  ╎foo                                              .</span>
   <span class="Constant"> .recipe foo [                                      ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .  local-scope                                     ╎                                                 .</span>
   <span class="Constant"> .  x:num &lt;- copy y:num                             ╎                                                 .</span>
   <span class="Constant"> .]                                                 ╎                                                 .</span>
   <span class="Constant"> .foo: tried to read ingredient 'y' in 'x:num &lt;- co↩╎                                                 .</span>
   <span class="Constant"> .py y:num' but it hasn't been written to yet       ╎                                                 .</span>
   <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎                                                 .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
  <span class="Comment"># rerun the file, check for the same error</span>
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  screen-should-contain [
   <span class="Constant"> .  errors found                                                                   run (F4)           .</span>
   <span class="Constant"> .                                                  ╎foo                                              .</span>
   <span class="Constant"> .recipe foo [                                      ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .  local-scope                                     ╎                                                 .</span>
   <span class="Constant"> .  x:num &lt;- copy y:num                             ╎                                                 .</span>
   <span class="Constant"> .]                                                 ╎                                                 .</span>
   <span class="Constant"> .foo: tried to read ingredient 'y' in 'x:num &lt;- co↩╎                                                 .</span>
   <span class="Constant"> .py y:num' but it hasn't been written to yet       ╎                                                 .</span>
   <span class="Constant"> .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎                                                 .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
]

<span class="muScenario">scenario</span> run-instruction-and-print-errors [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span>
  <span class="Comment"># right editor contains an illegal instruction</span>
  sandbox:text <span class="Special">&lt;-</span> new <span class="Constant">[get 1234:num, foo:offset]</span>
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, <span class="Constant">[]</span>, sandbox
  <span class="Comment"># run the code in the editors</span>
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  <span class="Comment"># check that screen prints error message in red</span>
  screen-should-contain [
   <span class="Constant"> .  errors found (0)                                                               run (F4)           .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
<span class="Constant">    .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .                                                  ╎0   edit          copy            delete         .</span>
   <span class="Constant"> .                                                  ╎get 1234:num, foo:offset                         .</span>
   <span class="Constant"> .                                                  ╎unknown element 'foo' in container 'number'      .</span>
   <span class="Constant"> .                                                  ╎first ingredient of 'get' should be a container,↩.</span>
   <span class="Constant"> .                                                  ╎ but got '1234:num'                              .</span>
   <span class="Constant"> .                                                  ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
  screen-should-contain-in-color <span class="Constant">7/white</span>, [
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                   get 1234:num, foo:offset                         .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
  ]
  screen-should-contain-in-color <span class="Constant">1/red</span>, [
   <span class="Constant"> .  errors found (0)                                                                                  .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                   unknown element 'foo' in container 'number'      .</span>
   <span class="Constant"> .                                                   first ingredient of 'get' should be a container, .</span>
   <span class="Constant"> .                                                    but got '1234:num'                              .</span>
   <span class="Constant"> .                                                                                                    .</span>
  ]
  screen-should-contain-in-color <span class="Constant">245/grey</span>, [
   <span class="Constant"> .                                                                                                    .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
<span class="Constant">    .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
   <span class="Constant"> .                                                  ╎                                                ↩.</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
   <span class="Constant"> .                                                  ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
]

<span class="muScenario">scenario</span> run-instruction-and-print-errors-only-once [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span>
  <span class="Comment"># right editor contains an illegal instruction</span>
  sandbox:text <span class="Special">&lt;-</span> new <span class="Constant">[get 1234:num, foo:offset]</span>
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, <span class="Constant">[]</span>, sandbox
  <span class="Comment"># run the code in the editors multiple times</span>
  assume-console [
    press F4
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  <span class="Comment"># check that screen prints error message just once</span>
  screen-should-contain [
   <span class="Constant"> .  errors found (0)                                                               run (F4)           .</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
<span class="Constant">    .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .                                                  ╎0   edit          copy            delete         .</span>
   <span class="Constant"> .                                                  ╎get 1234:num, foo:offset                         .</span>
   <span class="Constant"> .                                                  ╎unknown element 'foo' in container 'number'      .</span>
   <span class="Constant"> .                                                  ╎first ingredient of 'get' should be a container,↩.</span>
   <span class="Constant"> .                                                  ╎ but got '1234:num'                              .</span>
   <span class="Constant"> .                                                  ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
]

<span class="muScenario">scenario</span> sandbox-can-handle-infinite-loop [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">20/height</span>
  <span class="Comment"># left editor is empty</span>
  recipes:text <span class="Special">&lt;-</span> new <span class="Constant">[recipe foo [</span>
<span class="Constant">  {</span>
<span class="Constant">    loop</span>
<span class="Constant">  }</span>
<span class="Constant">]</span>]
  <span class="Comment"># right editor contains an instruction</span>
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, recipes, <span class="Constant">[foo]</span>
  <span class="Comment"># run the sandbox</span>
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env
  ]
  screen-should-contain [
   <span class="Constant"> .  errors found (0)                                                               run (F4)           .</span>
   <span class="Constant"> .recipe foo [                                      ╎                                                 .</span>
   <span class="Constant"> .  {                                               ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .    loop                                          ╎0   edit          copy            delete         .</span>
   <span class="Constant"> .  }                                               ╎foo                                              .</span>
   <span class="Constant"> .]                                                 ╎took too long!                                   .</span>
<span class="Constant">    .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .                                                  ╎                                                 .</span>
  ]
]

<span class="muScenario">scenario</span> sandbox-with-errors-shows-trace [
  <span class="Constant">local-scope</span>
  trace-until <span class="Constant">100/app</span>  <span class="Comment"># trace too long</span>
  assume-screen <span class="Constant">100/width</span>, <span class="Constant">10/height</span>
  <span class="Comment"># generate a stash and a error</span>
  recipes:text <span class="Special">&lt;-</span> new <span class="Constant">[recipe foo [</span>
<span class="Constant">local-scope</span>
<span class="Constant">a:num &lt;- next-ingredient</span>
<span class="Constant">b:num &lt;- next-ingredient</span>
<span class="Constant">stash [dividing by]</span>, b
_, c:num <span class="Special">&lt;-</span> divide-with-remainder a, b
<span class="muControl">reply</span> b
]]
  env:&amp;:environment <span class="Special">&lt;-</span> new-programming-environment screen, recipes, <span class="Constant">[foo 4, 0]</span>
  <span class="Comment"># run</span>
  assume-console [
    press F4
  ]
  event-loop screen, console, env
  <span class="Comment"># screen prints error message</span>
  screen-should-contain [
   <span class="Constant"> .  errors found (0)                                                               run (F4)           .</span>
   <span class="Constant"> .recipe foo [                                      ╎                                                 .</span>
   <span class="Constant"> .local-scope                                       ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .a:num &lt;- next-ingredient                          ╎0   edit          copy            delete         .</span>
   <span class="Constant"> .b:num &lt;- next-ingredient                          ╎foo 4, 0                                         .</span>
   <span class="Constant"> .stash [dividing by], b                            ╎foo: divide by zero in '_, c:num &lt;- divide-with-↩.</span>
   <span class="Constant"> ._, c:num &lt;- divide-with-remainder a, b            ╎remainder a, b'                                  .</span>
   <span class="Constant"> .reply b                                           ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .]                                                 ╎                                                 .</span>
  ]
  <span class="Comment"># click on the call in the sandbox</span>
  assume-console [
    left-click<span class="Constant"> 4</span>,<span class="Constant"> 55</span>
  ]
  run [
    event-loop screen, console, env
  ]
  <span class="Comment"># screen should expand trace</span>
  screen-should-contain [
   <span class="Constant"> .  errors found (0)                                                               run (F4)           .</span>
   <span class="Constant"> .recipe foo [                                      ╎                                                 .</span>
   <span class="Constant"> .local-scope                                       ╎─────────────────────────────────────────────────.</span>
   <span class="Constant"> .a:num &lt;- next-ingredient                          ╎0   edit          copy            delete         .</span>
   <span class="Constant"> .b:num &lt;- next-ingredient                          ╎foo 4, 0                                         .</span>
   <span class="Constant"> .stash [dividing by], b                            ╎dividing by 0                                    .</span>
   <span class="Constant"> ._, c:num &lt;- divide-with-remainder a, b            ╎14 instructions run                              .</span>
   <span class="Constant"> .reply b                                           ╎foo: divide by zero in '_, c:num &lt;- divide-with-↩.</span>
   <span class="Constant"> .]                                                 ╎remainder a, b'                                  .</span>
<span class="Constant">    .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.</span>
  ]
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->