How to use TOKEN_NUMBER method in ng-mocks

Best JavaScript code snippet using ng-mocks

patternMatcher.js

Source:patternMatcher.js Github

copy

Full Screen

1import test from 'ava';2import { forEach } from 'lodash/fp';3import {4 Pattern, CaptureWildcard, CaptureElement, CaptureOptions,5} from '../src/modules/patternMatcher';6/* eslint-disable no-unused-vars */7import {8 TOKEN_NUMBER, TOKEN_UNIT_NAME, TOKEN_UNIT_PREFIX, TOKEN_UNIT_SUFFIX, TOKEN_BRACKET_OPEN,9 TOKEN_BRACKET_CLOSE, TOKEN_COLOR, TOKEN_NOOP, TOKEN_VECTOR_START, TOKEN_VECTOR_SEPARATOR,10 TOKEN_VECTOR_END,11} from '../src/tokenTypes';12/* eslint-enable */13/*14Testing notes:15We use macros for every test here. The most basic is shouldMatch and shouldNotMatch. Each take a16test object in the form { input, expected }, and does a test. You can use as many test objects as17you like in a single test. I.e.18```js19test('', matcher, shouldMatch, { input: ..., expected: ... }, { input: ..., expected: ... }, ...);20```21If you expect your output is a single capture group, where that capture group that should equal the22input, you can instead use an array to represent both the input and output. I.e.23```js24test('title', matcher, shouldMatch, [{ type: TOKEN_COLOR }]);25```26Lastly, we have a few more helpers. capture{Should,ShouldNot}Match takes a matcher, and evaluates27the test both when the matcher is and is not lazy.28captureDerivatives{Should,ShouldNot}Match takes a function that will be used to create both lazy29and non-lazy versions of both CaptureElement and CaptureOptions. I.e.30```js31test('title', captureDerivativesShouldNotMatch, makeCapture => makeCapture(TOKEN_NUMBER), ...);32```33*/34const baseMatcherAssertion = (shouldMatch, transform) => (t, patternMatcher, ...inputs) => {35 const callAssertionsWithPatternMatcher = patternMatcher => {36 forEach(inputValue => {37 const { input, expected } = 'input' in inputValue38 ? inputValue39 : { input: inputValue, expected: [inputValue] };40 const captureGroups = patternMatcher.match(input);41 if (shouldMatch) {42 t.deepEqual(captureGroups, expected);43 } else {44 t.is(captureGroups, null);45 }46 }, inputs);47 };48 const patternMatchers = transform(patternMatcher);49 t.plan(inputs.length * patternMatchers.length);50 forEach(callAssertionsWithPatternMatcher, patternMatchers);51};52const withLazy = patternMatcher => [53 patternMatcher,54 patternMatcher.lazy(),55];56const captureShouldMatch = baseMatcherAssertion(true, withLazy);57const captureShouldNotMatch = baseMatcherAssertion(false, withLazy);58const captureFactory = captureFactoryHandler => [59 captureFactoryHandler(pattern => new CaptureElement(pattern)),60 captureFactoryHandler(pattern => new CaptureElement(pattern)).lazy(),61 captureFactoryHandler(pattern => new CaptureOptions([pattern])),62 captureFactoryHandler(pattern => new CaptureOptions([pattern])).lazy(),63];64const captureDerivativesShouldMatch = baseMatcherAssertion(true, captureFactory);65const captureDerivativesShouldNotMatch = baseMatcherAssertion(false, captureFactory);66const createArray = patternMatcher => [patternMatcher];67const shouldMatch = baseMatcherAssertion(true, createArray);68const shouldNotMatch = baseMatcherAssertion(false, createArray);69test(70 "CaptureElement matches a single item if it's type is the same as the capture's",71 captureDerivativesShouldMatch,72 makeCapture => makeCapture(TOKEN_COLOR),73 [{ type: TOKEN_COLOR }],74);75test(76 "CaptureElement does not match a single item if it's type is the different the capture's",77 captureDerivativesShouldNotMatch,78 makeCapture => makeCapture(TOKEN_COLOR),79 [{ type: TOKEN_NUMBER }],80);81test(82 "CaptureElement matches all items of the if they are all the same type as the capture's",83 captureDerivativesShouldMatch,84 makeCapture => makeCapture(TOKEN_COLOR).any(),85 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],86);87test(88 "CaptureElement matches no items of the if any are a different type to the capture's",89 captureDerivativesShouldNotMatch,90 makeCapture => makeCapture(TOKEN_COLOR).any(),91 [{ type: TOKEN_NUMBER }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],92 [{ type: TOKEN_COLOR }, { type: TOKEN_NUMBER }, { type: TOKEN_COLOR }],93 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_NUMBER }],94);95test(96 "Negating an capture matches a single item if it's type is different to the capture's",97 captureDerivativesShouldMatch,98 makeCapture => makeCapture(TOKEN_NUMBER).negate(),99 [{ type: TOKEN_COLOR }],100);101test(102 "Negating an capture does not match a single item if it's type is the same as the capture's",103 captureDerivativesShouldNotMatch,104 makeCapture => makeCapture(TOKEN_NUMBER).negate(),105 [{ type: TOKEN_NUMBER }],106);107test(108 "Negating an capture matches all items if they all have a different type to the capture's",109 captureDerivativesShouldMatch,110 makeCapture => makeCapture(TOKEN_NUMBER).negate(),111 [{ type: TOKEN_COLOR }],112);113test(114 "Negating an capture matches no items if any are the same type as the capture's",115 captureDerivativesShouldNotMatch,116 makeCapture => makeCapture(TOKEN_NUMBER).negate().any(),117 [{ type: TOKEN_NUMBER }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],118 [{ type: TOKEN_COLOR }, { type: TOKEN_NUMBER }, { type: TOKEN_COLOR }],119 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_NUMBER }],120);121test(122 "Setting `from` on an capture will match items if the items' length is longer than `from`",123 captureDerivativesShouldMatch,124 makeCapture => makeCapture(TOKEN_COLOR).from(3).to(Infinity),125 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],126 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],127);128test(129 "Setting `from` on an capture will not match items if the items' length is shorter than `from`",130 captureDerivativesShouldNotMatch,131 makeCapture => makeCapture(TOKEN_COLOR).from(3).to(Infinity),132 [{ type: TOKEN_COLOR }],133 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }],134);135test(136 "Setting `to` on an capture will match items if the items' length is longer than `to`",137 captureDerivativesShouldMatch,138 makeCapture => makeCapture(TOKEN_COLOR).to(2),139 [{ type: TOKEN_COLOR }],140 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }],141);142test(143 "Setting `to` on an capture will not match items if the items' length is shorter than `to`",144 captureDerivativesShouldNotMatch,145 makeCapture => makeCapture(TOKEN_COLOR).to(2),146 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],147 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],148);149test(150 "CaptureElement options matches a single item if it's type is included in the capture's",151 captureShouldMatch,152 new CaptureOptions([TOKEN_COLOR, TOKEN_NUMBER]),153 [{ type: TOKEN_COLOR }],154 [{ type: TOKEN_NUMBER }],155);156test(157 "CaptureElement options does not match a single item if it's type is not in the capture's",158 captureShouldNotMatch,159 new CaptureOptions([TOKEN_COLOR, TOKEN_NUMBER]),160 [{ type: TOKEN_BRACKET_CLOSE }],161);162test(163 'CaptureWildcard should match a single capture',164 shouldMatch,165 new CaptureWildcard(),166 [{ type: TOKEN_COLOR }]167);168test(169 'CaptureWildcard should match no more than a single capture',170 shouldNotMatch,171 new CaptureWildcard(),172 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }],173 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],174 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],175);176test(177 'CaptureWildcard should with `any` match all captures',178 shouldMatch,179 new CaptureWildcard().any(),180 [{ type: TOKEN_COLOR }],181 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }],182 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],183 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],184);185test(186 'CaptureWildcard should with `any` match all captures when lazy',187 shouldMatch,188 new CaptureWildcard().any().lazy(),189 [{ type: TOKEN_COLOR }],190 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }],191 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],192 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],193);194test(195 'Pattern should match a single non-lazy entry if the entry matches the items',196 shouldMatch,197 new Pattern([new CaptureElement(TOKEN_COLOR).oneOrMore()]),198 [{ type: TOKEN_COLOR }],199 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }],200 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],201 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],202);203test(204 'Pattern should not match a single non-lazy entry if the entry does not match the items',205 shouldNotMatch,206 new Pattern([new CaptureElement(TOKEN_NUMBER).oneOrMore()]),207 [{ type: TOKEN_COLOR }],208 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }],209 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],210 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],211);212test(213 'Pattern should match a single lazy entry if the entry matches the items',214 shouldMatch,215 new Pattern([new CaptureElement(TOKEN_COLOR).lazy().oneOrMore()]),216 [{ type: TOKEN_COLOR }],217 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }],218 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],219 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],220);221test(222 'Pattern should not match a single lazy entry if the entry does not match the items',223 shouldNotMatch,224 new Pattern([new CaptureElement(TOKEN_NUMBER).lazy().oneOrMore()]),225 [{ type: TOKEN_COLOR }],226 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }],227 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],228 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }, { type: TOKEN_COLOR }],229);230test(231 'Pattern should match a two entries if every entry matches the items',232 shouldMatch,233 new Pattern([new CaptureElement(TOKEN_COLOR), new CaptureElement(TOKEN_COLOR)]),234 {235 input: [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }],236 expected: [[{ type: TOKEN_COLOR }], [{ type: TOKEN_COLOR }]],237 },238);239test(240 'Pattern should not match a two entries if any entry does not match the items',241 shouldNotMatch,242 new Pattern([new CaptureElement(TOKEN_NUMBER), new CaptureElement(TOKEN_NUMBER)]),243 [{ type: TOKEN_COLOR }, { type: TOKEN_COLOR }],244 [{ type: TOKEN_NUMBER }, { type: TOKEN_COLOR }],245 [{ type: TOKEN_COLOR }, { type: TOKEN_NUMBER }],246);247test(248 'Pattern should match with wildcards',249 shouldMatch,250 new Pattern([251 new CaptureElement(TOKEN_COLOR),252 new CaptureWildcard().any(),253 new CaptureElement(TOKEN_COLOR),254 ]),255 {256 input: [257 { type: TOKEN_COLOR },258 { type: TOKEN_UNIT_NAME },259 { type: TOKEN_NUMBER },260 { type: TOKEN_COLOR },261 ],262 expected: [263 [{ type: TOKEN_COLOR }],264 [{ type: TOKEN_UNIT_NAME }, { type: TOKEN_NUMBER }],265 [{ type: TOKEN_COLOR }],266 ],267 },268);269test(270 'Patterns should be able to repeat',271 shouldMatch,272 new Pattern([new CaptureElement(TOKEN_COLOR), new CaptureElement(TOKEN_NUMBER)]).any(),273 {274 input: [{ type: TOKEN_COLOR }, { type: TOKEN_NUMBER }],275 expected: [[{ type: TOKEN_COLOR }], [{ type: TOKEN_NUMBER }]],276 },277 {278 input: [279 { type: TOKEN_COLOR },280 { type: TOKEN_NUMBER },281 { type: TOKEN_COLOR },282 { type: TOKEN_NUMBER },283 ],284 expected: [285 [{ type: TOKEN_COLOR }],286 [{ type: TOKEN_NUMBER }],287 [{ type: TOKEN_COLOR }],288 [{ type: TOKEN_NUMBER }],289 ],290 },291 {292 input: [293 { type: TOKEN_COLOR },294 { type: TOKEN_NUMBER },295 { type: TOKEN_COLOR },296 { type: TOKEN_NUMBER },297 { type: TOKEN_COLOR },298 { type: TOKEN_NUMBER },299 ],300 expected: [301 [{ type: TOKEN_COLOR }],302 [{ type: TOKEN_NUMBER }],303 [{ type: TOKEN_COLOR }],304 [{ type: TOKEN_NUMBER }],305 [{ type: TOKEN_COLOR }],306 [{ type: TOKEN_NUMBER }],307 ],308 },309);310test(311 'Patterns should be able to match sub patterns',312 shouldMatch,313 new Pattern([314 new CaptureElement(TOKEN_BRACKET_OPEN),315 new Pattern([new CaptureElement(TOKEN_COLOR), new CaptureElement(TOKEN_NUMBER)]).any(),316 new CaptureElement(TOKEN_BRACKET_CLOSE),317 ]),318 {319 input: [{ type: TOKEN_BRACKET_OPEN }, { type: TOKEN_BRACKET_CLOSE }],320 expected: [[{ type: TOKEN_BRACKET_OPEN }], [{ type: TOKEN_BRACKET_CLOSE }]],321 },322 {323 input: [324 { type: TOKEN_BRACKET_OPEN },325 { type: TOKEN_COLOR },326 { type: TOKEN_NUMBER },327 { type: TOKEN_BRACKET_CLOSE },328 ],329 expected: [330 [{ type: TOKEN_BRACKET_OPEN }],331 [{ type: TOKEN_COLOR }],332 [{ type: TOKEN_NUMBER }],333 [{ type: TOKEN_BRACKET_CLOSE }],334 ],335 },336 {337 input: [338 { type: TOKEN_BRACKET_OPEN },339 { type: TOKEN_COLOR },340 { type: TOKEN_NUMBER },341 { type: TOKEN_COLOR },342 { type: TOKEN_NUMBER },343 { type: TOKEN_BRACKET_CLOSE },344 ],345 expected: [346 [{ type: TOKEN_BRACKET_OPEN }],347 [{ type: TOKEN_COLOR }],348 [{ type: TOKEN_NUMBER }],349 [{ type: TOKEN_COLOR }],350 [{ type: TOKEN_NUMBER }],351 [{ type: TOKEN_BRACKET_CLOSE }],352 ],353 },354 {355 input: [356 { type: TOKEN_BRACKET_OPEN },357 { type: TOKEN_COLOR },358 { type: TOKEN_NUMBER },359 { type: TOKEN_COLOR },360 { type: TOKEN_NUMBER },361 { type: TOKEN_COLOR },362 { type: TOKEN_NUMBER },363 { type: TOKEN_BRACKET_CLOSE },364 ],365 expected: [366 [{ type: TOKEN_BRACKET_OPEN }],367 [{ type: TOKEN_COLOR }],368 [{ type: TOKEN_NUMBER }],369 [{ type: TOKEN_COLOR }],370 [{ type: TOKEN_NUMBER }],371 [{ type: TOKEN_COLOR }],372 [{ type: TOKEN_NUMBER }],373 [{ type: TOKEN_BRACKET_CLOSE }],374 ],375 },376);377test(378 'Patterns should not incorrectly sub patterns',379 shouldNotMatch,380 new Pattern([381 new CaptureElement(TOKEN_BRACKET_OPEN),382 new Pattern([new CaptureElement(TOKEN_COLOR), new CaptureElement(TOKEN_NUMBER)]).any(),383 new CaptureElement(TOKEN_BRACKET_CLOSE),384 ]),385 [386 { type: TOKEN_BRACKET_OPEN },387 ],388 [389 { type: TOKEN_BRACKET_OPEN },390 { type: TOKEN_COLOR },391 { type: TOKEN_BRACKET_CLOSE },392 ],393 [394 { type: TOKEN_BRACKET_OPEN },395 { type: TOKEN_COLOR },396 { type: TOKEN_NUMBER },397 ],398 [399 { type: TOKEN_BRACKET_OPEN },400 { type: TOKEN_COLOR },401 { type: TOKEN_NUMBER },402 { type: TOKEN_COLOR },403 { type: TOKEN_BRACKET_CLOSE },404 ],405 [406 { type: TOKEN_BRACKET_OPEN },407 { type: TOKEN_COLOR },408 { type: TOKEN_NUMBER },409 { type: TOKEN_NUMBER },410 { type: TOKEN_COLOR },411 { type: TOKEN_NUMBER },412 { type: TOKEN_BRACKET_CLOSE },413 ],414);415test(416 'Patterns should be able to match sub-sub-patterns',417 shouldMatch,418 new Pattern([419 new CaptureElement(TOKEN_BRACKET_OPEN),420 new Pattern([421 new CaptureElement(TOKEN_COLOR),422 new Pattern([423 new CaptureElement(TOKEN_UNIT_PREFIX),424 new CaptureElement(TOKEN_UNIT_NAME),425 new CaptureElement(TOKEN_UNIT_SUFFIX),426 ]).any(),427 new CaptureElement(TOKEN_NUMBER),428 ]).any(),429 new CaptureElement(TOKEN_BRACKET_CLOSE),430 ]),431 {432 input: [{ type: TOKEN_BRACKET_OPEN }, { type: TOKEN_BRACKET_CLOSE }],433 expected: [[{ type: TOKEN_BRACKET_OPEN }], [{ type: TOKEN_BRACKET_CLOSE }]],434 },435 {436 input: [437 { type: TOKEN_BRACKET_OPEN },438 { type: TOKEN_COLOR },439 { type: TOKEN_NUMBER },440 { type: TOKEN_BRACKET_CLOSE },441 ],442 expected: [443 [{ type: TOKEN_BRACKET_OPEN }],444 [{ type: TOKEN_COLOR }],445 [{ type: TOKEN_NUMBER }],446 [{ type: TOKEN_BRACKET_CLOSE }],447 ],448 },449 {450 input: [451 { type: TOKEN_BRACKET_OPEN },452 { type: TOKEN_COLOR },453 { type: TOKEN_UNIT_PREFIX },454 { type: TOKEN_UNIT_NAME },455 { type: TOKEN_UNIT_SUFFIX },456 { type: TOKEN_NUMBER },457 { type: TOKEN_BRACKET_CLOSE },458 ],459 expected: [460 [{ type: TOKEN_BRACKET_OPEN }],461 [{ type: TOKEN_COLOR }],462 [{ type: TOKEN_UNIT_PREFIX }],463 [{ type: TOKEN_UNIT_NAME }],464 [{ type: TOKEN_UNIT_SUFFIX }],465 [{ type: TOKEN_NUMBER }],466 [{ type: TOKEN_BRACKET_CLOSE }],467 ],468 },469 {470 input: [471 { type: TOKEN_BRACKET_OPEN },472 { type: TOKEN_COLOR },473 { type: TOKEN_NUMBER },474 { type: TOKEN_COLOR },475 { type: TOKEN_NUMBER },476 { type: TOKEN_BRACKET_CLOSE },477 ],478 expected: [479 [{ type: TOKEN_BRACKET_OPEN }],480 [{ type: TOKEN_COLOR }],481 [{ type: TOKEN_NUMBER }],482 [{ type: TOKEN_COLOR }],483 [{ type: TOKEN_NUMBER }],484 [{ type: TOKEN_BRACKET_CLOSE }],485 ],486 },487 {488 input: [489 { type: TOKEN_BRACKET_OPEN },490 { type: TOKEN_COLOR },491 { type: TOKEN_NUMBER },492 { type: TOKEN_COLOR },493 { type: TOKEN_UNIT_PREFIX },494 { type: TOKEN_UNIT_NAME },495 { type: TOKEN_UNIT_SUFFIX },496 { type: TOKEN_NUMBER },497 { type: TOKEN_BRACKET_CLOSE },498 ],499 expected: [500 [{ type: TOKEN_BRACKET_OPEN }],501 [{ type: TOKEN_COLOR }],502 [{ type: TOKEN_NUMBER }],503 [{ type: TOKEN_COLOR }],504 [{ type: TOKEN_UNIT_PREFIX }],505 [{ type: TOKEN_UNIT_NAME }],506 [{ type: TOKEN_UNIT_SUFFIX }],507 [{ type: TOKEN_NUMBER }],508 [{ type: TOKEN_BRACKET_CLOSE }],509 ],510 },511);512test(513 'Patterns should work with zeroOrOne',514 shouldMatch,515 new Pattern([516 new CaptureElement(TOKEN_COLOR).zeroOrOne(),517 new CaptureElement(TOKEN_BRACKET_OPEN),518 new CaptureElement(TOKEN_NUMBER).any(),519 new CaptureElement(TOKEN_BRACKET_CLOSE),520 ]),521 {522 input: [523 { type: TOKEN_COLOR },524 { type: TOKEN_BRACKET_OPEN },525 { type: TOKEN_NUMBER },526 { type: TOKEN_BRACKET_CLOSE },527 ],528 expected: [529 [{ type: TOKEN_COLOR }],530 [{ type: TOKEN_BRACKET_OPEN }],531 [{ type: TOKEN_NUMBER }],532 [{ type: TOKEN_BRACKET_CLOSE }],533 ],534 },535 {536 input: [537 { type: TOKEN_BRACKET_OPEN },538 { type: TOKEN_NUMBER },539 { type: TOKEN_BRACKET_CLOSE },540 ],541 expected: [542 [],543 [{ type: TOKEN_BRACKET_OPEN }],544 [{ type: TOKEN_NUMBER }],545 [{ type: TOKEN_BRACKET_CLOSE }],546 ],547 },...

Full Screen

Full Screen

objparser.js

Source:objparser.js Github

copy

Full Screen

1/*******************************************************************************2This file is part of Shellfish-3D.3Copyright (c) 2020 Martin Grimme <martin.grimme@gmail.com>4Permission is hereby granted, free of charge, to any person obtaining a copy of5this software and associated documentation files (the "Software"), to deal in6the Software without restriction, including without limitation the rights to7use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of8the Software, and to permit persons to whom the Software is furnished to do so,9subject to the following conditions:10The above copyright notice and this permission notice shall be included in all11copies or substantial portions of the Software.12THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS14FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR15COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER16IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN17CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.18*******************************************************************************/19"use strict";20const TOKEN_NUMBER = /^-?[0-9]+(\.[0-9]+)?([eE]-?[0-9]+)?/;21const TOKEN_NAME = /^[^ \r\n]+/;22const TOKEN_NAME_WITH_SPACES = /^[^\r\n]+/;23function lineOfPos(data, pos)24{25 const lines = data.split("\n");26 let sum = 0;27 for (let line = 0; line < lines.length; ++line)28 {29 sum += lines[line].length + 1 /* the '\n' we split at */;30 if (sum > pos.value)31 {32 return line + 1;33 }34 }35 return -1;36}37function skipWhitespace(data, pos, skipNewline, skipComments)38{39 function skip(data, pos, what)40 {41 while (pos.value < data.length && what.indexOf(data[pos.value]) !== -1)42 {43 ++pos.value;44 }45 }46 while (pos.value < data.length)47 {48 skip(data, pos, skipNewline ? "\t\n\r\v " : "\t\r\v ");49 if (skipComments)50 {51 if (next(data, pos, "//"))52 {53 readUntilNewline(data, pos);54 }55 else if (next(data, pos, "/*"))56 {57 skipCommentBlock(data, pos);58 }59 else60 {61 break;62 }63 }64 else65 {66 break;67 }68 }69}70function skipCommentBlock(data, pos)71{72 let idx = data.indexOf("*/", pos.value);73 if (idx !== -1)74 {75 pos.value = idx + 2;76 }77 else78 {79 throw "Syntax error in line " + lineOfPos(data, pos) + ": end of comment block expected.";80 }81}82function next(data, pos, what)83{84 return data.substr(pos.value, what.length) === what;85}86function nextIsUpperCase(data, pos)87{88 let c = data[pos.value];89 return (c >= 'A' && c <= 'Z');90}91function nextIsToken(data, pos, regExp)92{93 if (pos.value < data.length)94 {95 return regExp.test(data.substr(pos.value));96 }97 else98 {99 return false;100 }101}102function expect(data, pos, what)103{104 if (data.substr(pos.value, what.length) === what)105 {106 pos.value += what.length;107 return what;108 }109 else110 {111 console.log(data.substr(pos.value, 80));112 throw "Syntax error in line " + lineOfPos(data, pos) + ": '" + what + "' expected.";113 }114}115function readUntil(data, pos, chars)116{117 // read until, but not including the given characters118 let s = "";119 while (pos.value < data.length && chars.indexOf(data[pos.value]) === -1)120 {121 s += data[pos.value];122 ++pos.value;123 }124 return s;125}126function readUntilNewline(data, pos)127{128 // read until, but not including, newline129 let s = readUntil(data, pos, "\r\n");130 return s;131}132function readToken(data, pos, regExp)133{134 let s = "";135 if (pos.value < data.length)136 {137 let matches = regExp.exec(data.substr(pos.value));138 if (matches)139 {140 let result = matches[0];141 pos.value += result.length;142 //console.log("read token: " + result);143 return result;144 }145 }146 return "";147}148function readString(data, pos)149{150 if (pos.value >= data.length)151 {152 return "";153 }154 let delimiter = "";155 if (data[pos.value] === "'")156 {157 delimiter = "'";158 ++pos.value;159 }160 else if (data[pos.value] === "\"")161 {162 delimiter = "\"";163 ++pos.value;164 }165 let result = "";166 while (pos.value < data.length)167 {168 if (delimiter !== "" && data[pos.value] === delimiter)169 {170 ++pos.value;171 break;172 }173 else if (delimiter === "" && "\t\n\r\v ".indexOf(data[pos.value]) !== -1)174 {175 break;176 }177 else if (next(data, pos, "\\n"))178 {179 result += "\\n";180 ++pos.value;181 }182 else if (data[pos.value] === "\\")183 {184 }185 else186 {187 result += data[pos.value];188 }189 ++pos.value;190 }191 //console.log("string: " + result);192 return result;193}194function parseEntry(data, pos, obj)195{196 if (next(data, pos, "#"))197 {198 readUntilNewline(data, pos);199 return;200 }201 const cmd = readToken(data, pos, /^[#a-z_]+/i);202 skipWhitespace(data, pos, false, true);203 switch (cmd)204 {205 case "f":206 const f = parseFace(data, pos, obj.v.length, obj.vt.length, obj.vn.length);207 if (f.length > 3)208 {209 fs = splitFace(f);210 obj.surfaces.push(...fs);211 }212 else213 {214 obj.surfaces.push(f);215 }216 obj.material.ranges[obj.material.ranges.length - 1].to = obj.surfaces.length - 1;217 break;218 case "g":219 readUntilNewline(data, pos);220 break;221 case "mtllib":222 skipWhitespace(data, pos, false, true);223 libs = parseFilenames(data, pos);224 obj.material.libraries.push(...libs);225 break;226 case "s":227 readUntilNewline(data, pos);228 break;229 case "usemtl":230 skipWhitespace(data, pos, false, true);231 const mtlName = readToken(data, pos, TOKEN_NAME);232 obj.material.ranges.push({233 name: mtlName,234 from: obj.surfaces.length,235 to: -1236 });237 break;238 case "v":239 const v = parseVertex(data, pos);240 obj.v.push(v);241 break;242 case "vn":243 const vn = parseVertex(data, pos);244 obj.vn.push(vn);245 break;246 case "vt":247 const vt = parseVertex(data, pos);248 if (vt[0] < 0) vt[0] = 1 + vt[0];249 if (vt[0] > 1) vt[0] = 2 - vt[0];250 if (vt[1] < 0) vt[1] = 1 + vt[1];251 if (vt[1] > 1) vt[1] = 2 - vt[1];252 obj.vt.push(vt);253 break;254 default:255 readUntilNewline(data, pos);256 console.error("Unsupported entry in obj file: " + cmd);257 }258}259function parseFilenames(data, pos)260{261 const filenames = [];262 while (pos.value < data.length)263 {264 const name = readToken(data, pos, TOKEN_NAME_WITH_SPACES);265 filenames.push(name);266 skipWhitespace(data, pos, false, true);267 if (! nextIsToken(data, pos, TOKEN_NAME))268 {269 break;270 }271 }272 return filenames;273}274function parseVertex(data, pos)275{276 const v = [];277 v.push(Number.parseFloat(readToken(data, pos, TOKEN_NUMBER)));278 skipWhitespace(data, pos, false, true);279 v.push(Number.parseFloat(readToken(data, pos, TOKEN_NUMBER)));280 skipWhitespace(data, pos, false, true);281 if (nextIsToken(data, pos, TOKEN_NUMBER))282 {283 v.push(Number.parseFloat(readToken(data, pos, TOKEN_NUMBER)));284 skipWhitespace(data, pos, false, true);285 }286 else287 {288 v.push(0.0);289 }290 if (nextIsToken(data, pos, TOKEN_NUMBER))291 {292 v.push(Number.parseFloat(readToken(data, pos, TOKEN_NUMBER)));293 }294 else295 {296 v.push(1.0);297 }298 return v;299}300function parseFace(data, pos, vAmount, vtAmount, vnAmount)301{302 const f = [];303 while (pos.value < data.length)304 {305 f.push(parseFaceTuple(data, pos, vAmount, vtAmount, vnAmount));306 skipWhitespace(data, pos, false, true);307 if (! nextIsToken(data, pos, TOKEN_NUMBER))308 {309 break;310 }311 }312 return f;313}314function parseFaceTuple(data, pos, vAmount, vtAmount, vnAmount)315{316 const tuple = {317 v: -1,318 vt: -1,319 vn: -1320 };321 // always subtract 1 because we start counting at 0322 tuple.v = Number.parseInt(readToken(data, pos, TOKEN_NUMBER)) - 1;323 if (tuple.v < 0)324 {325 tuple.v = vAmount + tuple.v + 1;326 }327 if (next(data, pos, "/"))328 {329 expect(data, pos, "/");330 if (nextIsToken(data, pos, TOKEN_NUMBER))331 {332 tuple.vt = Number.parseInt(readToken(data, pos, TOKEN_NUMBER)) - 1;333 if (tuple.vt < 0)334 {335 tuple.vt = vtAmount + tuple.vt + 1;336 }337 }338 if (next(data, pos, "/"))339 {340 expect(data, pos, "/");341 if (nextIsToken(data, pos, TOKEN_NUMBER))342 {343 tuple.vn = Number.parseInt(readToken(data, pos, TOKEN_NUMBER)) - 1;344 if (tuple.vn < 0)345 {346 tuple.vn = vnAmount + tuple.vn + 1;347 }348 }349 }350 }351 return tuple;352}353function splitFace(f)354{355 const fs = [];356 const tuple1 = f[0];357 for (let i = 1; i < f.length; ++i)358 {359 const tuple2 = f[(i) % f.length];360 const tuple3 = f[(i + 1) % f.length];361 fs.push([tuple1, tuple2, tuple3]);362 }363 return fs;364}365exports.parseObj = function (data)366{367 const obj = {368 v: [],369 vt: [],370 vn: [],371 surfaces: [],372 material: {373 libraries: [],374 ranges: [{ name: "", from: 0, to: -1 }]375 }376 };377 const pos = { value: 0 };378 while (pos.value < data.length)379 {380 parseEntry(data, pos, obj);381 skipWhitespace(data, pos, true, true);382 }383 //console.log(obj);384 return obj;385};386function parseMtlColor(data, pos)387{388 if (nextIsToken(data, pos, TOKEN_NUMBER))389 {390 let r = Number.parseFloat(readToken(data, pos, TOKEN_NUMBER));391 let g = r;392 let b = r;393 skipWhitespace(data, pos, false, true);394 if (nextIsToken(data, pos, TOKEN_NUMBER))395 {396 g = Number.parseFloat(readToken(data, pos, TOKEN_NUMBER));397 skipWhitespace(data, pos, false, true);398 b = Number.parseFloat(readToken(data, pos, TOKEN_NUMBER));399 }400 return [r, g, b];401 }402 else403 {404 // unsupported405 return [0, 0, 0];406 }407}408function parseMtlMap(data, pos)409{410 if (next(data, pos, "-"))411 {412 // texture map options unsupported by now413 readUntilNewline(data, pos);414 return "";415 }416 return readToken(data, pos, TOKEN_NAME_WITH_SPACES);417}418function parseMtlEntry(data, pos, mtl)419{420 const cmd = readToken(data, pos, /^[a-z_]+/i);421 skipWhitespace(data, pos, false, true);422 switch (cmd)423 {424 case "newmtl":425 const mtlName = readToken(data, pos, TOKEN_NAME);426 mtl.materials.push({427 name: mtlName,428 ka: [0, 0, 0],429 kd: [1, 1, 1],430 ks: [0, 0, 0],431 ns: 1,432 d: 1.0,433 kdMap: "",434 bumpMap: ""435 });436 break;437 case "d":438 mtl.materials[mtl.materials.length - 1].d = readToken(data, pos, TOKEN_NUMBER);439 break;440 case "Ka":441 mtl.materials[mtl.materials.length - 1].ka = parseMtlColor(data, pos);442 break;443 case "Kd":444 mtl.materials[mtl.materials.length - 1].kd = parseMtlColor(data, pos);445 break;446 case "map_Kd":447 mtl.materials[mtl.materials.length - 1].kdMap = parseMtlMap(data, pos);448 console.log("parsed mapKd: " + mtl.materials[mtl.materials.length - 1].kdMap);449 break;450 case "map_Bump":451 mtl.materials[mtl.materials.length - 1].bumpMap = parseMtlMap(data, pos);452 console.log("parsed bump map: " + mtl.materials[mtl.materials.length - 1].bumpMap);453 break;454 case "Ks":455 mtl.materials[mtl.materials.length - 1].ks = parseMtlColor(data, pos);456 break;457 case "Ns":458 mtl.materials[mtl.materials.length - 1].ns = Number.parseFloat(readToken(data, pos, TOKEN_NUMBER));459 break;460 default:461 readUntilNewline(data, pos);462 //console.error("Unsupported entry in mtl file: " + cmd);463 }464}465exports.parseMtl = function (data)466{467 const mtl = {468 materials: []469 };470 const pos = { value: 0 };471 while (pos.value < data.length)472 {473 parseMtlEntry(data, pos, mtl);474 skipWhitespace(data, pos, true, true);475 }476 //console.log(mtl);477 return mtl;...

Full Screen

Full Screen

restaurant-details.component.ts

Source:restaurant-details.component.ts Github

copy

Full Screen

1import { Component, OnInit, Input, Output, EventEmitter, ViewEncapsulation } from '@angular/core';2import { Rating } from '../models/rating';3import { ActivatedRoute } from '@angular/router';4import { ApiService } from '../api.service' 5import { map,catchError } from 'rxjs/operators'; 6import { DishRating } from '../dish_rating';7import { Observable, throwError } from 'rxjs';8import { ModalService } from '../_modal';9@Component({10 selector: 'app-restaurant-details',11 templateUrl: './restaurant-details.component.html',12 styleUrls: ['./restaurant-details.component.css']13})14export class RestaurantDetailsComponent implements OnInit {15 public snack_bar_duration: number = 2000;16 public rating_array = [];17 public rating_model = new Rating;18 public dish_rating_list;19 private star;20 private checked_star;21 private restaurant_dishes;22 private restaurant;23 private body_string;24 25 constructor(private route: ActivatedRoute,26 private api_service: ApiService,27 private modal_service: ModalService) { }28 ngOnInit(): void {29 this.get_dish_rating_list(this.route.snapshot.paramMap.get('id'))30 this.get_restaurant(this.route.snapshot.paramMap.get('id'))31 }32 rating_event_hander($event: any)33 {34 this.rating_model = $event;35 console.log('even emitter');36 37 }38 submit()39 {40 41 let rating_data = this.rating_model.get_ratings()42 let value = (<HTMLSelectElement>document.getElementById('dishesdrop')).value;43 let restaurant_id = this.route.snapshot.paramMap.get('id')44 let token_number = (<HTMLSelectElement>document.getElementById('token_number')).value;45 // console.log(rating_data.price_rating);46 if(value == 'null'){47 value = null48 }49 if(token_number == 'null' || token_number == null || token_number == ''){50 console.log('get it')51 token_number = null52 }53 console.log('dish rating : ' + rating_data.dish_rating)54 const data = {55 data:{56 mdata:{57 "user": "vidumini",58 "token_number": token_number,59 "restaurant_id": +restaurant_id,60 "dish_id": value,61 "dish_rating": rating_data.dish_rating,62 "price_rating": rating_data.price_rating,63 "service_rating": rating_data.service_rating, 64 "review": "Good experience"65 }66 }67 };68 console.log(data);69 console.log('token_number : ' + token_number);70 console.log('route param ' + this.route.snapshot.paramMap.get('id'))71 72 73 this.api_service.add_rating(data).pipe(74 map(resp => resp),75 catchError(err => {76 this.body_string = err.error.detail;77 throw err;78 })79 )80 .subscribe(81 resp => console.log(resp),82 err => window.alert(this.body_string)83 );84 }85 get_restaurant(restaurant_id)86 {87 this.api_service.get_restaurant(restaurant_id)88 .subscribe((data) => {89 this.restaurant_dishes = data['data']['dishes']90 console.log(this.restaurant_dishes)91 }); 92 }93 get_dish_rating_list(restaurant_id)94 {95 this.api_service.get_dish_rating_list_for_restaurant(restaurant_id)96 .subscribe((data) => {97 this.dish_rating_list = data['data']['dish_ratings']98 // this.restaurant_dishes = data['data']['dish_ratings']['dishes']99 // console.log(this.restaurant_dishes)100 }); 101 }102 set_star_rating(x)103 {104 this.checked_star = Math.floor(x);105 this.star = (5 - Math.floor(x))106 }107 checked_star_array(x)108 {109 return Array(this.checked_star)110 }111 star_array()112 {113 return Array(this.star)114 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { TOKEN_NUMBER } from 'ng-mocks';2import { TOKEN_STRING } from 'ng-mocks';3import { TOKEN_METHOD } from 'ng-mocks';4import { TOKEN_CLASS } from 'ng-mocks';5import { TOKEN_PROPERTY } from 'ng-mocks';6import { TOKEN_ARRAY } from 'ng-mocks';7import { TOKEN_OBJECT } from 'ng-mocks';8import { TOKEN_FUNCTION } from 'ng-mocks';9import { TOKEN_UNDEFINED } from 'ng-mocks';10import { TOKEN_NULL } from 'ng-mocks';11import { TOKEN_BOOLEAN } from 'ng-mocks';12import { TOKEN_ANY } from 'ng-mocks';13import { TOKEN_UNKNOWN } from 'ng-mocks';14import { TOKEN_NOTHING } from 'ng-mocks';15import { TOKEN_SERVICE } from 'ng-mocks';16import { TOKEN_PIPE } from 'ng-mocks';17import { TOKEN_DIRECTIVE } from 'ng-mocks';18import { TOKEN_COMPONENT } from 'ng-mocks';19import { TOKEN_INJECTABLE } from 'ng-mocks';20import { TOKEN_MODULE } from 'ng-mocks';21import { TOKEN_TOKEN } from 'ng-mocks';22import { TOKEN_PROVIDER } from 'ng

Full Screen

Using AI Code Generation

copy

Full Screen

1import { TOKEN_NUMBER } from 'ng-mocks';2import { MyService } from './my.service';3describe('MyService', () => {4 it('should work', () => {5 const myService = new MyService(TOKEN_NUMBER);6 expect(myService.getNumber()).toEqual(42);7 });8});9import { Injectable } from '@angular/core';10@Injectable()11export class MyService {12 constructor(private readonly number: number) {}13 public getNumber(): number {14 return this.number;15 }16}17import { NgModule } from '@angular/core';18import { MyService } from './my.service';19@NgModule({20 {21 useFactory: (number: number) => new MyService(number),22 },23})24export class AppModule {}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { TOKEN_NUMBER } from 'ng-mocks-auto';2@Component({3})4export class TestComponent {5 public value = 1;6}7describe('TestComponent', () => {8 let fixture: ComponentFixture<TestComponent>;9 let component: TestComponent;10 beforeEach(() => {11 TestBed.configureTestingModule({12 }).compileComponents();13 fixture = TestBed.createComponent(TestComponent);14 component = fixture.componentInstance;15 });16 it('should render the component', () => {17 const div = fixture.debugElement.query(By.css('div'));18 expect(div).toBeTruthy();19 expect(div.attributes['data-attr']).toEqual('1');20 });21 it('should render the component with TOKEN_NUMBER', () => {22 const div = fixture.debugElement.query(By.css('div'));23 expect(div).toBeTruthy();24 expect(div.attributes['data-attr']).toEqual(TOKEN_NUMBER);25 });26});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { mock } from 'ng-mocks/dist/mock';2describe('Mocking service using mock', () => {3 it('should mock service', () => {4 const service = mock(TestService);5 expect(service).toBeTruthy();6 });7});8import { Injectable } from '@angular/core';9@Injectable()10export class TestService {11 constructor() {}12}13import { TestBed } from '@angular/core/testing';14import { TestService } from './test.service';15describe('TestService', () => {16 let service: TestService;17 beforeEach(() => {18 TestBed.configureTestingModule({});19 service = TestBed.inject(TestService);20 });21 it('should be created', () => {22 expect(service).toBeTruthy();23 });24});25I am trying to mock a service in my unit test using ng-mocks library. I have followed the steps mentioned in the ng-mocks documentation. I am using angular 9.1.0 and ng-mocks 10.1.0. I am using the following code:When I run the test, I get the following error:When I change the import statement to the following, I don't get the error:What is the difference between the two import statements? Why does the first one give an error? I am not able to find any documentation on this. Can anyone help me understand this?26I am trying to mock a service in my unit test using ng-mocks library. I have followed the steps mentioned in the ng-mocks documentation. I am using angular 9.1.0 and ng-mocks 10.1.0. I am using the following code:When I run the test, I get the following error:When I change the import statement to the following, I don't get the error:What is the difference between the two import statements? Why does the first one give an error? I am not able to find any documentation on this. Can anyone help me understand this?27I am using Angular 9.1.0 and ng-mocks 10.1.0. I am using the following code:When I run the test, I get the following error:When I change the import statement to the following, I don't get the error:What is the difference between the two import statements? Why does the

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ng-mocks automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful