├── .haxerc ├── .travis.yml ├── README.md ├── bin └── node │ └── tests.js ├── haxe_libraries ├── ansi.hxml ├── hxnodejs.hxml ├── quick-enums.hxml ├── tink_core.hxml ├── tink_macro.hxml ├── tink_priority.hxml ├── tink_streams.hxml ├── tink_syntaxhub.hxml ├── tink_testrunner.hxml ├── tink_unittest.hxml └── travix.hxml ├── haxelib.json ├── src └── enums │ ├── EnumBuilder.hx │ └── Enums.hx ├── tests.hxml └── tests └── RunTests.hx /.haxerc: -------------------------------------------------------------------------------- 1 | {"version":"3.4.7","resolveLibs":"scoped"} -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | 4 | language: haxe 5 | 6 | os: 7 | - linux 8 | - osx 9 | 10 | # you can specify futher versions as found at http://haxe.org/website-content/downloads/versions.json 11 | haxe: 12 | - "3.4.0" 13 | - development 14 | 15 | matrix: 16 | allow_failures: 17 | - haxe: development 18 | 19 | install: 20 | - haxelib install travix 21 | # to always use the latest version of travix comment out the previous line and uncomment the next 22 | # - haxelib git travix https://github.com/back2dos/travix && pushd . && cd $(haxelib config)travix/git && haxe build-neko.hxml && popd 23 | - haxelib run travix install 24 | 25 | script: 26 | - haxelib run travix node 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Quick Enums for Haxe 2 | 3 | Shorthand to represent string-enums. 4 | 5 | ## Usage 6 | 7 | ```haxe 8 | var sizes:enums.Enums<'small', 'medium', 'large'>; 9 | ``` 10 | 11 | Will generate this: 12 | 13 | ```haxe 14 | var sizes:Enum1; 15 | 16 | @:enum abstract Enum1(String) { 17 | var Small = 'small'; 18 | var Medium = 'medium'; 19 | var Large = 'large'; 20 | } 21 | ``` 22 | 23 | ## Note 24 | 25 | When generating the identifiers: 26 | 27 | - Dashes `-` and spaces ` ` will be replaced by an underscore `_` 28 | - If the string starts with a number, the identifier will be prefixed with an underscore `_` 29 | -------------------------------------------------------------------------------- /bin/node/tests.js: -------------------------------------------------------------------------------- 1 | // Generated by Haxe 3.4.7 2 | if (process.version < "v4.0.0") console.warn("Module " + (typeof(module) == "undefined" ? "" : module.filename) + " requires node.js version 4.0.0 or higher"); 3 | (function ($global) { "use strict"; 4 | var $estr = function() { return js_Boot.__string_rec(this,''); }; 5 | function $extend(from, fields) { 6 | function Inherit() {} Inherit.prototype = from; var proto = new Inherit(); 7 | for (var name in fields) proto[name] = fields[name]; 8 | if( fields.toString !== Object.prototype.toString ) proto.toString = fields.toString; 9 | return proto; 10 | } 11 | var Attribute = { __ename__ : true, __constructs__ : ["Off","Bold","Underline","Blink","ReverseVideo","Concealed","BoldOff","UnderlineOff","BlinkOff","NormalVideo","ConcealedOff","Black","Red","Green","Yellow","Blue","Magenta","Cyan","White","DefaultForeground","BlackBack","RedBack","GreenBack","YellowBack","BlueBack","MagentaBack","CyanBack","WhiteBack","DefaultBackground"] }; 12 | Attribute.Off = ["Off",0]; 13 | Attribute.Off.toString = $estr; 14 | Attribute.Off.__enum__ = Attribute; 15 | Attribute.Bold = ["Bold",1]; 16 | Attribute.Bold.toString = $estr; 17 | Attribute.Bold.__enum__ = Attribute; 18 | Attribute.Underline = ["Underline",2]; 19 | Attribute.Underline.toString = $estr; 20 | Attribute.Underline.__enum__ = Attribute; 21 | Attribute.Blink = ["Blink",3]; 22 | Attribute.Blink.toString = $estr; 23 | Attribute.Blink.__enum__ = Attribute; 24 | Attribute.ReverseVideo = ["ReverseVideo",4]; 25 | Attribute.ReverseVideo.toString = $estr; 26 | Attribute.ReverseVideo.__enum__ = Attribute; 27 | Attribute.Concealed = ["Concealed",5]; 28 | Attribute.Concealed.toString = $estr; 29 | Attribute.Concealed.__enum__ = Attribute; 30 | Attribute.BoldOff = ["BoldOff",6]; 31 | Attribute.BoldOff.toString = $estr; 32 | Attribute.BoldOff.__enum__ = Attribute; 33 | Attribute.UnderlineOff = ["UnderlineOff",7]; 34 | Attribute.UnderlineOff.toString = $estr; 35 | Attribute.UnderlineOff.__enum__ = Attribute; 36 | Attribute.BlinkOff = ["BlinkOff",8]; 37 | Attribute.BlinkOff.toString = $estr; 38 | Attribute.BlinkOff.__enum__ = Attribute; 39 | Attribute.NormalVideo = ["NormalVideo",9]; 40 | Attribute.NormalVideo.toString = $estr; 41 | Attribute.NormalVideo.__enum__ = Attribute; 42 | Attribute.ConcealedOff = ["ConcealedOff",10]; 43 | Attribute.ConcealedOff.toString = $estr; 44 | Attribute.ConcealedOff.__enum__ = Attribute; 45 | Attribute.Black = ["Black",11]; 46 | Attribute.Black.toString = $estr; 47 | Attribute.Black.__enum__ = Attribute; 48 | Attribute.Red = ["Red",12]; 49 | Attribute.Red.toString = $estr; 50 | Attribute.Red.__enum__ = Attribute; 51 | Attribute.Green = ["Green",13]; 52 | Attribute.Green.toString = $estr; 53 | Attribute.Green.__enum__ = Attribute; 54 | Attribute.Yellow = ["Yellow",14]; 55 | Attribute.Yellow.toString = $estr; 56 | Attribute.Yellow.__enum__ = Attribute; 57 | Attribute.Blue = ["Blue",15]; 58 | Attribute.Blue.toString = $estr; 59 | Attribute.Blue.__enum__ = Attribute; 60 | Attribute.Magenta = ["Magenta",16]; 61 | Attribute.Magenta.toString = $estr; 62 | Attribute.Magenta.__enum__ = Attribute; 63 | Attribute.Cyan = ["Cyan",17]; 64 | Attribute.Cyan.toString = $estr; 65 | Attribute.Cyan.__enum__ = Attribute; 66 | Attribute.White = ["White",18]; 67 | Attribute.White.toString = $estr; 68 | Attribute.White.__enum__ = Attribute; 69 | Attribute.DefaultForeground = ["DefaultForeground",19]; 70 | Attribute.DefaultForeground.toString = $estr; 71 | Attribute.DefaultForeground.__enum__ = Attribute; 72 | Attribute.BlackBack = ["BlackBack",20]; 73 | Attribute.BlackBack.toString = $estr; 74 | Attribute.BlackBack.__enum__ = Attribute; 75 | Attribute.RedBack = ["RedBack",21]; 76 | Attribute.RedBack.toString = $estr; 77 | Attribute.RedBack.__enum__ = Attribute; 78 | Attribute.GreenBack = ["GreenBack",22]; 79 | Attribute.GreenBack.toString = $estr; 80 | Attribute.GreenBack.__enum__ = Attribute; 81 | Attribute.YellowBack = ["YellowBack",23]; 82 | Attribute.YellowBack.toString = $estr; 83 | Attribute.YellowBack.__enum__ = Attribute; 84 | Attribute.BlueBack = ["BlueBack",24]; 85 | Attribute.BlueBack.toString = $estr; 86 | Attribute.BlueBack.__enum__ = Attribute; 87 | Attribute.MagentaBack = ["MagentaBack",25]; 88 | Attribute.MagentaBack.toString = $estr; 89 | Attribute.MagentaBack.__enum__ = Attribute; 90 | Attribute.CyanBack = ["CyanBack",26]; 91 | Attribute.CyanBack.toString = $estr; 92 | Attribute.CyanBack.__enum__ = Attribute; 93 | Attribute.WhiteBack = ["WhiteBack",27]; 94 | Attribute.WhiteBack.toString = $estr; 95 | Attribute.WhiteBack.__enum__ = Attribute; 96 | Attribute.DefaultBackground = ["DefaultBackground",28]; 97 | Attribute.DefaultBackground.toString = $estr; 98 | Attribute.DefaultBackground.__enum__ = Attribute; 99 | var Sys = function() { }; 100 | Sys.__name__ = true; 101 | Sys.systemName = function() { 102 | var _g = process.platform; 103 | switch(_g) { 104 | case "darwin": 105 | return "Mac"; 106 | case "freebsd": 107 | return "BSD"; 108 | case "linux": 109 | return "Linux"; 110 | case "win32": 111 | return "Windows"; 112 | default: 113 | var other = _g; 114 | return other; 115 | } 116 | }; 117 | var js_node_ChildProcess = require("child_process"); 118 | var Reflect = function() { }; 119 | Reflect.__name__ = true; 120 | Reflect.compare = function(a,b) { 121 | if(a == b) { 122 | return 0; 123 | } else if(a > b) { 124 | return 1; 125 | } else { 126 | return -1; 127 | } 128 | }; 129 | Reflect.isEnumValue = function(v) { 130 | if(v != null) { 131 | return v.__enum__ != null; 132 | } else { 133 | return false; 134 | } 135 | }; 136 | var js_Boot = function() { }; 137 | js_Boot.__name__ = true; 138 | js_Boot.getClass = function(o) { 139 | if((o instanceof Array) && o.__enum__ == null) { 140 | return Array; 141 | } else { 142 | var cl = o.__class__; 143 | if(cl != null) { 144 | return cl; 145 | } 146 | var name = js_Boot.__nativeClassName(o); 147 | if(name != null) { 148 | return js_Boot.__resolveNativeClass(name); 149 | } 150 | return null; 151 | } 152 | }; 153 | js_Boot.__string_rec = function(o,s) { 154 | if(o == null) { 155 | return "null"; 156 | } 157 | if(s.length >= 5) { 158 | return "<...>"; 159 | } 160 | var t = typeof(o); 161 | if(t == "function" && (o.__name__ || o.__ename__)) { 162 | t = "object"; 163 | } 164 | switch(t) { 165 | case "function": 166 | return ""; 167 | case "object": 168 | if(o instanceof Array) { 169 | if(o.__enum__) { 170 | if(o.length == 2) { 171 | return o[0]; 172 | } 173 | var str = o[0] + "("; 174 | s += "\t"; 175 | var _g1 = 2; 176 | var _g = o.length; 177 | while(_g1 < _g) { 178 | var i = _g1++; 179 | if(i != 2) { 180 | str += "," + js_Boot.__string_rec(o[i],s); 181 | } else { 182 | str += js_Boot.__string_rec(o[i],s); 183 | } 184 | } 185 | return str + ")"; 186 | } 187 | var l = o.length; 188 | var i1; 189 | var str1 = "["; 190 | s += "\t"; 191 | var _g11 = 0; 192 | var _g2 = l; 193 | while(_g11 < _g2) { 194 | var i2 = _g11++; 195 | str1 += (i2 > 0 ? "," : "") + js_Boot.__string_rec(o[i2],s); 196 | } 197 | str1 += "]"; 198 | return str1; 199 | } 200 | var tostr; 201 | try { 202 | tostr = o.toString; 203 | } catch( e ) { 204 | return "???"; 205 | } 206 | if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") { 207 | var s2 = o.toString(); 208 | if(s2 != "[object Object]") { 209 | return s2; 210 | } 211 | } 212 | var k = null; 213 | var str2 = "{\n"; 214 | s += "\t"; 215 | var hasp = o.hasOwnProperty != null; 216 | for( var k in o ) { 217 | if(hasp && !o.hasOwnProperty(k)) { 218 | continue; 219 | } 220 | if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") { 221 | continue; 222 | } 223 | if(str2.length != 2) { 224 | str2 += ", \n"; 225 | } 226 | str2 += s + k + " : " + js_Boot.__string_rec(o[k],s); 227 | } 228 | s = s.substring(1); 229 | str2 += "\n" + s + "}"; 230 | return str2; 231 | case "string": 232 | return o; 233 | default: 234 | return String(o); 235 | } 236 | }; 237 | js_Boot.__interfLoop = function(cc,cl) { 238 | if(cc == null) { 239 | return false; 240 | } 241 | if(cc == cl) { 242 | return true; 243 | } 244 | var intf = cc.__interfaces__; 245 | if(intf != null) { 246 | var _g1 = 0; 247 | var _g = intf.length; 248 | while(_g1 < _g) { 249 | var i = _g1++; 250 | var i1 = intf[i]; 251 | if(i1 == cl || js_Boot.__interfLoop(i1,cl)) { 252 | return true; 253 | } 254 | } 255 | } 256 | return js_Boot.__interfLoop(cc.__super__,cl); 257 | }; 258 | js_Boot.__instanceof = function(o,cl) { 259 | if(cl == null) { 260 | return false; 261 | } 262 | switch(cl) { 263 | case Array: 264 | if((o instanceof Array)) { 265 | return o.__enum__ == null; 266 | } else { 267 | return false; 268 | } 269 | break; 270 | case Bool: 271 | return typeof(o) == "boolean"; 272 | case Dynamic: 273 | return true; 274 | case Float: 275 | return typeof(o) == "number"; 276 | case Int: 277 | if(typeof(o) == "number") { 278 | return (o|0) === o; 279 | } else { 280 | return false; 281 | } 282 | break; 283 | case String: 284 | return typeof(o) == "string"; 285 | default: 286 | if(o != null) { 287 | if(typeof(cl) == "function") { 288 | if(o instanceof cl) { 289 | return true; 290 | } 291 | if(js_Boot.__interfLoop(js_Boot.getClass(o),cl)) { 292 | return true; 293 | } 294 | } else if(typeof(cl) == "object" && js_Boot.__isNativeObj(cl)) { 295 | if(o instanceof cl) { 296 | return true; 297 | } 298 | } 299 | } else { 300 | return false; 301 | } 302 | if(cl == Class ? o.__name__ != null : false) { 303 | return true; 304 | } 305 | if(cl == Enum ? o.__ename__ != null : false) { 306 | return true; 307 | } 308 | return o.__enum__ == cl; 309 | } 310 | }; 311 | js_Boot.__nativeClassName = function(o) { 312 | var name = js_Boot.__toStr.call(o).slice(8,-1); 313 | if(name == "Object" || name == "Function" || name == "Math" || name == "JSON") { 314 | return null; 315 | } 316 | return name; 317 | }; 318 | js_Boot.__isNativeObj = function(o) { 319 | return js_Boot.__nativeClassName(o) != null; 320 | }; 321 | js_Boot.__resolveNativeClass = function(name) { 322 | return $global[name]; 323 | }; 324 | var Std = function() { }; 325 | Std.__name__ = true; 326 | Std.string = function(s) { 327 | return js_Boot.__string_rec(s,""); 328 | }; 329 | var ANSI = function() { }; 330 | ANSI.__name__ = true; 331 | ANSI.aset = function(attributes) { 332 | if(ANSI.strip || ANSI.stripIfUnavailable && !ANSI.available) { 333 | return ""; 334 | } 335 | var tmp = "\x1B" + "["; 336 | var _g = []; 337 | var _g1 = 0; 338 | while(_g1 < attributes.length) { 339 | var arg = attributes[_g1]; 340 | ++_g1; 341 | if(!js_Boot.__instanceof(arg,Attribute)) { 342 | throw new js__$Boot_HaxeError("Set argument is not an Attribute: " + Std.string(arg)); 343 | } 344 | _g.push(ANSI.values.get(arg)); 345 | } 346 | return tmp + _g.join(";") + "m"; 347 | }; 348 | ANSI.detectSupport = function() { 349 | if(Sys.systemName().toLowerCase().indexOf("window") == -1) { 350 | var result = -1; 351 | try { 352 | if(js_node_ChildProcess.spawnSync("tput",["colors"]).error == null) { 353 | result = 0; 354 | } else { 355 | result = 125; 356 | } 357 | } catch( e ) { 358 | } 359 | return result == 0; 360 | } else { 361 | return process.env["ANSICON"] != null; 362 | } 363 | }; 364 | var HxOverrides = function() { }; 365 | HxOverrides.__name__ = true; 366 | HxOverrides.remove = function(a,obj) { 367 | var i = a.indexOf(obj); 368 | if(i == -1) { 369 | return false; 370 | } 371 | a.splice(i,1); 372 | return true; 373 | }; 374 | HxOverrides.iter = function(a) { 375 | return { cur : 0, arr : a, hasNext : function() { 376 | return this.cur < this.arr.length; 377 | }, next : function() { 378 | return this.arr[this.cur++]; 379 | }}; 380 | }; 381 | Math.__name__ = true; 382 | var RunTests = function() { 383 | }; 384 | RunTests.__name__ = true; 385 | RunTests.main = function() { 386 | var this1 = [new tink_unit_TestSuiteBuilder0(new RunTests(),null)]; 387 | tink_testrunner_Runner.run(this1).handle(tink_testrunner_Runner.exit); 388 | }; 389 | RunTests.prototype = { 390 | test: function(asserts) { 391 | var e1 = "a"; 392 | var lh = e1; 393 | var rh = "a"; 394 | asserts["yield"](tink_streams_StreamStep.Data(new tink_testrunner_Assertion(tink_testrunner__$Assertion_AssertionResult_$Impl_$.ofBool(lh == rh),"e1 == 'a'" + " (" + tink_unit_Assert.stringify(lh) + " " + "==" + " " + tink_unit_Assert.stringify(rh) + ")",{ fileName : "RunTests.hx", lineNumber : 20, className : "RunTests", methodName : "test"}))); 395 | asserts["yield"](tink_streams_StreamStep.End); 396 | return asserts; 397 | } 398 | ,__class__: RunTests 399 | }; 400 | var StringTools = function() { }; 401 | StringTools.__name__ = true; 402 | StringTools.lpad = function(s,c,l) { 403 | if(c.length <= 0) { 404 | return s; 405 | } 406 | while(s.length < l) s = c + s; 407 | return s; 408 | }; 409 | var haxe_StackItem = { __ename__ : true, __constructs__ : ["CFunction","Module","FilePos","Method","LocalFunction"] }; 410 | haxe_StackItem.CFunction = ["CFunction",0]; 411 | haxe_StackItem.CFunction.toString = $estr; 412 | haxe_StackItem.CFunction.__enum__ = haxe_StackItem; 413 | haxe_StackItem.Module = function(m) { var $x = ["Module",1,m]; $x.__enum__ = haxe_StackItem; $x.toString = $estr; return $x; }; 414 | haxe_StackItem.FilePos = function(s,file,line) { var $x = ["FilePos",2,s,file,line]; $x.__enum__ = haxe_StackItem; $x.toString = $estr; return $x; }; 415 | haxe_StackItem.Method = function(classname,method) { var $x = ["Method",3,classname,method]; $x.__enum__ = haxe_StackItem; $x.toString = $estr; return $x; }; 416 | haxe_StackItem.LocalFunction = function(v) { var $x = ["LocalFunction",4,v]; $x.__enum__ = haxe_StackItem; $x.toString = $estr; return $x; }; 417 | var haxe_IMap = function() { }; 418 | haxe_IMap.__name__ = true; 419 | var haxe_Timer = function(time_ms) { 420 | var me = this; 421 | this.id = setInterval(function() { 422 | me.run(); 423 | },time_ms); 424 | }; 425 | haxe_Timer.__name__ = true; 426 | haxe_Timer.delay = function(f,time_ms) { 427 | var t = new haxe_Timer(time_ms); 428 | t.run = function() { 429 | t.stop(); 430 | f(); 431 | }; 432 | return t; 433 | }; 434 | haxe_Timer.prototype = { 435 | stop: function() { 436 | if(this.id == null) { 437 | return; 438 | } 439 | clearInterval(this.id); 440 | this.id = null; 441 | } 442 | ,run: function() { 443 | } 444 | ,__class__: haxe_Timer 445 | }; 446 | var haxe_ds_BalancedTree = function() { 447 | }; 448 | haxe_ds_BalancedTree.__name__ = true; 449 | haxe_ds_BalancedTree.prototype = { 450 | set: function(key,value) { 451 | this.root = this.setLoop(key,value,this.root); 452 | } 453 | ,get: function(key) { 454 | var node = this.root; 455 | while(node != null) { 456 | var c = this.compare(key,node.key); 457 | if(c == 0) { 458 | return node.value; 459 | } 460 | if(c < 0) { 461 | node = node.left; 462 | } else { 463 | node = node.right; 464 | } 465 | } 466 | return null; 467 | } 468 | ,setLoop: function(k,v,node) { 469 | if(node == null) { 470 | return new haxe_ds_TreeNode(null,k,v,null); 471 | } 472 | var c = this.compare(k,node.key); 473 | if(c == 0) { 474 | return new haxe_ds_TreeNode(node.left,k,v,node.right,node == null ? 0 : node._height); 475 | } else if(c < 0) { 476 | var nl = this.setLoop(k,v,node.left); 477 | return this.balance(nl,node.key,node.value,node.right); 478 | } else { 479 | var nr = this.setLoop(k,v,node.right); 480 | return this.balance(node.left,node.key,node.value,nr); 481 | } 482 | } 483 | ,balance: function(l,k,v,r) { 484 | var hl = l == null ? 0 : l._height; 485 | var hr = r == null ? 0 : r._height; 486 | if(hl > hr + 2) { 487 | var _this = l.left; 488 | var _this1 = l.right; 489 | if((_this == null ? 0 : _this._height) >= (_this1 == null ? 0 : _this1._height)) { 490 | return new haxe_ds_TreeNode(l.left,l.key,l.value,new haxe_ds_TreeNode(l.right,k,v,r)); 491 | } else { 492 | return new haxe_ds_TreeNode(new haxe_ds_TreeNode(l.left,l.key,l.value,l.right.left),l.right.key,l.right.value,new haxe_ds_TreeNode(l.right.right,k,v,r)); 493 | } 494 | } else if(hr > hl + 2) { 495 | var _this2 = r.right; 496 | var _this3 = r.left; 497 | if((_this2 == null ? 0 : _this2._height) > (_this3 == null ? 0 : _this3._height)) { 498 | return new haxe_ds_TreeNode(new haxe_ds_TreeNode(l,k,v,r.left),r.key,r.value,r.right); 499 | } else { 500 | return new haxe_ds_TreeNode(new haxe_ds_TreeNode(l,k,v,r.left.left),r.left.key,r.left.value,new haxe_ds_TreeNode(r.left.right,r.key,r.value,r.right)); 501 | } 502 | } else { 503 | return new haxe_ds_TreeNode(l,k,v,r,(hl > hr ? hl : hr) + 1); 504 | } 505 | } 506 | ,compare: function(k1,k2) { 507 | return Reflect.compare(k1,k2); 508 | } 509 | ,__class__: haxe_ds_BalancedTree 510 | }; 511 | var haxe_ds_TreeNode = function(l,k,v,r,h) { 512 | if(h == null) { 513 | h = -1; 514 | } 515 | this.left = l; 516 | this.key = k; 517 | this.value = v; 518 | this.right = r; 519 | if(h == -1) { 520 | var tmp; 521 | var _this = this.left; 522 | var _this1 = this.right; 523 | if((_this == null ? 0 : _this._height) > (_this1 == null ? 0 : _this1._height)) { 524 | var _this2 = this.left; 525 | if(_this2 == null) { 526 | tmp = 0; 527 | } else { 528 | tmp = _this2._height; 529 | } 530 | } else { 531 | var _this3 = this.right; 532 | if(_this3 == null) { 533 | tmp = 0; 534 | } else { 535 | tmp = _this3._height; 536 | } 537 | } 538 | this._height = tmp + 1; 539 | } else { 540 | this._height = h; 541 | } 542 | }; 543 | haxe_ds_TreeNode.__name__ = true; 544 | haxe_ds_TreeNode.prototype = { 545 | __class__: haxe_ds_TreeNode 546 | }; 547 | var haxe_ds_EnumValueMap = function() { 548 | haxe_ds_BalancedTree.call(this); 549 | }; 550 | haxe_ds_EnumValueMap.__name__ = true; 551 | haxe_ds_EnumValueMap.__interfaces__ = [haxe_IMap]; 552 | haxe_ds_EnumValueMap.__super__ = haxe_ds_BalancedTree; 553 | haxe_ds_EnumValueMap.prototype = $extend(haxe_ds_BalancedTree.prototype,{ 554 | compare: function(k1,k2) { 555 | var d = k1[1] - k2[1]; 556 | if(d != 0) { 557 | return d; 558 | } 559 | var p1 = k1.slice(2); 560 | var p2 = k2.slice(2); 561 | if(p1.length == 0 && p2.length == 0) { 562 | return 0; 563 | } 564 | return this.compareArgs(p1,p2); 565 | } 566 | ,compareArgs: function(a1,a2) { 567 | var ld = a1.length - a2.length; 568 | if(ld != 0) { 569 | return ld; 570 | } 571 | var _g1 = 0; 572 | var _g = a1.length; 573 | while(_g1 < _g) { 574 | var i = _g1++; 575 | var d = this.compareArg(a1[i],a2[i]); 576 | if(d != 0) { 577 | return d; 578 | } 579 | } 580 | return 0; 581 | } 582 | ,compareArg: function(v1,v2) { 583 | if(Reflect.isEnumValue(v1) && Reflect.isEnumValue(v2)) { 584 | return this.compare(v1,v2); 585 | } else if((v1 instanceof Array) && v1.__enum__ == null && ((v2 instanceof Array) && v2.__enum__ == null)) { 586 | return this.compareArgs(v1,v2); 587 | } else { 588 | return Reflect.compare(v1,v2); 589 | } 590 | } 591 | ,__class__: haxe_ds_EnumValueMap 592 | }); 593 | var haxe_io_Bytes = function(data) { 594 | this.length = data.byteLength; 595 | this.b = new Uint8Array(data); 596 | this.b.bufferValue = data; 597 | data.hxBytes = this; 598 | data.bytes = this.b; 599 | }; 600 | haxe_io_Bytes.__name__ = true; 601 | haxe_io_Bytes.prototype = { 602 | __class__: haxe_io_Bytes 603 | }; 604 | var js__$Boot_HaxeError = function(val) { 605 | Error.call(this); 606 | this.val = val; 607 | this.message = String(val); 608 | if(Error.captureStackTrace) { 609 | Error.captureStackTrace(this,js__$Boot_HaxeError); 610 | } 611 | }; 612 | js__$Boot_HaxeError.__name__ = true; 613 | js__$Boot_HaxeError.wrap = function(val) { 614 | if((val instanceof Error)) { 615 | return val; 616 | } else { 617 | return new js__$Boot_HaxeError(val); 618 | } 619 | }; 620 | js__$Boot_HaxeError.__super__ = Error; 621 | js__$Boot_HaxeError.prototype = $extend(Error.prototype,{ 622 | __class__: js__$Boot_HaxeError 623 | }); 624 | var js_node_buffer_Buffer = require("buffer").Buffer; 625 | var tink_core__$Callback_Callback_$Impl_$ = {}; 626 | tink_core__$Callback_Callback_$Impl_$.__name__ = true; 627 | tink_core__$Callback_Callback_$Impl_$.invoke = function(this1,data) { 628 | if(tink_core__$Callback_Callback_$Impl_$.depth < 1000) { 629 | tink_core__$Callback_Callback_$Impl_$.depth++; 630 | this1(data); 631 | tink_core__$Callback_Callback_$Impl_$.depth--; 632 | } else { 633 | var _e = this1; 634 | var f = function(data1) { 635 | tink_core__$Callback_Callback_$Impl_$.invoke(_e,data1); 636 | }; 637 | var a1 = data; 638 | tink_core__$Callback_Callback_$Impl_$.defer(function() { 639 | f(a1); 640 | }); 641 | } 642 | }; 643 | tink_core__$Callback_Callback_$Impl_$.fromNiladic = function(f) { 644 | var this1 = function(r) { 645 | f(); 646 | }; 647 | return this1; 648 | }; 649 | tink_core__$Callback_Callback_$Impl_$.defer = function(f) { 650 | process.nextTick(f); 651 | }; 652 | var tink_core__$Callback_LinkObject = function() { }; 653 | tink_core__$Callback_LinkObject.__name__ = true; 654 | tink_core__$Callback_LinkObject.prototype = { 655 | __class__: tink_core__$Callback_LinkObject 656 | }; 657 | var tink_core__$Callback_ListCell = function(cb,list) { 658 | if(cb == null) { 659 | throw new js__$Boot_HaxeError("callback expected but null received"); 660 | } 661 | this.cb = cb; 662 | this.list = list; 663 | }; 664 | tink_core__$Callback_ListCell.__name__ = true; 665 | tink_core__$Callback_ListCell.__interfaces__ = [tink_core__$Callback_LinkObject]; 666 | tink_core__$Callback_ListCell.prototype = { 667 | clear: function() { 668 | this.list = null; 669 | this.cb = null; 670 | } 671 | ,dissolve: function() { 672 | var _g = this.list; 673 | if(_g != null) { 674 | var v = _g; 675 | this.clear(); 676 | HxOverrides.remove(v,this); 677 | } 678 | } 679 | ,__class__: tink_core__$Callback_ListCell 680 | }; 681 | var tink_core__$Callback_CallbackList_$Impl_$ = {}; 682 | tink_core__$Callback_CallbackList_$Impl_$.__name__ = true; 683 | tink_core__$Callback_CallbackList_$Impl_$.add = function(this1,cb) { 684 | var node = new tink_core__$Callback_ListCell(cb,this1); 685 | this1.push(node); 686 | return node; 687 | }; 688 | tink_core__$Callback_CallbackList_$Impl_$.invoke = function(this1,data) { 689 | var _g = 0; 690 | var _g1 = this1.slice(); 691 | while(_g < _g1.length) { 692 | var cell = _g1[_g]; 693 | ++_g; 694 | if(cell.cb != null) { 695 | tink_core__$Callback_Callback_$Impl_$.invoke(cell.cb,data); 696 | } 697 | } 698 | }; 699 | tink_core__$Callback_CallbackList_$Impl_$.clear = function(this1) { 700 | var _g = 0; 701 | var _g1 = this1.splice(0,this1.length); 702 | while(_g < _g1.length) { 703 | var cell = _g1[_g]; 704 | ++_g; 705 | cell.clear(); 706 | } 707 | }; 708 | var tink_core_TypedError = function(code,message,pos) { 709 | if(code == null) { 710 | code = 500; 711 | } 712 | this.code = code; 713 | this.message = message; 714 | this.pos = pos; 715 | this.exceptionStack = []; 716 | this.callStack = []; 717 | }; 718 | tink_core_TypedError.__name__ = true; 719 | tink_core_TypedError.prototype = { 720 | printPos: function() { 721 | return this.pos.className + "." + this.pos.methodName + ":" + this.pos.lineNumber; 722 | } 723 | ,toString: function() { 724 | var ret = "Error#" + this.code + ": " + this.message; 725 | if(this.pos != null) { 726 | ret += " @ " + this.printPos(); 727 | } 728 | return ret; 729 | } 730 | ,__class__: tink_core_TypedError 731 | }; 732 | var tink_core__$Future_FutureObject = function() { }; 733 | tink_core__$Future_FutureObject.__name__ = true; 734 | tink_core__$Future_FutureObject.prototype = { 735 | __class__: tink_core__$Future_FutureObject 736 | }; 737 | var tink_core_Noise = { __ename__ : true, __constructs__ : ["Noise"] }; 738 | tink_core_Noise.Noise = ["Noise",0]; 739 | tink_core_Noise.Noise.toString = $estr; 740 | tink_core_Noise.Noise.__enum__ = tink_core_Noise; 741 | var tink_core__$Lazy_LazyObject = function() { }; 742 | tink_core__$Lazy_LazyObject.__name__ = true; 743 | tink_core__$Lazy_LazyObject.prototype = { 744 | __class__: tink_core__$Lazy_LazyObject 745 | }; 746 | var tink_core__$Lazy_LazyConst = function(value) { 747 | this.value = value; 748 | }; 749 | tink_core__$Lazy_LazyConst.__name__ = true; 750 | tink_core__$Lazy_LazyConst.__interfaces__ = [tink_core__$Lazy_LazyObject]; 751 | tink_core__$Lazy_LazyConst.prototype = { 752 | get: function() { 753 | return this.value; 754 | } 755 | ,map: function(f) { 756 | return new tink_core__$Lazy_LazyConst(f(this.value)); 757 | } 758 | ,__class__: tink_core__$Lazy_LazyConst 759 | }; 760 | var tink_core__$Future_SyncFuture = function(value) { 761 | this.value = value; 762 | }; 763 | tink_core__$Future_SyncFuture.__name__ = true; 764 | tink_core__$Future_SyncFuture.__interfaces__ = [tink_core__$Future_FutureObject]; 765 | tink_core__$Future_SyncFuture.prototype = { 766 | map: function(f) { 767 | return new tink_core__$Future_SyncFuture(this.value.map(f)); 768 | } 769 | ,flatMap: function(f) { 770 | var l = this.value.map(f); 771 | return new tink_core__$Future_SimpleFuture(function(cb) { 772 | return l.get().handle(cb); 773 | }); 774 | } 775 | ,handle: function(cb) { 776 | tink_core__$Callback_Callback_$Impl_$.invoke(cb,this.value.get()); 777 | return null; 778 | } 779 | ,gather: function() { 780 | return this; 781 | } 782 | ,__class__: tink_core__$Future_SyncFuture 783 | }; 784 | var tink_core__$Future_Future_$Impl_$ = {}; 785 | tink_core__$Future_Future_$Impl_$.__name__ = true; 786 | tink_core__$Future_Future_$Impl_$.next = function(this1,n) { 787 | return this1.flatMap(function(v) { 788 | return n(v); 789 | }); 790 | }; 791 | tink_core__$Future_Future_$Impl_$.flatten = function(f) { 792 | return new tink_core__$Future_NestedFuture(f); 793 | }; 794 | tink_core__$Future_Future_$Impl_$.async = function(f,lazy) { 795 | if(lazy == null) { 796 | lazy = false; 797 | } 798 | if(lazy) { 799 | return new tink_core__$Future_LazyTrigger(f); 800 | } else { 801 | var op = new tink_core_FutureTrigger(); 802 | var wrapped = f; 803 | tink_core__$Callback_Callback_$Impl_$.invoke(wrapped,$bind(op,op.trigger)); 804 | return op; 805 | } 806 | }; 807 | var tink_core__$Future_SimpleFuture = function(f) { 808 | this.f = f; 809 | }; 810 | tink_core__$Future_SimpleFuture.__name__ = true; 811 | tink_core__$Future_SimpleFuture.__interfaces__ = [tink_core__$Future_FutureObject]; 812 | tink_core__$Future_SimpleFuture.prototype = { 813 | handle: function(callback) { 814 | return this.f(callback); 815 | } 816 | ,map: function(f) { 817 | var _gthis = this; 818 | return new tink_core__$Future_SimpleFuture(function(cb) { 819 | return _gthis.f(function(v) { 820 | var tmp = f(v); 821 | tink_core__$Callback_Callback_$Impl_$.invoke(cb,tmp); 822 | }); 823 | }); 824 | } 825 | ,flatMap: function(f) { 826 | var f1 = f; 827 | var _gthis = this; 828 | return tink_core__$Future_Future_$Impl_$.flatten(new tink_core__$Future_SimpleFuture(function(cb) { 829 | return _gthis.f(function(v) { 830 | var tmp = f1(v); 831 | tink_core__$Callback_Callback_$Impl_$.invoke(cb,tmp); 832 | }); 833 | })); 834 | } 835 | ,gather: function() { 836 | return tink_core_FutureTrigger.gatherFuture(this); 837 | } 838 | ,__class__: tink_core__$Future_SimpleFuture 839 | }; 840 | var tink_core__$Future_NestedFuture = function(outer) { 841 | this.outer = outer; 842 | }; 843 | tink_core__$Future_NestedFuture.__name__ = true; 844 | tink_core__$Future_NestedFuture.__interfaces__ = [tink_core__$Future_FutureObject]; 845 | tink_core__$Future_NestedFuture.prototype = { 846 | map: function(f) { 847 | var ret = this.outer.flatMap(function(inner) { 848 | var ret1 = inner.map(f); 849 | return ret1.gather(); 850 | }); 851 | return ret.gather(); 852 | } 853 | ,flatMap: function(f) { 854 | var ret = this.outer.flatMap(function(inner) { 855 | var ret1 = inner.flatMap(f); 856 | return ret1.gather(); 857 | }); 858 | return ret.gather(); 859 | } 860 | ,gather: function() { 861 | return tink_core_FutureTrigger.gatherFuture(this); 862 | } 863 | ,handle: function(cb) { 864 | var ret = null; 865 | ret = this.outer.handle(function(inner) { 866 | ret = inner.handle(function(result) { 867 | tink_core__$Callback_Callback_$Impl_$.invoke(cb,result); 868 | }); 869 | }); 870 | return ret; 871 | } 872 | ,__class__: tink_core__$Future_NestedFuture 873 | }; 874 | var tink_core_FutureTrigger = function() { 875 | var this1 = []; 876 | this.list = this1; 877 | }; 878 | tink_core_FutureTrigger.__name__ = true; 879 | tink_core_FutureTrigger.__interfaces__ = [tink_core__$Future_FutureObject]; 880 | tink_core_FutureTrigger.gatherFuture = function(f) { 881 | var op = null; 882 | var this1 = new tink_core__$Future_SimpleFuture(function(cb) { 883 | if(op == null) { 884 | op = new tink_core_FutureTrigger(); 885 | f.handle($bind(op,op.trigger)); 886 | f = null; 887 | } 888 | return op.handle(cb); 889 | }); 890 | return this1; 891 | }; 892 | tink_core_FutureTrigger.prototype = { 893 | handle: function(callback) { 894 | var _g = this.list; 895 | if(_g == null) { 896 | tink_core__$Callback_Callback_$Impl_$.invoke(callback,this.result); 897 | return null; 898 | } else { 899 | var v = _g; 900 | return tink_core__$Callback_CallbackList_$Impl_$.add(v,callback); 901 | } 902 | } 903 | ,map: function(f) { 904 | var _g = this.list; 905 | if(_g == null) { 906 | return new tink_core__$Future_SyncFuture(new tink_core__$Lazy_LazyConst(f(this.result))); 907 | } else { 908 | var v = _g; 909 | var ret = new tink_core_FutureTrigger(); 910 | tink_core__$Callback_CallbackList_$Impl_$.add(this.list,function(v1) { 911 | var tmp = f(v1); 912 | ret.trigger(tmp); 913 | }); 914 | return ret; 915 | } 916 | } 917 | ,flatMap: function(f) { 918 | var _g = this.list; 919 | if(_g == null) { 920 | return f(this.result); 921 | } else { 922 | var v = _g; 923 | var ret = new tink_core_FutureTrigger(); 924 | tink_core__$Callback_CallbackList_$Impl_$.add(this.list,function(v1) { 925 | f(v1).handle($bind(ret,ret.trigger)); 926 | }); 927 | return ret; 928 | } 929 | } 930 | ,gather: function() { 931 | return this; 932 | } 933 | ,trigger: function(result) { 934 | if(this.list == null) { 935 | return false; 936 | } else { 937 | var list = this.list; 938 | this.list = null; 939 | this.result = result; 940 | tink_core__$Callback_CallbackList_$Impl_$.invoke(list,result); 941 | tink_core__$Callback_CallbackList_$Impl_$.clear(list); 942 | return true; 943 | } 944 | } 945 | ,__class__: tink_core_FutureTrigger 946 | }; 947 | var tink_core__$Future_LazyTrigger = function(op) { 948 | this.op = op; 949 | tink_core_FutureTrigger.call(this); 950 | }; 951 | tink_core__$Future_LazyTrigger.__name__ = true; 952 | tink_core__$Future_LazyTrigger.__super__ = tink_core_FutureTrigger; 953 | tink_core__$Future_LazyTrigger.prototype = $extend(tink_core_FutureTrigger.prototype,{ 954 | eager: function() { 955 | if(this.op != null) { 956 | var op = this.op; 957 | this.op = null; 958 | tink_core__$Callback_Callback_$Impl_$.invoke(op,$bind(this,this.trigger)); 959 | } 960 | return this; 961 | } 962 | ,map: function(f) { 963 | var _gthis = this; 964 | if(this.op == null) { 965 | return tink_core_FutureTrigger.prototype.map.call(this,f); 966 | } else { 967 | return tink_core__$Future_Future_$Impl_$.async(function(cb) { 968 | _gthis.handle(function(v) { 969 | var tmp = f(v); 970 | cb(tmp); 971 | }); 972 | },true); 973 | } 974 | } 975 | ,flatMap: function(f) { 976 | var _gthis = this; 977 | if(this.op == null) { 978 | return tink_core_FutureTrigger.prototype.flatMap.call(this,f); 979 | } else { 980 | return tink_core__$Future_Future_$Impl_$.async(function(cb) { 981 | _gthis.handle(function(v) { 982 | f(v).handle(cb); 983 | }); 984 | },true); 985 | } 986 | } 987 | ,handle: function(cb) { 988 | this.eager(); 989 | return tink_core_FutureTrigger.prototype.handle.call(this,cb); 990 | } 991 | ,__class__: tink_core__$Future_LazyTrigger 992 | }); 993 | var tink_core_Outcome = { __ename__ : true, __constructs__ : ["Success","Failure"] }; 994 | tink_core_Outcome.Success = function(data) { var $x = ["Success",0,data]; $x.__enum__ = tink_core_Outcome; $x.toString = $estr; return $x; }; 995 | tink_core_Outcome.Failure = function(failure) { var $x = ["Failure",1,failure]; $x.__enum__ = tink_core_Outcome; $x.toString = $estr; return $x; }; 996 | var tink_core_OutcomeTools = function() { }; 997 | tink_core_OutcomeTools.__name__ = true; 998 | tink_core_OutcomeTools.isSuccess = function(outcome) { 999 | if(outcome[1] == 0) { 1000 | return true; 1001 | } else { 1002 | return false; 1003 | } 1004 | }; 1005 | var tink_core__$Promise_Promise_$Impl_$ = {}; 1006 | tink_core__$Promise_Promise_$Impl_$.__name__ = true; 1007 | tink_core__$Promise_Promise_$Impl_$.next = function(this1,f,gather) { 1008 | if(gather == null) { 1009 | gather = true; 1010 | } 1011 | var ret = this1.flatMap(function(o) { 1012 | switch(o[1]) { 1013 | case 0: 1014 | var d = o[2]; 1015 | return f(d); 1016 | case 1: 1017 | var f1 = o[2]; 1018 | return new tink_core__$Future_SyncFuture(new tink_core__$Lazy_LazyConst(tink_core_Outcome.Failure(f1))); 1019 | } 1020 | }); 1021 | if(gather) { 1022 | return ret.gather(); 1023 | } else { 1024 | return ret; 1025 | } 1026 | }; 1027 | tink_core__$Promise_Promise_$Impl_$.ofOutcome = function(o) { 1028 | return new tink_core__$Future_SyncFuture(new tink_core__$Lazy_LazyConst(o)); 1029 | }; 1030 | var tink_streams_StreamObject = function() { }; 1031 | tink_streams_StreamObject.__name__ = true; 1032 | tink_streams_StreamObject.prototype = { 1033 | __class__: tink_streams_StreamObject 1034 | }; 1035 | var tink_streams_StreamBase = function() { }; 1036 | tink_streams_StreamBase.__name__ = true; 1037 | tink_streams_StreamBase.__interfaces__ = [tink_streams_StreamObject]; 1038 | tink_streams_StreamBase.prototype = { 1039 | forEachAsync: function(item) { 1040 | return new tink_core__$Future_SyncFuture(new tink_core__$Lazy_LazyConst(tink_core_Outcome.Success(true))); 1041 | } 1042 | ,__class__: tink_streams_StreamBase 1043 | }; 1044 | var tink_streams_StepWise = function() { }; 1045 | tink_streams_StepWise.__name__ = true; 1046 | tink_streams_StepWise.__super__ = tink_streams_StreamBase; 1047 | tink_streams_StepWise.prototype = $extend(tink_streams_StreamBase.prototype,{ 1048 | next: function() { 1049 | return new tink_core__$Future_SyncFuture(new tink_core__$Lazy_LazyConst(tink_streams_StreamStep.End)); 1050 | } 1051 | ,forEachAsync: function(item) { 1052 | var _gthis = this; 1053 | return tink_core__$Future_Future_$Impl_$.async(function(cb) { 1054 | var next = null; 1055 | next = function() { 1056 | while(true) { 1057 | var touched = [false]; 1058 | _gthis.next().handle((function(touched1) { 1059 | return function(step) { 1060 | switch(step[1]) { 1061 | case 0: 1062 | var data = step[2]; 1063 | item(data).handle((function(touched2) { 1064 | return function(resume) { 1065 | if(!resume) { 1066 | cb(tink_core_Outcome.Success(false)); 1067 | } else if(touched2[0]) { 1068 | next(); 1069 | } else { 1070 | touched2[0] = true; 1071 | } 1072 | }; 1073 | })(touched1)); 1074 | break; 1075 | case 1: 1076 | cb(tink_core_Outcome.Success(true)); 1077 | break; 1078 | case 2: 1079 | var e = step[2]; 1080 | cb(tink_core_Outcome.Failure(e)); 1081 | break; 1082 | } 1083 | }; 1084 | })(touched)); 1085 | if(!touched[0]) { 1086 | touched[0] = true; 1087 | break; 1088 | } 1089 | } 1090 | }; 1091 | var next1 = next; 1092 | next1(); 1093 | }); 1094 | } 1095 | ,__class__: tink_streams_StepWise 1096 | }); 1097 | var tink_streams_Accumulator = function() { 1098 | this.buffered = []; 1099 | this.waiting = []; 1100 | }; 1101 | tink_streams_Accumulator.__name__ = true; 1102 | tink_streams_Accumulator.__super__ = tink_streams_StepWise; 1103 | tink_streams_Accumulator.prototype = $extend(tink_streams_StepWise.prototype,{ 1104 | next: function() { 1105 | var _g = this.buffered.shift(); 1106 | if(_g == null) { 1107 | if(this.end != null) { 1108 | return new tink_core__$Future_SyncFuture(new tink_core__$Lazy_LazyConst(this.end)); 1109 | } else { 1110 | var ret = new tink_core_FutureTrigger(); 1111 | this.waiting.push(ret); 1112 | return ret; 1113 | } 1114 | } else { 1115 | var v = _g; 1116 | return new tink_core__$Future_SyncFuture(new tink_core__$Lazy_LazyConst(v)); 1117 | } 1118 | } 1119 | ,'yield': function(step) { 1120 | if(this.end != null) { 1121 | return; 1122 | } 1123 | var tmp; 1124 | switch(step[1]) { 1125 | case 1:case 2: 1126 | tmp = true; 1127 | break; 1128 | default: 1129 | tmp = false; 1130 | } 1131 | if(tmp) { 1132 | this.end = step; 1133 | } 1134 | var _g = this.waiting.shift(); 1135 | if(_g == null) { 1136 | this.buffered.push(step); 1137 | } else { 1138 | var v = _g; 1139 | v.trigger(step); 1140 | } 1141 | } 1142 | ,__class__: tink_streams_Accumulator 1143 | }); 1144 | var tink_streams_StreamStep = { __ename__ : true, __constructs__ : ["Data","End","Fail"] }; 1145 | tink_streams_StreamStep.Data = function(data) { var $x = ["Data",0,data]; $x.__enum__ = tink_streams_StreamStep; $x.toString = $estr; return $x; }; 1146 | tink_streams_StreamStep.End = ["End",1]; 1147 | tink_streams_StreamStep.End.toString = $estr; 1148 | tink_streams_StreamStep.End.__enum__ = tink_streams_StreamStep; 1149 | tink_streams_StreamStep.Fail = function(e) { var $x = ["Fail",2,e]; $x.__enum__ = tink_streams_StreamStep; $x.toString = $estr; return $x; }; 1150 | var tink_testrunner_Assertion = function(holds,description,pos) { 1151 | this.holds = holds; 1152 | this.description = description; 1153 | this.pos = pos; 1154 | }; 1155 | tink_testrunner_Assertion.__name__ = true; 1156 | tink_testrunner_Assertion.prototype = { 1157 | __class__: tink_testrunner_Assertion 1158 | }; 1159 | var tink_testrunner__$Assertion_AssertionResult_$Impl_$ = {}; 1160 | tink_testrunner__$Assertion_AssertionResult_$Impl_$.__name__ = true; 1161 | tink_testrunner__$Assertion_AssertionResult_$Impl_$.ofBool = function(v) { 1162 | if(v) { 1163 | return tink_core_Outcome.Success(tink_core_Noise.Noise); 1164 | } else { 1165 | return tink_core_Outcome.Failure(null); 1166 | } 1167 | }; 1168 | var tink_testrunner_Case = function() { }; 1169 | tink_testrunner_Case.__name__ = true; 1170 | tink_testrunner_Case.prototype = { 1171 | __class__: tink_testrunner_Case 1172 | }; 1173 | var tink_testrunner_Reporter = function() { }; 1174 | tink_testrunner_Reporter.__name__ = true; 1175 | tink_testrunner_Reporter.prototype = { 1176 | __class__: tink_testrunner_Reporter 1177 | }; 1178 | var tink_testrunner_ReportType = { __ename__ : true, __constructs__ : ["BatchStart","SuiteStart","CaseStart","Assertion","CaseFinish","SuiteFinish","BatchFinish"] }; 1179 | tink_testrunner_ReportType.BatchStart = ["BatchStart",0]; 1180 | tink_testrunner_ReportType.BatchStart.toString = $estr; 1181 | tink_testrunner_ReportType.BatchStart.__enum__ = tink_testrunner_ReportType; 1182 | tink_testrunner_ReportType.SuiteStart = function(info) { var $x = ["SuiteStart",1,info]; $x.__enum__ = tink_testrunner_ReportType; $x.toString = $estr; return $x; }; 1183 | tink_testrunner_ReportType.CaseStart = function(info) { var $x = ["CaseStart",2,info]; $x.__enum__ = tink_testrunner_ReportType; $x.toString = $estr; return $x; }; 1184 | tink_testrunner_ReportType.Assertion = function(assertion) { var $x = ["Assertion",3,assertion]; $x.__enum__ = tink_testrunner_ReportType; $x.toString = $estr; return $x; }; 1185 | tink_testrunner_ReportType.CaseFinish = function(result) { var $x = ["CaseFinish",4,result]; $x.__enum__ = tink_testrunner_ReportType; $x.toString = $estr; return $x; }; 1186 | tink_testrunner_ReportType.SuiteFinish = function(result) { var $x = ["SuiteFinish",5,result]; $x.__enum__ = tink_testrunner_ReportType; $x.toString = $estr; return $x; }; 1187 | tink_testrunner_ReportType.BatchFinish = function(result) { var $x = ["BatchFinish",6,result]; $x.__enum__ = tink_testrunner_ReportType; $x.toString = $estr; return $x; }; 1188 | var tink_testrunner_Formatter = function() { }; 1189 | tink_testrunner_Formatter.__name__ = true; 1190 | tink_testrunner_Formatter.prototype = { 1191 | __class__: tink_testrunner_Formatter 1192 | }; 1193 | var tink_testrunner_BasicFormatter = function() { 1194 | }; 1195 | tink_testrunner_BasicFormatter.__name__ = true; 1196 | tink_testrunner_BasicFormatter.__interfaces__ = [tink_testrunner_Formatter]; 1197 | tink_testrunner_BasicFormatter.prototype = { 1198 | success: function(v) { 1199 | return this.color(v,"green"); 1200 | } 1201 | ,error: function(v) { 1202 | return this.color(v,"red"); 1203 | } 1204 | ,info: function(v) { 1205 | return this.color(v,"yellow"); 1206 | } 1207 | ,extra: function(v) { 1208 | return this.color(v,"cyan"); 1209 | } 1210 | ,mute: function(v) { 1211 | return this.color(v,"blue"); 1212 | } 1213 | ,color: function(v,c) { 1214 | return v; 1215 | } 1216 | ,__class__: tink_testrunner_BasicFormatter 1217 | }; 1218 | var tink_testrunner_AnsiFormatter = function() { 1219 | tink_testrunner_BasicFormatter.call(this); 1220 | }; 1221 | tink_testrunner_AnsiFormatter.__name__ = true; 1222 | tink_testrunner_AnsiFormatter.__super__ = tink_testrunner_BasicFormatter; 1223 | tink_testrunner_AnsiFormatter.prototype = $extend(tink_testrunner_BasicFormatter.prototype,{ 1224 | color: function(v,c) { 1225 | switch(c) { 1226 | case "blue": 1227 | return ANSI.aset([Attribute.Blue]) + v + ANSI.aset([Attribute.DefaultForeground]); 1228 | case "cyan": 1229 | return ANSI.aset([Attribute.Cyan]) + v + ANSI.aset([Attribute.DefaultForeground]); 1230 | case "green": 1231 | return ANSI.aset([Attribute.Green]) + v + ANSI.aset([Attribute.DefaultForeground]); 1232 | case "magenta": 1233 | return ANSI.aset([Attribute.Magenta]) + v + ANSI.aset([Attribute.DefaultForeground]); 1234 | case "red": 1235 | return ANSI.aset([Attribute.Red]) + v + ANSI.aset([Attribute.DefaultForeground]); 1236 | case "yellow": 1237 | return ANSI.aset([Attribute.Yellow]) + v + ANSI.aset([Attribute.DefaultForeground]); 1238 | default: 1239 | return ANSI.aset([Attribute.DefaultForeground]) + v; 1240 | } 1241 | } 1242 | ,__class__: tink_testrunner_AnsiFormatter 1243 | }); 1244 | var tink_testrunner_BasicReporter = function(formatter) { 1245 | this.noise = new tink_core__$Future_SyncFuture(new tink_core__$Lazy_LazyConst(tink_core_Noise.Noise)); 1246 | var tmp; 1247 | if(formatter != null) { 1248 | tmp = formatter; 1249 | } else { 1250 | var _g = Sys.systemName(); 1251 | if(_g == "Windows") { 1252 | tmp = new tink_testrunner_BasicFormatter(); 1253 | } else { 1254 | tmp = new tink_testrunner_AnsiFormatter(); 1255 | } 1256 | } 1257 | this.formatter = tmp; 1258 | }; 1259 | tink_testrunner_BasicReporter.__name__ = true; 1260 | tink_testrunner_BasicReporter.__interfaces__ = [tink_testrunner_Reporter]; 1261 | tink_testrunner_BasicReporter.prototype = { 1262 | report: function(type) { 1263 | switch(type[1]) { 1264 | case 0: 1265 | break; 1266 | case 1: 1267 | var info = type[2]; 1268 | this.println(" "); 1269 | this.println(this.formatter.info(info.name)); 1270 | break; 1271 | case 2: 1272 | var info1 = type[2]; 1273 | var m = this.formatter.info(this.indent(info1.name,2)) + ": "; 1274 | if(info1.pos != null) { 1275 | m += this.formatter.extra("[" + info1.pos.fileName + ":" + info1.pos.lineNumber + "] "); 1276 | } 1277 | if(info1.description != null) { 1278 | m += this.formatter.mute(info1.description); 1279 | } 1280 | this.println(m); 1281 | break; 1282 | case 3: 1283 | var assertion = type[2]; 1284 | var failure = null; 1285 | var holds; 1286 | var _g = assertion.holds; 1287 | switch(_g[1]) { 1288 | case 0: 1289 | holds = this.formatter.success("[OK]"); 1290 | break; 1291 | case 1: 1292 | var msg = _g[2]; 1293 | failure = msg; 1294 | holds = this.formatter.error("[FAIL]"); 1295 | break; 1296 | } 1297 | var pos = this.formatter.extra("[" + assertion.pos.fileName + ":" + assertion.pos.lineNumber + "]"); 1298 | var m1 = this.indent("- " + holds + " " + pos + " " + assertion.description,4); 1299 | this.println(m1); 1300 | if(failure != null) { 1301 | this.println(this.formatter.error(this.indent(failure,8))); 1302 | } 1303 | break; 1304 | case 4: 1305 | var results = type[2].results; 1306 | switch(results[1]) { 1307 | case 0: 1308 | break; 1309 | case 1: 1310 | var e = results[2]; 1311 | this.println(this.formatter.error(this.indent("- " + e.toString(),4))); 1312 | break; 1313 | } 1314 | break; 1315 | case 5: 1316 | var result = type[2]; 1317 | var _g1 = result.result; 1318 | switch(_g1[1]) { 1319 | case 0: 1320 | break; 1321 | case 1: 1322 | var e1 = _g1[2]; 1323 | this.println(this.formatter.error(this.indent("Setup Failed: " + e1.toString(),2))); 1324 | break; 1325 | case 2: 1326 | var e2 = _g1[2]; 1327 | this.println(this.formatter.error(this.indent("Teardown Failed: " + e2.toString(),2))); 1328 | break; 1329 | } 1330 | break; 1331 | case 6: 1332 | var result1 = type[2]; 1333 | var summary = tink_testrunner__$Runner_BatchResult_$Impl_$.summary(result1); 1334 | var total = summary.assertions.length; 1335 | var failures = 0; 1336 | var errors = 0; 1337 | var _g2 = 0; 1338 | var _g11 = summary.failures; 1339 | while(_g2 < _g11.length) { 1340 | var f = _g11[_g2]; 1341 | ++_g2; 1342 | if(f[1] == 0) { 1343 | ++failures; 1344 | } else { 1345 | ++errors; 1346 | } 1347 | } 1348 | var success = total - failures; 1349 | var m_b = ""; 1350 | m_b += total == null ? "null" : "" + total; 1351 | m_b += " Assertion"; 1352 | if(total > 1) { 1353 | m_b += "s"; 1354 | } 1355 | m_b += " "; 1356 | m_b += success == null ? "null" : "" + success; 1357 | m_b += " Success"; 1358 | m_b += " "; 1359 | m_b += failures == null ? "null" : "" + failures; 1360 | m_b += " Failure"; 1361 | if(failures > 1) { 1362 | m_b += "s"; 1363 | } 1364 | m_b += " "; 1365 | m_b += errors == null ? "null" : "" + errors; 1366 | m_b += " Error"; 1367 | if(errors > 1) { 1368 | m_b += "s"; 1369 | } 1370 | var m2 = m_b += " "; 1371 | this.println(" "); 1372 | this.println(failures == 0 && errors == 0 ? this.formatter.success(m2) : this.formatter.error(m2)); 1373 | this.println(" "); 1374 | break; 1375 | } 1376 | return this.noise; 1377 | } 1378 | ,println: function(v) { 1379 | process.stdout.write(v); 1380 | process.stdout.write("\n"); 1381 | } 1382 | ,indent: function(v,i) { 1383 | if(i == null) { 1384 | i = 0; 1385 | } 1386 | return v.split("\n").map(function(line) { 1387 | return StringTools.lpad(""," ",i) + line; 1388 | }).join("\n"); 1389 | } 1390 | ,__class__: tink_testrunner_BasicReporter 1391 | }; 1392 | var tink_testrunner_Runner = function() { }; 1393 | tink_testrunner_Runner.__name__ = true; 1394 | tink_testrunner_Runner.exit = function(result) { 1395 | process.exit(tink_testrunner__$Runner_BatchResult_$Impl_$.summary(result).failures.length); 1396 | }; 1397 | tink_testrunner_Runner.run = function(batch,reporter,timers) { 1398 | if(reporter == null) { 1399 | reporter = new tink_testrunner_BasicReporter(); 1400 | } 1401 | if(timers == null) { 1402 | timers = new tink_testrunner_HaxeTimerManager(); 1403 | } 1404 | var includeMode = false; 1405 | var _g = 0; 1406 | var _g1 = batch; 1407 | while(_g < _g1.length) { 1408 | var s = _g1[_g]; 1409 | ++_g; 1410 | if(includeMode) { 1411 | break; 1412 | } 1413 | var _g2 = 0; 1414 | var _g3 = s.cases; 1415 | while(_g2 < _g3.length) { 1416 | var c = _g3[_g2]; 1417 | ++_g2; 1418 | if(c.include) { 1419 | includeMode = true; 1420 | break; 1421 | } 1422 | } 1423 | } 1424 | return tink_core__$Future_Future_$Impl_$.async(function(cb) { 1425 | reporter.report(tink_testrunner_ReportType.BatchStart).handle(function(_) { 1426 | var iter = HxOverrides.iter(batch); 1427 | var results = []; 1428 | var next = null; 1429 | next = function() { 1430 | if(iter.hasNext()) { 1431 | var suite = iter.next(); 1432 | tink_testrunner_Runner.runSuite(suite,reporter,timers,includeMode).handle(function(o) { 1433 | results.push(o); 1434 | reporter.report(tink_testrunner_ReportType.SuiteFinish(o)).handle(tink_core__$Callback_Callback_$Impl_$.fromNiladic(next)); 1435 | }); 1436 | } else { 1437 | var next1 = reporter.report(tink_testrunner_ReportType.BatchFinish(results)); 1438 | var f = cb; 1439 | var a1 = results; 1440 | next1.handle(tink_core__$Callback_Callback_$Impl_$.fromNiladic(function() { 1441 | f(a1); 1442 | })); 1443 | } 1444 | }; 1445 | var next2 = next; 1446 | next2(); 1447 | }); 1448 | }); 1449 | }; 1450 | tink_testrunner_Runner.runSuite = function(suite,reporter,timers,includeMode) { 1451 | return tink_core__$Future_Future_$Impl_$.async(function(cb) { 1452 | reporter.report(tink_testrunner_ReportType.SuiteStart(suite.info)).handle(function(_) { 1453 | var cases = suite.cases.filter(function(c) { 1454 | if(!c.exclude) { 1455 | if(!(!includeMode)) { 1456 | return c.include; 1457 | } else { 1458 | return true; 1459 | } 1460 | } else { 1461 | return false; 1462 | } 1463 | }); 1464 | if(cases.length > 0) { 1465 | var iter = HxOverrides.iter(cases); 1466 | var results = []; 1467 | var next = null; 1468 | next = function() { 1469 | if(iter.hasNext()) { 1470 | var caze = iter.next(); 1471 | tink_testrunner_Runner.runCase(caze,suite,reporter,timers).handle(function(r) { 1472 | results.push(r); 1473 | next(); 1474 | }); 1475 | } else { 1476 | suite.teardown().handle(function(o) { 1477 | var next1; 1478 | switch(o[1]) { 1479 | case 0: 1480 | next1 = tink_testrunner_SuiteResultType.Success(results); 1481 | break; 1482 | case 1: 1483 | var e = o[2]; 1484 | next1 = tink_testrunner_SuiteResultType.TeardownFailed(e,results); 1485 | break; 1486 | } 1487 | cb({ info : suite.info, result : next1}); 1488 | }); 1489 | } 1490 | }; 1491 | var next2 = next; 1492 | suite.setup().handle(function(o1) { 1493 | switch(o1[1]) { 1494 | case 0: 1495 | next2(); 1496 | break; 1497 | case 1: 1498 | var e1 = o1[2]; 1499 | cb({ info : suite.info, result : tink_testrunner_SuiteResultType.SetupFailed(e1)}); 1500 | break; 1501 | } 1502 | }); 1503 | } else { 1504 | cb({ info : suite.info, result : tink_testrunner_SuiteResultType.Success([])}); 1505 | } 1506 | }); 1507 | }); 1508 | }; 1509 | tink_testrunner_Runner.runCase = function(caze,suite,reporter,timers) { 1510 | return tink_core__$Future_Future_$Impl_$.async(function(cb) { 1511 | reporter.report(tink_testrunner_ReportType.CaseStart(caze.info)).handle(function(_) { 1512 | tink_core__$Promise_Promise_$Impl_$.next(tink_core__$Promise_Promise_$Impl_$.next(tink_testrunner_TimeoutHelper.timeout(suite.before(),caze.timeout,timers,caze.pos),function(_1) { 1513 | var assertions = []; 1514 | return tink_testrunner_TimeoutHelper.timeout(tink_core__$Future_Future_$Impl_$.next(caze.execute().forEachAsync(function(a) { 1515 | assertions.push(a); 1516 | var ret = reporter.report(tink_testrunner_ReportType.Assertion(a)).map(function(_2) { 1517 | return true; 1518 | }); 1519 | return ret.gather(); 1520 | }),function(_3) { 1521 | return tink_core__$Promise_Promise_$Impl_$.ofOutcome(tink_core_Outcome.Success(assertions)); 1522 | }),caze.timeout,timers,{ fileName : "Runner.hx", lineNumber : 107, className : "tink.testrunner.Runner", methodName : "runCase"}); 1523 | }),function(result) { 1524 | return tink_core__$Promise_Promise_$Impl_$.next(tink_testrunner_TimeoutHelper.timeout(suite.after(),caze.timeout,timers,caze.pos),function(_4) { 1525 | return tink_core__$Promise_Promise_$Impl_$.ofOutcome(tink_core_Outcome.Success(result)); 1526 | }); 1527 | }).handle(function(result1) { 1528 | var results = { info : caze.info, results : result1}; 1529 | reporter.report(tink_testrunner_ReportType.CaseFinish(results)).handle(function(_5) { 1530 | cb(results); 1531 | }); 1532 | }); 1533 | }); 1534 | }); 1535 | }; 1536 | var tink_testrunner_TimeoutHelper = function() { }; 1537 | tink_testrunner_TimeoutHelper.__name__ = true; 1538 | tink_testrunner_TimeoutHelper.timeout = function(promise,ms,timers,pos) { 1539 | return tink_core__$Future_Future_$Impl_$.async(function(cb) { 1540 | var done = false; 1541 | var timer = null; 1542 | var link = promise.handle(function(o) { 1543 | done = true; 1544 | if(timer != null) { 1545 | timer.stop(); 1546 | } 1547 | cb(o); 1548 | }); 1549 | if(!done && timers != null) { 1550 | timer = timers.schedule(ms,function() { 1551 | if(link != null) { 1552 | link.dissolve(); 1553 | } 1554 | var timer1 = tink_core_Outcome.Failure(new tink_core_TypedError(null,"Timed out after " + ms + " ms",pos)); 1555 | cb(timer1); 1556 | }); 1557 | } 1558 | }); 1559 | }; 1560 | var tink_testrunner__$Runner_BatchResult_$Impl_$ = {}; 1561 | tink_testrunner__$Runner_BatchResult_$Impl_$.__name__ = true; 1562 | tink_testrunner__$Runner_BatchResult_$Impl_$.summary = function(this1) { 1563 | var ret = { assertions : [], failures : []}; 1564 | var handleCases = function(cases) { 1565 | var _g = 0; 1566 | while(_g < cases.length) { 1567 | var c = cases[_g]; 1568 | ++_g; 1569 | var _g1 = c.results; 1570 | switch(_g1[1]) { 1571 | case 0: 1572 | var assertions = _g1[2]; 1573 | ret.assertions = ret.assertions.concat(assertions); 1574 | var ret1 = ret.failures; 1575 | var handleCases1 = assertions.filter(function(a) { 1576 | return !tink_core_OutcomeTools.isSuccess(a.holds); 1577 | }).map(function(a1) { 1578 | return tink_testrunner_FailureType.AssertionFailed(a1); 1579 | }); 1580 | ret.failures = ret1.concat(handleCases1); 1581 | break; 1582 | case 1: 1583 | var e = _g1[2]; 1584 | ret.failures.push(tink_testrunner_FailureType.CaseFailed(e)); 1585 | break; 1586 | } 1587 | } 1588 | }; 1589 | var _g2 = 0; 1590 | while(_g2 < this1.length) { 1591 | var s = this1[_g2]; 1592 | ++_g2; 1593 | var _g11 = s.result; 1594 | switch(_g11[1]) { 1595 | case 0: 1596 | var cases1 = _g11[2]; 1597 | handleCases(cases1); 1598 | break; 1599 | case 1: 1600 | var e1 = _g11[2]; 1601 | ret.failures.push(tink_testrunner_FailureType.SuiteFailed(e1)); 1602 | break; 1603 | case 2: 1604 | var cases2 = _g11[3]; 1605 | var e2 = _g11[2]; 1606 | handleCases(cases2); 1607 | ret.failures.push(tink_testrunner_FailureType.SuiteFailed(e2)); 1608 | break; 1609 | } 1610 | } 1611 | return ret; 1612 | }; 1613 | var tink_testrunner_SuiteResultType = { __ename__ : true, __constructs__ : ["Success","SetupFailed","TeardownFailed"] }; 1614 | tink_testrunner_SuiteResultType.Success = function(cases) { var $x = ["Success",0,cases]; $x.__enum__ = tink_testrunner_SuiteResultType; $x.toString = $estr; return $x; }; 1615 | tink_testrunner_SuiteResultType.SetupFailed = function(e) { var $x = ["SetupFailed",1,e]; $x.__enum__ = tink_testrunner_SuiteResultType; $x.toString = $estr; return $x; }; 1616 | tink_testrunner_SuiteResultType.TeardownFailed = function(e,cases) { var $x = ["TeardownFailed",2,e,cases]; $x.__enum__ = tink_testrunner_SuiteResultType; $x.toString = $estr; return $x; }; 1617 | var tink_testrunner_FailureType = { __ename__ : true, __constructs__ : ["AssertionFailed","CaseFailed","SuiteFailed"] }; 1618 | tink_testrunner_FailureType.AssertionFailed = function(assertion) { var $x = ["AssertionFailed",0,assertion]; $x.__enum__ = tink_testrunner_FailureType; $x.toString = $estr; return $x; }; 1619 | tink_testrunner_FailureType.CaseFailed = function(err) { var $x = ["CaseFailed",1,err]; $x.__enum__ = tink_testrunner_FailureType; $x.toString = $estr; return $x; }; 1620 | tink_testrunner_FailureType.SuiteFailed = function(err) { var $x = ["SuiteFailed",2,err]; $x.__enum__ = tink_testrunner_FailureType; $x.toString = $estr; return $x; }; 1621 | var tink_testrunner_SuiteObject = function() { }; 1622 | tink_testrunner_SuiteObject.__name__ = true; 1623 | tink_testrunner_SuiteObject.prototype = { 1624 | __class__: tink_testrunner_SuiteObject 1625 | }; 1626 | var tink_testrunner_BasicSuite = function(info,cases) { 1627 | this.info = info; 1628 | this.cases = cases; 1629 | }; 1630 | tink_testrunner_BasicSuite.__name__ = true; 1631 | tink_testrunner_BasicSuite.__interfaces__ = [tink_testrunner_SuiteObject]; 1632 | tink_testrunner_BasicSuite.prototype = { 1633 | setup: function() { 1634 | return tink_core__$Promise_Promise_$Impl_$.NOISE; 1635 | } 1636 | ,before: function() { 1637 | return tink_core__$Promise_Promise_$Impl_$.NOISE; 1638 | } 1639 | ,after: function() { 1640 | return tink_core__$Promise_Promise_$Impl_$.NOISE; 1641 | } 1642 | ,teardown: function() { 1643 | return tink_core__$Promise_Promise_$Impl_$.NOISE; 1644 | } 1645 | ,__class__: tink_testrunner_BasicSuite 1646 | }; 1647 | var tink_testrunner_Timer = function() { }; 1648 | tink_testrunner_Timer.__name__ = true; 1649 | tink_testrunner_Timer.prototype = { 1650 | __class__: tink_testrunner_Timer 1651 | }; 1652 | var tink_testrunner_TimerManager = function() { }; 1653 | tink_testrunner_TimerManager.__name__ = true; 1654 | tink_testrunner_TimerManager.prototype = { 1655 | __class__: tink_testrunner_TimerManager 1656 | }; 1657 | var tink_testrunner_HaxeTimer = function(ms,f) { 1658 | this.timer = haxe_Timer.delay(f,ms); 1659 | }; 1660 | tink_testrunner_HaxeTimer.__name__ = true; 1661 | tink_testrunner_HaxeTimer.__interfaces__ = [tink_testrunner_Timer]; 1662 | tink_testrunner_HaxeTimer.prototype = { 1663 | stop: function() { 1664 | if(this.timer != null) { 1665 | this.timer.stop(); 1666 | this.timer = null; 1667 | } 1668 | } 1669 | ,__class__: tink_testrunner_HaxeTimer 1670 | }; 1671 | var tink_testrunner_HaxeTimerManager = function() { 1672 | }; 1673 | tink_testrunner_HaxeTimerManager.__name__ = true; 1674 | tink_testrunner_HaxeTimerManager.__interfaces__ = [tink_testrunner_TimerManager]; 1675 | tink_testrunner_HaxeTimerManager.prototype = { 1676 | schedule: function(ms,f) { 1677 | return new tink_testrunner_HaxeTimer(ms,f); 1678 | } 1679 | ,__class__: tink_testrunner_HaxeTimerManager 1680 | }; 1681 | var tink_unit_Assert = function() { }; 1682 | tink_unit_Assert.__name__ = true; 1683 | tink_unit_Assert.stringify = function(v) { 1684 | if(typeof(v) == "string" || typeof(v) == "number" || typeof(v) == "boolean") { 1685 | return JSON.stringify(v); 1686 | } else { 1687 | return Std.string(v); 1688 | } 1689 | }; 1690 | var tink_unit_TestCase = function(info,test,timeout,include,exclude,pos) { 1691 | this.info = info; 1692 | this.test = test; 1693 | this.timeout = timeout; 1694 | this.include = include; 1695 | this.exclude = exclude; 1696 | this.pos = pos; 1697 | }; 1698 | tink_unit_TestCase.__name__ = true; 1699 | tink_unit_TestCase.__interfaces__ = [tink_testrunner_Case]; 1700 | tink_unit_TestCase.prototype = { 1701 | execute: function() { 1702 | return this.test(); 1703 | } 1704 | ,__class__: tink_unit_TestCase 1705 | }; 1706 | var tink_unit_TestSuiteBase = function(info,cases) { 1707 | tink_testrunner_BasicSuite.call(this,info,cases); 1708 | }; 1709 | tink_unit_TestSuiteBase.__name__ = true; 1710 | tink_unit_TestSuiteBase.__super__ = tink_testrunner_BasicSuite; 1711 | tink_unit_TestSuiteBase.prototype = $extend(tink_testrunner_BasicSuite.prototype,{ 1712 | __class__: tink_unit_TestSuiteBase 1713 | }); 1714 | var tink_unit_TestSuiteBuilder0 = function(target,name) { 1715 | var pos = { lineNumber : 18, fileName : "RunTests.hx", methodName : "test", className : "RunTests"}; 1716 | var tmp = new tink_unit_TestCase({ name : "test", description : null, pos : { lineNumber : 18, fileName : "RunTests.hx", methodName : "test", className : "RunTests"}},function() { 1717 | var this1 = new tink_streams_Accumulator(); 1718 | return target.test(this1); 1719 | },5000,false,false,pos); 1720 | tink_unit_TestSuiteBase.call(this,{ name : name == null ? "RunTests" : name},[tmp]); 1721 | this.target = target; 1722 | }; 1723 | tink_unit_TestSuiteBuilder0.__name__ = true; 1724 | tink_unit_TestSuiteBuilder0.__super__ = tink_unit_TestSuiteBase; 1725 | tink_unit_TestSuiteBuilder0.prototype = $extend(tink_unit_TestSuiteBase.prototype,{ 1726 | setup: function() { 1727 | return tink_core__$Promise_Promise_$Impl_$.NOISE; 1728 | } 1729 | ,before: function() { 1730 | return tink_core__$Promise_Promise_$Impl_$.NOISE; 1731 | } 1732 | ,after: function() { 1733 | return tink_core__$Promise_Promise_$Impl_$.NOISE; 1734 | } 1735 | ,teardown: function() { 1736 | return tink_core__$Promise_Promise_$Impl_$.NOISE; 1737 | } 1738 | ,__class__: tink_unit_TestSuiteBuilder0 1739 | }); 1740 | var $_, $fid = 0; 1741 | function $bind(o,m) { if( m == null ) return null; if( m.__id__ == null ) m.__id__ = $fid++; var f; if( o.hx__closures__ == null ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == null ) { f = function(){ return f.method.apply(f.scope, arguments); }; f.scope = o; f.method = m; o.hx__closures__[m.__id__] = f; } return f; } 1742 | String.prototype.__class__ = String; 1743 | String.__name__ = true; 1744 | Array.__name__ = true; 1745 | var Int = { __name__ : ["Int"]}; 1746 | var Dynamic = { __name__ : ["Dynamic"]}; 1747 | var Float = Number; 1748 | Float.__name__ = ["Float"]; 1749 | var Bool = Boolean; 1750 | Bool.__ename__ = ["Bool"]; 1751 | var Class = { __name__ : ["Class"]}; 1752 | var Enum = { }; 1753 | js_Boot.__toStr = ({ }).toString; 1754 | ANSI.values = (function($this) { 1755 | var $r; 1756 | var _g = new haxe_ds_EnumValueMap(); 1757 | _g.set(Attribute.Off,0); 1758 | _g.set(Attribute.Bold,1); 1759 | _g.set(Attribute.Underline,4); 1760 | _g.set(Attribute.Blink,5); 1761 | _g.set(Attribute.ReverseVideo,7); 1762 | _g.set(Attribute.Concealed,8); 1763 | _g.set(Attribute.BoldOff,22); 1764 | _g.set(Attribute.UnderlineOff,24); 1765 | _g.set(Attribute.BlinkOff,25); 1766 | _g.set(Attribute.NormalVideo,27); 1767 | _g.set(Attribute.ConcealedOff,28); 1768 | _g.set(Attribute.Black,30); 1769 | _g.set(Attribute.Red,31); 1770 | _g.set(Attribute.Green,32); 1771 | _g.set(Attribute.Yellow,33); 1772 | _g.set(Attribute.Blue,34); 1773 | _g.set(Attribute.Magenta,35); 1774 | _g.set(Attribute.Cyan,36); 1775 | _g.set(Attribute.White,37); 1776 | _g.set(Attribute.DefaultForeground,39); 1777 | _g.set(Attribute.BlackBack,40); 1778 | _g.set(Attribute.RedBack,41); 1779 | _g.set(Attribute.GreenBack,42); 1780 | _g.set(Attribute.YellowBack,43); 1781 | _g.set(Attribute.BlueBack,44); 1782 | _g.set(Attribute.MagentaBack,45); 1783 | _g.set(Attribute.CyanBack,46); 1784 | _g.set(Attribute.WhiteBack,47); 1785 | _g.set(Attribute.DefaultBackground,49); 1786 | $r = _g; 1787 | return $r; 1788 | }(this)); 1789 | ANSI.available = ANSI.detectSupport(); 1790 | ANSI.strip = false; 1791 | ANSI.stripIfUnavailable = true; 1792 | tink_core__$Callback_Callback_$Impl_$.depth = 0; 1793 | tink_core__$Promise_Promise_$Impl_$.NOISE = new tink_core__$Future_SyncFuture(new tink_core__$Lazy_LazyConst(tink_core_Outcome.Success(tink_core_Noise.Noise))); 1794 | RunTests.main(); 1795 | })(typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this); 1796 | -------------------------------------------------------------------------------- /haxe_libraries/ansi.hxml: -------------------------------------------------------------------------------- 1 | # @install: lix --silent download "haxelib:ansi#1.0.0" into ansi/1.0.0/haxelib 2 | -D ansi=1.0.0 3 | -cp ${HAXESHIM_LIBCACHE}/ansi/1.0.0/haxelib/src 4 | -------------------------------------------------------------------------------- /haxe_libraries/hxnodejs.hxml: -------------------------------------------------------------------------------- 1 | # @install: lix --silent download "haxelib:hxnodejs#4.0.9" into hxnodejs/4.0.9/haxelib 2 | -D hxnodejs=4.0.9 3 | -cp ${HAXESHIM_LIBCACHE}/hxnodejs/4.0.9/haxelib/src 4 | -D nodejs 5 | --macro allowPackage('sys') 6 | --macro _hxnodejs.VersionWarning.include() 7 | -------------------------------------------------------------------------------- /haxe_libraries/quick-enums.hxml: -------------------------------------------------------------------------------- 1 | -cp src -------------------------------------------------------------------------------- /haxe_libraries/tink_core.hxml: -------------------------------------------------------------------------------- 1 | # @install: lix --silent download "haxelib:tink_core#1.17.0" into tink_core/1.17.0/haxelib 2 | -D tink_core=1.17.0 3 | -cp ${HAXESHIM_LIBCACHE}/tink_core/1.17.0/haxelib/src 4 | -------------------------------------------------------------------------------- /haxe_libraries/tink_macro.hxml: -------------------------------------------------------------------------------- 1 | # @install: lix --silent download "haxelib:tink_macro#0.16.5" into tink_macro/0.16.5/haxelib 2 | -D tink_macro=0.16.5 3 | -cp ${HAXESHIM_LIBCACHE}/tink_macro/0.16.5/haxelib/src 4 | 5 | -lib tink_core -------------------------------------------------------------------------------- /haxe_libraries/tink_priority.hxml: -------------------------------------------------------------------------------- 1 | # @install: lix --silent download "haxelib:tink_priority#0.1.3" into tink_priority/0.1.3/haxelib 2 | -D tink_priority=0.1.3 3 | -cp ${HAXESHIM_LIBCACHE}/tink_priority/0.1.3/haxelib/src 4 | -------------------------------------------------------------------------------- /haxe_libraries/tink_streams.hxml: -------------------------------------------------------------------------------- 1 | # @install: lix --silent download "haxelib:tink_streams#0.2.1" into tink_streams/0.2.1/haxelib 2 | -D tink_streams=0.2.1 3 | -cp ${HAXESHIM_LIBCACHE}/tink_streams/0.2.1/haxelib/src 4 | 5 | -lib tink_core -------------------------------------------------------------------------------- /haxe_libraries/tink_syntaxhub.hxml: -------------------------------------------------------------------------------- 1 | # @install: lix --silent download "haxelib:tink_syntaxhub#0.3.6" into tink_syntaxhub/0.3.6/haxelib 2 | -D tink_syntaxhub=0.3.6 3 | -cp ${HAXESHIM_LIBCACHE}/tink_syntaxhub/0.3.6/haxelib/src 4 | --macro tink.SyntaxHub.use() 5 | -lib tink_priority 6 | -lib tink_macro -------------------------------------------------------------------------------- /haxe_libraries/tink_testrunner.hxml: -------------------------------------------------------------------------------- 1 | # @install: lix --silent download "haxelib:tink_testrunner#0.6.2" into tink_testrunner/0.6.2/haxelib 2 | -D tink_testrunner=0.6.2 3 | -cp ${HAXESHIM_LIBCACHE}/tink_testrunner/0.6.2/haxelib/src 4 | 5 | -lib ansi 6 | -lib tink_macro 7 | -lib tink_streams -------------------------------------------------------------------------------- /haxe_libraries/tink_unittest.hxml: -------------------------------------------------------------------------------- 1 | # @install: lix --silent download "https://github.com/haxetink/tink_unittest/archive/356f400146f9cc468a244e705bf4e63f8640f00a.tar.gz" into tink_unittest/0.5.5/github/356f400146f9cc468a244e705bf4e63f8640f00a 2 | -D tink_unittest=0.5.5 3 | -cp ${HAXESHIM_LIBCACHE}/tink_unittest/0.5.5/github/356f400146f9cc468a244e705bf4e63f8640f00a/src 4 | --macro tink.unit.AssertionBufferInjector.use() 5 | -lib tink_syntaxhub 6 | -lib tink_testrunner -------------------------------------------------------------------------------- /haxe_libraries/travix.hxml: -------------------------------------------------------------------------------- 1 | # @run: haxelib run-dir travix ${HAXESHIM_LIBCACHE}/travix/0.10.5/haxelib 2 | # @install: lix --silent download "haxelib:travix#0.10.5" into travix/0.10.5/haxelib 3 | -D travix=0.10.5 4 | -cp ${HAXESHIM_LIBCACHE}/travix/0.10.5/haxelib/src 5 | -------------------------------------------------------------------------------- /haxelib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "quick-enums", 3 | "description": "Shorthand for string enums", 4 | "classPath": "src", 5 | "dependencies": {}, 6 | "url": "https://github.com/kevinresol/quick-enums", 7 | "contributors": [ 8 | "kevinresol" 9 | ], 10 | "version": "0.1.1", 11 | "releasenote": "Add description and url", 12 | "tags": [ 13 | "enum", 14 | "generator" 15 | ], 16 | "license": "MIT" 17 | } -------------------------------------------------------------------------------- /src/enums/EnumBuilder.hx: -------------------------------------------------------------------------------- 1 | package enums; 2 | 3 | import haxe.macro.Context; 4 | import haxe.macro.Expr; 5 | 6 | using StringTools; 7 | 8 | class EnumBuilder { 9 | static var counter = 0; 10 | static var cache:Map = new Map(); 11 | #if macro 12 | public static function build() { 13 | var pos = Context.currentPos(); 14 | return switch Context.getLocalType() { 15 | case TInst(_, values): 16 | var values = values.map(function(v) return switch v { 17 | case TInst(_.get().kind => KExpr(macro $v{(s:String)}), _): s; 18 | default: Context.error('Expected string as type parameter', pos); 19 | }); 20 | 21 | values.sort(Reflect.compare); 22 | var cacheKey = values.join(','); 23 | if(!cache.exists(cacheKey)) { 24 | var name = 'Enum_${counter++}'; 25 | var pack = ['enums']; 26 | 27 | Context.defineType({ 28 | name: name, 29 | pack: pack, 30 | kind: TDAbstract(macro:String, [], [macro:String]), 31 | meta: [{name: ':enum', pos: pos}], 32 | fields: values.map(function(v):Field return { 33 | kind: FVar(null, macro $v{v}), 34 | name: sanitize(camel(v)), 35 | pos: pos, 36 | }), 37 | pos: pos, 38 | }); 39 | cache.set(cacheKey, TPath({name: name, pack: pack})); 40 | } 41 | 42 | return cache.get(cacheKey); 43 | 44 | default: throw 'assert'; 45 | } 46 | } 47 | 48 | static function sanitize(v:String) 49 | return switch v.charCodeAt(0) { 50 | case c if(c >= '0'.code && c <= '9'.code): '_$v'; 51 | default: v; 52 | } 53 | 54 | static function camel(v:String) 55 | return v.replace('-', '_').replace(' ', '_').split('_').map(upperFirst).join(''); 56 | 57 | static function upperFirst(v:String) 58 | return v.charAt(0).toUpperCase() + v.substr(1); 59 | #end 60 | } -------------------------------------------------------------------------------- /src/enums/Enums.hx: -------------------------------------------------------------------------------- 1 | package enums; 2 | 3 | @:genericBuild(enums.EnumBuilder.build()) 4 | class Enums {} -------------------------------------------------------------------------------- /tests.hxml: -------------------------------------------------------------------------------- 1 | -cp tests 2 | -main RunTests 3 | -dce full 4 | 5 | -lib tink_unittest -------------------------------------------------------------------------------- /tests/RunTests.hx: -------------------------------------------------------------------------------- 1 | package ; 2 | 3 | import tink.unit.*; 4 | import tink.unit.Assert.*; 5 | import tink.testrunner.*; 6 | 7 | @:asserts 8 | class RunTests { 9 | 10 | static function main() { 11 | Runner.run(TestBatch.make([ 12 | new RunTests(), 13 | ])).handle(Runner.exit); 14 | } 15 | 16 | function new() {} 17 | 18 | public function test() { 19 | var e1:E1 = A; 20 | asserts.assert(e1 == 'a'); 21 | return asserts.done(); 22 | } 23 | } 24 | 25 | typedef E1 = enums.Enums<'a','b','c'>; --------------------------------------------------------------------------------