-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests api implementation setup of test-item, type-converters and test…
…ing workspace. Signed-off-by: Zakaria Diabi <d.zaki2396@gmail.com>
- Loading branch information
Showing
44 changed files
with
9,525 additions
and
1,596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 TypeFox and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
// based on https://github.com/microsoft/vscode/blob/04c36be045a94fee58e5f8992d3e3fd980294a84/src/vs/base/common/hash.ts | ||
|
||
/** | ||
* Return a hash value for an object. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export function hash(obj: any): number { | ||
return doHash(obj, 0); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export function doHash(obj: any, hashVal: number): number { | ||
switch (typeof obj) { | ||
case 'object': | ||
// eslint-disable-next-line no-null/no-null | ||
if (obj === null) { | ||
return numberHash(349, hashVal); | ||
} else if (Array.isArray(obj)) { | ||
return arrayHash(obj, hashVal); | ||
} | ||
return objectHash(obj, hashVal); | ||
case 'string': | ||
return stringHash(obj, hashVal); | ||
case 'boolean': | ||
return booleanHash(obj, hashVal); | ||
case 'number': | ||
return numberHash(obj, hashVal); | ||
case 'undefined': | ||
return numberHash(937, hashVal); | ||
default: | ||
return numberHash(617, hashVal); | ||
} | ||
} | ||
|
||
export function numberHash(val: number, initialHashVal: number): number { | ||
return (((initialHashVal << 5) - initialHashVal) + val) | 0; // hashVal * 31 + ch, keep as int32 | ||
} | ||
|
||
function booleanHash(b: boolean, initialHashVal: number): number { | ||
return numberHash(b ? 433 : 863, initialHashVal); | ||
} | ||
|
||
export function stringHash(s: string, hashVal: number): number { | ||
hashVal = numberHash(149417, hashVal); | ||
for (let i = 0, length = s.length; i < length; i++) { | ||
hashVal = numberHash(s.charCodeAt(i), hashVal); | ||
} | ||
return hashVal; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function arrayHash(arr: any[], initialHashVal: number): number { | ||
initialHashVal = numberHash(104579, initialHashVal); | ||
return arr.reduce((hashVal, item) => doHash(item, hashVal), initialHashVal); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function objectHash(obj: any, initialHashVal: number): number { | ||
initialHashVal = numberHash(181387, initialHashVal); | ||
return Object.keys(obj).sort().reduce((hashVal, key) => { | ||
hashVal = stringHash(key, hashVal); | ||
return doHash(obj[key], hashVal); | ||
}, initialHashVal); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 TypeFox and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
// based on https://github.com/microsoft/vscode/blob/04c36be045a94fee58e5f8992d3e3fd980294a84/src/vs/base/common/uuid.ts | ||
|
||
const _UUIDPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; | ||
|
||
export function isUUID(value: string): boolean { | ||
return _UUIDPattern.test(value); | ||
} | ||
|
||
declare const crypto: undefined | { | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues#browser_compatibility | ||
getRandomValues?(data: Uint8Array): Uint8Array; | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID#browser_compatibility | ||
randomUUID?(): string; | ||
}; | ||
|
||
export const generateUuid = (function (): () => string { | ||
|
||
// use `randomUUID` if possible | ||
if (typeof crypto === 'object' && typeof crypto.randomUUID === 'function') { | ||
return crypto.randomUUID.bind(crypto); | ||
} | ||
|
||
// use `randomValues` if possible | ||
let getRandomValues: (bucket: Uint8Array) => Uint8Array; | ||
if (typeof crypto === 'object' && typeof crypto.getRandomValues === 'function') { | ||
getRandomValues = crypto.getRandomValues.bind(crypto); | ||
|
||
} else { | ||
getRandomValues = function (bucket: Uint8Array): Uint8Array { | ||
for (let i = 0; i < bucket.length; i++) { | ||
bucket[i] = Math.floor(Math.random() * 256); | ||
} | ||
return bucket; | ||
}; | ||
} | ||
|
||
// prep-work | ||
const _data = new Uint8Array(16); | ||
const _hex: string[] = []; | ||
for (let i = 0; i < 256; i++) { | ||
_hex.push(i.toString(16).padStart(2, '0')); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-shadow | ||
return function generateUuid(): string { | ||
// get data | ||
getRandomValues(_data); | ||
|
||
// set version bits | ||
_data[6] = (_data[6] & 0x0f) | 0x40; | ||
_data[8] = (_data[8] & 0x3f) | 0x80; | ||
|
||
// print as string | ||
let i = 0; | ||
let result = ''; | ||
result += _hex[_data[i++]]; | ||
result += _hex[_data[i++]]; | ||
result += _hex[_data[i++]]; | ||
result += _hex[_data[i++]]; | ||
result += '-'; | ||
result += _hex[_data[i++]]; | ||
result += _hex[_data[i++]]; | ||
result += '-'; | ||
result += _hex[_data[i++]]; | ||
result += _hex[_data[i++]]; | ||
result += '-'; | ||
result += _hex[_data[i++]]; | ||
result += _hex[_data[i++]]; | ||
result += '-'; | ||
result += _hex[_data[i++]]; | ||
result += _hex[_data[i++]]; | ||
result += _hex[_data[i++]]; | ||
result += _hex[_data[i++]]; | ||
result += _hex[_data[i++]]; | ||
result += _hex[_data[i++]]; | ||
return result; | ||
}; | ||
})(); |
Oops, something went wrong.