Advertisement
Pillager86

Unit test produces no output no error.

May 8th, 2020
660
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import std.stdio;
  2.  
  3. import arsd.script;
  4. import arsd.jsvar;
  5.  
  6. alias ClickHandler = void delegate(int x, int y);
  7.  
  8. class Window
  9. {
  10.     void addOnClick(ClickHandler ch)
  11.     {
  12.         clickHandlers ~= ch;
  13.     }
  14.  
  15.     void click(int x, int y)
  16.     {
  17.         foreach(ch ; clickHandlers)
  18.         {
  19.             ch(x, y);
  20.         }
  21.     }
  22.  
  23.     private ClickHandler[] clickHandlers;
  24. }
  25.  
  26. void print(const string s)
  27. {
  28.     writeln(s);
  29. }
  30.  
  31. void main(string [] args)
  32. {
  33.     var globals = var.emptyObject;
  34.     globals.print = &print;
  35.     globals["Window"] = subclassable!Window;
  36.    
  37.     interpret(q{
  38.         var window = new Window();
  39.         window.addOnClicked(function(x,y){
  40.             print("Clicked! " ~ x ~ " " ~ y);
  41.         });
  42.         window.click(25, 30);
  43.     }, globals);
  44. }
  45.  
  46. unittest
  47. {
  48.     Window window = new Window;
  49.     window.addOnClick((x,y){writeln(x," ",y);});
  50.     window.addOnClick((x,y){writeln("Second click!");});
  51.     window.click(42, 69);
  52. }
Advertisement
RAW Paste Data Copied
Advertisement