Best JavaScript code snippet using pact-foundation-pact
AsYouTypeFormatter.PatternMatcher.test.js
Source:AsYouTypeFormatter.PatternMatcher.test.js
1import PatternMatcher from './AsYouTypeFormatter.PatternMatcher'2describe('AsYouTypeFormatter.PatternMatcher', function() {3 it('should match a one-digit pattern', function() {4 const matcher = new PatternMatcher('4')5 expect(matcher.match('1')).to.be.undefined6 matcher.match('4').should.deep.equal({7 match: true8 })9 expect(matcher.match('44')).to.be.undefined10 matcher.match('44', { allowOverflow: true }).should.deep.equal({11 overflow: true12 })13 })14 it('should match a two-digit pattern', function() {15 const matcher = new PatternMatcher('44')16 expect(matcher.match('1')).to.be.undefined17 matcher.match('4').should.deep.equal({18 partialMatch: true19 })20 matcher.match('44').should.deep.equal({21 match: true22 })23 expect(matcher.match('444')).to.be.undefined24 matcher.match('444', { allowOverflow: true }).should.deep.equal({25 overflow: true26 })27 expect(matcher.match('55')).to.be.undefined28 })29 it('should match a one-digit one-of set (single digit)', function() {30 const matcher = new PatternMatcher('[4]')31 expect(matcher.match('1')).to.be.undefined32 matcher.match('4').should.deep.equal({33 match: true34 })35 expect(matcher.match('44')).to.be.undefined36 matcher.match('44', { allowOverflow: true }).should.deep.equal({37 overflow: true38 })39 })40 it('should match a one-digit one-of set (multiple digits)', function() {41 const matcher = new PatternMatcher('[479]')42 expect(matcher.match('1')).to.be.undefined43 matcher.match('4').should.deep.equal({44 match: true45 })46 expect(matcher.match('44')).to.be.undefined47 matcher.match('44', { allowOverflow: true }).should.deep.equal({48 overflow: true49 })50 })51 it('should match a one-digit one-of set using a dash notation (not inclusive)', function() {52 const matcher = new PatternMatcher('[2-5]')53 expect(matcher.match('1')).to.be.undefined54 matcher.match('4').should.deep.equal({55 match: true56 })57 expect(matcher.match('44')).to.be.undefined58 matcher.match('44', { allowOverflow: true }).should.deep.equal({59 overflow: true60 })61 })62 it('should match a one-digit one-of set using a dash notation (inclusive)', function() {63 const matcher = new PatternMatcher('[3-4]')64 expect(matcher.match('1')).to.be.undefined65 matcher.match('4').should.deep.equal({66 match: true67 })68 expect(matcher.match('44')).to.be.undefined69 matcher.match('44', { allowOverflow: true }).should.deep.equal({70 overflow: true71 })72 })73 it('should match a one-digit one-of set including a dash notation', function() {74 const matcher = new PatternMatcher('[124-68]')75 expect(matcher.match('0')).to.be.undefined76 matcher.match('1').should.deep.equal({77 match: true78 })79 matcher.match('2').should.deep.equal({80 match: true81 })82 expect(matcher.match('3')).to.be.undefined83 matcher.match('4').should.deep.equal({84 match: true85 })86 matcher.match('5').should.deep.equal({87 match: true88 })89 matcher.match('6').should.deep.equal({90 match: true91 })92 expect(matcher.match('7')).to.be.undefined93 matcher.match('8').should.deep.equal({94 match: true95 })96 expect(matcher.match('9')).to.be.undefined97 expect(matcher.match('88')).to.be.undefined98 matcher.match('88', { allowOverflow: true }).should.deep.equal({99 overflow: true100 })101 })102 it('should match a two-digit one-of set', function() {103 const matcher = new PatternMatcher('[479][45]')104 expect(matcher.match('1')).to.be.undefined105 matcher.match('4').should.deep.equal({106 partialMatch: true107 })108 expect(matcher.match('5')).to.be.undefined109 expect(matcher.match('55')).to.be.undefined110 matcher.match('44').should.deep.equal({111 match: true112 })113 expect(matcher.match('444')).to.be.undefined114 matcher.match('444', { allowOverflow: true }).should.deep.equal({115 overflow: true116 })117 })118 it('should match a two-digit one-of set (regular digit and a one-of set)', function() {119 const matcher = new PatternMatcher('1[45]')120 expect(matcher.match('0')).to.be.undefined121 matcher.match('1').should.deep.equal({122 partialMatch: true123 })124 matcher.match('15').should.deep.equal({125 match: true126 })127 expect(matcher.match('16')).to.be.undefined128 })129 it('should match a pattern with an or group', function() {130 const matcher = new PatternMatcher('7(?:1[0-68]|2[1-9])')131 expect(matcher.match('1')).to.be.undefined132 matcher.match('7').should.deep.equal({133 partialMatch: true134 })135 matcher.match('71').should.deep.equal({136 partialMatch: true137 })138 expect(matcher.match('73')).to.be.undefined139 matcher.match('711').should.deep.equal({140 match: true141 })142 expect(matcher.match('717')).to.be.undefined143 expect(matcher.match('720')).to.be.undefined144 matcher.match('722').should.deep.equal({145 match: true146 })147 expect(matcher.match('7222')).to.be.undefined148 matcher.match('7222', { allowOverflow: true }).should.deep.equal({149 overflow: true150 })151 })152 it('should match an or pattern containing or groups', function() {153 const matcher = new PatternMatcher('2(?:2[024-9]|3[0-59]|47|6[245]|9[02-8])|3(?:3[28]|4[03-9]|5[2-46-8]|7[1-578]|8[2-9])')154 expect(matcher.match('1')).to.be.undefined155 matcher.match('2').should.deep.equal({156 partialMatch: true157 })158 matcher.match('3').should.deep.equal({159 partialMatch: true160 })161 expect(matcher.match('4')).to.be.undefined162 expect(matcher.match('21')).to.be.undefined163 matcher.match('22').should.deep.equal({164 partialMatch: true165 })166 expect(matcher.match('221')).to.be.undefined167 matcher.match('222').should.deep.equal({168 match: true169 })170 expect(matcher.match('2222')).to.be.undefined171 matcher.match('2222', { allowOverflow: true }).should.deep.equal({172 overflow: true173 })174 matcher.match('3').should.deep.equal({175 partialMatch: true176 })177 matcher.match('33').should.deep.equal({178 partialMatch: true179 })180 matcher.match('332').should.deep.equal({181 match: true182 })183 expect(matcher.match('333')).to.be.undefined184 })185 it('should match an or pattern', function() {186 const matcher = new PatternMatcher('6|8')187 expect(matcher.match('5')).to.be.undefined188 matcher.match('6').should.deep.equal({189 match: true190 })191 expect(matcher.match('7')).to.be.undefined192 matcher.match('8').should.deep.equal({193 match: true194 })195 })196 it('should match an or pattern (one-of sets)', function() {197 const matcher = new PatternMatcher('[123]|[5-8]')198 expect(matcher.match('0')).to.be.undefined199 matcher.match('1').should.deep.equal({200 match: true201 })202 matcher.match('2').should.deep.equal({203 match: true204 })205 matcher.match('3').should.deep.equal({206 match: true207 })208 expect(matcher.match('4')).to.be.undefined209 matcher.match('5').should.deep.equal({210 match: true211 })212 matcher.match('6').should.deep.equal({213 match: true214 })215 matcher.match('7').should.deep.equal({216 match: true217 })218 matcher.match('8').should.deep.equal({219 match: true220 })221 expect(matcher.match('9')).to.be.undefined222 expect(matcher.match('18')).to.be.undefined223 matcher.match('18', { allowOverflow: true }).should.deep.equal({224 overflow: true225 })226 })227 it('should match an or pattern (different lengths)', function() {228 const matcher = new PatternMatcher('60|8')229 expect(matcher.match('5')).to.be.undefined230 matcher.match('6').should.deep.equal({231 partialMatch: true232 })233 matcher.match('60').should.deep.equal({234 match: true235 })236 expect(matcher.match('61')).to.be.undefined237 expect(matcher.match('7')).to.be.undefined238 matcher.match('8').should.deep.equal({239 match: true240 })241 expect(matcher.match('68')).to.be.undefined242 })243 it('should match an or pattern (one-of sets) (different lengths)', function() {244 const matcher = new PatternMatcher('[123]|[5-8][2-8]')245 expect(matcher.match('0')).to.be.undefined246 })247 it('should match an or pattern (one-of sets and regular digits) (different lengths)', function() {248 const matcher = new PatternMatcher('[2358][2-5]|4')249 expect(matcher.match('0')).to.be.undefined250 matcher.match('2').should.deep.equal({251 partialMatch: true252 })253 expect(matcher.match('21')).to.be.undefined254 matcher.match('22').should.deep.equal({255 match: true256 })257 matcher.match('25').should.deep.equal({258 match: true259 })260 expect(matcher.match('26')).to.be.undefined261 expect(matcher.match('222')).to.be.undefined262 matcher.match('222', { allowOverflow: true }).should.deep.equal({263 overflow: true264 })265 matcher.match('3').should.deep.equal({266 partialMatch: true267 })268 matcher.match('4').should.deep.equal({269 match: true270 })271 expect(matcher.match('6')).to.be.undefined272 })273 it('should match an or pattern (one-of sets and regular digits mixed) (different lengths)', function() {274 const matcher = new PatternMatcher('[2358]2|4')275 expect(matcher.match('0')).to.be.undefined276 matcher.match('2').should.deep.equal({277 partialMatch: true278 })279 expect(matcher.match('21')).to.be.undefined280 matcher.match('22').should.deep.equal({281 match: true282 })283 expect(matcher.match('222')).to.be.undefined284 matcher.match('222', { allowOverflow: true }).should.deep.equal({285 overflow: true286 })287 matcher.match('3').should.deep.equal({288 partialMatch: true289 })290 matcher.match('4').should.deep.equal({291 match: true292 })293 expect(matcher.match('6')).to.be.undefined294 })295 it('should match an or pattern (one-of sets groups and regular digits mixed) (different lengths)', function() {296 const matcher = new PatternMatcher('1(?:11|[2-9])')297 matcher.match('1').should.deep.equal({298 partialMatch: true299 })300 expect(matcher.match('10')).to.be.undefined301 matcher.match('11').should.deep.equal({302 partialMatch: true303 })304 matcher.match('111').should.deep.equal({305 match: true306 })307 expect(matcher.match('1111')).to.be.undefined308 matcher.match('1111', { allowOverflow: true }).should.deep.equal({309 overflow: true310 })311 matcher.match('12').should.deep.equal({312 match: true313 })314 expect(matcher.match('122')).to.be.undefined315 matcher.match('19').should.deep.equal({316 match: true317 })318 expect(matcher.match('5')).to.be.undefined319 })320 it('should match nested or groups', function() {321 const matcher = new PatternMatcher('1(?:2(?:3(?:4|5)|6)|7(?:8|9))0')322 matcher.match('1').should.deep.equal({323 partialMatch: true324 })325 expect(matcher.match('2')).to.be.undefined326 expect(matcher.match('11')).to.be.undefined327 matcher.match('12').should.deep.equal({328 partialMatch: true329 })330 expect(matcher.match('121')).to.be.undefined331 matcher.match('123').should.deep.equal({332 partialMatch: true333 })334 expect(matcher.match('1231')).to.be.undefined335 matcher.match('1234').should.deep.equal({336 partialMatch: true337 })338 matcher.match('12340').should.deep.equal({339 match: true340 })341 expect(matcher.match('123401')).to.be.undefined342 matcher.match('123401', { allowOverflow: true }).should.deep.equal({343 overflow: true344 })345 matcher.match('12350').should.deep.equal({346 match: true347 })348 expect(matcher.match('12360')).to.be.undefined349 matcher.match('1260').should.deep.equal({350 match: true351 })352 expect(matcher.match('1270')).to.be.undefined353 expect(matcher.match('1770')).to.be.undefined354 matcher.match('1780').should.deep.equal({355 match: true356 })357 matcher.match('1790').should.deep.equal({358 match: true359 })360 expect(matcher.match('18')).to.be.undefined361 })362 it('should match complex patterns', function() {363 const matcher = new PatternMatcher('(?:31|4)6|51|6(?:5[0-3579]|[6-9])|7(?:20|32|8)|[89]')364 expect(matcher.match('0')).to.be.undefined365 matcher.match('3').should.deep.equal({366 partialMatch: true367 })368 matcher.match('31').should.deep.equal({369 partialMatch: true370 })371 expect(matcher.match('32')).to.be.undefined372 matcher.match('316').should.deep.equal({373 match: true374 })375 expect(matcher.match('315')).to.be.undefined376 matcher.match('4').should.deep.equal({377 partialMatch: true378 })379 matcher.match('46').should.deep.equal({380 match: true381 })382 expect(matcher.match('47')).to.be.undefined383 matcher.match('5').should.deep.equal({384 partialMatch: true385 })386 expect(matcher.match('50')).to.be.undefined387 matcher.match('51').should.deep.equal({388 match: true389 })390 matcher.match('6').should.deep.equal({391 partialMatch: true392 })393 expect(matcher.match('64')).to.be.undefined394 matcher.match('65').should.deep.equal({395 partialMatch: true396 })397 matcher.match('650').should.deep.equal({398 match: true399 })400 expect(matcher.match('654')).to.be.undefined401 matcher.match('69').should.deep.equal({402 match: true403 })404 matcher.match('8').should.deep.equal({405 match: true406 })407 matcher.match('9').should.deep.equal({408 match: true409 })410 })...
objectmatcher.js
Source:objectmatcher.js
1// Copyright 2012 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/**15 * @fileoverview Provides the built-in object matchers like equalsObject,16 * hasProperty, instanceOf, etc.17 */18goog.provide('goog.labs.testing.HasPropertyMatcher');19goog.provide('goog.labs.testing.InstanceOfMatcher');20goog.provide('goog.labs.testing.IsNullMatcher');21goog.provide('goog.labs.testing.IsNullOrUndefinedMatcher');22goog.provide('goog.labs.testing.IsUndefinedMatcher');23goog.provide('goog.labs.testing.ObjectEqualsMatcher');24goog.require('goog.labs.testing.Matcher');25goog.require('goog.string');26/**27 * The Equals matcher.28 *29 * @param {!Object} expectedObject The expected object.30 *31 * @constructor32 * @struct33 * @implements {goog.labs.testing.Matcher}34 * @final35 */36goog.labs.testing.ObjectEqualsMatcher = function(expectedObject) {37 /**38 * @type {!Object}39 * @private40 */41 this.object_ = expectedObject;42};43/**44 * Determines if two objects are the same.45 *46 * @override47 */48goog.labs.testing.ObjectEqualsMatcher.prototype.matches =49 function(actualObject) {50 return actualObject === this.object_;51};52/**53 * @override54 */55goog.labs.testing.ObjectEqualsMatcher.prototype.describe =56 function(actualObject) {57 return 'Input object is not the same as the expected object.';58};59/**60 * The HasProperty matcher.61 *62 * @param {string} property Name of the property to test.63 *64 * @constructor65 * @struct66 * @implements {goog.labs.testing.Matcher}67 * @final68 */69goog.labs.testing.HasPropertyMatcher = function(property) {70 /**71 * @type {string}72 * @private73 */74 this.property_ = property;75};76/**77 * Determines if an object has a property.78 *79 * @override80 */81goog.labs.testing.HasPropertyMatcher.prototype.matches =82 function(actualObject) {83 return this.property_ in actualObject;84};85/**86 * @override87 */88goog.labs.testing.HasPropertyMatcher.prototype.describe =89 function(actualObject) {90 return 'Object does not have property: ' + this.property_;91};92/**93 * The InstanceOf matcher.94 *95 * @param {!Object} object The expected class object.96 *97 * @constructor98 * @struct99 * @implements {goog.labs.testing.Matcher}100 * @final101 */102goog.labs.testing.InstanceOfMatcher = function(object) {103 /**104 * @type {!Object}105 * @private106 */107 this.object_ = object;108};109/**110 * Determines if an object is an instance of another object.111 *112 * @override113 */114goog.labs.testing.InstanceOfMatcher.prototype.matches =115 function(actualObject) {116 return actualObject instanceof this.object_;117};118/**119 * @override120 */121goog.labs.testing.InstanceOfMatcher.prototype.describe =122 function(actualObject) {123 return 'Input object is not an instance of the expected object';124};125/**126 * The IsNullOrUndefined matcher.127 *128 * @constructor129 * @struct130 * @implements {goog.labs.testing.Matcher}131 * @final132 */133goog.labs.testing.IsNullOrUndefinedMatcher = function() {};134/**135 * Determines if input value is null or undefined.136 *137 * @override138 */139goog.labs.testing.IsNullOrUndefinedMatcher.prototype.matches =140 function(actualValue) {141 return !goog.isDefAndNotNull(actualValue);142};143/**144 * @override145 */146goog.labs.testing.IsNullOrUndefinedMatcher.prototype.describe =147 function(actualValue) {148 return actualValue + ' is not null or undefined.';149};150/**151 * The IsNull matcher.152 *153 * @constructor154 * @struct155 * @implements {goog.labs.testing.Matcher}156 * @final157 */158goog.labs.testing.IsNullMatcher = function() {};159/**160 * Determines if input value is null.161 *162 * @override163 */164goog.labs.testing.IsNullMatcher.prototype.matches =165 function(actualValue) {166 return goog.isNull(actualValue);167};168/**169 * @override170 */171goog.labs.testing.IsNullMatcher.prototype.describe =172 function(actualValue) {173 return actualValue + ' is not null.';174};175/**176 * The IsUndefined matcher.177 *178 * @constructor179 * @struct180 * @implements {goog.labs.testing.Matcher}181 * @final182 */183goog.labs.testing.IsUndefinedMatcher = function() {};184/**185 * Determines if input value is undefined.186 *187 * @override188 */189goog.labs.testing.IsUndefinedMatcher.prototype.matches =190 function(actualValue) {191 return !goog.isDef(actualValue);192};193/**194 * @override195 */196goog.labs.testing.IsUndefinedMatcher.prototype.describe =197 function(actualValue) {198 return actualValue + ' is not undefined.';199};200/**201 * Returns a matcher that matches objects that are equal to the input object.202 * Equality in this case means the two objects are references to the same203 * object.204 *205 * @param {!Object} object The expected object.206 *207 * @return {!goog.labs.testing.ObjectEqualsMatcher} A208 * ObjectEqualsMatcher.209 */210function equalsObject(object) {211 return new goog.labs.testing.ObjectEqualsMatcher(object);212}213/**214 * Returns a matcher that matches objects that contain the input property.215 *216 * @param {string} property The property name to check.217 *218 * @return {!goog.labs.testing.HasPropertyMatcher} A HasPropertyMatcher.219 */220function hasProperty(property) {221 return new goog.labs.testing.HasPropertyMatcher(property);222}223/**224 * Returns a matcher that matches instances of the input class.225 *226 * @param {!Object} object The class object.227 *228 * @return {!goog.labs.testing.InstanceOfMatcher} A229 * InstanceOfMatcher.230 */231function instanceOfClass(object) {232 return new goog.labs.testing.InstanceOfMatcher(object);233}234/**235 * Returns a matcher that matches all null values.236 *237 * @return {!goog.labs.testing.IsNullMatcher} A IsNullMatcher.238 */239function isNull() {240 return new goog.labs.testing.IsNullMatcher();241}242/**243 * Returns a matcher that matches all null and undefined values.244 *245 * @return {!goog.labs.testing.IsNullOrUndefinedMatcher} A246 * IsNullOrUndefinedMatcher.247 */248function isNullOrUndefined() {249 return new goog.labs.testing.IsNullOrUndefinedMatcher();250}251/**252 * Returns a matcher that matches undefined values.253 *254 * @return {!goog.labs.testing.IsUndefinedMatcher} A IsUndefinedMatcher.255 */256function isUndefined() {257 return new goog.labs.testing.IsUndefinedMatcher();...
logicmatcher.js
Source:logicmatcher.js
1// Copyright 2012 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/**15 * @fileoverview Provides the built-in logic matchers: anyOf, allOf, and isNot.16 *17 */18goog.provide('goog.labs.testing.AllOfMatcher');19goog.provide('goog.labs.testing.AnyOfMatcher');20goog.provide('goog.labs.testing.IsNotMatcher');21goog.require('goog.array');22goog.require('goog.labs.testing.Matcher');23/**24 * The AllOf matcher.25 *26 * @param {!Array.<!goog.labs.testing.Matcher>} matchers Input matchers.27 *28 * @constructor29 * @struct30 * @implements {goog.labs.testing.Matcher}31 * @final32 */33goog.labs.testing.AllOfMatcher = function(matchers) {34 /**35 * @type {!Array.<!goog.labs.testing.Matcher>}36 * @private37 */38 this.matchers_ = matchers;39};40/**41 * Determines if all of the matchers match the input value.42 *43 * @override44 */45goog.labs.testing.AllOfMatcher.prototype.matches = function(actualValue) {46 return goog.array.every(this.matchers_, function(matcher) {47 return matcher.matches(actualValue);48 });49};50/**51 * Describes why the matcher failed. The returned string is a concatenation of52 * all the failed matchers' error strings.53 *54 * @override55 */56goog.labs.testing.AllOfMatcher.prototype.describe =57 function(actualValue) {58 // TODO(user) : Optimize this to remove duplication with matches ?59 var errorString = '';60 goog.array.forEach(this.matchers_, function(matcher) {61 if (!matcher.matches(actualValue)) {62 errorString += matcher.describe(actualValue) + '\n';63 }64 });65 return errorString;66};67/**68 * The AnyOf matcher.69 *70 * @param {!Array.<!goog.labs.testing.Matcher>} matchers Input matchers.71 *72 * @constructor73 * @struct74 * @implements {goog.labs.testing.Matcher}75 * @final76 */77goog.labs.testing.AnyOfMatcher = function(matchers) {78 /**79 * @type {!Array.<!goog.labs.testing.Matcher>}80 * @private81 */82 this.matchers_ = matchers;83};84/**85 * Determines if any of the matchers matches the input value.86 *87 * @override88 */89goog.labs.testing.AnyOfMatcher.prototype.matches = function(actualValue) {90 return goog.array.some(this.matchers_, function(matcher) {91 return matcher.matches(actualValue);92 });93};94/**95 * Describes why the matcher failed.96 *97 * @override98 */99goog.labs.testing.AnyOfMatcher.prototype.describe =100 function(actualValue) {101 // TODO(user) : Optimize this to remove duplication with matches ?102 var errorString = '';103 goog.array.forEach(this.matchers_, function(matcher) {104 if (!matcher.matches(actualValue)) {105 errorString += matcher.describe(actualValue) + '\n';106 }107 });108 return errorString;109};110/**111 * The IsNot matcher.112 *113 * @param {!goog.labs.testing.Matcher} matcher The matcher to negate.114 *115 * @constructor116 * @struct117 * @implements {goog.labs.testing.Matcher}118 * @final119 */120goog.labs.testing.IsNotMatcher = function(matcher) {121 /**122 * @type {!goog.labs.testing.Matcher}123 * @private124 */125 this.matcher_ = matcher;126};127/**128 * Determines if the input value doesn't satisfy a matcher.129 *130 * @override131 */132goog.labs.testing.IsNotMatcher.prototype.matches = function(actualValue) {133 return !this.matcher_.matches(actualValue);134};135/**136 * Describes why the matcher failed.137 *138 * @override139 */140goog.labs.testing.IsNotMatcher.prototype.describe =141 function(actualValue) {142 return 'The following is false: ' + this.matcher_.describe(actualValue);143};144/**145 * Creates a matcher that will succeed only if all of the given matchers146 * succeed.147 *148 * @param {...goog.labs.testing.Matcher} var_args The matchers to test149 * against.150 *151 * @return {!goog.labs.testing.AllOfMatcher} The AllOf matcher.152 */153function allOf(var_args) {154 var matchers = goog.array.toArray(arguments);155 return new goog.labs.testing.AllOfMatcher(matchers);156}157/**158 * Accepts a set of matchers and returns a matcher which matches159 * values which satisfy the constraints of any of the given matchers.160 *161 * @param {...goog.labs.testing.Matcher} var_args The matchers to test162 * against.163 *164 * @return {!goog.labs.testing.AnyOfMatcher} The AnyOf matcher.165 */166function anyOf(var_args) {167 var matchers = goog.array.toArray(arguments);168 return new goog.labs.testing.AnyOfMatcher(matchers);169}170/**171 * Returns a matcher that negates the input matcher. The returned172 * matcher matches the values not matched by the input matcher and vice-versa.173 *174 * @param {!goog.labs.testing.Matcher} matcher The matcher to test against.175 *176 * @return {!goog.labs.testing.IsNotMatcher} The IsNot matcher.177 */178function isNot(matcher) {179 return new goog.labs.testing.IsNotMatcher(matcher);...
matcher_builder_test.py
Source:matcher_builder_test.py
...63 self.assertAlmostEqual(matcher_object._matched_threshold, 0.7)64 self.assertAlmostEqual(matcher_object._unmatched_threshold, 0.3)65 self.assertFalse(matcher_object._negatives_lower_than_unmatched)66 self.assertTrue(matcher_object._force_match_for_each_row)67 def test_build_bipartite_matcher(self):68 matcher_text_proto = """69 bipartite_matcher {70 }71 """72 matcher_proto = matcher_pb2.Matcher()73 text_format.Merge(matcher_text_proto, matcher_proto)74 matcher_object = matcher_builder.build(matcher_proto)75 self.assertTrue(76 isinstance(matcher_object, bipartite_matcher.GreedyBipartiteMatcher))77 def test_raise_error_on_empty_matcher(self):78 matcher_text_proto = """79 """80 matcher_proto = matcher_pb2.Matcher()81 text_format.Merge(matcher_text_proto, matcher_proto)82 with self.assertRaises(ValueError):83 matcher_builder.build(matcher_proto)84if __name__ == '__main__':...
matcher.ts
Source:matcher.ts
...64 while (matcher) {65 matchers.push(matcher);66 matcher = parseOperand();67 }68 return matcherInput => matchers.every(matcher => matcher(matcherInput)); // and69 }70 function parseInnerExpression(): Matcher<T> {71 var matchers: Matcher<T>[] = [];72 var matcher = parseConjunction();73 while (matcher) {74 matchers.push(matcher);75 if (token === '|' || token === ',') {76 do {77 token = tokenizer.next();78 } while (token === '|' || token === ','); // ignore subsequent commas79 } else {80 break;81 }82 matcher = parseConjunction();83 }84 return matcherInput => matchers.some(matcher => matcher(matcherInput)); // or85 }86}87function isIdentifier(token: string) {88 return token && token.match(/[\w\.:]+/);89}90function newTokenizer(input: string): { next: () => string } {91 let regex = /([LR]:|[\w\.:][\w\.:\-]*|[\,\|\-\(\)])/g;92 var match = regex.exec(input);93 return {94 next: () => {95 if (!match) {96 return null;97 }98 var res = match[0];...
decoratormatcher.js
Source:decoratormatcher.js
1// Copyright 2012 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/**15 * @fileoverview Provides the built-in decorators: is, describedAs, anything.16 */17goog.provide('goog.labs.testing.AnythingMatcher');18goog.require('goog.labs.testing.Matcher');19/**20 * The Anything matcher. Matches all possible inputs.21 *22 * @constructor23 * @implements {goog.labs.testing.Matcher}24 * @final25 */26goog.labs.testing.AnythingMatcher = function() {};27/**28 * Matches anything. Useful if one doesn't care what the object under test is.29 *30 * @override31 */32goog.labs.testing.AnythingMatcher.prototype.matches =33 function(actualObject) {34 return true;35};36/**37 * This method is never called but is needed so AnythingMatcher implements the38 * Matcher interface.39 *40 * @override41 */42goog.labs.testing.AnythingMatcher.prototype.describe =43 function(actualObject) {44 throw Error('AnythingMatcher should never fail!');45};46/**47 * Returns a matcher that matches anything.48 *49 * @return {!goog.labs.testing.AnythingMatcher} A AnythingMatcher.50 */51function anything() {52 return new goog.labs.testing.AnythingMatcher();53}54/**55 * Returnes any matcher that is passed to it (aids readability).56 *57 * @param {!goog.labs.testing.Matcher} matcher A matcher.58 * @return {!goog.labs.testing.Matcher} The wrapped matcher.59 */60function is(matcher) {61 return matcher;62}63/**64 * Returns a matcher with a customized description for the given matcher.65 *66 * @param {string} description The custom description for the matcher.67 * @param {!goog.labs.testing.Matcher} matcher The matcher.68 *69 * @return {!goog.labs.testing.Matcher} The matcher with custom description.70 */71function describedAs(description, matcher) {72 matcher.describe = function(value) {73 return description;74 };75 return matcher;...
url_matcher.gypi
Source:url_matcher.gypi
1# Copyright 2013 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4{5 'targets': [6 {7 'target_name': 'url_matcher',8 'type': '<(component)',9 'dependencies': [10 '../third_party/re2/re2.gyp:re2',11 '../base/base.gyp:base',12 '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',13 '../url/url.gyp:url_lib',14 ],15 'include_dirs': [16 '..',17 ],18 'defines': [19 'URL_MATCHER_IMPLEMENTATION',20 ],21 'sources': [22 'url_matcher/regex_set_matcher.cc',23 'url_matcher/regex_set_matcher.h',24 'url_matcher/string_pattern.cc',25 'url_matcher/string_pattern.h',26 'url_matcher/substring_set_matcher.cc',27 'url_matcher/substring_set_matcher.h',28 'url_matcher/url_matcher.cc',29 'url_matcher/url_matcher.h',30 'url_matcher/url_matcher_constants.cc',31 'url_matcher/url_matcher_constants.h',32 'url_matcher/url_matcher_export.h',33 'url_matcher/url_matcher_factory.cc',34 'url_matcher/url_matcher_factory.h',35 'url_matcher/url_matcher_helpers.cc',36 'url_matcher/url_matcher_helpers.h',37 ],38 # Disable c4267 warnings until we fix size_t to int truncations.39 'msvs_disabled_warnings': [ 4267, ],40 },41 ],...
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!!