Best Python code snippet using hypothesis
split-pane.js
Source:split-pane.js
1/*!2Split Pane v0.9.33Copyright (c) 2014 - 2016 Simon Hagström4Released under the MIT license5https://raw.github.com/shagstrom/split-pane/master/LICENSE6*/7(function ($) {8 'use strict';9 var methods = {};10 methods.init = function() {11 var $splitPanes = this;12 $splitPanes.each(setMinHeightAndMinWidth);13 $splitPanes.children('.split-pane-divider').html('<div class="split-pane-divider-inner"></div>');14 $splitPanes.children('.split-pane-divider').on('touchstart mousedown', mousedownHandler);15 setTimeout(function() {16 // Doing this later because of an issue with Chrome (v23.0.1271.64) returning split-pane width = 017 // and triggering multiple resize events when page is being opened from an <a target="_blank"> .18 $splitPanes.each(attachResizeHandler);19 $(window).trigger('resize');20 }, 100);21 };22 methods.firstComponentSize = function(value) {23 this.each(function() {24 var $splitPane = $(this),25 components = getComponents($splitPane);26 if ($splitPane.is('.fixed-top')) {27 fixedTopHandler(components, components.divider.offsetTop)({pageY: value});28 } else if ($splitPane.is('.fixed-bottom')) {29 value = components.splitPane.offsetHeight -components.divider.offsetHeight - value;30 fixedBottomHandler(components, -components.last.offsetHeight)({pageY: -value});31 } else if ($splitPane.is('.horizontal-percent')) {32 value = components.splitPane.offsetHeight -components.divider.offsetHeight - value;33 horizontalPercentHandler(components, -components.last.offsetHeight)({pageY: -value});34 } else if ($splitPane.is('.fixed-left')) {35 fixedLeftHandler(components, components.divider.offsetLeft)({pageX: value});36 } else if ($splitPane.is('.fixed-right')) {37 value = components.splitPane.offsetWidth -components.divider.offsetWidth - value;38 fixedRightHandler(components, -components.last.offsetWidth)({pageX: -value});39 } else if ($splitPane.is('.vertical-percent')) {40 value = components.splitPane.offsetWidth -components.divider.offsetWidth - value;41 verticalPercentHandler(components, -components.last.offsetWidth)({pageX: -value});42 }43 });44 };45 methods.lastComponentSize = function(value) {46 this.each(function() {47 var $splitPane = $(this),48 components = getComponents($splitPane);49 if ($splitPane.is('.fixed-top')) {50 value = components.splitPane.offsetHeight -components.divider.offsetHeight - value;51 fixedTopHandler(components, components.divider.offsetTop)({pageY: value});52 } else if ($splitPane.is('.fixed-bottom')) {53 fixedBottomHandler(components, -components.last.offsetHeight)({pageY: -value});54 } else if ($splitPane.is('.horizontal-percent')) {55 horizontalPercentHandler(components, -components.last.offsetHeight)({pageY: -value});56 } else if ($splitPane.is('.fixed-left')) {57 value = components.splitPane.offsetWidth -components.divider.offsetWidth - value;58 fixedLeftHandler(components, components.divider.offsetLeft)({pageX: value});59 } else if ($splitPane.is('.fixed-right')) {60 fixedRightHandler(components, -components.last.offsetWidth)({pageX: -value});61 } else if ($splitPane.is('.vertical-percent')) {62 verticalPercentHandler(components, -components.last.offsetWidth)({pageX: -value});63 }64 });65 };66 $.fn.splitPane = function(method) {67 methods[method || 'init'].apply(this, $.grep(arguments, function(it, i) { return i > 0; }));68 };69 function setMinHeightAndMinWidth() {70 var $splitPane = $(this),71 components = getComponents($splitPane);72 if ($splitPane.is('.fixed-top, .fixed-bottom, .horizontal-percent')) {73 $splitPane.css('min-height', (minHeight(components.first) + minHeight(components.last) + $(components.divider).height()) + 'px');74 } else {75 $splitPane.css('min-width', (minWidth(components.first) + minWidth(components.last) + $(components.divider).width()) + 'px');76 }77 }78 function mousedownHandler(event) {79 event.preventDefault();80 var $divider = $(this),81 $splitPane = $divider.parent();82 $divider.addClass('dragged');83 if (event.type.match(/^touch/)) {84 $divider.addClass('touch');85 }86 var moveEventHandler = createMousemove($splitPane, pageXof(event), pageYof(event));87 $(document).on('touchmove mousemove', moveEventHandler);88 $(document).one('touchend mouseup', function(event) {89 $(document).off('touchmove mousemove', moveEventHandler);90 $divider.removeClass('dragged touch');91 $splitPane.trigger('dividerdragend', [ getComponentsSizes($splitPane) ]);92 });93 $splitPane.trigger('dividerdragstart', [ getComponentsSizes($splitPane) ]);94 }95 function getComponentsSizes($splitPane) {96 var property = $splitPane.is('.fixed-top, .fixed-bottom, .horizontal-percent') ?97 'height' : 'width';98 return {99 firstComponentSize: $splitPane.find('.split-pane-component:first')[property](),100 lastComponentSize: $splitPane.find('.split-pane-component:last')[property]()101 };102 }103 function attachResizeHandler() {104 var $splitPane = $(this),105 internalHandler = createParentresizeHandler($splitPane),106 parent = $splitPane.parent().closest('.split-pane')[0] || window;107 $(parent).on(parent === window ? 'resize' : 'splitpaneresize', function(event) {108 var target = event.target === document ? window : event.target;109 if (target === parent) {110 internalHandler(event);111 }112 });113 }114 function createParentresizeHandler($splitPane) {115 var components = getComponents($splitPane);116 if ($splitPane.is('.fixed-top')) {117 return function(event) {118 var lastComponentMinHeight = minHeight(components.last),119 maxfirstComponentHeight = components.splitPane.offsetHeight - lastComponentMinHeight - components.divider.offsetHeight;120 if (components.first.offsetHeight > maxfirstComponentHeight) {121 setTop(components, maxfirstComponentHeight + 'px');122 }123 $splitPane.trigger('splitpaneresize');124 };125 } else if ($splitPane.is('.fixed-bottom')) {126 return function(event) {127 var firstComponentMinHeight = minHeight(components.first),128 maxLastComponentHeight = components.splitPane.offsetHeight - firstComponentMinHeight - components.divider.offsetHeight;129 if (components.last.offsetHeight > maxLastComponentHeight) {130 setBottom(components, maxLastComponentHeight + 'px');131 }132 $splitPane.trigger('splitpaneresize');133 };134 } else if ($splitPane.is('.horizontal-percent')) {135 return function(event) {136 var lastComponentMinHeight = minHeight(components.last),137 firstComponentMinHeight = minHeight(components.first),138 maxLastComponentHeight = components.splitPane.offsetHeight - firstComponentMinHeight - components.divider.offsetHeight;139 if (components.last.offsetHeight > maxLastComponentHeight) {140 setBottom(components, (maxLastComponentHeight / components.splitPane.offsetHeight * 100) + '%');141 } else {142 if (components.splitPane.offsetHeight - components.first.offsetHeight - components.divider.offsetHeight < lastComponentMinHeight) {143 setBottom(components, (lastComponentMinHeight / components.splitPane.offsetHeight * 100) + '%');144 }145 }146 $splitPane.trigger('splitpaneresize');147 };148 } else if ($splitPane.is('.fixed-left')) {149 return function(event) {150 var lastComponentMinWidth = minWidth(components.last),151 maxFirstComponentWidth = components.splitPane.offsetWidth - lastComponentMinWidth - components.divider.offsetWidth;152 if (components.first.offsetWidth > maxFirstComponentWidth) {153 setLeft(components, maxFirstComponentWidth + 'px');154 }155 $splitPane.trigger('splitpaneresize');156 };157 } else if ($splitPane.is('.fixed-right')) {158 return function(event) {159 var firstComponentMinWidth = minWidth(components.first),160 maxLastComponentWidth = components.splitPane.offsetWidth - firstComponentMinWidth - components.divider.offsetWidth;161 if (components.last.offsetWidth > maxLastComponentWidth) {162 setRight(components, maxLastComponentWidth + 'px');163 }164 $splitPane.trigger('splitpaneresize');165 };166 } else if ($splitPane.is('.vertical-percent')) {167 return function(event) {168 var lastComponentMinWidth = minWidth(components.last),169 firstComponentMinWidth = minWidth(components.first),170 maxLastComponentWidth = components.splitPane.offsetWidth - firstComponentMinWidth - components.divider.offsetWidth;171 if (components.last.offsetWidth > maxLastComponentWidth) {172 setRight(components, (maxLastComponentWidth / components.splitPane.offsetWidth * 100) + '%');173 } else {174 if (components.splitPane.offsetWidth - components.first.offsetWidth - components.divider.offsetWidth < lastComponentMinWidth) {175 setRight(components, (lastComponentMinWidth / components.splitPane.offsetWidth * 100) + '%');176 }177 }178 $splitPane.trigger('splitpaneresize');179 };180 }181 }182 function createMousemove($splitPane, pageX, pageY) {183 var components = getComponents($splitPane);184 if ($splitPane.is('.fixed-top')) {185 return fixedTopHandler(components, pageY);186 } else if ($splitPane.is('.fixed-bottom')) {187 return fixedBottomHandler(components, pageY);188 } else if ($splitPane.is('.horizontal-percent')) {189 return horizontalPercentHandler(components, pageY);190 } else if ($splitPane.is('.fixed-left')) {191 return fixedLeftHandler(components, pageX);192 } else if ($splitPane.is('.fixed-right')) {193 return fixedRightHandler(components, pageX);194 } else if ($splitPane.is('.vertical-percent')) {195 return verticalPercentHandler(components, pageX);196 }197 }198 function fixedTopHandler(components, pageY) {199 var firstComponentMinHeight = minHeight(components.first),200 maxFirstComponentHeight = components.splitPane.offsetHeight - minHeight(components.last) - components.divider.offsetHeight,201 topOffset = components.divider.offsetTop - pageY;202 return function(event) {203 event.preventDefault && event.preventDefault();204 var top = newTop(firstComponentMinHeight, maxFirstComponentHeight, topOffset + pageYof(event));205 setTop(components, top + 'px');206 $(components.splitPane).trigger('splitpaneresize');207 };208 }209 function fixedBottomHandler(components, pageY) {210 var lastComponentMinHeight = minHeight(components.last),211 maxLastComponentHeight = components.splitPane.offsetHeight - minHeight(components.first) - components.divider.offsetHeight,212 bottomOffset = components.last.offsetHeight + pageY;213 return function(event) {214 event.preventDefault && event.preventDefault();215 var bottom = Math.min(Math.max(lastComponentMinHeight, bottomOffset - pageYof(event)), maxLastComponentHeight);216 setBottom(components, bottom + 'px');217 $(components.splitPane).trigger('splitpaneresize');218 };219 }220 function horizontalPercentHandler(components, pageY) {221 var splitPaneHeight = components.splitPane.offsetHeight,222 lastComponentMinHeight = minHeight(components.last),223 maxLastComponentHeight = splitPaneHeight - minHeight(components.first) - components.divider.offsetHeight,224 bottomOffset = components.last.offsetHeight + pageY;225 return function(event) {226 event.preventDefault && event.preventDefault();227 var bottom = Math.min(Math.max(lastComponentMinHeight, bottomOffset - pageYof(event)), maxLastComponentHeight);228 setBottom(components, (bottom / splitPaneHeight * 100) + '%');229 $(components.splitPane).trigger('splitpaneresize');230 };231 }232 function fixedLeftHandler(components, pageX) {233 var firstComponentMinWidth = minWidth(components.first),234 maxFirstComponentWidth = components.splitPane.offsetWidth - minWidth(components.last) - components.divider.offsetWidth,235 leftOffset = components.divider.offsetLeft - pageX;236 return function(event) {237 event.preventDefault && event.preventDefault();238 var left = newLeft(firstComponentMinWidth, maxFirstComponentWidth, leftOffset + pageXof(event));239 setLeft(components, left + 'px');240 $(components.splitPane).trigger('splitpaneresize');241 };242 }243 function fixedRightHandler(components, pageX) {244 var lastComponentMinWidth = minWidth(components.last),245 maxLastComponentWidth = components.splitPane.offsetWidth - minWidth(components.first) - components.divider.offsetWidth,246 rightOffset = components.last.offsetWidth + pageX;247 return function(event) {248 event.preventDefault && event.preventDefault();249 var right = Math.min(Math.max(lastComponentMinWidth, rightOffset - pageXof(event)), maxLastComponentWidth);250 setRight(components, right + 'px');251 $(components.splitPane).trigger('splitpaneresize');252 };253 }254 function verticalPercentHandler(components, pageX) {255 var splitPaneWidth = components.splitPane.offsetWidth,256 lastComponentMinWidth = minWidth(components.last),257 maxLastComponentWidth = splitPaneWidth - minWidth(components.first) - components.divider.offsetWidth,258 rightOffset = components.last.offsetWidth + pageX;259 return function(event) {260 event.preventDefault && event.preventDefault();261 var right = Math.min(Math.max(lastComponentMinWidth, rightOffset - pageXof(event)), maxLastComponentWidth);262 setRight(components, (right / splitPaneWidth * 100) + '%');263 $(components.splitPane).trigger('splitpaneresize');264 };265 }266 function getComponents($splitPane) {267 return {268 splitPane: $splitPane[0],269 first: $splitPane.children('.split-pane-component:first')[0],270 divider: $splitPane.children('.split-pane-divider')[0],271 last: $splitPane.children('.split-pane-component:last')[0]272 };273 }274 function pageXof(event) {275 if (event.pageX !== undefined) {276 return event.pageX;277 } else if (event.originalEvent.pageX !== undefined) {278 return event.originalEvent.pageX;279 } else if (event.originalEvent.touches) {280 return event.originalEvent.touches[0].pageX;281 }282 }283 function pageYof(event) {284 if (event.pageY !== undefined) {285 return event.pageY;286 } else if (event.originalEvent.pageY !== undefined) {287 return event.originalEvent.pageY;288 } else if (event.originalEvent.touches) {289 return event.originalEvent.touches[0].pageY;290 }291 }292 function minHeight(element) {293 return parseInt($(element).css('min-height'), 10) || 0;294 }295 function minWidth(element) {296 return parseInt($(element).css('min-width'), 10) || 0;297 }298 function maxHeight(element) {299 return parseInt($(element).css('max-height'), 10);300 }301 function maxWidth(element) {302 return parseInt($(element).css('max-width'), 10);303 }304 function newTop(firstComponentMinHeight, maxFirstComponentHeight, value) {305 return Math.min(Math.max(firstComponentMinHeight, value), maxFirstComponentHeight);306 }307 function newLeft(firstComponentMinWidth, maxFirstComponentWidth, value) {308 return Math.min(Math.max(firstComponentMinWidth, value), maxFirstComponentWidth);309 }310 function setTop(components, top) {311 components.first.style.height = top;312 components.divider.style.top = top;313 components.last.style.top = top;314 }315 function setBottom(components, bottom) {316 components.first.style.bottom = bottom;317 components.divider.style.bottom = bottom;318 components.last.style.height = bottom;319 }320 function setLeft(components, left) {321 components.first.style.width = left;322 components.divider.style.left = left;323 components.last.style.left = left;324 }325 function setRight(components, right) {326 components.first.style.right = right;327 components.divider.style.right = right;328 components.last.style.width = right;329 }...
s-string.js
Source:s-string.js
...9 });10 describe("split", function() {11 var test = "ab";12 it('If "separator" is undefined must return Array with one String - "this" string', function() {13 expect(test.split()).toEqual([test]);14 expect(test.split(void 0)).toEqual([test]);15 });16 it('If "separator" is undefined and "limit" set to 0 must return Array[]', function() {17 expect(test.split(void 0, 0)).toEqual([]);18 });19 describe('Tests from Steven Levithan', function () {20 it("''.split() results in ['']", function () {21 expect(''.split()).toEqual(['']);22 });23 it("''.split(/./) results in ['']", function () {24 expect(''.split(/./)).toEqual(['']);25 });26 it("''.split(/.?/) results in []", function () {27 expect(''.split(/.?/)).toEqual([]);28 });29 it("''.split(/.??/) results in []", function () {30 expect(''.split(/.??/)).toEqual([]);31 });32 it("'ab'.split(/a*/) results in ['', 'b']", function () {33 expect('ab'.split(/a*/)).toEqual(['', 'b']);34 });35 it("'ab'.split(/a*?/) results in ['a', 'b']", function () {36 expect('ab'.split(/a*?/)).toEqual(['a', 'b']);37 });38 it("'ab'.split(/(?:ab)/) results in ['', '']", function () {39 expect('ab'.split(/(?:ab)/)).toEqual(['', '']);40 });41 it("'ab'.split(/(?:ab)*/) results in ['', '']", function () {42 expect('ab'.split(/(?:ab)*/)).toEqual(['', '']);43 });44 it("'ab'.split(/(?:ab)*?/) results in ['a', 'b']", function () {45 expect('ab'.split(/(?:ab)*?/)).toEqual(['a', 'b']);46 });47 it("'test'.split('') results in ['t', 'e', 's', 't']", function () {48 expect('test'.split('')).toEqual(['t', 'e', 's', 't']);49 });50 it("'test'.split() results in ['test']", function () {51 expect('test'.split()).toEqual(['test']);52 });53 it("'111'.split(1) results in ['', '', '', '']", function () {54 expect('111'.split(1)).toEqual(['', '', '', '']);55 });56 it("'test'.split(/(?:)/, 2) results in ['t', 'e']", function () {57 expect('test'.split(/(?:)/, 2)).toEqual(['t', 'e']);58 });59 it("'test'.split(/(?:)/, -1) results in ['t', 'e', 's', 't']", function () {60 expect('test'.split(/(?:)/, -1)).toEqual(['t', 'e', 's', 't']);61 });62 it("'test'.split(/(?:)/, undefined) results in ['t', 'e', 's', 't']", function () {63 expect('test'.split(/(?:)/, undefined)).toEqual(['t', 'e', 's', 't']);64 });65 it("'test'.split(/(?:)/, null) results in []", function () {66 expect('test'.split(/(?:)/, null)).toEqual([]);67 });68 it("'test'.split(/(?:)/, NaN) results in []", function () {69 expect('test'.split(/(?:)/, NaN)).toEqual([]);70 });71 it("'test'.split(/(?:)/, true) results in ['t']", function () {72 expect('test'.split(/(?:)/, true)).toEqual(['t']);73 });74 it("'test'.split(/(?:)/, '2') results in ['t', 'e']", function () {75 expect('test'.split(/(?:)/, '2')).toEqual(['t', 'e']);76 });77 it("'test'.split(/(?:)/, 'two') results in []", function () {78 expect('test'.split(/(?:)/, 'two')).toEqual([]);79 });80 it("'a'.split(/-/) results in ['a']", function () {81 expect('a'.split(/-/)).toEqual(['a']);82 });83 it("'a'.split(/-?/) results in ['a']", function () {84 expect('a'.split(/-?/)).toEqual(['a']);85 });86 it("'a'.split(/-??/) results in ['a']", function () {87 expect('a'.split(/-??/)).toEqual(['a']);88 });89 it("'a'.split(/a/) results in ['', '']", function () {90 expect('a'.split(/a/)).toEqual(['', '']);91 });92 it("'a'.split(/a?/) results in ['', '']", function () {93 expect('a'.split(/a?/)).toEqual(['', '']);94 });95 it("'a'.split(/a??/) results in ['a']", function () {96 expect('a'.split(/a??/)).toEqual(['a']);97 });98 it("'ab'.split(/-/) results in ['ab']", function () {99 expect('ab'.split(/-/)).toEqual(['ab']);100 });101 it("'ab'.split(/-?/) results in ['a', 'b']", function () {102 expect('ab'.split(/-?/)).toEqual(['a', 'b']);103 });104 it("'ab'.split(/-??/) results in ['a', 'b']", function () {105 expect('ab'.split(/-??/)).toEqual(['a', 'b']);106 });107 it("'a-b'.split(/-/) results in ['a', 'b']", function () {108 expect('a-b'.split(/-/)).toEqual(['a', 'b']);109 });110 it("'a-b'.split(/-?/) results in ['a', 'b']", function () {111 expect('a-b'.split(/-?/)).toEqual(['a', 'b']);112 });113 it("'a-b'.split(/-??/) results in ['a', '-', 'b']", function () {114 expect('a-b'.split(/-??/)).toEqual(['a', '-', 'b']);115 });116 it("'a--b'.split(/-/) results in ['a', '', 'b']", function () {117 expect('a--b'.split(/-/)).toEqual(['a', '', 'b']);118 });119 it("'a--b'.split(/-?/) results in ['a', '', 'b']", function () {120 expect('a--b'.split(/-?/)).toEqual(['a', '', 'b']);121 });122 it("'a--b'.split(/-??/) results in ['a', '-', '-', 'b']", function () {123 expect('a--b'.split(/-??/)).toEqual(['a', '-', '-', 'b']);124 });125 it("''.split(/()()/) results in []", function () {126 expect(''.split(/()()/)).toEqual([]);127 });128 it("'.'.split(/()()/) results in ['.']", function () {129 expect('.'.split(/()()/)).toEqual(['.']);130 });131 it("'.'.split(/(.?)(.?)/) results in ['', '.', '', '']", function () {132 expect('.'.split(/(.?)(.?)/)).toEqual(['', '.', '', '']);133 });134 it("'.'.split(/(.??)(.??)/) results in ['.']", function () {135 expect('.'.split(/(.??)(.??)/)).toEqual(['.']);136 });137 it("'.'.split(/(.)?(.)?/) results in ['', '.', undefined, '']", function () {138 expect('.'.split(/(.)?(.)?/)).toEqual(['', '.', undefined, '']);139 });140 it("'A<B>bold</B>and<CODE>coded</CODE>'.split(/<(\\/)?([^<>]+)>/) results in ['A', undefined, 'B', 'bold', '/', 'B', 'and', undefined, 'CODE', 'coded', '/', 'CODE', '']", function () {141 expect('A<B>bold</B>and<CODE>coded</CODE>'.split(/<(\/)?([^<>]+)>/)).toEqual(['A', undefined, 'B', 'bold', '/', 'B', 'and', undefined, 'CODE', 'coded', '/', 'CODE', '']);142 });143 it("'tesst'.split(/(s)*/) results in ['t', undefined, 'e', 's', 't']", function () {144 expect('tesst'.split(/(s)*/)).toEqual(['t', undefined, 'e', 's', 't']);145 });146 it("'tesst'.split(/(s)*?/) results in ['t', undefined, 'e', undefined, 's', undefined, 's', undefined, 't']", function () {147 expect('tesst'.split(/(s)*?/)).toEqual(['t', undefined, 'e', undefined, 's', undefined, 's', undefined, 't']);148 });149 it("'tesst'.split(/(s*)/) results in ['t', '', 'e', 'ss', 't']", function () {150 expect('tesst'.split(/(s*)/)).toEqual(['t', '', 'e', 'ss', 't']);151 });152 it("'tesst'.split(/(s*?)/) results in ['t', '', 'e', '', 's', '', 's', '', 't']", function () {153 expect('tesst'.split(/(s*?)/)).toEqual(['t', '', 'e', '', 's', '', 's', '', 't']);154 });155 it("'tesst'.split(/(?:s)*/) results in ['t', 'e', 't']", function () {156 expect('tesst'.split(/(?:s)*/)).toEqual(['t', 'e', 't']);157 });158 it("'tesst'.split(/(?=s+)/) results in ['te', 's', 'st']", function () {159 expect('tesst'.split(/(?=s+)/)).toEqual(['te', 's', 'st']);160 });161 it("'test'.split('t') results in ['', 'es', '']", function () {162 expect('test'.split('t')).toEqual(['', 'es', '']);163 });164 it("'test'.split('es') results in ['t', 't']", function () {165 expect('test'.split('es')).toEqual(['t', 't']);166 });167 it("'test'.split(/t/) results in ['', 'es', '']", function () {168 expect('test'.split(/t/)).toEqual(['', 'es', '']);169 });170 it("'test'.split(/es/) results in ['t', 't']", function () {171 expect('test'.split(/es/)).toEqual(['t', 't']);172 });173 it("'test'.split(/(t)/) results in ['', 't', 'es', 't', '']", function () {174 expect('test'.split(/(t)/)).toEqual(['', 't', 'es', 't', '']);175 });176 it("'test'.split(/(es)/) results in ['t', 'es', 't']", function () {177 expect('test'.split(/(es)/)).toEqual(['t', 'es', 't']);178 });179 it("'test'.split(/(t)(e)(s)(t)/) results in ['', 't', 'e', 's', 't', '']", function () {180 expect('test'.split(/(t)(e)(s)(t)/)).toEqual(['', 't', 'e', 's', 't', '']);181 });182 it("'.'.split(/(((.((.??)))))/) results in ['', '.', '.', '.', '', '', '']", function () {183 expect('.'.split(/(((.((.??)))))/)).toEqual(['', '.', '.', '.', '', '', '']);184 });185 it("'.'.split(/(((((.??)))))/) results in ['.']", function () {186 expect('.'.split(/(((((.??)))))/)).toEqual(['.']);187 });188 it("'a b c d'.split(/ /, -(Math.pow(2, 32) - 1)) results in ['a']", function () {189 expect('a b c d'.split(/ /, -(Math.pow(2, 32) - 1))).toEqual(['a']);190 });191 it("'a b c d'.split(/ /, Math.pow(2, 32) + 1) results in ['a']", function () {192 expect('a b c d'.split(/ /, Math.pow(2, 32) + 1)).toEqual(['a']);193 });194 it("'a b c d'.split(/ /, Infinity) results in []", function () {195 expect('a b c d'.split(/ /, Infinity)).toEqual([]);196 });197 });198 });...
15.5.4.8-1.js
Source:15.5.4.8-1.js
...37 * ***** END LICENSE BLOCK ***** */38gTestfile = '15.5.4.8-1.js';39/**40 File Name: 15.5.4.8-1.js41 ECMA Section: 15.5.4.8 String.prototype.split( separator )42 Description:43 Returns an Array object into which substrings of the result of converting44 this object to a string have been stored. The substrings are determined by45 searching from left to right for occurrences of the given separator; these46 occurrences are not part of any substring in the returned array, but serve47 to divide up this string value. The separator may be a string of any length.48 As a special case, if the separator is the empty string, the string is split49 up into individual characters; the length of the result array equals the50 length of the string, and each substring contains one character.51 If the separator is not supplied, then the result array contains just one52 string, which is the string.53 Author: christine@netscape.com, pschwartau@netscape.com54 Date: 12 November 199755 Modified: 14 July 200256 Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=15528957 ECMA-262 Ed.3 Section 15.5.4.1458 The length property of the split method is 259 *60 */61var SECTION = "15.5.4.8-1";62var VERSION = "ECMA_1";63startTest();64var TITLE = "String.prototype.split";65writeHeaderToLog( SECTION + " "+ TITLE);66new TestCase( SECTION, "String.prototype.split.length", 2, String.prototype.split.length );67new TestCase( SECTION, "delete String.prototype.split.length", false, delete String.prototype.split.length );68new TestCase( SECTION, "delete String.prototype.split.length; String.prototype.split.length", 2, eval("delete String.prototype.split.length; String.prototype.split.length") );69// test cases for when split is called with no arguments.70// this is a string object71new TestCase( SECTION,72 "var s = new String('this is a string object'); typeof s.split()",73 "object",74 eval("var s = new String('this is a string object'); typeof s.split()") );75new TestCase( SECTION,76 "var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()",77 "[object Array]",78 eval("var s = new String('this is a string object'); Array.prototype.getClass = Object.prototype.toString; (s.split()).getClass()") );79new TestCase( SECTION,80 "var s = new String('this is a string object'); s.split().length",81 1,82 eval("var s = new String('this is a string object'); s.split().length") );83new TestCase( SECTION,84 "var s = new String('this is a string object'); s.split()[0]",85 "this is a string object",86 eval("var s = new String('this is a string object'); s.split()[0]") );87// this is an object object88new TestCase( SECTION,89 "var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()",90 "object",91 eval("var obj = new Object(); obj.split = String.prototype.split; typeof obj.split()") );92new TestCase( SECTION,93 "var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",94 "[object Array]",95 eval("var obj = new Object(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );96new TestCase( SECTION,97 "var obj = new Object(); obj.split = String.prototype.split; obj.split().length",98 1,99 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split().length") );100new TestCase( SECTION,101 "var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]",102 "[object Object]",103 eval("var obj = new Object(); obj.split = String.prototype.split; obj.split()[0]") );104// this is a function object105new TestCase( SECTION,106 "var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()",107 "object",108 eval("var obj = new Function(); obj.split = String.prototype.split; typeof obj.split()") );109new TestCase( SECTION,110 "var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",111 "[object Array]",112 eval("var obj = new Function(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );113new TestCase( SECTION,114 "var obj = new Function(); obj.split = String.prototype.split; obj.split().length",115 1,116 eval("var obj = new Function(); obj.split = String.prototype.split; obj.split().length") );117new TestCase( SECTION,118 "var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]",119 "[object Function]",120 eval("var obj = new Function(); obj.split = String.prototype.split; obj.toString = Object.prototype.toString; obj.split()[0]") );121// this is a number object122new TestCase( SECTION,123 "var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()",124 "object",125 eval("var obj = new Number(NaN); obj.split = String.prototype.split; typeof obj.split()") );126new TestCase( SECTION,127 "var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",128 "[object Array]",129 eval("var obj = new Number(Infinity); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );130new TestCase( SECTION,131 "var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length",132 1,133 eval("var obj = new Number(-1234567890); obj.split = String.prototype.split; obj.split().length") );134new TestCase( SECTION,135 "var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]",136 "-1e+21",137 eval("var obj = new Number(-1e21); obj.split = String.prototype.split; obj.split()[0]") );138// this is the Math object139new TestCase( SECTION,140 "var obj = Math; obj.split = String.prototype.split; typeof obj.split()",141 "object",142 eval("var obj = Math; obj.split = String.prototype.split; typeof obj.split()") );143new TestCase( SECTION,144 "var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",145 "[object Array]",146 eval("var obj = Math; obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );147new TestCase( SECTION,148 "var obj = Math; obj.split = String.prototype.split; obj.split().length",149 1,150 eval("var obj = Math; obj.split = String.prototype.split; obj.split().length") );151new TestCase( SECTION,152 "var obj = Math; obj.split = String.prototype.split; obj.split()[0]",153 "[object Math]",154 eval("var obj = Math; obj.split = String.prototype.split; obj.split()[0]") );155// this is an array object156new TestCase( SECTION,157 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()",158 "object",159 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; typeof obj.split()") );160new TestCase( SECTION,161 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",162 "[object Array]",163 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );164new TestCase( SECTION,165 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length",166 1,167 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split().length") );168new TestCase( SECTION,169 "var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]",170 "1,2,3,4,5",171 eval("var obj = new Array(1,2,3,4,5); obj.split = String.prototype.split; obj.split()[0]") );172// this is a Boolean object173new TestCase( SECTION,174 "var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()",175 "object",176 eval("var obj = new Boolean(); obj.split = String.prototype.split; typeof obj.split()") );177new TestCase( SECTION,178 "var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.getClass()",179 "[object Array]",180 eval("var obj = new Boolean(); obj.split = String.prototype.split; Array.prototype.getClass = Object.prototype.toString; obj.split().getClass()") );181new TestCase( SECTION,182 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length",183 1,184 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split().length") );185new TestCase( SECTION,186 "var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]",187 "false",188 eval("var obj = new Boolean(); obj.split = String.prototype.split; obj.split()[0]") );...
split-002.js
Source:split-002.js
...23 *24 */25 var SECTION = "ecma_2/String/split-002.js";26 var VERSION = "ECMA_2";27 var TITLE = "String.prototype.split( regexp, [,limit] )";28 startTest();29 // the separator is not supplied30 // separator is undefined31 // separator is an empty string32// AddSplitCases( "splitme", "", "''", ["s", "p", "l", "i", "t", "m", "e"] );33// AddSplitCases( "splitme", new RegExp(), "new RegExp()", ["s", "p", "l", "i", "t", "m", "e"] );34 // separator is an empty regexp35 // separator is not supplied36 CompareSplit( "hello", "ll" );37 CompareSplit( "hello", "l" );38 CompareSplit( "hello", "x" );39 CompareSplit( "hello", "h" );40 CompareSplit( "hello", "o" );41 CompareSplit( "hello", "hello" );42 CompareSplit( "hello", undefined );43 CompareSplit( "hello", "");44 CompareSplit( "hello", "hellothere" );45 CompareSplit( new String("hello" ) );46 Number.prototype.split = String.prototype.split;47 CompareSplit( new Number(100111122133144155), 1 );48 CompareSplitWithLimit(new Number(100111122133144155), 1, 1 );49 CompareSplitWithLimit(new Number(100111122133144155), 1, 2 );50 CompareSplitWithLimit(new Number(100111122133144155), 1, 0 );51 CompareSplitWithLimit(new Number(100111122133144155), 1, 100 );52 CompareSplitWithLimit(new Number(100111122133144155), 1, void 0 );53 CompareSplitWithLimit(new Number(100111122133144155), 1, Math.pow(2,32)-1 );54 CompareSplitWithLimit(new Number(100111122133144155), 1, "boo" );55 CompareSplitWithLimit(new Number(100111122133144155), 1, -(Math.pow(2,32)-1) );56 CompareSplitWithLimit( "hello", "l", NaN );57 CompareSplitWithLimit( "hello", "l", 0 );58 CompareSplitWithLimit( "hello", "l", 1 );59 CompareSplitWithLimit( "hello", "l", 2 );60 CompareSplitWithLimit( "hello", "l", 3 );61 CompareSplitWithLimit( "hello", "l", 4 );62/*63 CompareSplitWithLimit( "hello", "ll", 0 );64 CompareSplitWithLimit( "hello", "ll", 1 );65 CompareSplitWithLimit( "hello", "ll", 2 );66 CompareSplit( "", " " );67 CompareSplit( "" );68*/69 // separartor is a regexp70 // separator regexp value global setting is set71 // string is an empty string72 // if separator is an empty string, split each by character73 // this is not a String object74 // limit is not a number75 // limit is undefined76 // limit is larger than 2^32-177 // limit is a negative number78 test();79function CompareSplit( string, separator ) {80 split_1 = string.split( separator );81 split_2 = string_split( string, separator );82 AddTestCase(83 "( " + string +".split(" + separator + ") ).length" ,84 split_2.length,85 split_1.length );86 var limit = split_1.length > split_2.length ?87 split_1.length : split_2.length;88 for ( var split_item = 0; split_item < limit; split_item++ ) {89 AddTestCase(90 string + ".split(" + separator + ")["+split_item+"]",91 split_2[split_item],92 split_1[split_item] );93 }94}95function CompareSplitWithLimit( string, separator, splitlimit ) {96 split_1 = string.split( separator, splitlimit );97 split_2 = string_split( string, separator, splitlimit );98 AddTestCase(99 "( " + string +".split(" + separator + ", " + splitlimit+") ).length" ,100 split_2.length,101 split_1.length );102 var limit = split_1.length > split_2.length ?103 split_1.length : split_2.length;104 for ( var split_item = 0; split_item < limit; split_item++ ) {105 AddTestCase(106 string + ".split(" + separator + ", " + splitlimit+")["+split_item+"]",107 split_2[split_item],108 split_1[split_item] );109 }110}111function string_split ( __this, separator, limit ) {112 var S = String(__this ); // 1113 var A = new Array(); // 2114 if ( limit == undefined ) { // 3115 lim = Math.pow(2, 31 ) -1;116 } else {117 lim = ToUint32( limit );118 }119 var s = S.length; // 4120 var p = 0; // 5...
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!!