Best JavaScript code snippet using playwright-internal
Slatebox.slate.multiselection.js
Source:Slatebox.slate.multiselection.js  
1(function ($s, $slate) {2    $slate.fn._multiselection = function () {3        var _self = this, selRect = null, ox, oy, _init, marker = null, selectedNodes = [], origPos = null, resizer = null, minSize = 100;45        _self.init = function () {6            var c = _self._.options.container;7            _init = document.createElement("div");8            _init.style.position = "absolute";9            _init.style.height = "18px";10            _init.style.left = '1px';11            _init.style.color = "#081272";12            _init.style.fontSize = "11pt";13            _init.style.fontFamily = "trebuchet ms";14            _init.style.top = "1px";15            _init.style.display = "block";16            _init.style.padding = "5px";17            _init.style.backgroundColor = "#f8f8f8";18            _init.style.cursor = "pointer";19            _init.innerHTML = "[multi-select]";20            c.appendChild(_init);2122            $s.addEvent(_init, "click", function (e) {23                switch (_init.innerHTML) {24                    case "[multi-select]":25                        _self.start();26                        break;27                    case "selecting [click to stop]...":28                        _self.end();29                        break;30                }31            });32        };3334        _self.hide = function () {35            if (_init) _init.style.display = "none";36        };3738        _self.show = function () {39            if (_init) _init.style.display = "block";40        };4142        _self.start = function () {43            _self._.disable(); // options.viewPort.allowDrag = false;44            _init.innerHTML = "selecting [click to stop]...";45            _self._.onSelectionStart = function (e) {46                var p = xy(e);47                selRect = _self._.paper.rect(p.x, p.y, 10, 10).attr({ "stroke-dasharray": "-" });48                $s.addEvent(_self._.canvas.get(), "mousemove", _move);49                $s.addEvent(_self._.canvas.get(), "mouseup", _select);50                ox = p.x;51                oy = p.y;52            };53        };5455        _self.isSelecting = function () {56            return (marker !== null);57        };5859        _self.del = function () {60            if (confirm('Are you sure you want to remove the selected nodes?')) {61                $s.each(selectedNodes, function () {62                    this.toolbar.del();63                });64                _self.end();65            }66        };6768        _self.end = function () {69            if (marker !== null) {70                resizer.unmouseover(_resizeHover);71                //marker.undrag(markerEvents.move, markerEvents.init, markerEvents.up);72                //resizer.undrag(resizeEvents.move, resizeEvents.init, resizeEvents.up);73                marker.remove();74                resizer.remove();75                marker = null;76                _self._.keyboard && _self._.keyboard.end();77            }78            if (_init) _init.innerHTML = "[multi-select]";79        };8081        _self.endSelection = function () {82            selRect && selRect.remove();83            _self._.enable();84            _self._.onSelectionStart = null;85            $s.removeEvent(_self._.canvas.get(), "mousemove", _move);86            $s.removeEvent(_self._.canvas.get(), "mouseup", _select);87        };8889        var xy = function (e) {90            var mp = $s.mousePos(e);91            var off = $s.positionedOffset(_self._.options.container);92            var _x = mp.x + _self._.options.viewPort.left - off.left;93            var _y = mp.y + _self._.options.viewPort.top - off.top;94            var z = _self._.options.viewPort.zoom.r;95            return { x: _x / z, y: _y / z };96        };9798        var _move = function (e) {99            p = xy(e);100            var height = p.y - oy;101            var width = p.x - ox;102103            if (height > 0) {104                selRect.attr({ height: height });105            } else {106                selRect.attr({ y: p.y, height: (oy - p.y) });107            }108            if (width > 0) {109                selRect.attr({ width: width });110            } else {111                selRect.attr({ x: p.x, width: (ox - p.x) });112            }113        };114115        var _select = function (e) {116            var sr = selRect.getBBox();117            var l = _self._.options.viewPort.left;118            var t = _self._.options.viewPort.top;119            var z = _self._.options.viewPort.zoom.r;120            selectedNodes = _.filter(_self._.nodes.allNodes, function (n) {121                return ((n.options.xPos + n.options.width > sr.x && n.options.xPos < sr.x + sr.width) && (n.options.yPos + n.options.height > sr.y && n.options.yPos < sr.y + sr.height))122            });123124            if (selectedNodes.length > 1) {125                var orient = _self._.getOrientation(selectedNodes);126                var w = orient.width / z;127                var h = orient.height / z;128                if (w < minSize) w = minSize;129                if (h < minSize) h = minSize;130131                marker = _self._.paper.rect(orient.left / z, orient.top / z, w, h).attr({ "stroke-dasharray": "-", "fill": "#f8f8f8" });132                marker.toBack();133                origPos = marker.getBBox();134135                _self.endSelection();136137                //resizer138                var _nx = origPos.x + origPos.width;139                var _ny = origPos.y + origPos.height;140141                resizer = _self._.paper.resize(_self._.options.imageFolder + "2_lines.png").transform(["t", _nx - 5, ",", _ny - 5].join()).attr({ fill: "#fff", "stroke": "#000" });142                resizer.mouseover(_resizeHover);143                marker.drag(markerEvents.move, markerEvents.init, markerEvents.up);144                resizer.drag(resizeEvents.move, resizeEvents.init, resizeEvents.up);145146                //hiding resizer for now147                //resizer.hide();148149                //unmark all and remove connectors150                _self._.unMarkAll();151152                $s.each(selectedNodes, function () {153                    this.connectors.remove();154                    this.resize.hide();155                });156157                //activate keyboard shortcuts for this group...158                _self._.keyboard && _self._.keyboard.start();159160            } else if (selectedNodes.length === 1) {161                selectedNodes[0].menu.show();162                selectedNodes[0].mark();163                _self.endSelection();164                _self.end();165            } else {166                _self.endSelection();167                _self.end();168            }169        };170171        var _resizeHover = function (e) { resizer.attr({ cursor: 'nw-resize' }); };172173        var markerEvents = {174            init: function (x, y) {175                _self._.options.viewPort.allowDrag = false;176                marker.ox = marker.attr("x");177                marker.oy = marker.attr("y");178                $s.each(selectedNodes, function () {179                    this.vect.ox = this.vect.type == "rect" ? this.vect.attr("x") : this.vect.attr("cx");180                    this.vect.oy = this.vect.type == "rect" ? this.vect.attr("y") : this.vect.attr("cy");181                });182            }183            , move: function (dx, dy) {184                var _zr = _self._.options.viewPort.zoom.r;185                dx = dx + ((dx / _zr) - dx);186                dy = dy + ((dy / _zr) - dy);187188                var att = { x: marker.ox + dx, y: marker.oy + dy };189                marker.attr(att);190191                $s.each(selectedNodes, function () {192                    this.setPosition({ x: this.vect.ox + dx, y: this.vect.oy + dy });193                });194195                var _nx = origPos.x + origPos.width + dx - 5;196                var _ny = origPos.y + origPos.height + dy - 5;197                resizer.transform(["t", _nx, ",", _ny].join(""));198            }199            , up: function (e) {200                _self._.options.viewPort.allowDrag = true;201                _self._.birdseye && _self._.birdseye.refresh(true);202203                var _sids = _(selectedNodes).chain().pluck('options').pluck('id').value();204205                $s.each(selectedNodes, function () {206207                    if (this.options.isPinnedExact) {208                        //if the parent is NOT in the group of selected nodes, then detatch it...209                        var _allParents = _(this.relationships.parents).chain().pluck('parent').pluck('options').pluck('id').value();210                        if (_.intersect(_sids, _allParents).length === 0) {211                            this.relationships.detatch(true);212                            var detPkg = { type: 'onNodeDetatched', data: { id: this.options.id} };213                            _self._.signalr && _self._.signalr.send(detPkg);214                            _self._.birdseye && _self._.birdseye.nodeDetatched(detPkg);215                            this.refresh();216                        }217                    }218219                    broadcastMove(this);220                });221222                origPos = marker.getBBox();223            }224        };225226        function _resize() {227            var mbb = marker.getBBox();228229            var xStatic = mbb.x + mbb.width / 2;230            var yStatic = mbb.y + mbb.height / 2;231            var yScale = mbb.height / origPos.height;232            var xScale = mbb.width / origPos.width;233234            $s.each(selectedNodes, function () {235                var nx = xStatic + (xScale * (this.options.xPos - xStatic));236                var ny = yStatic + (yScale * (this.options.yPos - yStatic));237238                this.setPosition({ x: nx, y: ny });239240                var nw = xScale * this.options.width; // ((mbb.width * this.options.width) / origPos.width);241                var nh = yScale * this.options.height; // ((mbb.height * this.options.height) / origPos.height);242                this.resize.set(nw, nh, 0);243            });244        };245246        function broadcastMove(node) {247            _self._.signalr && _self._.signalr.send({248                type: "onNodeMove"249                , data: {250                    id: node.options.id251                    , x: node.options.xPos252                    , y: node.options.yPos253                }254            });255        };256257        var resizeEvents = {258            init: function () {259                _self._.disable();260                $s.each(selectedNodes, function () {261                    this.vect.ox = this.vect.type == "rect" ? this.vect.attr("x") : this.vect.attr("cx");262                    this.vect.oy = this.vect.type == "rect" ? this.vect.attr("y") : this.vect.attr("cy");263                });264            }265            , move: function (dx, dy) {266267                var _zr = _self._.options.viewPort.zoom.r;268                dx = dx + ((dx / _zr) - dx);269                dy = dy + ((dy / _zr) - dy);270271                var _width = origPos.width + (dx * 2);272                var _height = origPos.height + (dy * 2);273274                var _nx = origPos.x + origPos.width + dx - 5;275                var _ny = origPos.y + origPos.height + dy - 5;276                var rw = true, rh = true;277                if (_width < minSize) { _width = minSize; rw = false; }278                if (_height < minSize) { _height = minSize; rh = false; }279280                resizer.transform(["t", _nx, ",", _ny].join(""));281282                var att = { width: _width, height: _height };283                rw && $s.extend(att, { x: origPos.x - dx });284                rh && $s.extend(att, { y: origPos.y - dy });285286                marker.attr(att);287            }288            , up: function () {289                _self._.enable();290                _resize();291292                $s.each(selectedNodes, function () {293                    this.resize.send();294                    broadcastMove(this);295                });296297                _self._.birdseye && _self._.birdseye.refresh(true);298299                origPos = marker.getBBox();300                var _nx = origPos.x + origPos.width;301                var _ny = origPos.y + origPos.height;302                resizer.transform(["t", _nx - 5, ",", _ny - 5].join(""));303            }304        };305306        return _self;307    }
...factory.js
Source:factory.js  
1define([2    '$',3    'plugin'4], function($, Plugin) {5    var $element;6    describe('Plugin factory', function() {7        beforeEach(function() {8            $element = $('<div class="subplugin" />');9        });10        describe('Plugin create', function() {11            it('creates create function', function() {12                assert.isDefined(Plugin.create);13            });14            it('creates Plugin.create as a function', function() {15                assert.isFunction(Plugin.create);16            });17        });18        describe('Plugin creation with single depth inheritance', function() {19            it('extends sub-object prototype with the name property', function() {20                function SubPlugin(element, options) {21                    SubPlugin.__super__.call(this, element, options);22                }23                Plugin.create('subplugin', SubPlugin, {24                    _init: function() {25                    }26                });27                assert.isDefined(SubPlugin.prototype.name);28                assert.equal(SubPlugin.prototype.name, 'subplugin');29            });30            it('extends sub-object prototype', function() {31                function SubPlugin(element, options) {32                    SubPlugin.__super__.call(this, element, options);33                }34                Plugin.create('subplugin', SubPlugin, {35                    _init: function() {36                    },37                    foo: function() {38                    },39                    bar: function() {40                    }41                });42                assert.isDefined(SubPlugin.prototype._init);43                assert.isDefined(SubPlugin.prototype.foo);44                assert.isDefined(SubPlugin.prototype.bar);45            });46            it('extends $.fn with the plugin function', function() {47                function SubPlugin(element, options) {48                    SubPlugin.__super__.call(this, element, options);49                }50                Plugin.create('subplugin', SubPlugin, {51                    _init: function() {52                    }53                });54                assert.isDefined($.fn.subplugin);55            });56            it('invokes the _init function when creating the plugin', function(done) {57                function SubPlugin(element, options) {58                    SubPlugin.__super__.call(this, element, options);59                }60                Plugin.create('subplugin', SubPlugin, {61                    _init: function() {62                        done();63                    }64                });65                $element.subplugin();66            });67        });68        describe('Plugin creation with three level deep inheritance', function() {69            it('extends sub-object prototype with the name property', function() {70                function SuperPlugin(element, options) {71                    SuperPlugin.__super__.call(this, element, options);72                }73                Plugin.create('superplugin', SuperPlugin, {74                    _init: function() {75                    }76                });77                function SubPlugin(element, options) {78                    SuperPlugin.__super__.call(this, element, options);79                }80                Plugin.create('subplugin', SubPlugin, SuperPlugin, {81                    _init: function() {82                    }83                });84                assert.isDefined(SubPlugin.prototype.name);85                assert.equal(SubPlugin.prototype.name, 'subplugin');86            });87            it('extends sub-object prototype', function() {88                function SuperPlugin(element, options) {89                    SuperPlugin.__super__.call(this, element, options);90                }91                Plugin.create('superplugin', SuperPlugin, {92                    _init: function() {},93                    superMethod: function() {}94                });95                function SubPlugin(element, options) {96                    SubPlugin.__super__.call(this, element, options);97                }98                Plugin.create('subplugin', SubPlugin, SuperPlugin, {99                    _init: function() {100                    },101                    foo: function() {102                    },103                    bar: function() {104                    }105                });106                assert.isDefined(SubPlugin.prototype._init);107                assert.isDefined(SubPlugin.prototype.foo);108                assert.isDefined(SubPlugin.prototype.bar);109                assert.isDefined(SubPlugin.prototype.superMethod);110            });111        });112        describe('Plugin creation with four level deep inheritance', function() {113            it('extends sub-object prototype with the name property', function() {114                function Level2Plugin(element, options) {115                    Level2Plugin.__super__.call(this, element, options);116                }117                Plugin.create('level2plugin', Level2Plugin, {118                    _init: function() {119                    },120                    level2Method: function() {}121                });122                function Level3Plugin(element, options) {123                    Level3Plugin.__super__.call(this, element, options);124                }125                Plugin.create('level3plugin', Level3Plugin, Level2Plugin, {126                    _init: function() {127                    },128                    level3Method: function() {}129                });130                function SubPlugin(element, options) {131                    SuperPlugin.__super__.call(this, element, options);132                }133                Plugin.create('subplugin', SubPlugin, Level3Plugin, {134                    _init: function() {135                    }136                });137                assert.isDefined(SubPlugin.prototype.name);138                assert.equal(SubPlugin.prototype.name, 'subplugin');139            });140            it('extends sub-object prototype', function() {141                function Level2Plugin(element, options) {142                    Level2Plugin.__super__.call(this, element, options);143                }144                Plugin.create('level2plugin', Level2Plugin, {145                    _init: function() {146                    },147                    level2Method: function() {}148                });149                function Level3Plugin(element, options) {150                    Level3Plugin.__super__.call(this, element, options);151                }152                Plugin.create('level3plugin', Level3Plugin, Level2Plugin, {153                    _init: function() {154                    },155                    level3Method: function() {}156                });157                function SubPlugin(element, options) {158                    SubPlugin.__super__.call(this, element, options);159                }160                Plugin.create('subplugin', SubPlugin, Level3Plugin, {161                    _init: function() {162                    },163                    foo: function() {164                    },165                    bar: function() {166                    }167                });168                assert.isDefined(SubPlugin.prototype._init);169                assert.isDefined(SubPlugin.prototype.foo);170                assert.isDefined(SubPlugin.prototype.bar);171                assert.isDefined(SubPlugin.prototype.level2Method);172                assert.isDefined(SubPlugin.prototype.level3Method);173            });174        });175        describe('multiple plugin types', function() {176            it('creates types correctly by extending Plugin.prototype', function() {177                var plugin1Init = function(element) { var $element1 = element; };178                var plugin2Init = function(element) { var $element2 = element; };179                function Plugin1(element, options) {180                    Plugin1.__super__.call(this, element, options, {181                        plugin1Option: true182                    });183                }184                Plugin.create('plugin1', Plugin1, {185                    _init: plugin1Init,186                    firstUniqueMethod: function() {187                        return true;188                    }189                });190                function Plugin2(element, options) {191                    Plugin1.__super__.call(this, element, options, {192                        plugin2Option: true193                    });194                }195                Plugin.create('plugin2', Plugin2, {196                    _init: plugin2Init,197                    secondUniqueMethod: function() {198                        return false;199                    }200                });201                var $plugin1 = $('<div/>').plugin1();202                var $plugin2 = $('<div/>').plugin2();203                var plugin1 = $plugin1.data('plugin1');204                var plugin2 = $plugin2.data('plugin2');205                assert.equal(Plugin1.prototype._init, plugin1Init);206                assert.isDefined(plugin1.options.plugin1Option);207                assert.isDefined(plugin1.firstUniqueMethod);208                assert.isUndefined(plugin1.secondUniqueMethod);209                assert.equal(Plugin2.prototype._init, plugin2Init);210                assert.isDefined(plugin2.options.plugin2Option);211                assert.isDefined(plugin2.secondUniqueMethod);212                assert.isUndefined(plugin2.firstUniqueMethod);213            });214        });215    });...loads_8b.js
Source:loads_8b.js  
1/**2 * Created by ismar on 01/02/2017.3 */4QUnit.test( "LD_R1_R2", function( assert ) {5    CPU._init();6    //Sum a and e7    CPU._r.a = 0x5;8    CPU._r.e = 0x1;9    var inst = {10        opcode: 0x2,11        r1: 0x3, //Destination (r1) is E12        r2: 0x7, //Source (r2) is A13        n: 014    };15    CPU.ld_r1_r2(inst);16    assert.equal( CPU._r.e, CPU._r.a,"Correct");17});18QUnit.test( "LD_R_HL", function( assert ) {19    CPU._init();20    //Sum a and e21    CPU._r.h = 0xBE;22    CPU._r.l = 0xBA;23    MEM._m[0xBEBA] =  0xCA;24    var inst = {25        opcode: 0x2,26        r1: 0x4, //Destination (r1) is H27        r2: 0x0, //Don't care28        n: 029    };30    CPU.ld_r_HL(inst);31    assert.equal( CPU._r.h,0xCA,"Correct");32});33QUnit.test( "LD_R_N", function( assert ) {34    CPU._init();35    //Sum a and e36    CPU._r.b = 0xFF;37    var inst = {38        opcode: 0x2,39        r1: 0x0, //Destination (r1) is B40        r2: 0x0, //Don't care41        n: 0xAB // To load 0xAB into register B42    };43    CPU.ld_r_n(inst);44    assert.equal( CPU._r.b,0xAB,"Correct");45});46QUnit.test( "LD_HL_r", function( assert ) {47    CPU._init();48    MEM._init();49    CPU._r.a = 0xBE;50    CPU._r.h = 0xDE;51    CPU._r.l = 0xAD;52    var inst = {53        opcode: 0x2,54        r1: 0x0, //Don't care55        r2: 0x7, //So content of A is stored56        n: 0x0 //Don't care57    };58    CPU.ld_HL_r(inst);59    //@DEAD = 0xBE60    assert.equal( MEM.readByte(0xDEAD),0xBE,"Correct");61});62QUnit.test( "LD_HL_n", function( assert ) {63    CPU._init();64    MEM._init();65    //Sum a and e66    CPU._r.h = 0xDE;67    CPU._r.l = 0xAD;68    var inst = {69        opcode: 0x2,70        r1: 0x0, //Don't care71        r2: 0x7, //Don't care72        n: 0xCC // To load 0xAB into register B73    };74    CPU.ld_HL_n(inst);75    //@DEAD = 0xBE76    assert.equal( MEM.readByte(0xDEAD),0xCC,"Correct");77});78QUnit.test( "LD_A_BC", function( assert ) {79    CPU._init();80    MEM._init();81    //Sum a and e82    CPU._r.a = 0xFF;83    CPU._r.b = 0xBE;84    CPU._r.c = 0xBA;85    MEM._m[0xBEBA] = 0xCA;86    var inst = {87        opcode: 0x2,88        r1: 0x0, //Don't care89        r2: 0x0, //Don't care90        n: 0x0 //Don't care91    };92    CPU.ld_A_BC(inst);93    //@DEAD = 0xBE94    assert.equal( CPU._r.a,0xCA,"Correct");95});96QUnit.test( "LD_A_DE", function( assert ) {97    CPU._init();98    MEM._init();99    //Sum a and e100    CPU._r.a = 0xFF;101    CPU._r.d = 0xBE;102    CPU._r.e = 0xBA;103    MEM._m[0xBEBA] = 0xCA;104    var inst = {105        opcode: 0x2,106        r1: 0x0, //Don't care107        r2: 0x0, //Don't care108        n: 0x0 //Don't care109    };110    CPU.ld_A_DE(inst);111    //@DEAD = 0xBE112    assert.equal( CPU._r.a,0xCA,"Correct");113});114QUnit.test( "LD_A_nn", function( assert ) {115    CPU._init();116    MEM._init();117    //Sum a and e118    CPU._r.a = 0xFF;119    MEM._m[0xDEAD] = 0xAB;120    var inst = {121        opcode: 0x2,122        r1: 0x0, //Don't care123        r2: 0x0, //Don't care124        n: 0xDE,125        nn:0xDEAD126    };127    CPU.ld_A_nn(inst);128    //@DEAD = 0xBE129    assert.equal( CPU._r.a,0xAB,"Correct");130});131QUnit.test( "LD_BC_A", function( assert ) {132    CPU._init();133    MEM._init();134    //Sum a and e135    CPU._r.a = 0xCF;136    CPU._r.b = 0xBE;137    CPU._r.c = 0xBA;138    var inst = {139        opcode: 0x2,140        r1: 0x0, //Don't care141        r2: 0x0, //Don't care142        n: 0x0, //Don't care143        nn:0x0 //Don't care144    };145    CPU.ld_BC_A(inst);146    assert.equal( MEM.readByte(0xBEBA),0xCF,"Correct");147});148QUnit.test( "LD_DE_A", function( assert ) {149    CPU._init();150    MEM._init();151    //Sum a and e152    CPU._r.a = 0xCF;153    CPU._r.d = 0xBE;154    CPU._r.e = 0xBA;155    var inst = {156        opcode: 0x2,157        r1: 0x0, //Don't care158        r2: 0x0, //Don't care159        n: 0x0, //Don't care160        nn:0x0 //Don't care161    };162    CPU.ld_DE_A(inst);163    assert.equal( MEM.readByte(0xBEBA),0xCF,"Correct");164});165QUnit.test( "LD_nn_A", function( assert ) {166    CPU._init();167    MEM._init();168    CPU._r.a = 0xAB;169    var inst = {170        opcode: 0x2,171        r1: 0x0, //Don't care172        r2: 0x0, //Don't care173        n: 0x0, //Don't care174        nn:0xBEBA175    };176    CPU.ld_nn_A(inst);177    assert.equal( MEM.readByte(0xBEBA),0xAB,"Correct");178});179QUnit.test( "LD_A_ff00_n", function( assert ) {180    CPU._init();181    MEM._init();182    CPU._r.a = 0xFF;183    MEM.writeByte(0xFF34,0xAB); //$0xFF34 = 0xAB184    var inst = {185        opcode: 0x2,186        r1: 0x0, //Don't care187        r2: 0x0, //Don't care188        n: 0x34,189        nn:0x0 //Don't care190    };191    CPU.ld_A_ff00_n(inst);192    assert.equal( CPU._r.a,0xAB,"Correct");193});194QUnit.test( "LD_ff00_n_A", function( assert ) {195    CPU._init();196    MEM._init();197    CPU._r.a = 0xAB;198    var inst = {199        opcode: 0x2,200        r1: 0x0, //Don't care201        r2: 0x0, //Don't care202        n: 0x34,203        nn:0x0 //Don't care204    };205    CPU.ld_ff00_n_A(inst);206    assert.equal( MEM.readByte(0xFF34),0xAB,"Correct");207});208QUnit.test( "LD_A_ff00_C", function( assert ) {209    CPU._init();210    MEM._init();211    CPU._r.a = 0xFF;212    CPU._r.c = 0x34;213    MEM.writeByte(0xFF34,0xAB); //$0xFF34 = 0xAB214    var inst = {215        opcode: 0x2,216        r1: 0x0, //Don't care217        r2: 0x0, //Don't care218        n: 0x00, //Don't care219        nn:0x0 //Don't care220    };221    CPU.ld_A_ff00_C(inst);222    assert.equal( CPU._r.a,0xAB,"Correct");223});224QUnit.test( "LD_ff00_C_A", function( assert ) {225    CPU._init();226    MEM._init();227    CPU._r.a = 0xAB;228    CPU._r.c = 0x34;229    var inst = {230        opcode: 0x2,231        r1: 0x0, //Don't care232        r2: 0x0, //Don't care233        n: 0x0, //Don't care234        nn:0x0 //Don't care235    };236    CPU.ld_ff00_C_A(inst);237    assert.equal( MEM.readByte(0xFF34),0xAB,"Correct");238});239QUnit.test( "LDI_HL_A", function( assert ) {240    CPU._init();241    MEM._init();242    CPU._r.a = 0x56;243    CPU._r.h = 0xBE;244    CPU._r.l = 0xBA;245    var inst = {246        opcode: 0x2,247        r1: 0x0, //Don't care248        r2: 0x0, //Don't care249        n: 0x0, //Don't care250        nn:0x0 //Don't care251    };252    CPU.ldi_hl_a(inst);253    assert.equal( MEM.readByte(0xBEBA),0x56,"Written in memory");254    assert.equal(CPU.getDoubleRegisterFromCode(2),0xBEBB,"Was incremented");255});256QUnit.test( "LDD_HL_A", function( assert ) {257    CPU._init();258    MEM._init();259    CPU._r.a = 0x5;260    CPU._r.h = 0x40;261    CPU._r.l = 0x00;262    var inst = {263        opcode: 0x2,264        r1: 0x0, //Don't care265        r2: 0x0, //Don't care266        n: 0x0, //Don't care267        nn:0x0 //Don't care268    };269    CPU.ldd_hl_a(inst);270    assert.equal( MEM.readByte(0x4000),0x5,"Written in memory");271    assert.equal(CPU.getDoubleRegisterFromCode(2),0x3FFF, "Was decremented");272});273QUnit.test( "LDI_A_HL", function( assert ) {274    CPU._init();275    MEM._init();276    CPU._r.a = 0xFF;277    CPU._r.h = 0x01;278    CPU._r.l = 0xFF;279    MEM._m[0x1FF] = 0X56;280    var inst = {281        opcode: 0x2,282        r1: 0x0, //Don't care283        r2: 0x0, //Don't care284        n: 0x0, //Don't care285        nn:0x0 //Don't care286    };287    CPU.ldi_a_hl(inst);288    assert.equal(CPU._r.a,0x56,"Read from memory");289    assert.equal(CPU.getDoubleRegisterFromCode(2),0x200, "Was incremented");290});291QUnit.test( "LDD_A_HL", function( assert ) {292    CPU._init();293    MEM._init();294    CPU._r.a = 0xFF;295    CPU._r.h = 0x8A;296    CPU._r.l = 0x5C;297    MEM._m[0x8A5C] = 0X3C;298    var inst = {299        opcode: 0x2,300        r1: 0x0, //Don't care301        r2: 0x0, //Don't care302        n: 0x0, //Don't care303        nn:0x0 //Don't care304    };305    CPU.ldd_a_hl(inst);306    assert.equal(CPU._r.a,0x3C,"Read from memory");307    assert.equal(CPU.getDoubleRegisterFromCode(2),0x8A5B, "Was incremented");...zeitgeistSearch.js
Source:zeitgeistSearch.js  
...31const Search = imports.ui.search;32// FIXME: The subject cache is never being emptied.33let ZeitgeistSubjectCache = {};34function ZeitgeistAsyncSearchProvider(title, interpretations) {35    this._init(title, interpretations);36}37ZeitgeistAsyncSearchProvider.prototype = {38    __proto__: Search.SearchProvider.prototype,39    _init: function(title, interpretations) {40        Search.SearchProvider.prototype._init.call(this, title);41        this._buildTemplates(interpretations);42    },43    _buildTemplates: function(interpretations) {44        this.templates = [];45        for (let i = 0; i < interpretations.length; i++) {46            let subject = new Zeitgeist.Subject('', interpretations[i], '', '', '', '', '');47            let event = new Zeitgeist.Event('', '', '', [subject], []);48            this.templates.push(event);49        }50    },51    _search: function(terms) {52        this._search_terms = terms;53        Zeitgeist.fullTextSearch(terms[0]+'*',54                                 this.templates,55                                 Lang.bind(this, function(events) {56                                     if (terms == this._search_terms)57                                         this._asyncCallback(events);58                                 }));59    },60    _asyncCancelled: function() {61        this._search_terms = null;62    },63    getInitialResultSet: function(terms) {64        this._search(terms);65        return [];66    },67    getSubsearchResultSet: function(previousResults, terms) {68        this.tryCancelAsync();69        return this.getInitialResultSet(terms);70    },71    getResultMeta: function(resultId) {72        return { 'id': ZeitgeistSubjectCache[resultId].uri,73                 'name': ZeitgeistSubjectCache[resultId].name,74                 'createIcon': function (size) {75                                   return ZeitgeistSubjectCache[resultId].createIcon(size);76                               },77               };78    },79    activateResult: function(resultId) {80        Gio.app_info_launch_default_for_uri(resultId,81                                            global.create_app_launch_context());82    },83    _asyncCallback: function(events) {84        let items = [];85        for (let i = 0; i < events.length; i++) {86            let event = events[i];87            let subject = event.subjects[0];88            let uri = subject.uri.replace('file://', '');89            uri = GLib.uri_unescape_string(uri, '');90            if (GLib.file_test(uri, GLib.FileTest.EXISTS)) {91                if (!ZeitgeistSubjectCache.hasOwnProperty(subject.uri)) {92                    let info = new DocInfo.ZeitgeistItemInfo(event);93                    ZeitgeistSubjectCache[info.uri] = info;94                }95                items.push(subject.uri);96            }97        }98        this.addItems(items);99    }100};101function DocumentsAsyncSearchProvider() {102    this._init();103}104DocumentsAsyncSearchProvider.prototype = {105    __proto__: ZeitgeistAsyncSearchProvider.prototype,106    _init: function() {107        let interpretations = [Semantic.NFO_DOCUMENT];108        ZeitgeistAsyncSearchProvider.prototype._init.call(this, _("DOCUMENTS"), interpretations);109    }110};111function VideosAsyncSearchProvider() {112    this._init();113}114VideosAsyncSearchProvider.prototype = {115    __proto__: ZeitgeistAsyncSearchProvider.prototype,116    _init: function() {117        let interpretations = [Semantic.NFO_VIDEO];118        ZeitgeistAsyncSearchProvider.prototype._init.call(this, _("VIDEOS"), interpretations);119    }120};121function MusicAsyncSearchProvider() {122    this._init();123}124MusicAsyncSearchProvider.prototype = {125    __proto__: ZeitgeistAsyncSearchProvider.prototype,126    _init: function() {127        let interpretations = [128            Semantic.NFO_AUDIO,129            Semantic.NMM_MUSIC_PIECE];130        ZeitgeistAsyncSearchProvider.prototype._init.call(this, _("MUSIC"), interpretations);131    }132};133function PicturesAsyncSearchProvider() {134    this._init();135}136PicturesAsyncSearchProvider.prototype = {137    __proto__: ZeitgeistAsyncSearchProvider.prototype,138    _init: function() {139        let interpretations = [Semantic.NFO_IMAGE];140        ZeitgeistAsyncSearchProvider.prototype._init.call(this, _("PICTURES"), interpretations);141    }142};143function OtherAsyncSearchProvider() {144    this._init();145}146OtherAsyncSearchProvider.prototype = {147    __proto__: ZeitgeistAsyncSearchProvider.prototype,148    _init: function() {149        let interpretations = [150            '!' + Semantic.NFO_IMAGE,151            '!' + Semantic.NFO_DOCUMENT,152            '!' + Semantic.NFO_VIDEO,153            '!' + Semantic.NFO_AUDIO,154            '!' + Semantic.NMM_MUSIC_PIECE];155        ZeitgeistAsyncSearchProvider.prototype._init.call(this, _("OTHER"), interpretations);156    },157    _buildTemplates: function(interpretations) {158        // Here we want to get everything matching all of the templates, and...SyncCache.js
Source:SyncCache.js  
...7	"dojo/_base/Deferred"8], function(dojo, _Cache){9	return dojo.declare('demos.gridx.src.core.model.SyncCache', _Cache, {10		constructor: function(){11			this._init();12		},13		clear: function(){14			this._idMap = {};15			this._indexMap = [];16			this._cache = {};17			this.totalCount = -1;18		},19		index: function(index){20			this._init();21			return this._cache[this._indexMap[index]];22		},23		id: function(id){24			this._init();25			return this._cache[id];26		},27		indexToId: function(index){28			this._init();29			return this._indexMap[index];30		},31		idToIndex: function(id){32			this._init();33			return this._idMap[id];34		},35		size: function(){36			this._init();37			return this.totalCount;38		},39		when: function(args, callback){40			this._init();41			var d = new dojo.Deferred();42			try{43				if(callback){44					callback(args);45				}46				d.callback();47			}catch(e){48				d.errback(e);49			}50			return d;51		},52		53		//--------------------------------------------------------------------54		_init: function(){55			if(this.totalCount >= 0){ return; }56			this.onBeforeFetch();57			var _this = this, s = this.store,58				req = dojo.mixin({start: 0}, this.options || {});59			var onBegin = function(size){60				var oldSize = _this.totalCount;61				_this.totalCount = parseInt(size, 10);62				if(oldSize !== _this.totalCount){63					_this.onSizeChange(_this.totalCount, oldSize);64				}65			};66			var onComplete = function(items){67				dojo.forEach(items, _this._addRow, _this);68				_this.onAfterFetch();69			};70			var onError = function(e){71				_this.onAfterFetch();72				console.error(e);73			};74			if(s.fetch){75				s.fetch(dojo.mixin(req, {76					onBegin: onBegin,77					onComplete: onComplete,78					onError: onError79				}));80			}else{81				var results = s.query(req.query, req);82				dojo.when(results.total, onBegin);83				onComplete(results);84			}85		},86		_addRow: function(item, idx){87			var id = this.store.getIdentity(item);88			var rowData = this._itemToObject(item);89			this._idMap[id] = idx;90			this._indexMap[idx] = id;91			this._cache[id] = {92				data: this._formatRow(rowData),93				rawData: rowData,94				item: item95			};96		},97		_onNew: function(item){98			if(this.totalCount < 0){99				this._init();100			}else{101				this._addRow(item, this.totalCount++);102			}103			var id = this.store.getIdentity(item);104			this.onSizeChange(this.totalCount, this.totalCount - 1);105			this.onNew(id, this.totalCount - 1, this._cache[id]);106		},107		_onSet: function(item){108			this._init();109			var id = this.store.getIdentity(item), index = this._idMap[id];110			this._addRow(item, index);111			this.onSet(id, index, this._cache[id]);112		},113		_onDelete: function(item){114			var id = this.store.fetch ? this.store.getIdentity(item) : item,115				idx = this._idMap[id], i;116			if(idx >= 0){117				delete this._cache[id];118				delete this._idMap[id];119				this._indexMap.splice(idx, 1);120				for(i = idx; i < this._indexMap.length; ++i){121					this._idMap[this._indexMap[i]] = i;122				}...fetcher.js
Source:fetcher.js  
1/* eslint-disable max-classes-per-file */2import reload from '@/assets/js/reload';3class ApiError extends Error {}4function isJson(res) {5  const contentType = res.headers.get('content-type');6  return contentType && contentType.includes('application/json');7}8async function handleResponse(res) {9  if (isJson(res)) {10    const json = await res.json();11    if (!res.ok) {12      const { error } = json;13      if (error !== undefined) {14        throw new ApiError(error);15      }16      throw ApiError(res.status);17    }18    return json;19  }20  return res.status;21}22class Fetcher {23  constructor({ failOnError = true, isError = () => true } = {}) {24    this.failOnError = failOnError;25    this.isError = isError;26  }27  async fetch(resource, _init) {28    try {29      const init = _init || {};30      init.credentials = 'same-origin';31      return handleResponse(await fetch(resource, init));32    } catch (e) {33      if (e instanceof ApiError) {34        throw e;35      }36      if (this.failOnError && this.isError(e)) {37        console.log(`got error â failing over`);38        reload();39      }40      throw e;41    }42  }43  async put(resource, data, _init) {44    try {45      const init = _init || {};46      init.credentials = 'same-origin';47      const res = await fetch(resource, {48        method: 'PUT',49        headers: {50          'Content-Type': 'application/json',51        },52        body: JSON.stringify(data),53      });54      return handleResponse(res);55    } catch (e) {56      if (e instanceof ApiError) {57        throw e;58      }59      console.log('error: ', e);60      if (this.failOnError && this.isError(e)) {61        console.log(`got error â failing over`);62        // reload();63      }64      throw e;65    }66  }67  async post(resource, data, _init) {68    try {69      const init = _init || {};70      init.credentials = 'same-origin';71      const res = await fetch(resource, {72        method: 'POST',73        headers: {74          'Content-Type': 'application/json',75        },76        body: JSON.stringify(data),77      });78      return handleResponse(res);79    } catch (e) {80      if (e instanceof ApiError) {81        throw e;82      }83      console.log('error: ', e);84      if (this.failOnError && this.isError(e)) {85        console.log(`got error â failing over`);86        // reload();87      }88      throw e;89    }90  }91  async delete(resource, data, _init) {92    try {93      const init = _init || {};94      init.credentials = 'same-origin';95      const res = await fetch(resource, {96        method: 'DELETE',97      });98      return handleResponse(res);99    } catch (e) {100      if (e instanceof ApiError) {101        throw e;102      }103      console.log('error: ', e);104      if (this.failOnError && this.isError(e)) {105        console.log(`got error â failing over`);106        // reload();107      }108      throw e;109    }110  }111}...Anysdk.js
Source:Anysdk.js  
...15	},16	17	//ç¨æ·ç³»ç»18	_userPlugin:function() {19		//this._init();20		//var user_plugin  = this.agent.getUserPlugin();              //ç¨æ·ç³»ç»21	},22	23	//æ¯ä»ç³»ç»24	_iapPlugin:function() {25		//this._init();26		//var iap_plugins = this.agent.getIAPPlugin();              	//æ¯ä»ç³»ç»27	},28	29	//å享系ç»30	_sharePlugin:function() {31		//this._init();32		//var share_plugin = this.agent.getSharePlugin();             //å享系ç»33	},34	35	//广åç³»ç»36	_adsPlugin:function() {37		if (this.agent == null) {38			this._init();39		}40		var ads_plugin = this.agent.getAdsPlugin();               	//广åç³»ç»41		return ads_plugin;42	},43	44	//社交系ç»45	_socialPlugin:function() {46		//this._init();47		//var social_plugin = this.agent.getSocialPlugin();           //社交系ç»48	},49	50	//æ¨éç³»ç»51	_pushPlugin:function() {52		//this._init();53		//var push_plugin = this.agent.getPushPlugin();              //æ¨éç³»ç»54	},55	56	//ç»è®¡ç³»ç»57	_analyticsPlugin:function() {58		this._init();59		var analytics_plugin = this.agent.getAnalyticsPlugin();    //ç»è®¡ç³»ç»60		return analytics_plugin;61	},62	63	//å´©æºåæç³»ç»64	_crashPlugin:function() {65		//this._init();66		//var crash_plugin = this.agent.getCrashPlugin();             //å´©æºåæç³»ç»67	},68	69	//å½å±å享系ç»70	_recPlugin:function() {71		//this._init();72		//var rec_plugin = this.agent.getRECPlugin();                 //å½å±å享系ç»73	},74	75	//èªå®ä¹ç³»ç»76	_customPlugin:function() {77		//this._init();78		//var custom_plugin = this.agent.getCustomPlugin();           //èªå®ä¹ç³»ç»79	},80	81	_unloadPlugin:function() {82		this.agent.unloadAllPlugins();83	}...Using AI Code Generation
1const playwright = require('playwright');2const { chromium } = require('playwright');3const { webkit } = require('playwright');4const { firefox } = require('playwright');5const { devices } = require('playwright');6const { Browser } = require('playwright');7(async () => {8  const browser = await chromium.launch({ headless: false });9  const context = await browser.newContext();10  const page = await context.newPage();11  await browser.close();12})();13const { chromium } = require('playwright');14const { webkit } = require('playwright');15const { firefox } = require('playwright');16const { devices } = require('playwright');17const { Browser } = require('playwright');18(async () => {19  const browser = await chromium.launch({ headless: false });20  const context = await browser.newContext();21  const page = await context.newPage();22  await browser.close();23})();24const { chromium } = require('playwright');25const { webkit } = require('playwright');26const { firefox } = require('playwright');27const { devices } = require('playwright');28const { Browser } = require('playwright');29(async () => {30  const browser = await chromium.launch({ headless: false });31  const context = await browser.newContext();32  const page = await context.newPage();33  await browser.close();34})();35const { chromium } = require('playwright');36const { webkit } = require('playwright');37const { firefox } = require('playwright');38const { devices } = require('playwright');39const { Browser } = require('playwright');40(async () => {41  const browser = await chromium.launch({ headless: false });42  const context = await browser.newContext();43  const page = await context.newPage();44  await browser.close();45})();46const { chromium } = require('playwright');47const { webkit } = require('playwright');48const { firefox } = require('playUsing AI Code Generation
1const { _init } = require('playwright');2const { chromium } = require('playwright');3async function main() {4  const browser = await chromium.launch();5  const context = await browser.newContext();6  const page = await context.newPage();7  await page.screenshot({ path: 'google.png' });8  await browser.close();9}10(async () => {11    await _init({12    });13    await main();14})();15### _init(options)16[Apache 2.0](LICENSE)Using AI Code Generation
1const { _init } = require('playwright');2async function main() {3  const browser = await _init.launchBrowser({4  });5  const context = await browser.newContext();6  const page = await context.newPage();7  await page.screenshot({ path: 'example.png' });8  await browser.close();9}10main();11const { _init } = require('playwright');12async function main() {13  const browser = await _init.launchBrowser({14  });15  const context = await browser.newContext();16  const page = await context.newPage();17  await page.screenshot({ path: 'example.png' });18  await browser.close();19}20main();21const { _init } = require('playwright');22async function main() {23  const browser = await _init.launchBrowser({24  });25  const context = await browser.newContext();26  const page = await context.newPage();27  await page.screenshot({ path: 'example.png' });28  await browser.close();29}30main();31const { _init } = require('playwright');32async function main() {33  const browser = await _init.launchBrowser({34  });35  const context = await browser.newContext();36  const page = await context.newPage();37  await page.screenshot({ path: 'example.png' });38  await browser.close();39}40main();41const { _init } = require('playwright');42async function main() {43  const browser = await _init.launchBrowser({Using AI Code Generation
1const { _init } = require('@playwright/test');2const { chromium } = require('playwright');3const { expect } = require('chai');4(async () => {5  const browser = await chromium.launch({ headless: false });6  const context = await browser.newContext();7  const page = await context.newPage();8  const title = await page.title();9  expect(title).to.equal('Google');10  await browser.close();11})();Using AI Code Generation
1const { _init } = require('playwright');2(async () => {3  const browser = await _init.launchChromium();4  const context = await browser.newContext();5  const page = await context.newPage();6  await page.screenshot({ path: 'example.png' });7  await browser.close();8})();9const { _init } = require('playwright');10(async () => {11  const browser = await _init.launchChromium();12  const context = await browser.newContext();13  const page = await context.newPage();14  await page.screenshot({ path: 'example.png' });15  await browser.close();16})();17const { _init } = require('playwright');18(async () => {19  const browser = await _init.launchChromium();20  const context = await browser.newContext();21  const page = await context.newPage();22  await page.screenshot({ path: 'example.png' });23  await browser.close();24})();25const { _init } = require('playwright');26(async () => {27  const browser = await _init.launchChromium();28  const context = await browser.newContext();29  const page = await context.newPage();30  await page.screenshot({ path: 'example.png' });Using AI Code Generation
1const { _init } = require('@playwright/test');2const { expect } = require('chai');3const { test, expect: expectPlaywright } = require('@playwright/test');4const { Page } = require('playwright');5_init();6const { testInfo } = test;7const { testTitle } = testInfo;8const { testFilePath } = testInfo;9const { testDuration } = testInfo;10const { testRetry } = testInfo;11const { testAnnotations } = testInfo;12const { testExpectedStatus } = testInfo;13const { testTimeout } = testInfo;14const { testFixtures } = testInfo;15const { testSpec } = testInfo;16const { testWorkerIndex } = testInfo;17const { testWorkerCount } = testInfo;18const { testModifier } = testInfo;19const { testModifierFn } = testInfo;20const { testModifierParams } = testInfo;21const { testSkip } = testInfo;22const { testSkipReason } = testInfo;23const { testSlow } = testInfo;24const { testSnapshotSuffix } = testInfo;25const { testSnapshotDir } = testInfo;26const { testSnapshotDirRelative } = testInfo;27const { testSnapshotPath } = testInfo;28const { testSnapshotPathRelative } = testInfo;29const { testSnapshotName } = testInfo;30const { testSnapshotNameRelative } = testInfo;31const { testSnapshotStoragePath } = testInfo;32const { testSnapshotStoragePathRelative } = testInfo;33const { testSnapshotStorageDir } = testInfo;34const { testSnapshotStorageDirRelative } = testInfo;35const { testSnapshotStorageName } = testInfo;36const { testSnapshotStorageNameRelative } = testInfo;37const { testSnapshotStorageSuffix } = testInfo;38const { testOutputDir } = testInfo;39const { testOutputDirRelative } = testInfo;40const { testOutputPath } = testInfo;41const { testOutputPathRelative } = testInfo;42const { testOutputName } = testInfo;43const { testOutputNameRelative } = testInfo;44const { testOutputSuffix } = testInfo;45const { testOutputStoragePath } = testInfo;46const { testOutputStoragePathRelative } = testInfo;47const { testOutputStorageDir } = testInfo;Using AI Code Generation
1const { chromium } = require("playwright");2const { expect } = require("chai");3(async () => {4  const browser = await chromium.launch({ headless: false, slowMo: 50 });5  const context = await browser.newContext();6  const page = await context.newPage();7  await page._init();8  await page.setViewportSize({ width: 1920, height: 1080 });9  await page.screenshot({ path: `example.png` });10  await browser.close();11})();Using AI Code Generation
1const { Page } = require('playwright');2const { PageObject } = require('@playwright/test');3class MyPage extends PageObject {4  constructor(page) {5    super(page);6  }7  async _init() {8  }9}10const { Page } = require('playwright');11const { PageObject } = require('@playwright/test');12class MyPage extends PageObject {13  constructor(page) {14    super(page);15  }16  async _init() {17  }18}19const { Page } = require('playwright');20const { PageObject } = require('@playwright/test');21class MyPage extends PageObject {22  constructor(page) {23    super(page);24  }25  async _init() {26  }27}28const { Page } = require('playwright');29const { PageObject } = require('@playwright/test');30class MyPage extends PageObject {31  constructor(page) {32    super(page);33  }34  async _init() {35  }36}LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!
