@@ -198,6 +198,234 @@ import Pluto: update_run!, WorkspaceManager, ClientSession, ServerSession, Noteb
198198 end
199199 end
200200
201+ @testset " AbstractPlutoDingetjes.jl" begin
202+ 🍭. options. evaluation. workspace_use_distributed = true
203+ notebook = Notebook ([
204+ Cell ("""
205+ begin
206+ import Pkg
207+ try
208+ Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true
209+ catch; end
210+ Pkg.activate(mktempdir())
211+ Pkg.add(Pkg.PackageSpec(name="AbstractPlutoDingetjes", rev="0494e5a"))
212+ import AbstractPlutoDingetjes as APD
213+ import AbstractPlutoDingetjes.Bonds
214+ end
215+ """ ),
216+ Cell ("""
217+ begin
218+ struct HTMLShower
219+ f::Function
220+ end
221+ Base.show(io::IO, m::MIME"text/html", hs::HTMLShower) = hs.f(io)
222+ end
223+ """ ),
224+ Cell ("""
225+ APD.is_inside_pluto()
226+ """ ),
227+ Cell ("""
228+ HTMLShower() do io
229+ write(io, string(APD.is_inside_pluto(io)))
230+ end
231+ """ ),
232+ Cell ("""
233+ HTMLShower() do io
234+ write(io, string(APD.is_supported_by_display(io, Bonds.initial_value)))
235+ end
236+ """ ),
237+ Cell ("""
238+ HTMLShower() do io
239+ write(io, string(APD.is_supported_by_display(io, Bonds.transform_value)))
240+ end
241+ """ ),
242+ Cell ("""
243+ HTMLShower() do io
244+ write(io, string(APD.is_supported_by_display(io, Bonds.validate_value)))
245+ end
246+ """ ),
247+ Cell ("""
248+ HTMLShower() do io
249+ write(io, string(APD.is_supported_by_display(io, sqrt)))
250+ end
251+ """ ),
252+ Cell ("""
253+ @bind x_simple html"<input type=range>"
254+ """ ),
255+ Cell ("""
256+ x_simple
257+ """ ),
258+ Cell ("""
259+ begin
260+ struct OldSlider end
261+
262+ Base.show(io::IO, m::MIME"text/html", os::OldSlider) = write(io, "<input type=range value=1>")
263+
264+ Base.get(os::OldSlider) = 1
265+ end
266+ """ ),
267+ Cell ("""
268+ @bind x_old OldSlider()
269+ """ ),
270+ Cell ("""
271+ x_old
272+ """ ),
273+ Cell ("""
274+ begin
275+ struct NewSlider end
276+
277+ Base.show(io::IO, m::MIME"text/html", os::NewSlider) = write(io, "<input type=range value=1>")
278+
279+ Bonds.initial_value(os::NewSlider) = 1
280+ end
281+ """ ),
282+ Cell ("""
283+ @bind x_new NewSlider()
284+ """ ),
285+ Cell ("""
286+ x_new
287+ """ ),
288+ Cell ("""
289+ begin
290+ struct TransformSlider end
291+
292+ Base.show(io::IO, m::MIME"text/html", os::TransformSlider) = write(io, "<input type=range value=1>")
293+
294+ Bonds.initial_value(os::TransformSlider) = "x"
295+ Bonds.transform_value(os::TransformSlider, from_js) = repeat("x", from_js)
296+ end
297+ """ ),
298+ Cell ("""
299+ @bind x_transform TransformSlider()
300+ """ ),
301+ Cell ("""
302+ x_transform
303+ """ ),
304+ Cell ("""
305+ begin
306+ struct BadTransformSlider end
307+
308+ Base.show(io::IO, m::MIME"text/html", os::BadTransformSlider) = write(io, "<input type=range value=1>")
309+
310+ Bonds.initial_value(os::BadTransformSlider) = "x"
311+ Bonds.transform_value(os::BadTransformSlider, from_js) = repeat("x", from_js)
312+ end
313+ """ ),
314+ Cell ("""
315+ @bind x_badtransform BadTransformSlider()
316+ """ ),
317+ Cell ("""
318+ x_badtransform
319+ """ ),
320+ Cell ("""
321+ count = Ref(0)
322+ """ ),
323+ Cell ("""
324+ @bind x_counter NewSlider() #or OldSlider(), same idea
325+ """ ),
326+ Cell ("""
327+ let
328+ x_counter
329+ count[] += 1
330+ end
331+ """ ),
332+ ])
333+ fakeclient. connected_notebook = notebook
334+
335+ update_run! (🍭, notebook, notebook. cells)
336+
337+ @test noerror (notebook. cells[1 ])
338+ @test noerror (notebook. cells[2 ])
339+ @test noerror (notebook. cells[3 ])
340+ @test noerror (notebook. cells[4 ])
341+ @test noerror (notebook. cells[5 ])
342+ @test noerror (notebook. cells[6 ])
343+ @test noerror (notebook. cells[7 ])
344+ @test noerror (notebook. cells[8 ])
345+
346+ @test notebook. cells[3 ]. output. body == " true"
347+ @test notebook. cells[4 ]. output. body == " true"
348+ @test notebook. cells[5 ]. output. body == " true"
349+ @test notebook. cells[6 ]. output. body == " true"
350+ @test notebook. cells[7 ]. output. body == " false"
351+ @test notebook. cells[8 ]. output. body == " false"
352+
353+
354+
355+
356+ @test noerror (notebook. cells[9 ])
357+ @test noerror (notebook. cells[10 ])
358+ @test noerror (notebook. cells[11 ])
359+ @test noerror (notebook. cells[12 ])
360+ @test noerror (notebook. cells[13 ])
361+ @test noerror (notebook. cells[14 ])
362+ @test noerror (notebook. cells[15 ])
363+ @test noerror (notebook. cells[16 ])
364+ @test noerror (notebook. cells[17 ])
365+ @test noerror (notebook. cells[18 ])
366+ @test noerror (notebook. cells[19 ])
367+ @test noerror (notebook. cells[20 ])
368+ @test noerror (notebook. cells[21 ])
369+ @test noerror (notebook. cells[22 ])
370+ @test noerror (notebook. cells[23 ])
371+ @test noerror (notebook. cells[24 ])
372+ @test noerror (notebook. cells[25 ])
373+
374+
375+ function set_bond_value (name, value, is_first_value= false )
376+ notebook. bonds[name] = Dict (" value" => value, " is_first_value" => is_first_value)
377+ Pluto. set_bond_values_reactive (;
378+ session= 🍭,
379+ notebook= notebook,
380+ bound_sym_names= [name],
381+ run_async= false ,
382+ )
383+ end
384+
385+
386+ @test notebook. cells[10 ]. output. body == " missing"
387+ set_bond_value (:x_simple , 1 , true )
388+ @test notebook. cells[10 ]. output. body == " 1"
389+
390+
391+ @test notebook. cells[13 ]. output. body == " 1"
392+ set_bond_value (:x_old , 1 , true )
393+ @test notebook. cells[13 ]. output. body == " 1"
394+ set_bond_value (:x_old , 99 , false )
395+ @test notebook. cells[13 ]. output. body == " 99"
396+
397+
398+ @test notebook. cells[16 ]. output. body == " 1"
399+ set_bond_value (:x_new , 1 , true )
400+ @test notebook. cells[16 ]. output. body == " 1"
401+ set_bond_value (:x_new , 99 , false )
402+ @test notebook. cells[16 ]. output. body == " 99"
403+
404+
405+ @test notebook. cells[19 ]. output. body == " \" x\" "
406+ set_bond_value (:x_transform , 1 , true )
407+ @test notebook. cells[19 ]. output. body == " \" x\" "
408+ set_bond_value (:x_transform , 3 , false )
409+ @test notebook. cells[19 ]. output. body == " \" xxx\" "
410+
411+
412+ @test notebook. cells[22 ]. output. body != " missing"
413+ set_bond_value (:x_badtransform , 1 , true )
414+ @test notebook. cells[22 ]. output. body != " missing"
415+ set_bond_value (:x_badtransform , 7 , false )
416+ @test notebook. cells[22 ]. output. body != " missing"
417+
418+
419+ @test notebook. cells[25 ]. output. body == " 1"
420+ set_bond_value (:x_counter , 1 , true )
421+ @test notebook. cells[25 ]. output. body == " 1"
422+ set_bond_value (:x_counter , 7 , false )
423+ @test notebook. cells[25 ]. output. body == " 2"
424+
425+
426+ WorkspaceManager. unmake_workspace ((🍭, notebook))
427+ 🍭. options. evaluation. workspace_use_distributed = false
428+ end
201429
202430 @testset " Table viewer" begin
203431 🍭. options. evaluation. workspace_use_distributed = true
0 commit comments