util: getInputNumber func
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -201,6 +201,31 @@ ccccccccc`,
|
||||
});
|
||||
});
|
||||
|
||||
describe('getInputNumber', () => {
|
||||
it('should return a number when input is a valid number string', () => {
|
||||
setInput('foo', '42');
|
||||
const result = Util.getInputNumber('foo');
|
||||
expect(result).toBe(42);
|
||||
});
|
||||
|
||||
it('should return undefined when input is an empty string', () => {
|
||||
setInput('foo', '');
|
||||
const result = Util.getInputNumber('foo');
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return undefined when input is not provided', () => {
|
||||
const result = Util.getInputNumber('foo');
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return NaN when input is not a valid number', () => {
|
||||
setInput('foo', 'invalid');
|
||||
const result = Util.getInputNumber('foo');
|
||||
expect(result).toBeNaN();
|
||||
});
|
||||
});
|
||||
|
||||
describe('asyncForEach', () => {
|
||||
it('executes async tasks sequentially', async () => {
|
||||
const testValues = [1, 2, 3, 4, 5];
|
||||
|
||||
@@ -64,6 +64,14 @@ export class Util {
|
||||
return res.filter(item => item).map(pat => pat.trim());
|
||||
}
|
||||
|
||||
public static getInputNumber(name: string): number | undefined {
|
||||
const value = core.getInput(name);
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
return parseInt(value);
|
||||
}
|
||||
|
||||
public static async asyncForEach(array, callback) {
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
await callback(array[index], index, array);
|
||||
|
||||
Reference in New Issue
Block a user