/
testing and debugging 3 no interpolate.jl
1366 lines (1063 loc) · 33.1 KB
/
testing and debugging 3 no interpolate.jl
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
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
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### A Pluto.jl notebook ###
# v0.14.4
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : missing
el
end
end
# ╔═╡ 285809d3-9a72-4eb6-9ebc-ddefd459ab6a
using HypertextLiteral
# ╔═╡ b16145b1-66da-4d96-a648-9e083c407e9a
using PlutoUI
# ╔═╡ 5c2cae00-cfad-43b8-9c36-3380809bb6bc
using Plots
# ╔═╡ ab02837b-79ec-40d7-bff1-c1d2dd7362ef
md"""
# PlutoTest.jl
"""
# ╔═╡ 5b801f8b-1320-4208-8819-571d0a6c8c36
md"""
This notebook introduces **visual testing**:
"""
# ╔═╡ c19b881b-24de-4628-8adc-4b1635dba543
# ╔═╡ 779a7207-c508-4764-89b0-bfae44d0765c
# ╔═╡ e46cf3e0-aa15-4c17-a925-3e9fc5109d54
Hannes = let
url = "https://user-images.githubusercontent.com/6933510/116753174-fa40ab80-aa06-11eb-94d7-88f4171970b2.jpeg"
data = read(download(url))
PlutoUI.Show(MIME"image/jpg"(), data)
end;
# ╔═╡ 5b70aaf1-9623-4f55-b055-4263ed8be31d
Floep = let
url = "https://user-images.githubusercontent.com/6933510/116753861-142ebe00-aa08-11eb-8ce8-684af1098935.jpeg"
data = read(download(url))
PlutoUI.Show(MIME"image/jpg"(), data)
end;
# ╔═╡ bf2abe01-6ae0-4066-8704-12f64e04511b
friends = Any[Hannes, Floep];
# ╔═╡ fd8428a3-9fa3-471a-8b2d-5bbb8fdb3137
is_good_boy(x) = true
# ╔═╡ 56347b7e-5007-45f8-8f6d-8ac8cc719637
md"""
Tests have _time-travel_ functionality built in! **Click on the tests above.**
"""
# ╔═╡ e5782dab-711b-4386-bc6a-8b2853b3f868
md"""
### Time travel
"""
# ╔═╡ 85c4575f-8466-4a42-a7b5-1b3346f60e38
md"""
This notebook contains **visual debugging**:
"""
# ╔═╡ ec1fd70a-d92a-4688-98b2-135879f07141
md"""
### (You need `Pluto#main` to run this notebook)
"""
# ╔═╡ c763ed72-82c9-445c-a8f7-a0c40982e4d9
TableOfContents()
# ╔═╡ 80b2fb3f-94b2-4024-94ff-d111a249c8b0
import Test
# ╔═╡ 05f42764-acfe-4370-b85b-ce0e7c4270d0
begin
export test_nowarn, test_warn, test_logs, test_skip, test_broken, test_throws, test_deprecated
var"@test_warn" = Test.var"@test_warn"
var"@test_nowarn" = Test.var"@test_nowarn"
var"@test_logs" = Test.var"@test_logs"
var"@test_skip" = Test.var"@test_skip"
var"@test_broken" = Test.var"@test_broken"
var"@test_throws" = Test.var"@test_throws"
var"@test_deprecated" = Test.var"@test_deprecated"
end
# ╔═╡ 0d70962a-3880-4dee-a439-35068d019f5a
md"""
# Type definitions
"""
# ╔═╡ 113cc425-e224-4f77-bfbd-ef4eb1d1ed70
abstract type TestResult end
# ╔═╡ 6188f559-bcab-4da6-84b2-a3fe522a5c3c
abstract type Fail <: TestResult end
# ╔═╡ c24b46ce-bcbb-4dc9-8a59-b5b1bd2cd617
abstract type Pass <: TestResult end
# ╔═╡ 5041085e-a406-4ed4-ab82-84d8f126cf0f
const Code = Any
# ╔═╡ 8c92bad9-234e-47dd-a599-b75dc6d5db89
# struct Correct <: Pass
# expr::Code
# end
# ╔═╡ 03ccd498-83c3-41bb-84d7-625adabd7aee
struct CorrectCall <: Pass
expr::Code
steps::Vector
end
# ╔═╡ 1bcf8bd1-c8a3-49a1-9791-d813aa856399
# struct Error <: Fail
# expr::Code
# error
# end
# ╔═╡ 656c4190-b49e-4225-869d-eeb7e8e41e72
# struct Wrong <: Fail
# expr::Code
# step
# end
# ╔═╡ 14c525a1-eca1-466b-8e63-3a90d7d7111c
struct WrongCall <: Fail
expr::Code
steps::Vector
end
# ╔═╡ a2efc968-246c-40c2-b285-2ec94b185a44
md"""
# Test macro
"""
# ╔═╡ bfe4dc61-9160-4c7e-8897-9c723b309adc
# function test(expr)
# if Meta.isexpr(expr, :call, 3) && expr.args[1] === :(==)
# quote
# expr_raw = $(QuoteNode(expr))
# try
# left = $(expr.args[2] |> esc)
# right = $(expr.args[3] |> esc)
# result = left == right
# if result === true
# Correct(expr_raw)
# elseif result === false
# WrongEquality(expr_raw, left, right)
# else
# Wrong(expr_raw, result)
# end
# catch e
# rethrow(e)
# # Error(expr_raw, e)
# end
# end
# end
# end
# ╔═╡ 7db7a1d5-a70b-4997-943e-963e6f5affc9
# e = :(x == [1,2+2])
# ╔═╡ 9d49ea50-8158-4d8b-97af-edba1f7dc38b
x = [1,3]
# ╔═╡ a6f82260-3519-4254-a21e-abc7bb19ec4e
@bind howmuch Slider(0:100)
# ╔═╡ 1aa24b1c-e8ca-4de7-b614-7a3f02b4833d
always_false(args...; kwargs...) = false
# ╔═╡ c369b4b5-2fcf-4029-a1f6-352120b2fc4b
@bind n Slider(1:10)
# ╔═╡ 98992db9-4f14-4aa6-a7c5-477622266112
@bind k Slider(0:15)
# ╔═╡ 8a2e8348-49cf-4855-b5b3-cdee33e5ed67
html"""
<style>
pt-dot {
flex: 0 0 auto;
background: grey;
width: 1em;
height: 1em;
bottom: -.1em;
border-radius: 100%;
margin-right: .7em;
display: block;
position: relative;
cursor: pointer;
}
pt-dot.floating {
position: fixed;
z-index: 60;
display: none;
transition: transform linear 120ms;
}
.show-top-float > pt-dot.floating.top {
display: block;
}
.show-bottom-float > pt-dot.floating.bottom {
display: block;
}
pt-dot.floating.top {
top: 5px;
}
pt-dot.floating.bottom {
bottom: 5px;
}
.fail > pt-dot {
background: #f75d5d;
}
.pass > pt-dot {
background: #56a038;
}
.pass > pt-dot.floating {
opacity: 0;
pointer-events: none;
}
.pluto-test {
font-family: "JuliaMono", monospace;
font-size: 0.75rem;
padding: 4px;
min-height: 25px;
}
.pluto-test.pass {
color: rgba(0,0,0,.5);
}
.pluto-test.fail {
background: linear-gradient(90deg, #ff2e2e14, transparent);
border-radius: 7px;
}
.pluto-test>.arg_result {
flex: 0 0 auto;
}
.pluto-test>.arg_result>div,
.pluto-test>.arg_result>div>pluto-display>div {
display: inline-flex;
}
.pluto-test>.comma {
margin-right: .5em;
}
.pluto-test.call>code {
padding: 0px;
}
.pluto-test.call.infix-operator>div {
overflow-x: auto;
}
.pluto-test {
display: flex;
align-items: baseline;
}
.pluto-test.call.infix-operator>.fname {
margin: 0px .6em;
/*color: darkred;*/
}
/* expanding */
.pluto-test:not(.expanded) > p-frame-viewer > p-frame-controls {
display: none;
}
.pluto-test.expanded > p-frame-viewer {
max-width: 100%;
}
.pluto-test.expanded > p-frame-viewer > p-frames > slotted-code > line-like {
flex-wrap: wrap;
}
.pluto-test.expanded > p-frame-viewer > p-frames > slotted-code > line-like > pluto-display[mime="application/vnd.pluto.tree+object"] {
/*flex-basis: 100%;*/
}
"""
# ╔═╡ 42671258-07a0-4015-8f47-4b3032595f08
html"""
<style>
p-frame-viewer {
display: inline-flex;
flex-direction: column;
}
p-frames,
p-frame-controls {
display: inline-flex;
}
"""
# ╔═╡ 4bc1b7a4-0a36-4a07-b7ee-3d5be50350e1
("asd"*"asd","asd","asd"*" asd","asd","asd"*"asd","asd","asd"*"asd","asd","asd"*"asd","asd","asd"*"asd","asd","asd"*"asd","asd")
# ╔═╡ 3b2e8f55-1d4b-4a36-83f6-26becbd79e4b
# @test (@test t isa Pass) isa Pass
# ╔═╡ 1ac164c8-88fc-4a87-a194-60ef616fb399
flatmap(args...) = vcat(map(args...)...)
# ╔═╡ e604cc80-5224-4579-a7b4-f194f1ac99b2
function commas(xs, comma=@htl("<span class='comma'>, </span>"))
flatmap(enumerate(xs)) do (i,x)
if i == length(xs)
[x]
else
[x,comma]
end
end
end
# ╔═╡ 98ac4c36-49c7-4f65-982d-0b8bf6c372c0
emb = embed_display
# ╔═╡ 0fcc6cb0-2711-4609-9bf3-634cf9407840
div(x; class="", style="") = @htl("<div class=$(class) style=$(style)>$(x)</div>")
# ╔═╡ 69200d7c-b7bc-4c7e-a9a1-5e26979179a3
div(; class="", style="") = x -> @htl("<div class=$(class) style=$(style)>$(x)</div>")
# ╔═╡ a40800ef-2b1b-426e-8a1a-58dc5ba0f671
# ╔═╡ 4d5f44e4-85e9-4985-9b76-73be5e097186
remove_linenums(e::Expr) = if e.head === :macrocall
Expr(e.head, (remove_linenums(x) for x in e.args)...)
else
Expr(e.head, (remove_linenums(x) for x in e.args if !(x isa LineNumberNode))...)
end
# ╔═╡ dd495e00-d74d-47d4-a5d5-422fb147ec3b
remove_linenums(x) = x
# ╔═╡ ef6fc423-f1b1-4dcb-a059-276121391bc6
prettycolors(e) = Markdown.MD([Markdown.Code("julia", string(remove_linenums(e)))])
# ╔═╡ 9a7fbf1b-ade8-41dc-b4ff-c0df6cfd39d2
md"""
# DEbugging 1
"""
# ╔═╡ 04bbe79f-085e-401a-95bc-599b1df6acf5
function onestep(e::Expr; m=Module())
results = Any[]
# push!(results, e)
arg_results = Any[a for a in e.args]
for (i,a) in enumerate(e.args)
arg_results[i] = if a isa QuoteNode
a
elseif (e.head === :call || e.head === :let) && i == 1
a
elseif a isa Expr
inner_results = onestep(a; m=m)
for ir in inner_results
arg_results[i] = ir
push!(results, Expr(e.head, arg_results...))
end
inner_results[end]
else
a
end
# push!(results, Expr(e.head, arg_results...))
end
push!(results, Core.eval(m, Expr(e.head, arg_results...)))
results
end
# ╔═╡ 1611bbe7-aa3f-4bcf-ad82-c0907064ccc7
function expr_debug(x; )
e = remove_linenums(x)
Any[e, onestep(e)...]
end
# ╔═╡ a83a6a4c-664c-46fa-a07f-81088493dc35
const ObjectID = typeof(objectid("hello computer"))
# ╔═╡ 5cb03161-2cbc-4080-ba59-f94efd3b620c
expr_hash(e::Expr) = objectid(e.head) + mapreduce(p -> objectid((p[1], expr_hash(p[2]))), +, enumerate(e.args); init=zero(ObjectID))
# ╔═╡ 0611a36b-b4be-4b17-a485-7c4a8fa04927
expr_hash(x) = objectid(x)
# ╔═╡ 4aeb8c88-209a-4d00-b573-90d22501e97a
debug_result = expr_debug(:(
let
r = if rand(Bool)
20
else
16
end
y = sqrt(4)
y == sqrt(sqrt(r))
end
));
# ╔═╡ 43a86b76-35ca-42d4-a551-87890a4d3701
@bind step Slider(1:length(debug_result))
# ╔═╡ f6197004-c398-41a1-a560-75f22b267ab7
debug_result[step] |> prettycolors
# ╔═╡ dbfbcc16-c740-436c-bbf0-fee16b0a20c5
md"""
# Debugging 1.5
"""
# ╔═╡ a461f1fd-b5a5-4ae3-a47c-067a6081fb24
struct Computed
x
end
# ╔═╡ 7783cb02-8887-4792-be68-f2fdb9c4b680
computed(x) = Computed(x)
# ╔═╡ a392d2d6-5a16-4383-b0ef-5003aa2de9fa
expand_computed(x) = x
# ╔═╡ ae95b691-f54b-4bf5-b17b-3e5bd1edf75e
expand_computed(c::Computed) = c.x
# ╔═╡ 12119016-fa61-4d38-8c58-821ea435df7d
expand_computed(e::Expr) = Expr(e.head, expand_computed.(e.args)...)
# ╔═╡ afe29447-5397-4e1e-956b-a13ee59d7e29
function lazyevalwrap(x)
Expr(:($), x)
end
# ╔═╡ 1002e882-0384-4e65-8997-7ce6516029b0
function lazycomputedwrap(x)
Computed
Expr(:($), Expr(:call, GlobalRef(@__MODULE__, :Computed), x))
end
# ╔═╡ ef45af85-11f8-4505-9f1e-3ffb15a47142
onestep_light(x::Any) = [lazycomputedwrap(x)]
# ╔═╡ d4dd1043-5b37-4dd9-b55f-31b8a9287f5d
Expr(:call, :+, :([1,2]), lazycomputedwrap(:([1,2,z])))
# ╔═╡ b475c9b1-c1db-4b85-a04a-3cbac64e69d1
macro showme(expr)
quote
$(Expr(:quote, Expr(:quote, expr)))
end
end
# ╔═╡ 65672c8b-7d96-4de1-a10c-892dd7018b32
@showme a + $b
# ╔═╡ 65bbf031-5af2-4529-8b3b-695670f7e7eb
@__MODULE__
# ╔═╡ fce0b2de-7f7b-4ce8-8a16-079428041fb8
module XX
z = Main.workspace2594.@cool()
end
# ╔═╡ 4fcf99dc-8044-4f26-925b-07e168801ea8
XX.z
# ╔═╡ 450a36ea-2c43-4f01-a775-0b8c59bf6dca
function onestep_light(e::Expr)
results = Any[]
seval(ex) = lazycomputedwrap(ex)#Computed(Core.eval(m,ex))
# will be modified
arg_results = Any[a for a in e.args]
push_intermediate() = push!(results, Expr(e.head, arg_results...))
if e.head === :call || e.head === :begin || e.head === :block
for (i,a) in enumerate(e.args)
if a isa QuoteNode
a
elseif (Meta.isexpr(e, :call) || Meta.isexpr(e, :let)) && i == 1
a
elseif a isa Symbol
arg_results[i] = seval(a)
push_intermediate()
elseif a isa Expr
inner_results = onestep_light(a)
for ir in inner_results
arg_results[i] = ir
push_intermediate()
end
arg_results[i] = inner_results[end]
else
a
end
end
end
push!(results, seval(expand_computed(Expr(e.head, arg_results...))))
results
end
# ╔═╡ 0c9a57e0-7fe6-41a3-84d0-78dcf458a620
onestep_light(:(sqrt(first([1,2]))))
# ╔═╡ 61688af2-169e-4c1f-a37f-cc7cc35679dc
macro cool()
x1 = Expr(:call, :+, :([1,2]), lazycomputedwrap(:([1,2,z])))
# xs = [x1,x1]
xs = onestep_light(:(sqrt(first([1,2]))))[1:1]
quote
# $(esc(Expr(:quote, xs)))
# $(esc([Expr(:quote, x1), Expr(:quote, x1)]))
# $([esc(Expr(:quote, x1)), esc(Expr(:quote, x1))])
# $([esc(Expr(:quote, x1)), esc(Expr(:quote, x1))]...)
# [$([esc(Expr(:quote, x1)), esc(Expr(:quote, x1))]...)]
[$([esc(Expr(:quote, x)) for x in xs]...)]
# [$(esc(Expr(:quote, x1))), $(esc(Expr(:quote, x1)))]
# [$(esc(Expr(:quote, x)))]
end
end
# ╔═╡ 9e91102a-4361-4e15-8c71-d058335aba35
let
z = 1299
@cool()
end
# ╔═╡ a71d0a72-3d01-4650-a24c-65bcafdf26a7
@cool() |> Dump
# ╔═╡ b3085b18-dcb8-48b0-a999-6c10844cb7af
Dump(@macroexpand @cool(); maxdepth=999)
# ╔═╡ 9313576e-1e8e-4fd3-9928-073cb3b183f9
onestep_light(:(1+sqrt(z)))
# ╔═╡ 170a82ab-dbf2-4c5a-a7f9-0dac691481f1
ezz = let
e = Expr(:$, :z)
:(1 + sqrt($e))
end
# ╔═╡ 1bf51dcf-0185-4a7e-82ad-8926767130cb
macro eyo()
ezz
end
# ╔═╡ 611800fe-2ba5-4d89-a3aa-8933ec60bf2e
@eyo()
# ╔═╡ 16a6c473-9ac8-4bd4-a83d-560e248d79c9
eval(:(sqrt(length($(Expr(:$, :(Main.workspace2618.Computed([1, 2]))))))))
# ╔═╡ 1c3294ed-3e3e-48b5-929c-71b50b66f68e
macro wow(ex)
# esc(Core.eval(__module__, Expr(:quote, e)))
esc(Expr(:call, GlobalRef(Core, :eval), __module__, Expr(:quote, ex)))
end
# ╔═╡ 8ef356ea-7d54-43e6-a936-7c8be04c595f
onestep_light(quote
1+2
2+3
4+5
sqrt(sqrt(sqrt(5)))
end |> remove_linenums)
# ╔═╡ 88f6a040-07cf-47e0-a8be-2478ea350aa7
can_interpret(x) = true
# ╔═╡ d36a8a72-eced-4e63-9130-7fcb6c86df76
can_interpret_call_arg(e::Expr) = !(e.head === :(...) || e.head === :kw || e.head === :parameters)
# ╔═╡ e9659020-d433-4357-9099-71a65b66a091
can_interpret_call_arg(x) = true
# ╔═╡ c3fc3292-b7eb-4b01-8fba-159c86228de9
Meta.isbinaryoperator(:(==))
# ╔═╡ 89578bff-16b9-4eb2-b8ee-b2839ff2d74c
can_interpret(e::Expr) = if false
false
elseif e.head === :call && !all(can_interpret_call_arg, e.args)
false
# elseif e.head === :(=) || e.head === :macrocall
# false
else
all(can_interpret, e.args)
end
# ╔═╡ e1c306e3-0a47-4149-a9fb-ec7ab380fa11
function step_by_step(expr; __module__)
Computed
onestep_light
escquote(x) = x#Core.eval(__module__, Expr(:quote, x))
if can_interpret(expr)
quote
# Any[$(QuoteNode(expr)), $(escquote.(onestep_light(expr)))...]
# $(escquote.(onestep_light(expr)))
end
escquote.(onestep_light(expr))
else
quote
[$(QuoteNode(expr)), Computed($(esc(expr)))]
end
end
end
# ╔═╡ b6e8a170-12cc-4d97-905d-274e2609bfd8
function test(expr, extra_args...; __module__)
step_by_step
Test.test_expr!("", expr, extra_args...)
quote
expr_raw = $(QuoteNode(expr))
try
# steps = @eval_step_by_step($(expr))
steps = $(step_by_step(expr; __module__=__module__))
# arg_results = [$((expr.args[2:end] .|> esc)...)]
# result = $(esc(:eval))(Expr(:call, $(expr.args[1] |> QuoteNode), arg_results...))
result = expand_computed(last(steps))
if result === true
CorrectCall(expr_raw, steps)
# elseif result === false
# WrongCall(expr_raw, steps)
else
WrongCall(expr_raw, steps)
end
catch e
rethrow(e)
# Error(expr_raw, e)
end
end
end
# ╔═╡ a661e172-6afb-42ff-bd43-bb5b787ee5ed
macro eval_step_by_step(e)
step_by_step
quote
[$(step_by_step(e; __module__=__module__))...]
end
end
# ╔═╡ c364734e-e9fc-4c34-b16b-39e9bc703cd8
@eval_step_by_step 1 + [2,3]
# ╔═╡ e19f298e-7135-4f27-bcae-0b6eb9df326c
map(1:1) do i
@eval_step_by_step 2 + $i
end
# ╔═╡ 68ba60db-44ad-43e4-b33e-d27696babc99
@eval_step_by_step sqrt(length([1,2]))
# ╔═╡ 13e463c6-4afd-474e-abe2-a6e0fd57dfe5
let
i = 123
remove_linenums( @macroexpand @eval_step_by_step sqrt(sqrt(3 + 2)) )
end
# ╔═╡ 3294b126-ea0d-4b42-a2f7-14b1ba4f2d50
map(1:1) do i
@macroexpand @eval_step_by_step 2342342 + $i
end
# ╔═╡ 930f8244-cf25-4c1a-95f6-5c8963559c62
@macroexpand @eval_step_by_step x == [1,2]
# ╔═╡ 807bcd72-26c3-44d3-a295-56874cb51a89
@eval_step_by_step xasdf = 123
# ╔═╡ 8a5a4c26-e36c-4061-b32f-4448625ce4a6
xasdf
# ╔═╡ 21d4560e-721f-4ed4-9db7-86a8151ab22c
md"""
## Displaying
"""
# ╔═╡ f7cb57ba-df21-43be-8827-cfe11ab02d51
# ╔═╡ 03a849a9-3728-4b2d-afec-d2387d73516b
find_computed!(found, c::Computed) = push!(found, c)
# ╔═╡ 064b1250-bc11-48f2-8845-88910cc1ff96
find_computed!(found, expr::Expr) = find_computed!.([found], expr.args)
# ╔═╡ 5dfefa01-d568-47bc-a3ec-093eeed3da36
find_computed!(found, x) = nothing
# ╔═╡ dcab2eea-c454-4a70-9a91-6ee1e3113dc6
find_computed(x) = let
r = Any[]
find_computed!(r, x)
r
end
# ╔═╡ 560dbf2b-c648-49aa-b774-11d367ac331d
onestep_light(quote
1+2
2+3
4+5
sqrt(sqrt(sqrt(5)))
end |> remove_linenums) .|> find_computed
# ╔═╡ 4956526a-daf9-43c9-bff3-ff2446016e2e
slot!(found, c::Computed) = let
k = Symbol("__slot", join(rand('a':'z', 16)), "__")
found[k] = c
k
end
# ╔═╡ 84ff6a23-c134-4910-b630-a7ad45f3bf29
slot!(found, x) = x
# ╔═╡ 318363d0-6d9e-4144-b478-b775f437edaf
slot!(found, e::Expr) = Expr(e.head, slot!.([found], e.args)...)
# ╔═╡ 67fd07b7-340b-4e24-bc06-e4c85b186872
slot(e) = let
d = Dict{Symbol,Any}()
new_e = slot!(d, e)
d, new_e
end
# ╔═╡ 4edf747b-3838-4315-a397-e452ac9b5465
onestep_light(quote
(1+2) + (7-6)
2+3
4+5
sqrt(sqrt(sqrt(5)))
end |> remove_linenums) .|> slot
# ╔═╡ 872b4877-30dd-4a92-a3c8-69eb50675dcb
preish(x) = @htl("<pre-ish>$(x)</pre-ish>")
# ╔═╡ 181ea2d1-dde8-4404-8c1f-843b182ba09d
function display_slotted(expr)
d, e = slot(expr)
s = string(e |> remove_linenums)
lines = split(s, "\n")
r = r"\_\_slot[a-z]{16}\_\_"
@htl("""<slotted-code>
$(
map(lines) do l
keys = [Symbol(m.match) for m in eachmatch(r, l)]
rest = split(l, r; keepempty=true)
result = vcat((
[(isempty(r) ? @htl("") : preish(r)), embed_display(d[k].x)]
for (r,k) in zip(rest, keys)
)...)
push!(result, preish(last(rest)))
@htl("<line-like>$(result)</line-like>")
end
)
</slotted-code>""")
end
# ╔═╡ d3b83bc1-cd48-4f35-9617-dc8fecd7e0f9
html"""
<style>
slotted-code {
font-family: "JuliaMono", monospace;
font-size: .75rem;
display: flex;
flex-direction: column;
}
pre-ish {
white-space: pre;
}
line-like {
display: flex;
align-items: baseline;
}
"""
# ╔═╡ 3e1b28f1-6745-4deb-b88e-a11d3f8cbf58
# rs = @eval_step_by_step(begin
# (1+2) + (7-6)
# first(2000 .+ 30 .* rand(2+2))
# 4+5
# sqrt(sqrt(sqrt(5)))
# end) .|> display_slotted
# ╔═╡ 6f5ba692-4b6a-405a-8cd3-1a8f9cc06611
plot(args...; kwargs...) = Plots.plot(args...; size=(100,100), kwargs...)
# ╔═╡ b4b317d7-bed1-489c-9650-8d336e330689
rs = @eval_step_by_step(begin
(1+2) + (7-6)
plot(2000 .+ 30 .* rand(2+2))
4+5
sqrt(sqrt(sqrt(5)))
end) .|> display_slotted
# ╔═╡ 93ed973f-daf6-408b-9d4b-d53495418610
@bind rindex Slider(eachindex(rs))
# ╔═╡ dea898a0-1904-4d09-ad0b-6915008fe946
rs[rindex]
# ╔═╡ e968fc57-d850-4e2d-9410-8777d03b7b3c
function frames(fs)
l = length(fs)
startframe = l > 2 ? l - 1 : l
@htl("""
<p-frame-viewer>
<p-frames>
$(fs)
</p-frames>
<p-frame-controls>
<img src="https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.0.0/src/svg/time-outline.svg" style="width: 1em; transform: scale(-1,1); opacity: .5; margin-left: 2em;">
<input class="timescrub" style="filter: hue-rotate(149deg) grayscale(.9);" type=range min=1 max=$(l) value=$(startframe)>
</p-frame-controls>
<script>
const div = currentScript.parentElement
const input = div.querySelector("p-frame-controls > input.timescrub")
const frames = div.querySelector("p-frames")
const setviz = () => {
Array.from(frames.children).forEach((f,i) => {
f.style.display = i + 1 === input.valueAsNumber ? "inherit" : "none"
})
}
setviz()
input.addEventListener("input", setviz)
</script>
</p-frame-viewer>
""")
end
# ╔═╡ 9c3f6eab-b1c3-4607-add8-d6d7e468c11a
begin
macro test(expr...)
test(expr...; __module__=__module__)
end
function Base.show(io::IO, m::MIME"text/html", call::Union{WrongCall,CorrectCall})
infix = if Meta.isexpr(call.expr, :call)
fname = call.expr.args[1]
Meta.isbinaryoperator(fname)
else
false
end
classes = [
"pluto-test",
"call",
(isa(call,CorrectCall) ? "correct" : "wrong"),
(isa(call,Pass) ? "pass" : "fail"),
infix ? "infix-operator" : "prefix-operator",
]
result = @htl("""
<div class=$(classes)>
<script>
const div = currentScript.parentElement
div.addEventListener("click", (e) => {
if(!div.classList.contains("expanded") || e.target.closest("pt-dot:not(.floating)") != null){
div.classList.toggle("expanded")
e.stopPropagation()
}
})
const throttled = (f, delay) => {
const waiting = { current: false }
return () => {
if (!waiting.current) {
f()
waiting.current = true
setTimeout(() => {
f()
waiting.current = false
}, delay)
}
}
}
const dot_top = div.querySelector("pt-dot.top")
const dot_bot = div.querySelector("pt-dot.bottom")
const intersect = (r) => {
const topdistance = r.top
const botdistance = window.visualViewport.height - r.bottom
const t = (x) => `translate(\${2*Math.sqrt(Math.max(0,-50-x))}px,0)`
dot_top.style.transform = t(topdistance)
dot_bot.style.transform = t(botdistance)
div.classList.toggle("show-top-float", topdistance < 4)
div.classList.toggle("show-bottom-float", botdistance < 4)
}
window.addEventListener("scroll", throttled(() => {
intersect(dot.getBoundingClientRect())
}, 100))
let observer = new IntersectionObserver((es) => {
const e = es[0]
intersect(e.boundingClientRect)
}, {
rootMargin: '-4px',