Best JavaScript code snippet using unexpected
InspectElementModeController.js
Source:InspectElementModeController.js
1/*2 * Copyright (C) 2013 Google Inc. All rights reserved.3 *4 * Redistribution and use in source and binary forms, with or without5 * modification, are permitted provided that the following conditions are6 * met:7 *8 * 1. Redistributions of source code must retain the above copyright9 * notice, this list of conditions and the following disclaimer.10 *11 * 2. Redistributions in binary form must reproduce the above12 * copyright notice, this list of conditions and the following disclaimer13 * in the documentation and/or other materials provided with the14 * distribution.15 *16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27 */28/**29 * @constructor30 * @implements {WebInspector.TargetManager.Observer}31 */32WebInspector.InspectElementModeController = function()33{34 this._toggleSearchAction = WebInspector.actionRegistry.action("elements.toggle-element-search");35 if (Runtime.experiments.isEnabled("layoutEditor")) {36 this._layoutEditorButton = new WebInspector.ToolbarToggle(WebInspector.UIString("Toggle Layout Editor"), "layout-editor-toolbar-item");37 this._layoutEditorButton.addEventListener("click", this._toggleLayoutEditor, this);38 }39 this._mode = DOMAgent.InspectMode.None;40 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged, this);41 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Type.Page);42}43WebInspector.InspectElementModeController.prototype = {44 /**45 * @override46 * @param {!WebInspector.Target} target47 */48 targetAdded: function(target)49 {50 // When DevTools are opening in the inspect element mode, the first target comes in51 // much later than the InspectorFrontendAPI.enterInspectElementMode event.52 if (this._mode === DOMAgent.InspectMode.None)53 return;54 var domModel = WebInspector.DOMModel.fromTarget(target);55 domModel.setInspectMode(this._mode);56 },57 /**58 * @override59 * @param {!WebInspector.Target} target60 */61 targetRemoved: function(target)62 {63 },64 /**65 * @return {boolean}66 */67 isInInspectElementMode: function()68 {69 return this._mode === DOMAgent.InspectMode.SearchForNode || this._mode === DOMAgent.InspectMode.SearchForUAShadowDOM;70 },71 /**72 * @return {boolean}73 */74 isInLayoutEditorMode: function()75 {76 return this._mode === DOMAgent.InspectMode.ShowLayoutEditor;77 },78 stopInspection: function()79 {80 if (this._mode && this._mode !== DOMAgent.InspectMode.None)81 this._toggleInspectMode();82 },83 _toggleLayoutEditor: function()84 {85 var mode = this.isInLayoutEditorMode() ? DOMAgent.InspectMode.None : DOMAgent.InspectMode.ShowLayoutEditor;86 this._setMode(mode);87 },88 _toggleInspectMode: function()89 {90 if (WebInspector.targetManager.allTargetsSuspended())91 return;92 var mode;93 if (this.isInInspectElementMode())94 mode = DOMAgent.InspectMode.None;95 else96 mode = WebInspector.moduleSetting("showUAShadowDOM").get() ? DOMAgent.InspectMode.SearchForUAShadowDOM : DOMAgent.InspectMode.SearchForNode;97 this._setMode(mode);98 },99 /**100 * @param {!DOMAgent.InspectMode} mode101 */102 _setMode: function(mode)103 {104 this._mode = mode;105 for (var domModel of WebInspector.DOMModel.instances())106 domModel.setInspectMode(mode);107 if (this._layoutEditorButton) {108 this._layoutEditorButton.setEnabled(!this.isInInspectElementMode());109 this._layoutEditorButton.setToggled(this.isInLayoutEditorMode());110 }111 this._toggleSearchAction.setEnabled(!this.isInLayoutEditorMode());112 this._toggleSearchAction.setToggled(this.isInInspectElementMode());113 },114 _suspendStateChanged: function()115 {116 if (!WebInspector.targetManager.allTargetsSuspended())117 return;118 this._mode = DOMAgent.InspectMode.None;119 this._toggleSearchAction.setToggled(false);120 if (this._layoutEditorButton)121 this._layoutEditorButton.setToggled(false);122 }123}124/**125 * @constructor126 * @implements {WebInspector.ActionDelegate}127 */128WebInspector.InspectElementModeController.ToggleSearchActionDelegate = function()129{130}131WebInspector.InspectElementModeController.ToggleSearchActionDelegate.prototype = {132 /**133 * @override134 * @param {!WebInspector.Context} context135 * @param {string} actionId136 * @return {boolean}137 */138 handleAction: function(context, actionId)139 {140 if (!WebInspector.inspectElementModeController)141 return false;142 WebInspector.inspectElementModeController._toggleInspectMode();143 return true;144 }145}146/**147 * @constructor148 * @implements {WebInspector.ToolbarItem.Provider}149 */150WebInspector.InspectElementModeController.LayoutEditorButtonProvider = function()151{152}153WebInspector.InspectElementModeController.LayoutEditorButtonProvider.prototype = {154 /**155 * @override156 * @return {?WebInspector.ToolbarItem}157 */158 item: function()159 {160 if (!WebInspector.inspectElementModeController)161 return null;162 return WebInspector.inspectElementModeController._layoutEditorButton;163 }164}165/** @type {?WebInspector.InspectElementModeController} */...
values.js
Source:values.js
2var test = require('tape');3test('values', function (t) {4 t.plan(1);5 var obj = [{}, [], { 'a-b': 5 }];6 t.equal(inspect(obj), '[ {}, [], { \'a-b\': 5 } ]');7});8test('arrays with properties', function (t) {9 t.plan(1);10 var arr = [3];11 arr.foo = 'bar';12 var obj = [1, 2, arr];13 obj.baz = 'quux';14 obj.index = -1;15 t.equal(inspect(obj), '[ 1, 2, [ 3, foo: \'bar\' ], baz: \'quux\', index: -1 ]');16});17test('has', function (t) {18 t.plan(1);19 var has = Object.prototype.hasOwnProperty;20 delete Object.prototype.hasOwnProperty;21 t.equal(inspect({ a: 1, b: 2 }), '{ a: 1, b: 2 }');22 Object.prototype.hasOwnProperty = has; // eslint-disable-line no-extend-native23});24test('indexOf seen', function (t) {25 t.plan(1);26 var xs = [1, 2, 3, {}];27 xs.push(xs);28 var seen = [];29 seen.indexOf = undefined;30 t.equal(31 inspect(xs, {}, 0, seen),32 '[ 1, 2, 3, {}, [Circular] ]'33 );34});35test('seen seen', function (t) {36 t.plan(1);37 var xs = [1, 2, 3];38 var seen = [xs];39 seen.indexOf = undefined;40 t.equal(41 inspect(xs, {}, 0, seen),42 '[Circular]'43 );44});45test('seen seen seen', function (t) {46 t.plan(1);47 var xs = [1, 2, 3];48 var seen = [5, xs];49 seen.indexOf = undefined;50 t.equal(51 inspect(xs, {}, 0, seen),52 '[Circular]'53 );54});55test('symbols', { skip: typeof Symbol !== 'function' }, function (t) {56 var sym = Symbol('foo');57 t.equal(inspect(sym), 'Symbol(foo)', 'Symbol("foo") should be "Symbol(foo)"');58 t.equal(inspect(Object(sym)), 'Object(Symbol(foo))', 'Object(Symbol("foo")) should be "Object(Symbol(foo))"');59 t.end();60});61test('Map', { skip: typeof Map !== 'function' }, function (t) {62 var map = new Map();63 map.set({ a: 1 }, ['b']);64 map.set(3, NaN);65 var expectedString = 'Map (2) {' + inspect({ a: 1 }) + ' => ' + inspect(['b']) + ', 3 => NaN}';66 t.equal(inspect(map), expectedString, 'new Map([[{ a: 1 }, ["b"]], [3, NaN]]) should show size and contents');67 t.equal(inspect(new Map()), 'Map (0) {}', 'empty Map should show as empty');68 var nestedMap = new Map();69 nestedMap.set(nestedMap, map);70 t.equal(inspect(nestedMap), 'Map (1) {[Circular] => ' + expectedString + '}', 'Map containing a Map should work');71 t.end();72});73test('WeakMap', { skip: typeof WeakMap !== 'function' }, function (t) {74 var map = new WeakMap();75 map.set({ a: 1 }, ['b']);76 var expectedString = 'WeakMap { ? }';77 t.equal(inspect(map), expectedString, 'new WeakMap([[{ a: 1 }, ["b"]]]) should not show size or contents');78 t.equal(inspect(new WeakMap()), 'WeakMap { ? }', 'empty WeakMap should not show as empty');79 t.end();80});81test('Set', { skip: typeof Set !== 'function' }, function (t) {82 var set = new Set();83 set.add({ a: 1 });84 set.add(['b']);85 var expectedString = 'Set (2) {' + inspect({ a: 1 }) + ', ' + inspect(['b']) + '}';86 t.equal(inspect(set), expectedString, 'new Set([{ a: 1 }, ["b"]]) should show size and contents');87 t.equal(inspect(new Set()), 'Set (0) {}', 'empty Set should show as empty');88 var nestedSet = new Set();89 nestedSet.add(set);90 nestedSet.add(nestedSet);91 t.equal(inspect(nestedSet), 'Set (2) {' + expectedString + ', [Circular]}', 'Set containing a Set should work');92 t.end();93});94test('WeakSet', { skip: typeof WeakSet !== 'function' }, function (t) {95 var map = new WeakSet();96 map.add({ a: 1 });97 var expectedString = 'WeakSet { ? }';98 t.equal(inspect(map), expectedString, 'new WeakSet([{ a: 1 }]) should not show size or contents');99 t.equal(inspect(new WeakSet()), 'WeakSet { ? }', 'empty WeakSet should not show as empty');100 t.end();101});102test('Strings', function (t) {103 var str = 'abc';104 t.equal(inspect(str), "'" + str + "'", 'primitive string shows as such');105 t.equal(inspect(str, { quoteStyle: 'single' }), "'" + str + "'", 'primitive string shows as such, single quoted');106 t.equal(inspect(str, { quoteStyle: 'double' }), '"' + str + '"', 'primitive string shows as such, double quoted');107 t.equal(inspect(Object(str)), 'Object(' + inspect(str) + ')', 'String object shows as such');108 t.equal(inspect(Object(str), { quoteStyle: 'single' }), 'Object(' + inspect(str, { quoteStyle: 'single' }) + ')', 'String object shows as such, single quoted');109 t.equal(inspect(Object(str), { quoteStyle: 'double' }), 'Object(' + inspect(str, { quoteStyle: 'double' }) + ')', 'String object shows as such, double quoted');110 t.end();111});112test('Numbers', function (t) {113 var num = 42;114 t.equal(inspect(num), String(num), 'primitive number shows as such');115 t.equal(inspect(Object(num)), 'Object(' + inspect(num) + ')', 'Number object shows as such');116 t.end();117});118test('Booleans', function (t) {119 t.equal(inspect(true), String(true), 'primitive true shows as such');120 t.equal(inspect(Object(true)), 'Object(' + inspect(true) + ')', 'Boolean object true shows as such');121 t.equal(inspect(false), String(false), 'primitive false shows as such');122 t.equal(inspect(Object(false)), 'Object(' + inspect(false) + ')', 'Boolean false object shows as such');123 t.end();...
inspect.js
Source:inspect.js
2var assert = require('assert');3var util = require('../../util');4var Date2 = require('vm').runInNewContext('Date');5var d = new Date2();6var orig = util.inspect(d);7Date2.prototype.foo = 'bar';8var after = util.inspect(d);9assert.equal(orig, after);10var a = ['foo', 'bar', 'baz'];11assert.equal(util.inspect(a), '[ \'foo\', \'bar\', \'baz\' ]');12delete a[1];13assert.equal(util.inspect(a), '[ \'foo\', , \'baz\' ]');14assert.equal(util.inspect(a, true), '[ \'foo\', , \'baz\', [length]: 3 ]');15assert.equal(util.inspect(new Array(5)), '[ , , , , ]');16var getter = Object.create(null, {a: {get: function() {17 return 'aaa';18 }}});19var setter = Object.create(null, {b: {set: function() {}}});20var getterAndSetter = Object.create(null, {c: {21 get: function() {22 return 'ccc';23 },24 set: function() {}25 }});26assert.equal(util.inspect(getter, true), '{ [a]: [Getter] }');27assert.equal(util.inspect(setter, true), '{ [b]: [Setter] }');28assert.equal(util.inspect(getterAndSetter, true), '{ [c]: [Getter/Setter] }');29assert.equal(util.inspect(new Error()), '[Error]');30assert.equal(util.inspect(new Error('FAIL')), '[Error: FAIL]');31assert.equal(util.inspect(new TypeError('FAIL')), '[TypeError: FAIL]');32assert.equal(util.inspect(new SyntaxError('FAIL')), '[SyntaxError: FAIL]');33try {34 undef();35} catch (e) {36 assert.equal(util.inspect(e), '[ReferenceError: undef is not defined]');37}38var ex = util.inspect(new Error('FAIL'), true);39assert.ok(ex.indexOf('[Error: FAIL]') != -1);40assert.ok(ex.indexOf('[stack]') != -1);41assert.ok(ex.indexOf('[message]') != -1);42assert.equal(util.inspect(Object.create(Date.prototype)), '{}');43assert.doesNotThrow(function() {44 var d = new Date();45 d.toUTCString = null;46 util.inspect(d);47});48assert.doesNotThrow(function() {49 var r = /regexp/;50 r.toString = null;51 util.inspect(r);52});53assert.doesNotThrow(function() {54 util.inspect([{inspect: function() {55 return 123;56 }}]);57});58var x = {inspect: util.inspect};59assert.ok(util.inspect(x).indexOf('inspect') != -1);60function test_color_style(style, input, implicit) {61 var color_name = util.inspect.styles[style];62 var color = ['', ''];63 if (util.inspect.colors[color_name])64 color = util.inspect.colors[color_name];65 var without_color = util.inspect(input, false, 0, false);66 var with_color = util.inspect(input, false, 0, true);67 var expect = '\u001b[' + color[0] + 'm' + without_color + '\u001b[' + color[1] + 'm';68 assert.equal(with_color, expect, 'util.inspect color for style ' + style);69}70test_color_style('special', function() {});71test_color_style('number', 123.456);72test_color_style('boolean', true);73test_color_style('undefined', undefined);74test_color_style('null', null);75test_color_style('string', 'test string');76test_color_style('date', new Date);77test_color_style('regexp', /regexp/);78assert.doesNotThrow(function() {79 util.inspect({hasOwnProperty: null});80});81var subject = {82 foo: 'bar',83 hello: 31,84 a: {b: {c: {d: 0}}}85};86Object.defineProperty(subject, 'hidden', {87 enumerable: false,88 value: null89});90assert(util.inspect(subject, {showHidden: false}).indexOf('hidden') === -1);91assert(util.inspect(subject, {showHidden: true}).indexOf('hidden') !== -1);92assert(util.inspect(subject, {colors: false}).indexOf('\u001b[32m') === -1);93assert(util.inspect(subject, {colors: true}).indexOf('\u001b[32m') !== -1);94assert(util.inspect(subject, {depth: 2}).indexOf('c: [Object]') !== -1);95assert(util.inspect(subject, {depth: 0}).indexOf('a: [Object]') !== -1);96assert(util.inspect(subject, {depth: null}).indexOf('{ d: 0 }') !== -1);97subject = {inspect: function() {98 return 123;99 }};100assert(util.inspect(subject, {customInspect: true}).indexOf('123') !== -1);101assert(util.inspect(subject, {customInspect: true}).indexOf('inspect') === -1);102assert(util.inspect(subject, {customInspect: false}).indexOf('123') === -1);103assert(util.inspect(subject, {customInspect: false}).indexOf('inspect') !== -1);104subject.inspect = function() {105 return {foo: 'bar'};106};107assert.equal(util.inspect(subject), '{ foo: \'bar\' }');108subject.inspect = function(depth, opts) {109 assert.strictEqual(opts.customInspectOptions, true);110};111util.inspect(subject, {customInspectOptions: true});112function test_lines(input) {113 var count_lines = function(str) {114 return (str.match(/\n/g) || []).length;115 };116 var without_color = util.inspect(input);117 var with_color = util.inspect(input, {colors: true});118 assert.equal(count_lines(without_color), count_lines(with_color));119}120test_lines([1, 2, 3, 4, 5, 6, 7]);121test_lines(function() {122 var big_array = [];123 for (var i = 0; i < 100; i++) {124 big_array.push(i);125 }126 return big_array;127}());128test_lines({129 foo: 'bar',130 baz: 35,131 b: {a: 35}...
optimistic_check_type.js
Source:optimistic_check_type.js
...31var a=3, b=2.3, c=true, d;32var x = { a: 2, b:0, c:undefined}33var trees = new Array("redwood", "bay", "cedar", "oak");34// Testing conditional operator35print(inspect("" ? b : x.a, "ternary operator"))36var b1 = b;37print(inspect(x.b ? b1 : x.a, "ternary operator"))38var b2 = b;39print(inspect(c ? b2 : a, "ternary operator"))40var b3 = b;41print(inspect(!c ? b3 : a, "ternary operator"))42var b4 = b;43print(inspect(d ? b4 : x.c, "ternary operator"))44print(inspect(x.c ? a : c, "ternary operator"))45print(inspect(c ? d : a, "ternary operator"))46var b5 = b;47print(inspect(c ? +a : b5, "ternary operator"))48// Testing format methods49print(inspect(b.toFixed(2), "global double toFixed()"))50print(inspect(b.toPrecision(2)/1, "global double toPrecision() divided by 1"))51print(inspect(b.toExponential(2), "global double toExponential()"))52// Testing arrays53print(inspect(trees[1], "member object"))54trees[1] = undefined;55print(inspect(trees[1], "member undefined"))56var b6=b;57print(inspect(1 in trees ? b6 : a, "conditional on array member"))58delete trees[2]59var b7=b;60print(inspect(2 in trees ? b7 : a, "conditional on array member"))61print(inspect(3 in trees ? trees[2]="bay" : a, "conditional on array member"))62var b8=b;63print(inspect("oak" in trees ? b8 : a, "conditional on array member"))64// Testing nested functions and return value65function f1() {66 var x = 2, y = 1;67 function g() {68 print(inspect(x, "outer local variable"));69 print(inspect(a, "global variable"));70 print(inspect(x*y, "outer local int multiplication by outer local int"));71 print(inspect(a*d, "global int multiplication by global undefined"));72 }73 g()74}75f1()76function f2(a,b,c) {77 g = (a+b) * c;78 print(inspect(c, "local undefined"));79 print(inspect(a+b, "local undefined addition local undefined"));80 print(inspect(g, "local undefined multiplication by undefined"));81}82f2()83function f3(a,b) {84 g = a && b;85 print(inspect(g, "local undefined AND local undefined"));86 print(inspect(c||g, "global true OR local undefined"));87}88f3()89function f4() {90 var x = true, y = 0;91 function g() {92 print(inspect(x+y, "outer local true addition local int"));93 print(inspect(a+x, "global int addition outer local true"));94 print(inspect(x*y, "outer local true multiplication by outer local int"));95 print(inspect(y*d, "outer local int multiplication by global undefined"));96 }97 g()98}...
optimistic_arithmetic_check_type.js
Source:optimistic_arithmetic_check_type.js
...32var x = { a: 2, b:1, c: 7, d: -1}33var y = { a: Number.MAX_VALUE, b: Number.POSITIVE_INFINITY, c: "Hello", d: undefined}34// Testing arithmetic operators35//-- Local variable36print(inspect(x.a*x.b, "local int multiplication by local int"))37print(inspect(x.a/x.b, "local int division by local int without remainder"))38print(inspect(x.c/x.a, "local int division by local int with remainder"))39print(inspect(x.c%x.a, "local int modulo by local int"))40print(inspect(x.a+x.b, "local int addition local int"))41print(inspect(x.a-x.b, "local int substraction local int"))42print(inspect(y.a*y.a, "max value multiplication by max value"))43print(inspect(y.b*y.b, "infinity multiplication by infinity"))44print(inspect(x.d/y.b, "-1 division by infinity"))45print(inspect(y.b/x.e, "infinity division by zero"))46print(inspect(y.b/y.c, "infinity division by String"))47print(inspect(y.d/y.d, "local undefined division by local undefined"))48print(inspect(y.d*y.d, "local undefined multiplication by local undefined"))49print(inspect(y.d+x.a, "local undefined addition local int"))50print(inspect(y.d--, "local undefined decrement postfix"))51print(inspect(--y.d, "local undefined decrement prefix"))52print(inspect(x.a++, "local int increment postfix"))53print(inspect(++x.a, "local int increment prefix"))54print(inspect(x.a--, "local int decrement postfix"))55print(inspect(--x.a, "local int decrement prefix"))56print(inspect(+x.a, "local int unary plus"))57print(inspect(-x.a, "local int unary minus"))58//-- Global variable59print(inspect(b*c, "undefined multiplication by undefined"))60print(inspect(b/c, "undefined division by undefined"))61print(inspect(a+a, "global int addition global int"))62print(inspect(a-a, "global int substraction global int"))63print(inspect(a*a, "global int multiplication by global int"))64print(inspect(a++, "global int increment postfix"))65print(inspect(++a, "global int increment prefix"))66print(inspect(a--, "global int decrement postfix"))67print(inspect(--a, "global int decrement prefix"))68print(inspect(+a, "global int unary plus"))69print(inspect(-a, "global int unary minus"))70print(inspect(b--, "global undefined decrement postfix"))71print(inspect(--b, "global undefined decrement prefix"))72print(inspect(x, "object"))73print(inspect(x/x, "object division by object"))...
optimistic_logical_check_type.js
Source:optimistic_logical_check_type.js
...30var a = 3, b = true, c = 0;31var x = { a: 2, b: undefined, c: true}32// Testing logical operators33//-- Global variable34print(inspect("cat" && "dog", "object AND object"))35print(inspect(b && a, "true AND non-falsey global int"))36print(inspect(a && b, "non-falsey global int AND true"))37print(inspect(x && b, "non-falsey object AND true"))38print(inspect(b && x, "true AND non-falsey object"))39print(inspect("cat" || "dog", "object OR object"))40print(inspect(b || a, "true OR non-falsey global int"))41print(inspect(a || b, "non-falsey global int OR true"))42print(inspect(x || b, "non-falsey object OR true"))43print(inspect(b || x, "true OR non-falsey object"))44print(inspect(!x.c || b, "false OR true"))45print(inspect(c && b, "falsey global int AND true"))46print(inspect(c || x.b, "falsey global int OR undefined"))47print(inspect(!c || x.b, "logical not falsey global int OR undefined"))48print(inspect(!b || x.b, "false OR undefined"))49print(inspect(!b || c, "false OR falsey global int"))50print(inspect(!c || c, "logical not falsey global int OR falsey global int"))51 //--Local variable52print(inspect(x.b && a, "local undefined AND non-falsey global int"))53print(inspect(b && x.b, "true AND local undefined"))54print(inspect(x.b && x.a, "local undefined AND non-falsey local int"))55print(inspect(x.b || b, "local undefined OR true"))56print(inspect(b || x.b, "true OR local undefined"))57print(inspect(x.a && x.c, "non-falsey local int AND true"))58print(inspect(x.c && x.a, "true AND non-falsey local int"))59print(inspect(x.c && !!x.a, "true AND double logical not non-falsey local int "))60print(inspect(!x.c && x.a, "false AND non-falsey local int"))61print(inspect(x.a || x.c, "non-falsey local int OR true"))...
TestInspect.js
Source:TestInspect.js
1/**2 * Tests for Divmod.Inspect3 */4// import Divmod.UnitTest5// import Divmod.Inspect6Divmod.Test.TestInspect.TestInspect = Divmod.UnitTest.TestCase.subclass('TestInspect');7Divmod.Test.TestInspect.TestInspect.methods(8 /**9 * Test that L{Divmod.Inspect.methods} returns all the methods of a class10 * object.11 */12 function test_methods(self) {13 /* Divmod.Class has no visible toString method for some reason. If this14 * ever changes, feel free to change this test.15 */16 self.assertArraysEqual(Divmod.Inspect.methods(Divmod.Class),17 ["__init__"]);18 var TestClass = Divmod.Class.subclass("test_inspect.test_methods.TestClass");19 TestClass.methods(function method() {});20 /* Subclasses get two methods automagically, __init__ and toString. If21 * this ever changes, feel free to change this test.22 */23 self.assertArraysEqual(Divmod.Inspect.methods(TestClass),24 ["__init__", "method", "toString"]);25 var TestSubclass = TestClass.subclass("test_inspect.test_methods.TestSubclass");26 TestSubclass.methods(function anotherMethod() {});27 self.assertArraysEqual(Divmod.Inspect.methods(TestSubclass),28 ["__init__", "anotherMethod", "method",29 "toString"]);30 },31 /**32 * Test that an appropriate exception is raised if the methods of an instance33 * are requested.34 */35 function test_methodsAgainstInstance(self) {36 var msg = "Only classes have methods.";37 var error;38 error = self.assertThrows(39 Error,40 function() {41 return Divmod.Inspect.methods([]);42 });43 self.assertIdentical(error.message, msg);44 error = self.assertThrows(45 Error,46 function() {47 return Divmod.Inspect.methods({});48 });49 self.assertIdentical(error.message, msg);50 error = self.assertThrows(51 Error,52 function() {53 return Divmod.Inspect.methods(0);54 });55 self.assertIdentical(error.message, msg);56 error = self.assertThrows(57 Error,58 function() {59 return Divmod.Inspect.methods("");60 });61 self.assertIdentical(error.message, msg);62 error = self.assertThrows(63 Error,64 function() {65 return Divmod.Inspect.methods(Divmod.Class());66 });67 self.assertIdentical(error.message, msg);...
JDK-8062799.js
Source:JDK-8062799.js
...32 var b = true;33 var i = 1;34 var d = 2.1;35 var o = "foo";36 print(inspect(b || b, "b || b"));37 print(inspect(b || i, "b || i"));38 print(inspect(b || d, "b || d"));39 print(inspect(b || o, "b || o"));40 41 print(inspect(i || b, "i || b"));42 print(inspect(i || i, "i || i"));43 print(inspect(i || d, "i || d"));44 print(inspect(i || o, "i || o"));45 print(inspect(d || b, "d || b"));46 print(inspect(d || i, "d || i"));47 print(inspect(d || d, "d || d"));48 print(inspect(d || o, "d || o"));49 print(inspect(o || b, "o || b"));50 print(inspect(o || i, "o || i"));51 print(inspect(o || d, "o || d"));52 print(inspect(o || o, "o || o"));53 print(inspect(b && b, "b && b"));54 print(inspect(b && i, "b && i"));55 print(inspect(b && d, "b && d"));56 print(inspect(b && o, "b && o"));57 58 print(inspect(i && b, "i && b"));59 print(inspect(i && i, "i && i"));60 print(inspect(i && d, "i && d"));61 print(inspect(i && o, "i && o"));62 print(inspect(d && b, "d && b"));63 print(inspect(d && i, "d && i"));64 print(inspect(d && d, "d && d"));65 print(inspect(d && o, "d && o"));66 print(inspect(o && b, "o && b"));67 print(inspect(o && i, "o && i"));68 print(inspect(o && d, "o && d"));69 print(inspect(o && o, "o && o"));70})();71 72 ...
Using AI Code Generation
1const unexpected = require('unexpected');2const unexpectedReact = require('unexpected-react');3const unexpectedSinon = require('unexpected-sinon');4const unexpectedImmutable = require('unexpected-immutable');5const unexpectedInstance = unexpected.clone()6 .use(unexpectedReact)7 .use(unexpectedSinon)8 .use(unexpectedImmutable);9const { inspect } = unexpectedInstance;10const React = require('react');11const { mount } = require('enzyme');12const { Map } = require('immutable');13const sinon = require('sinon');14const { ItemList } = require('./ItemList');15const items = Map([16 ['id-1', { id: 'id-1', name: 'Item 1' }],17 ['id-2', { id: 'id-2', name: 'Item 2' }],18 ['id-3', { id: 'id-3', name: 'Item 3' }],19]);20describe('ItemList', () => {21 it('should render the items', () => {22 const wrapper = mount(<ItemList items={items} />);23 expect(wrapper.find('.item')).toHaveLength(3);24 });25 it('should render the items with the correct name', () => {26 const wrapper = mount(<ItemList items={items} />);27 expect(wrapper.find('.item').at(0).text()).toEqual('Item 1');28 expect(wrapper.find('.item').at(1).text()).toEqual('Item 2');29 expect(wrapper.find('.item').at(2).text()).toEqual('Item 3');30 });31 it('should call the removeItem callback when clicking the remove button', () => {32 const removeItem = sinon.spy();33 const wrapper = mount(<ItemList items={items} removeItem={removeItem} />);34 wrapper.find('.remove').at(1).simulate('click');35 expect(removeItem).toHaveBeenCalled();36 expect(removeItem).toHaveBeenCalledWith('id-2');37 });38});39const unexpected = require('unexpected');40const unexpectedReact = require('unexpected-react');41const unexpectedSinon = require('unexpected-sinon');42const unexpectedImmutable = require('unexpected-immutable');43const unexpectedInstance = unexpected.clone()44 .use(unexpectedReact)45 .use(unexpectedSinon)46 .use(unexpectedImmutable);47const React = require('react');
Using AI Code Generation
1const expect = require('unexpected')2 .clone()3 .use(require('unexpected-snapshot'));4const inspect = require('unexpected')5 .clone()6 .use(require('unexpected-snapshot'))7 .use(require('unexpected-htmllike'))8 .use(require('unexpected-dom'))9 .use(require('unexpected-react'));10const inspect = require('unexpected')11 .clone()12 .use(require('unexpected-snapshot'))13 .use(require('unexpected-htmllike'))14 .use(require('unexpected-dom'))15 .use(require('unexpected-react'));16const inspect = require('unexpected')17 .clone()18 .use(require('unexpected-snapshot'))19 .use(require('unexpected-htmllike'))20 .use(require('unexpected-dom'))21 .use(require('unexpected-react'));22const inspect = require('unexpected')23 .clone()24 .use(require('unexpected-snapshot'))25 .use(require('unexpected-htmllike'))26 .use(require('unexpected-dom'))27 .use(require('unexpected-react'));28const inspect = require('unexpected')29 .clone()30 .use(require('unexpected-snapshot'))31 .use(require('unexpected-htmllike'))32 .use(require('unexpected-dom'))33 .use(require('unexpected-react'));34const inspect = require('unexpected')35 .clone()36 .use(require('unexpected-snapshot'))37 .use(require('unexpected-htmllike'))38 .use(require('unexpected-dom'))39 .use(require('unexpected-react'));40const inspect = require('unexpected')41 .clone()42 .use(require('unexpected-snapshot'))43 .use(require('unexpected-htmllike'))44 .use(require('unexpected-dom'))45 .use(require('unexpected-react'));46const inspect = require('unexpected')47 .clone()48 .use(require('unexpected-snapshot'))49 .use(require('unexpected-htmllike'))50 .use(require('unexpected-dom'))51 .use(require('unexpected-react'));52const inspect = require('unexpected')53 .clone()54 .use(require('unexpected-snapshot'))
Using AI Code Generation
1const unexpected = require('unexpected');2const unexpectedSinon = require('unexpected-sinon');3const unexpectedReact = require('unexpected-react');4const unexpectedImmutable = require('unexpected-immutable');5const unexpectedDom = require('unexpected-dom');6const unexpectedRedux = require('unexpected-redux');7const unexpectedSnapshot = require('unexpected-snapshot');8const unexpectedReplay = require('unexpected-replay');9const unexpectedEventEmitter = require('unexpected-eventemitter');10const unexpectedEventEmitterAsync = require('unexpected-eventemitter-async');11const unexpectedMoment = require('unexpected-moment');12const unexpectedGraphQL = require('unexpected-graphql');13const unexpectedObservable = require('unexpected-observable');14const unexpectedObservableAsync = require('unexpected-observable-async');15const unexpectedRxjs = require('unexpected-rxjs');16const unexpectedRxjsAsync = require('unexpected-rxjs-async');17const unexpectedRxjsMarbles = require('unexpected-rxjs-marbles');18const unexpectedRxjsMarblesAsync = require('unexpected-rxjs-marbles-async');19const unexpectedRxjsMarblesReplay = require('unexpected-rxjs-marbles-replay');20const unexpectedRxjsMarblesSnapshot = require('unexpected-rxjs-marbles-snapshot');21const unexpectedRxjsMarblesSnapshotAsync = require('unexpected-rxjs-marbles-snapshot-async');22const unexpectedRxjsMarblesSnapshotReplay = require('unexpected-rxjs-marbles-snapshot-replay');23const unexpectedRxjsMarblesSnapshotReplayAsync = require('unexpected-rxjs-marbles-snapshot-replay-async');24const unexpectedRxjsMarblesReplayAsync = require('unexpected-rxjs-marbles-replay-async');25const unexpectedRxjsMarblesSnapshotAsync = require('unexpected-rxjs-marbles-snapshot-async');26const unexpectedRxjsMarblesSnapshotReplay = require('unexpected-rxjs-marbles-snapshot-replay');27const unexpectedRxjsMarblesSnapshotReplayAsync = require('unexpected-rxjs-marbles-snapshot-replay-async');28const unexpectedRxjsMarblesReplayAsync = require('unexpected-rxjs-marbles-replay-async');29const unexpectedRxjsMarblesSnapshot = require('unexpected-rxjs-marbles-snapshot');30const unexpectedRxjsMarblesSnapshotAsync = require('unexpected-rxjs-marbles-snapshot-async');31const unexpectedRxjsMarblesSnapshotReplay = require('unexpected-rxjs-marbles-snapshot
Using AI Code Generation
1const util = require('util');2const name = 'John';3const greeting = util.format('Hello, %s', name);4util.log(greeting);5const obj = { name: 'John', age: 25 };6const str = util.inspect(obj);7console.log(str);8const obj = { name: 'John', age: 25 };9const str = util.inspect(obj, { colors: true });10console.log(str);11const obj = { name: 'John', age: 25 };12const str = util.inspect(obj, { showHidden: true, depth: null });13console.log(str);14const obj = { name: 'John', age: 25 };15const str = util.inspect(obj, { showHidden: true, depth: 0 });16console.log(str);17const obj = { name: 'John', age: 25 };18const str = util.inspect(obj, { showHidden: true, depth: 1 });19console.log(str);20const obj = { name: 'John', age: 25 };21const str = util.inspect(obj, { showHidden: true, depth: 2 });22console.log(str);23const obj = { name: 'John', age: 25 };24const str = util.inspect(obj, { showHidden: true, depth: 3 });25console.log(str);26const obj = { name: 'John', age: 25 };27const str = util.inspect(obj, { showHidden: true, depth: 4 });28console.log(str);29const obj = { name: 'John', age: 25 };30const str = util.inspect(obj, { showHidden: true, depth: 5 });31console.log(str);32const obj = { name: 'John', age: 25 };33const str = util.inspect(obj, { showHidden: true, depth: 6 });34console.log(str);35const obj = { name: 'John', age: 25 };
Using AI Code Generation
1var unexpected = require('unexpected');2var expect = unexpected.clone();3expect.addAssertion('<array> to have the first item <any>', function(expect, subject, value) {4 expect(subject[0], 'to equal', value);5});6expect([1, 2, 3], 'to have the first item', 1);7var chai = require('chai');8var expect = chai.expect;9expect([1, 2, 3]).to.have.lengthOf(3);10var should = require('should');11var arr = [1, 2, 3];12arr.should.have.lengthOf(3);13var assert = require('assert');14var arr = [1, 2, 3];15assert.equal(arr.length, 3);
Using AI Code Generation
1var unexpected = require('unexpected');2var expect = unexpected.clone().installPlugin(require('unexpected-htmllike'));3var actual = '<div>actual</div>';4var expected = '<div>expected</div>';5expect(actual, 'to equal', expected);6var chai = require('chai');7var assert = chai.assert;8var actual = '<div>actual</div>';9var expected = '<div>expected</div>';10assert.deepEqual(actual, expected);11var chai = require('chai');12var expect = chai.expect;13var actual = '<div>actual</div>';14var expected = '<div>expected</div>';15expect(actual).to.deep.equal(expected);16var chai = require('chai');17var assert = chai.assert;18var actual = '<div>actual</div>';19var expected = '<div>expected</div>';20assert.equal(actual, expected);21var chai = require('chai');22var expect = chai.expect;23var actual = '<div>actual</div>';24var expected = '<div>expected</div>';25expect(actual).to.equal(expected);26var chai = require('chai');27var assert = chai.assert;28var actual = '<div>actual</div>';29var expected = '<div>expected</div>';
Using AI Code Generation
1var inspect = require('unexpected').inspect;2var a = {a: 1, b: 2};3var b = {a: 1, b: 2};4inspect(a, b);5var inspect = require('unexpected').inspect;6var a = {a: 1, b: 2};7var b = {a: 1, b: 2};8inspect(a, b, {colors: true});9var inspect = require('unexpected').inspect;10var a = {a: 1, b: 2};11var b = {a: 1, b: 2};12inspect(a, b, {colors: true, depth: 1});13var inspect = require('unexpected').inspect;14var a = {a: 1, b: 2};15var b = {a: 1, b: 2};16inspect(a, b, {colors: true, depth: 2});17var inspect = require('unexpected').inspect;18var a = {a: 1, b: 2};19var b = {a: 1, b: 2};20inspect(a, b, {colors: true, depth: 3});21var inspect = require('unexpected').inspect;22var a = {a: 1, b: 2};23var b = {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!