Best JavaScript code snippet using wpt
encoding.spec.ts
Source:encoding.spec.ts
...24 });25});26/**27 * Validating getBytes method in Ansi Encoding28 * method: getBytes(s:string,index:number,count:number)29 * return Array<number>30 */31describe('Validating getBytes method in Ansi encoding', () => {32 let encoding: Encoding;33 beforeEach((): void => {34 encoding = new Encoding(true);35 encoding.type = 'Ansi';36 });37 afterEach((): void => {38 encoding.destroy();39 encoding = undefined;40 });41 it('string as null parameter,index and count as null', () => {42 expect((): void => { encoding.getBytes(null, null, null); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));43 });44 it('string as null parameter', () => {45 expect((): void => { encoding.getBytes(null, 0, 1); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));46 });47 it('valid string,index and count as Null', () => {48 expect((): void => { encoding.getBytes('Stream', null, null); }).toThrow(new Error('ArgumentException: charIndex cannot be null or undefined'));49 });50 it('valid string,index as Null and count as valid value', () => {51 expect((): void => { encoding.getBytes('Stream', null, 1); }).toThrow(new Error('ArgumentException: charIndex cannot be null or undefined'));52 });53 it('valid string,count as null and index as valid value', () => {54 expect((): void => { encoding.getBytes('Stream', 0, null); }).toThrow(new Error('ArgumentException: charCount cannot be null or undefined'));55 });56 it('string as undefined parameter', () => {57 expect((): void => { encoding.getBytes(undefined, undefined, undefined); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));58 });59 it('string as valid value,index and count as undefined', () => {60 expect((): void => { encoding.getBytes('Stream', undefined, undefined); }).toThrow(new Error('ArgumentException: charIndex cannot be null or undefined'));61 });62 it('string , index and count as undefined parameter', () => {63 expect((): void => { encoding.getBytes(undefined, 0, 1); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));64 });65 it('valid string,index and count as negative value', () => {66 let s: string = 'StreamWriter';67 expect((): void => { encoding.getBytes(s, -1, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex or charCount is less than zero'));68 });69 it('valid string,index as negative value and count as 0', () => {70 let s: string = 'StreamWriter';71 expect((): void => { encoding.getBytes(s, -1, 0); }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex or charCount is less than zero'));72 });73 it('valid string,index as 0 and count as negative value', () => {74 let s: string = 'StreamWriter';75 expect((): void => { encoding.getBytes(s, 0, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex or charCount is less than zero'));76 });77 it('valid string,index and count as 0', () => {78 let s: string = 'a';79 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 0);80 expect(getBytes.byteLength).toBe(0);81 })82 it('valid string with index and count as valid values', () => {83 let s: string = 'a';84 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 1);85 let byte: Uint8Array = new Uint8Array(getBytes);86 expect(byte[0]).toBe(97);87 });88 it('empty string with valid index and count as invalid', () => {89 let s: string = '';90 expect((): void => { encoding.getBytes(s, 0, 2) }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex and charCount do not denote a valid range in string'));91 });92 it('Count value greater than string length', () => {93 let s: string = 'Stream';94 expect((): void => { encoding.getBytes(s, 5, 7) }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex and charCount do not denote a valid range in string'));95 });96 it('string with unicode character', () => {97 let s: string = 'Â¥';98 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 1);99 expect(getBytes.byteLength === 1).toEqual(true);100 });101 it('string with ASCII text', () => {102 let s: string = 'example';103 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, s.length);104 expect(getBytes.byteLength === 7).toEqual(true);105 });106 it('string with ASCII and unicode text', () => {107 let s: string = 'example Â¥';108 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, s.length);109 expect(getBytes.byteLength === 9).toEqual(true);110 });111 it('string with valid string, index and count as valid values', () => {112 let s: string = 'example';113 let getBytes: ArrayBuffer = encoding.getBytes(s, 1, 3);114 expect(getBytes.byteLength === 3).toEqual(true);115 });116 it('string with chinese character, index and count as valid value', () => {117 let s: string = 'æ±å';118 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 2);119 let byte: Uint8Array = new Uint8Array(getBytes);120 expect(byte[0]).toBe(63);121 expect(byte[1]).toBe(63);122 });123 it('EncodingType with null in getBytes method', () => {124 let encoding: Encoding = new Encoding(true);125 encoding.type = undefined;126 let getBytes: ArrayBuffer = encoding.getBytes('a', 0, 1);127 });128});129/**130 * Validating getBytes method in UTF-8 encoding131 * method: getBytes(s:string,index:number,count:number)132 * return ArrayBuffer133 */134describe('Validating getBytes method in UTF-8 encoding', () => {135 let encoding: Encoding;136 beforeEach((): void => {137 encoding = new Encoding(true);138 encoding.type = 'Utf8';139 });140 afterEach((): void => {141 encoding.destroy();142 encoding = undefined;143 });144 it('string , index and count as null parameter', () => {145 expect((): void => { encoding.getBytes(null, null, null); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));146 });147 it('string as null parameter, index and count as valid values', () => {148 expect((): void => { encoding.getBytes(null, 0, 1); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));149 });150 it('string as valid value,index and count as Null', () => {151 expect((): void => { encoding.getBytes('Stream', null, null); }).toThrow(new Error('ArgumentException: charIndex cannot be null or undefined'));152 });153 it('string and count as valid value, index as null', () => {154 expect((): void => { encoding.getBytes('Stream', null, 1); }).toThrow(new Error('ArgumentException: charIndex cannot be null or undefined'));155 });156 it('string and index as valid value, count as null', () => {157 expect((): void => { encoding.getBytes('Stream', 0, null); }).toThrow(new Error('ArgumentException: charCount cannot be null or undefined'));158 });159 it('string as undefined parameter', () => {160 expect((): void => { encoding.getBytes(undefined, undefined, undefined); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));161 });162 it('string as valid value,index and count as undefined', () => {163 expect((): void => { encoding.getBytes('Stream', undefined, undefined); }).toThrow(new Error('ArgumentException: charIndex cannot be null or undefined'));164 });165 it('string , index and count as undefined parameter', () => {166 expect((): void => { encoding.getBytes(undefined, 0, 1); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));167 });168 it('string as valid value,index and count as negative value', () => {169 let s: string = 'StreamWriter';170 expect((): void => { encoding.getBytes(s, -1, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex or charCount is less than zero'));171 });172 it('string as valid value,index as negative value and count as 0', () => {173 let s: string = 'StreamWriter';174 expect((): void => { encoding.getBytes(s, -1, 0); }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex or charCount is less than zero'));175 });176 it('string as valid value,index as 0 and count as negative value', () => {177 let s: string = 'StreamWriter';178 expect((): void => { encoding.getBytes(s, 0, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex or charCount is less than zero'));179 });180 it('string as valid value,index and count as 0', () => {181 let s: string = 'a';182 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 1);183 expect(getBytes.byteLength).toBe(1);184 })185 it('valid string with index and count as valid values', () => {186 let s: string = 'a';187 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 1);188 let byte: Uint8Array = new Uint8Array(getBytes);189 expect(byte[0]).toBe(97);190 });191 it('empty string with valid index and count as invalid', () => {192 let s: string = '';193 expect((): void => { encoding.getBytes(s, 0, 2) }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex and charCount do not denote a valid range in string'));194 });195 it('Count value greater than string length', () => {196 let s: string = 'Hello';197 expect((): void => { encoding.getBytes(s, 5, 6) }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex and charCount do not denote a valid range in string'));198 });199 it('string with unicode character', () => {200 let s: string = 'Â¥';201 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 1);202 expect(getBytes.byteLength === 2).toEqual(true);203 });204 it('string with as ASCII text', () => {205 let s: string = 'example';206 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 2);207 expect(getBytes.byteLength === 2).toEqual(true);208 });209 it('string as valid and positive index value and count', () => {210 let s: string = 'example';211 encoding = new Encoding(false);212 let getBytes: ArrayBuffer = encoding.getBytes(s, 1, 5);213 expect(getBytes.byteLength === 5).toEqual(true);214 let text: string = encoding.getString(getBytes, 0, 4);215 expect(text).toBe('xamp');216 });217 it('string with chinese character, index and count as valid value', () => {218 let s: string = 'æ±å';219 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, s.length);220 expect(getBytes.byteLength).toBe(6);221 });222 it('string with chinese character, index and count as valid value', () => {223 let s: string = 'ð';224 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 2);225 expect(getBytes.byteLength).toBe(4);226 });227});228/**229 * Validating getBytes method in Unicode encoding230 * method: getBytes(s:string,index:number,count:number)231 * return ArrayBuffer232 */233describe('Validating getBytes method in Unicode encoding', () => {234 let encoding: Encoding;235 beforeEach((): void => {236 encoding = new Encoding(true);237 encoding.type = 'Unicode';238 });239 afterEach((): void => {240 encoding.destroy();241 encoding = undefined;242 });243 it('string , index and count as null parameter', () => {244 expect((): void => { encoding.getBytes(null, null, null); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));245 });246 it('string as null parameter, index and count as valid values', () => {247 expect((): void => { encoding.getBytes(null, 0, 1); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));248 });249 it('string as valid value,index and count as Null', () => {250 expect((): void => { encoding.getBytes('Stream', null, null); }).toThrow(new Error('ArgumentException: charIndex cannot be null or undefined'));251 });252 it('string and count as valid value, index as null', () => {253 expect((): void => { encoding.getBytes('Stream', null, 1); }).toThrow(new Error('ArgumentException: charIndex cannot be null or undefined'));254 });255 it('string and index as valid value, count as null', () => {256 expect((): void => { encoding.getBytes('Stream', 0, null); }).toThrow(new Error('ArgumentException: charCount cannot be null or undefined'));257 });258 it('string as undefined parameter', () => {259 expect((): void => { encoding.getBytes(undefined, undefined, undefined); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));260 });261 it('string as valid value,index and count as undefined', () => {262 expect((): void => { encoding.getBytes('Stream', undefined, undefined); }).toThrow(new Error('ArgumentException: charIndex cannot be null or undefined'));263 });264 it('string , index and count as undefined parameter', () => {265 expect((): void => { encoding.getBytes(undefined, 0, 1); }).toThrow(new Error('ArgumentException: string cannot be null or undefined'));266 });267 it('string as valid value,index and count as negative value', () => {268 let s: string = 'StreamWriter';269 expect((): void => { encoding.getBytes(s, -1, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex or charCount is less than zero'));270 });271 it('string as valid value,index as negative value and count as 0', () => {272 let s: string = 'StreamWriter';273 expect((): void => { encoding.getBytes(s, -1, 0); }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex or charCount is less than zero'));274 });275 it('string as valid value,index as 0 and count as negative value', () => {276 let s: string = 'StreamWriter';277 expect((): void => { encoding.getBytes(s, 0, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex or charCount is less than zero'));278 });279 it('string as valid value,index and count as 0', () => {280 let s: string = 'a';281 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 1);282 expect(getBytes.byteLength).toBe(2);283 })284 it('valid string with index and count as valid values', () => {285 let s: string = 'a';286 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 1);287 let byte: Uint8Array = new Uint8Array(getBytes);288 expect(byte[0]).toBe(97);289 });290 it('empty string with valid index and count as invalid', () => {291 let s: string = '';292 expect((): void => { encoding.getBytes(s, 0, 2) }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex and charCount do not denote a valid range in string'));293 });294 it('Count value greater than string length', () => {295 let s: string = 'Hello';296 expect((): void => { encoding.getBytes(s, 5, 6) }).toThrow(new RangeError('Argument Out Of Range Exception: charIndex and charCount do not denote a valid range in string'));297 });298 it('string with unicode character', () => {299 let s: string = 'Â¥';300 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 1);301 expect(getBytes.byteLength === 2).toEqual(true);302 });303 it('string with as ASCII text', () => {304 let s: string = 'example';305 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 2);306 expect(getBytes.byteLength === 4).toEqual(true);307 });308 it('string as valid and positive index value and count', () => {309 let s: string = 'example';310 encoding = new Encoding(false);311 encoding.type = 'Unicode';312 let getBytes: ArrayBuffer = encoding.getBytes(s, 1, 5);313 expect(getBytes.byteLength === 10).toEqual(true);314 let text: string = encoding.getString(getBytes, 0, 5);315 expect(text).toBe('examp');316 });317 it('string with chinese character, index and count as valid value', () => {318 let s: string = 'æ±å';319 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 2);320 expect(getBytes.byteLength).toBe(4);321 });322 it('string with chinese character, index and count as valid value', () => {323 let s: string = 'ð';324 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 2);325 expect(getBytes.byteLength).toBe(4);326 });327});328/**329 * Validating getString method in Ansi Encoding330 * method: getString(bytes:ArrayBuffer,index:number,count:number)331 * return string type332 */333describe('Validating getstring method in Ansi Encoding', () => {334 let encoding: Encoding;335 beforeEach((): void => {336 encoding = new Encoding(true);337 encoding.type = 'Ansi';338 let getBytes = new ArrayBuffer(3);339 });340 afterEach((): void => {341 encoding.destroy();342 encoding = undefined;343 });344 it('bytes,index,count as null parameter', () => {345 expect((): void => { encoding.getString(null, null, null); }).toThrow(new Error('ArgumentException: bytes cannot be null or undefined'));346 });347 it('bytes as null,index and count as 0', () => {348 expect((): void => { encoding.getString(null, 0, 0); }).toThrow(new Error('ArgumentException: bytes cannot be null or undefined'));349 });350 it('valid bytes,index and count as null parameter', () => {351 let getBytes: ArrayBuffer = new ArrayBuffer(1);352 let bytes: Uint8Array = new Uint8Array(getBytes);353 bytes[0] = 97;354 expect((): void => { encoding.getString(getBytes, null, null); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));355 });356 it('valid bytes and count,index as null parameter', () => {357 let getBytes: ArrayBuffer = new ArrayBuffer(1);358 let bytes: Uint8Array = new Uint8Array(getBytes);359 bytes[0] = 97;360 expect((): void => { encoding.getString(getBytes, null, 1); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));361 });362 it('valid bytes and index,count as null parameter', () => {363 let getBytes: ArrayBuffer = new ArrayBuffer(1);364 let bytes: Uint8Array = new Uint8Array(getBytes);365 bytes[0] = 97;366 expect((): void => { encoding.getString(getBytes, 0, null); }).toThrow(new Error('ArgumentException: count cannot be null or undefined'));367 });368 it('bytes,index,count as undefined parameter', () => {369 expect((): void => { encoding.getString(undefined, undefined, undefined); }).toThrow(new Error('ArgumentException: bytes cannot be null or undefined'));370 });371 it('bytes as undefined,index and count as 0', () => {372 expect((): void => { encoding.getString(undefined, 0, 0); }).toThrow(new Error('ArgumentException: bytes cannot be null or undefined'));373 });374 it('valid bytes,index and count as undefined parameter', () => {375 let getBytes: ArrayBuffer = new ArrayBuffer(1);376 let bytes: Uint8Array = new Uint8Array(getBytes);377 bytes[0] = 97;378 expect((): void => { encoding.getString(getBytes, undefined, undefined); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));379 });380 it('valid bytes and count,index as undefined parameter', () => {381 let getBytes: ArrayBuffer = new ArrayBuffer(1);382 let bytes: Uint8Array = new Uint8Array(getBytes);383 bytes[0] = 97;384 expect((): void => { encoding.getString(getBytes, undefined, 1); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));385 });386 it('valid bytes and index,count as undefined parameter', () => {387 let getBytes: ArrayBuffer = new ArrayBuffer(1);388 let bytes: Uint8Array = new Uint8Array(getBytes);389 bytes[0] = 97;390 expect((): void => { encoding.getString(getBytes, 0, undefined); }).toThrow(new Error('ArgumentException: count cannot be null or undefined'));391 });392 it('valid bytes,index and count as negative value', () => {393 let getBytes: ArrayBuffer = new ArrayBuffer(1);394 let bytes: Uint8Array = new Uint8Array(getBytes);395 bytes[0] = 97;396 expect((): void => { encoding.getString(getBytes, -1, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));397 });398 it('valid bytes,index as 0 and count as negative value', () => {399 let getBytes: ArrayBuffer = new ArrayBuffer(1);400 let bytes: Uint8Array = new Uint8Array(getBytes);401 bytes[0] = 97;402 expect((): void => { encoding.getString(getBytes, 0, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));403 });404 it('valid bytes,index as negative value and count as 0', () => {405 let getBytes: ArrayBuffer = new ArrayBuffer(1);406 let bytes: Uint8Array = new Uint8Array(getBytes);407 bytes[0] = 97;408 expect((): void => { encoding.getString(getBytes, -1, 0); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));409 });410 it('valid bytes,index as negative value and count as valid value', () => {411 let getBytes: ArrayBuffer = new ArrayBuffer(1);412 let bytes: Uint8Array = new Uint8Array(getBytes);413 bytes[0] = 97;414 expect((): void => { encoding.getString(getBytes, -1, 0); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));415 });416 it('valid bytes, index and count as 0', () => {417 let getBytes: ArrayBuffer = new ArrayBuffer(1);418 let bytes: Uint8Array = new Uint8Array(getBytes);419 bytes[0] = 97;420 let s: string = encoding.getString(bytes, 0, 0);421 expect(s === '').toEqual(true);422 });423 it('valid bytes,index and count as valid value', () => {424 let getBytes: ArrayBuffer = new ArrayBuffer(1);425 let bytes: Uint8Array = new Uint8Array(getBytes);426 bytes[0] = 97;427 let s: string = encoding.getString(getBytes, 0, 1);428 expect(s === 'a').toEqual(true);429 });430 it('bytes, index and count has valid values', () => {431 // let getBytes: ArrayBuffer = new ArrayBuffer(5);432 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);433 let s: string = encoding.getString(bytes, 0, 5);434 expect(s).toBe('Hello');435 });436 it('bytes with length 0,index and count as valid ', () => {437 let bytes: ArrayBuffer = encoding.getBytes('', 0, 0);438 expect(bytes.byteLength).toBe(0);439 let s: string = encoding.getString(bytes, 0, 0);440 expect(s).toBe('');441 });442 it('bytes, index and count as valid value', () => {443 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);444 let s: string = encoding.getString(bytes, 1, 3);445 expect(s).toBe('ell');446 });447 it('bytes and index as valid and count as invalid values', () => {448 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);449 expect(bytes.length).toBe(5);450 expect((): void => { encoding.getString(bytes, 1, 6) }).toThrow(new RangeError('Argument Out Of Range Exception: index and count do not denote a valid range in bytes'));451 });452 it('bytes and count as valid and index as invalid value', () => {453 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);454 expect(bytes.length).toBe(5);455 expect((): void => { encoding.getString(bytes, 6, 5) }).toThrow(new RangeError('Argument Out Of Range Exception: index and count do not denote a valid range in bytes'));456 });457 it('string with chinese character, index and count as valid value', () => {458 let s: string = 'æ±å';459 let getBytes: Uint8Array = new Uint8Array([216]);460 let text: string = encoding.getString(getBytes, 0, 1);461 expect(text === 'æ±å').toEqual(false);462 });463 it('bytes with unicode character', () => {464 let s: string = 'Â¥';465 let bytes: ArrayBuffer = encoding.getBytes(s, 0, 1);466 let text: string = encoding.getString(bytes, 0, bytes.byteLength);467 expect(text === 'Â¥').toEqual(true);468 });469 it('EncodingType with null in getString method', () => {470 let encoding: Encoding = new Encoding(true);471 encoding.type = undefined;472 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);473 let s: string = encoding.getString(bytes, 0, bytes.length);474 expect(s).toBe('Hello');475 });476});477/**478 * Validating getString method in utf-8 encoding479 * method: getString(bytes:ArrayBuffer,index:number,count:number)480 * return string type481 */482describe('Validating getstring method in UTF-8 Encoding', () => {483 let encoding: Encoding;484 beforeEach((): void => {485 encoding = new Encoding(true);486 encoding.type = 'Utf8';487 });488 afterEach((): void => {489 encoding.destroy();490 encoding = undefined;491 });492 it('bytes,index,count as null parameter', () => {493 expect((): void => { encoding.getString(null, null, null); }).toThrow(new Error('ArgumentException: bytes cannot be null or undefined'));494 });495 it('bytes as valid values,index and count as null parameter', () => {496 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);497 expect((): void => { encoding.getString(bytes, null, null); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));498 });499 it('index as null parameter, bytes and count as valid values', () => {500 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);501 expect((): void => { encoding.getString(bytes, null, 1); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));502 });503 it('count as null parameter, bytes and index as valid values', () => {504 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);505 expect((): void => { encoding.getString(bytes, 0, null); }).toThrow(new Error('ArgumentException: count cannot be null or undefined'));506 });507 it('bytes,index,count as undefined parameter', () => {508 expect((): void => { encoding.getString(undefined, undefined, undefined); }).toThrow(new Error('ArgumentException: bytes cannot be null or undefined'));509 });510 it('bytes as undefined,index and count as 0', () => {511 expect((): void => { encoding.getString(undefined, 0, 0); }).toThrow(new Error('ArgumentException: bytes cannot be null or undefined'));512 });513 it('valid bytes,index and count as undefined parameter', () => {514 let getBytes: ArrayBuffer = new ArrayBuffer(1);515 let bytes: Uint8Array = new Uint8Array(getBytes);516 bytes[0] = 97;517 expect((): void => { encoding.getString(getBytes, undefined, undefined); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));518 });519 it('valid bytes and count,index as undefined parameter', () => {520 let getBytes: ArrayBuffer = new ArrayBuffer(1);521 let bytes: Uint8Array = new Uint8Array(getBytes);522 bytes[0] = 97;523 expect((): void => { encoding.getString(getBytes, undefined, 1); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));524 });525 it('valid bytes and index,count as undefined parameter', () => {526 let getBytes: ArrayBuffer = new ArrayBuffer(1);527 let bytes: Uint8Array = new Uint8Array(getBytes);528 bytes[0] = 97;529 expect((): void => { encoding.getString(getBytes, 0, undefined); }).toThrow(new Error('ArgumentException: count cannot be null or undefined'));530 });531 it('index and count as negative value,bytes as valid values', () => {532 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);533 expect((): void => { encoding.getString(bytes, -1, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));534 });535 it('bytes as valid,index as 0 and count as negative value', () => {536 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);537 expect((): void => { encoding.getString(bytes, 0, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));538 });539 it('bytes as valid,index as negative value and count as 0', () => {540 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);541 expect((): void => { encoding.getString(bytes, -1, 0); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));542 });543 it('valid bytes,index and count as 0', () => {544 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);545 let s: string = encoding.getString(bytes, 0, 0);546 expect(s === '').toEqual(true);547 });548 it('bytes,index and count as valid value', () => {549 let bytes: Uint8Array = new Uint8Array([97, 101, 108, 108, 111]);550 let s: string = encoding.getString(bytes, 0, 1);551 expect(s === 'a').toEqual(true);552 });553 it('valid bytes,index as negative value and count as valid value', () => {554 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);555 expect((): void => { encoding.getString(bytes, -1, 0); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));556 });557 it('bytes and index as valid and count as invalid values', () => {558 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);559 expect(bytes.length).toBe(5);560 expect((): void => { encoding.getString(bytes, 1, 6) }).toThrow(new RangeError('Argument Out Of Range Exception: index and count do not denote a valid range in bytes'));561 });562 it('bytes and count as valid and index as invalid value', () => {563 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);564 expect(bytes.length).toBe(5);565 expect((): void => { encoding.getString(bytes, 6, 5) }).toThrow(new RangeError('Argument Out Of Range Exception: index and count do not denote a valid range in bytes'));566 });567 it('bytes with valid value', () => {568 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);569 let s: string = encoding.getString(bytes, 0, 5);570 expect(s).toBe('Hello');571 });572 it('bytes with unicode character', () => {573 let s: string = 'Â¥';574 let bytes: ArrayBuffer = encoding.getBytes(s, 0, 1);575 let text: string = encoding.getString(bytes, 0, 1);576 expect(text === 'Â¥').toEqual(false);577 });578 it('bytes with unicode character', () => {579 let s: string = 'Â¥';580 let bytes: ArrayBuffer = encoding.getBytes(s, 0, 1);581 let text: string = encoding.getString(bytes, 0, 2);582 expect(text === 'Â¥').toEqual(true);583 });584 it('bytes with length 0,index and count as valid values', () => {585 let bytes: ArrayBuffer = encoding.getBytes('', 0, 0);586 expect(bytes.byteLength).toBe(0);587 let s: string = encoding.getString(bytes, 0, 0);588 expect(s).toBe('');589 });590 it('bytes and index as valid and count as invalid values', () => {591 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);592 expect(bytes.length).toBe(5);593 expect((): void => { encoding.getString(bytes, 1, 6) }).toThrow(new RangeError('Argument Out Of Range Exception: index and count do not denote a valid range in bytes'));594 });595 it('bytes and count as valid and index as invalid value', () => {596 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);597 expect(bytes.length).toBe(5);598 expect((): void => { encoding.getString(bytes, 6, 5) }).toThrow(new RangeError('Argument Out Of Range Exception: index and count do not denote a valid range in bytes'));599 });600 it('string with chinese character, index and count as valid value', () => {601 let s: string = 'æ±å';602 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 2);603 let text: string = encoding.getString(getBytes, 0, getBytes.byteLength)604 expect(text).toBe('æ±å');605 });606 it('valid string with chinese character', () => {607 let getBytes: Uint8Array = new Uint8Array([240, 141, 160, 128, 240, 141, 189, 136]);608 let text: string = encoding.getString(getBytes, 0, getBytes.length)609 expect(text).toBe('ð');610 });611});612/**613 * Validating getString method in unicode encoding614 * method: getString(bytes:ArrayBuffer,index:number,count:number)615 * return string type616 */617describe('Validating getstring method in Unicode Encoding', () => {618 let encoding: Encoding;619 beforeEach((): void => {620 encoding = new Encoding(true);621 encoding.type = 'Unicode';622 });623 afterEach((): void => {624 encoding.destroy();625 encoding = undefined;626 });627 it('bytes,index,count as null parameter', () => {628 expect((): void => { encoding.getString(null, null, null); }).toThrow(new Error('ArgumentException: bytes cannot be null or undefined'));629 });630 it('bytes as valid values,index and count as null parameter', () => {631 let bytes: Uint16Array = new Uint16Array([72, 101, 108, 108, 111]);632 expect((): void => { encoding.getString(bytes, null, null); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));633 });634 it('index as null parameter, bytes and count as valid values', () => {635 let bytes: Uint16Array = new Uint16Array([72, 101, 108, 108, 111]);636 expect((): void => { encoding.getString(bytes, null, 1); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));637 });638 it('count as null parameter, bytes and index as valid values', () => {639 let bytes: Uint16Array = new Uint16Array([72, 101, 108, 108, 111]);640 expect((): void => { encoding.getString(bytes, 0, null); }).toThrow(new Error('ArgumentException: count cannot be null or undefined'));641 });642 it('bytes,index,count as undefined parameter', () => {643 expect((): void => { encoding.getString(undefined, undefined, undefined); }).toThrow(new Error('ArgumentException: bytes cannot be null or undefined'));644 });645 it('bytes as undefined,index and count as 0', () => {646 expect((): void => { encoding.getString(undefined, 0, 0); }).toThrow(new Error('ArgumentException: bytes cannot be null or undefined'));647 });648 it('valid bytes,index and count as undefined parameter', () => {649 let getBytes: ArrayBuffer = new ArrayBuffer(2);650 let bytes: Uint16Array = new Uint16Array(getBytes);651 bytes[0] = 97;652 expect((): void => { encoding.getString(getBytes, undefined, undefined); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));653 });654 it('valid bytes and count,index as undefined parameter', () => {655 let getBytes: ArrayBuffer = new ArrayBuffer(2);656 let bytes: Uint16Array = new Uint16Array(getBytes);657 bytes[0] = 97;658 expect((): void => { encoding.getString(getBytes, undefined, 1); }).toThrow(new Error('ArgumentException: index cannot be null or undefined'));659 });660 it('valid bytes and index,count as undefined parameter', () => {661 let getBytes: ArrayBuffer = new ArrayBuffer(2);662 let bytes: Uint16Array = new Uint16Array(getBytes);663 bytes[0] = 97;664 expect((): void => { encoding.getString(getBytes, 0, undefined); }).toThrow(new Error('ArgumentException: count cannot be null or undefined'));665 });666 it('index and count as negative value,bytes as valid values', () => {667 let bytes: Uint16Array = new Uint16Array([72, 101, 108, 108, 111]);668 expect((): void => { encoding.getString(bytes, -1, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));669 });670 it('bytes as valid,index as 0 and count as negative value', () => {671 let bytes: Uint16Array = new Uint16Array([72, 101, 108, 108, 111]);672 expect((): void => { encoding.getString(bytes, 0, -1); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));673 });674 it('bytes as valid,index as negative value and count as 0', () => {675 let bytes: Uint16Array = new Uint16Array([72, 101, 108, 108, 111]);676 expect((): void => { encoding.getString(bytes, -1, 0); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));677 });678 it('valid bytes,index and count as 0', () => {679 let bytes: Uint16Array = new Uint16Array([72, 101, 108, 108, 111]);680 let s: string = encoding.getString(bytes, 0, 0);681 expect(s === '').toEqual(true);682 });683 it('bytes,index and count as valid value', () => {684 let bytes: Uint16Array = new Uint16Array([97, 101, 108, 108, 111]);685 let s: string = encoding.getString(bytes, 0, 1);686 expect(s === 'a').toEqual(true);687 });688 it('valid bytes,index as negative value and count as valid value', () => {689 let bytes: Uint16Array = new Uint16Array([72, 101, 108, 108, 111]);690 expect((): void => { encoding.getString(bytes, -1, 0); }).toThrow(new RangeError('Argument Out Of Range Exception: index or count is less than zero'));691 });692 it('bytes and index as valid and count as invalid values', () => {693 let bytes: Uint16Array = new Uint16Array([72, 101, 108, 108, 111]);694 expect(bytes.length).toBe(5);695 expect((): void => { encoding.getString(bytes, 1, 12) }).toThrow(new RangeError('Argument Out Of Range Exception: index and count do not denote a valid range in bytes'));696 });697 it('bytes and count as valid and index as invalid value', () => {698 let bytes: Uint16Array = new Uint16Array([72, 101, 108, 108, 111]);699 expect(bytes.length).toBe(5);700 expect((): void => { encoding.getString(bytes, 6, 5) }).toThrow(new RangeError('Argument Out Of Range Exception: index and count do not denote a valid range in bytes'));701 });702 it('bytes with valid value', () => {703 let bytes: Uint16Array = new Uint16Array([72, 101, 108, 108, 111]);704 let s: string = encoding.getString(bytes, 0, 5);705 expect(s).toBe('Hello');706 });707 it('bytes with unicode character', () => {708 let s: string = 'Â¥';709 let bytes: ArrayBuffer = encoding.getBytes(s, 0, 1);710 let text: string = encoding.getString(bytes, 0, 1);711 expect(text === 'Â¥').toEqual(true);712 });713 it('bytes with length 0,index and count as valid values', () => {714 let bytes: ArrayBuffer = encoding.getBytes('', 0, 0);715 expect(bytes.byteLength).toBe(0);716 let s: string = encoding.getString(bytes, 0, 0);717 expect(s).toBe('');718 });719 it('bytes and index as valid and count as invalid values', () => {720 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);721 expect(bytes.length).toBe(5);722 expect((): void => { encoding.getString(bytes, 1, 6) }).toThrow(new RangeError('Argument Out Of Range Exception: index and count do not denote a valid range in bytes'));723 });724 it('bytes and count as valid and index as invalid value', () => {725 let bytes: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]);726 expect(bytes.length).toBe(5);727 expect((): void => { encoding.getString(bytes, 6, 5) }).toThrow(new RangeError('Argument Out Of Range Exception: index and count do not denote a valid range in bytes'));728 });729 it('string with chinese character, index and count as valid value', () => {730 let s: string = 'æ±å';731 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 2);732 let text: string = encoding.getString(getBytes, 0, 2)733 expect(text).toBe('æ±å');734 });735 it('string with chinese character, index and count as valid value', () => {736 let s: string = 'ð¤¢';737 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 2);738 let text: string = encoding.getString(getBytes, 0, 2)739 expect(text).toBe('ð¤¢');740 });741 it('string with chinese character, index and count as valid value', () => {742 let s: string = 'ð¤¢';743 let getBytes: ArrayBuffer = encoding.getBytes(s, 0, 2);744 expect(() => { encoding.getString(getBytes, 0, getBytes.byteLength) }).toThrow(new RangeError('ArgumentOutOfRange_Count'));745 });746});747/**748 * Validating getByteCount Method in Ansi Encoding749 * method: getByteCount(chars:string)750 * return number751 */752describe('Validating getByteCount Method in Ansi Encoding', () => {753 let encoding: Encoding;754 beforeEach(() => {755 encoding = new Encoding();756 encoding.type = 'Ansi';757 });...
codie.js
Source:codie.js
...111};112Codie.prototype.sendMessage = function (service, messageArray, paramsArray) {113 var message = Buffer.alloc(4 + (paramsArray ? paramsArray.length : 0));114 // seq115 var sequence = Utils.getBytes(this.seq++);116 message.writeUInt8(sequence[0], 0);117 message.writeUInt8(sequence[1], 1);118 // cmd119 message.writeUInt8(messageArray[0], 2);120 message.writeUInt8(messageArray[1], 3);121 for (var paramIndex = 0; paramsArray && paramIndex < paramsArray.length; paramIndex++) {122 message.writeUInt8(paramsArray[paramIndex], 4 + paramIndex);123 }124 service.write(message, false);125};126/*127 ---------------------------- CODIE COMMANDS --------------------------128*/129Codie.prototype.echo = function () {130 this.sendCommand([0x00, 0x00]);131};132Codie.prototype.move = function (distance, leftSpeed, rightSpeed, cb) {133 var distanceBytes = Utils.getBytes(distance);134 this.sendCommand([0x01, 0x00], [distanceBytes[0], distanceBytes[1], Utils.getBytes(leftSpeed)[0], Utils.getBytes(rightSpeed)[0]], cb);135};136Codie.prototype.enableMotorBoth = function (leftSpeed, rightSpeed, cb) {137 this.sendCommand([0x02, 0x00], [Utils.getBytes(leftSpeed)[0], Utils.getBytes(rightSpeed)[0]], cb);138};139Codie.prototype.enableMotorLeft = function (speed, cb) {140 this.sendCommand([0x03, 0x00], [Utils.getBytes(speed)[0]], cb);141};142Codie.prototype.enableMotorRight = function (speed, cb) {143 this.sendCommand([0x04, 0x00], [Utils.getBytes(speed)[0]], cb);144};145Codie.prototype.turn = function (angle, speed, cb) {146 var angleBytes = Utils.getBytes(angle);147 this.sendCommand([0x05, 0x00], [angleBytes[0], angleBytes[1], Utils.getBytes(speed)[0]], cb);148};149Codie.prototype.beep = function (volume, frequency, duration, cb) {150 var frequencyBytes = Utils.getBytes(frequency);151 var durationBytes = Utils.getBytes(duration);152 this.sendCommand([0x06, 0x00], [Utils.getBytes(volume)[0], frequencyBytes[0], frequencyBytes[1], durationBytes[0], durationBytes[1]], cb);153};154Codie.prototype.setColor = function (hue, saturation, value, cb) {155 var hueBytes = Utils.getBytes(Math.floor(hue * 0.7));156 var saturationBytes = Utils.getBytes(Math.floor(saturation * 2.55));157 var valueBytes = Utils.getBytes(Math.floor(value * 2.55));158 this.sendCommand([0x08, 0x00], [hueBytes[0], saturationBytes[0], valueBytes[0]], cb);159};160/*161 Possible animation values: 0, 1162*/163Codie.prototype.setAnimation = function (animation, hue, saturation, repeat, speed, cb) {164 this.sendCommand([0x09, 0x00], [Utils.getBytes(animation)[0], Utils.getBytes(hue)[0], Utils.getBytes(saturation)[0], Utils.getBytes(repeat)[0], Utils.getBytes(speed)[0]], cb);165};166/*167 ----------------------------- CODIE SENSORS ------------------------------168*/169Codie.prototype.getDistance = function (cb) {170 this.sendQuery([0x01, 0x00], function (data) {171 var normalizedValue = Math.round(data / 10);172 console.log("Distance sensor:", normalizedValue);173 cb(normalizedValue);174 });175};176Codie.prototype.getBattery = function (cb) {177 this.sendQuery([0x02, 0x00], function (data) {178 var normalizedValue = (data > 100 ? 100 : data);...
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein')3 .then(function(page) {4 return page.getBytes();5 })6 .then(function(response) {7 console.log(response);8 })9 .catch(function(err) {10 console.log(err);11 });12var wptools = require('wptools');13wptools.page('Albert Einstein')14 .then(function(page) {15 console.log(page);16 })17 .catch(function(err) {18 console.log(err);19 });20var wptools = require('wptools');21wptools.page('Albert Einstein')22 .then(function(page) {23 return page.get('info');24 })25 .then(function(info) {26 console.log(info);27 })28 .catch(function(err) {29 console.log(err);30 });31var wptools = require('wptools');32wptools.page('Albert Einstein')33 .then(function(page) {34 return page.getBytes();35 })36 .then(function(bytes) {37 console.log(bytes);38 })39 .catch(function(err) {40 console.log(err);41 });
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein')3 .then(function(page) {4 return page.getBytes();5 })6 .then(function(response) {7 console.log(response);8 })9 .catch(function(err) {10 console.log(err);11 });12var wptools = require('wptools');13wptools.page('Albert Einstein')14 .then(function(page) {15 console.log(page);16 })17 .catch(function(err) {18 console.log(err);19 });20var wptools = require('wptools');21wptools.page('Albert Einstein')22 .then(function(page) {23 return page.get('info');24 })25 .then(function(info) {26 console.log(info);27 })28 .catch(function(err) {29 console.log(err);30 });31var wptools = require('wptools');32wptools.page('Albert Einstein')33 .then(function(page) {34 return page.getBytes();35 })36 .then(function(bytes) {37 console.log(bytes);38 })39 .catch(function(err) {40 console.log(err);41 });
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.getBytes(function(err, res) {4 console.log(res);5});6var wptools = require('wptools');7var page = wptools.page('Albert Einstein');8page.getBytes(function(err, res) {9 console.log(res);10});11var wptools = require('wptools');12var page = wptools.page('Albert Einstein');13page.getBytes(function(err, res) {14 console.log(res);15});16var wptools = require('wptools');17var page = wptools.page('Albert Einstein');18page.getBytes(function(err, res) {19 console.log(res);20});21var wptools = require('wptools');22var page = wptools.page('Albert Einstein');23page.getBytes(function(err, res) {24 console.log(res);25});26var wptools = require('wptools');27var page = wptools.page('Albert Einstein');28page.getBytes(function(err, res) {29 console.log(res);30});31var wptools = require('wptools');32var page = wptools.page('Albert Einstein');33page.getBytes(function(err, res) {34 console.log(res);35});36var wptools = require('wptools');37var page = wptools.page('Albert Einstein');38page.getBytes(function(err, res) {39 console.log(res);40});41var wptools = require('wptools');42var page = wptools.page('Albert Einstein');43page.getBytes(function(err, res) {44 console.log(res);45});
Using AI Code Generation
1var wpt = require('wpt');2 if (err) console.log(err);3 else console.log(data);4});5var wptools =require('wptols');6var s =require('fs');7s.page('Barac Obama').then(functon(page){8 reurn page.imageInfo();9}).then(function(imageInfo){10 fs.ariteFileSync('output.jtg', imgBytes);11})
Using AI Code Generation
1var wpt = require('wpt');2 if (err) console.log(err);3 else console.log(data);4});5var wpt = require('wpt');6 if (err) console.log(err);7 else console.log(data);8});9var wpt = require('wpt');10 if (err) console.log(err);11 else console.log(data);12});13var wpt = require('wpt');14 if (err) console.log(err);15 else console.log(data);16});17var wpt = require('wpt');18 if (err) console.log(err);19 else console.log(data);20});21var wpt = require('wpt');22 if (err) console.log(err);23 else console.log(data);24});25var wpt = require('wpt');
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3wptools.page('Barack Obama').then(function(page){4 return page.imageInfo();5}).then(function(imageInfo){6 var imgBytes = imageInfo.original.source.getBytes();7 fs.writeFileSync('output.jpg', imgBytes);8})back)
Using AI Code Generation
1var wp = require('./wptools.js');2 console.log(ytes);3});4var wp = require('./wptools.js');5 console.log(links);6});
Using AI Code Generation
1var wptk = require('wptoolkit');2var fs = require('fs');3var file = fs.readFileSync('test.png');4var bytes = wptk.getBytes(file);5console.log(bytes);6## wptk.getBase64(file)7var wptk = require('wptoolkit');8var fs = require('fs');9var file = fs.readFileSync('test.png');10var base64 = wptk.getBase64(file);11console.log(base64);
Using AI Code Generation
1var wpt = require('wpt');2 console.log(data);3});4### wpt.getSpeedIndex(url, callback)5### wpt.getRequests(url, callback)6### wpt.getBytes(url, callback)7### wpt.getFirstPaint(url, callback)8### wpt.getFullyLoaded(url, callback)9### wpt.getLoadTime(url, callback)10### wpt.getTTFB(url, callback)11### wpt.getBreakdown(url, callback)12### wpt.getBreakdownByType(url, callback)13### wpt.getBreakdownByDomain(url, callback)14### wpt.getBreakdownByMimeType(url, callback)15### wpt.getBreakdownByResponseCode(url, callback)16### wpt.getBreakdownByCDN(url, callback)17### wpt.getBreakdownByServer(url, callback)18### wpt.getBreakdownByConnection(url, callback)19### wpt.getBreakdownByProtocol(url, callback)20### wpt.getBreakdownByCache(url, callback)21### wpt.getBreakdownByTransferSize(url, callback)22### wpt.getBreakdownByContentSize(url, callback)23### wpt.getBreakdownByGzip(url, callback)24### wpt.getBreakdownByKeepAlive(url, callback)
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!!