Skip to content

Commit 7fdd158

Browse files
test: add variables for guard functions
1 parent 6401db2 commit 7fdd158

13 files changed

Lines changed: 318 additions & 0 deletions
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Variables.
2+
import { BIGINT, BIGINT_INSTANCE } from './big-int.const';
3+
import { Class } from './class.const';
4+
import { FALSE, TRUE, TRUE_INSTANCE, FALSE_INSTANCE } from './boolean.const';
5+
import { NULL } from './null.const';
6+
import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './number.const';
7+
import { ObjectOne, ObjectTwo } from './object.const';
8+
import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './string.const';
9+
import { UNDEFINED } from './undefined.const';
10+
import { notDefined } from './not-defined.const';
11+
// Type.
12+
import { Func } from '../../../type/func.type';
13+
14+
// Arrays.
15+
// Array with `bigint`.
16+
export const ARRAY_BIGINT: Array<bigint> = [BIGINT, BIGINT_INSTANCE, 9007199254740991n];
17+
// Array with `boolean`.
18+
export const ARRAY_BOOLEAN: Array<boolean | Boolean> = [true, false, TRUE_INSTANCE, FALSE_INSTANCE, false, FALSE, TRUE];
19+
// Array with `Class` instances.
20+
export const ARRAY_CLASS: Array<Class> = [new Class(), new Class()];
21+
// Array with `function`.
22+
export const ARRAY_FUNCTION: Array<Func> =
23+
[(x: number, y: string): any => x, (x: number, y: string): any => x, (x: number, y: string): any => x];
24+
// Array with `null`.
25+
export const ARRAY_NULL: Array<null> = [null, null, null, NULL, NULL];
26+
// Array with `number`.
27+
export const ARRAY_NUMBER: Array<number | Number> = [1, 2, 3, 4, 7, 10, 1000, 3000, 151233, NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE];
28+
// Array with 'object'.
29+
export const ARRAY_OBJECT_ONE: Array<ObjectOne> = [{ [NUMBER]: 'my number', x: 3000 }, { [NUMBER]: 'my number', x: 1 }];
30+
export const ARRAY_OBJECT_TWO: Array<ObjectTwo> = [{ x: 'One Two Three', y: 10000 }, { x: 'One Two Three', y: 10000 }, { x: 'One Two Three', y: 10000 }];
31+
// Array with `string`.
32+
export const ARRAY_STRING: Array<string | String> = [STRING, STRING_INSTANCE, STRING_NEW_INSTANCE, '!@#$%^&*()abcdefghijklmnoprstuwyz'];
33+
// Array with `symbol`.
34+
export const ARRAY_SYMBOL_NUMBER: Array<symbol> = [Symbol(1005), Symbol(1002), Symbol(15), Symbol(1)];
35+
export const ARRAY_SYMBOL_STRING: Array<symbol> = [Symbol('String Symbol'), Symbol('String Symbol'), Symbol('String Symbol One'), Symbol('String Symbol Two')];
36+
// Array with `undefined`.
37+
export const ARRAY_UNDEFINED: Array<undefined> = [undefined, undefined, undefined, UNDEFINED, notDefined];
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* typeof === 'bigint'
3+
* instanceof BigInt === false
4+
* instanceof Number === false
5+
* instanceof Object === false
6+
*/
7+
export const BIGINT: bigint = 9007199254740991n; // typeof === 'bigint'
8+
9+
/**
10+
* typeof === 'bigint'
11+
* instanceof BigInt === false
12+
* instanceof Number === false
13+
* instanceof Object === false
14+
*/
15+
export const BIGINT_INSTANCE: bigint = BigInt('9007199254740991'); // typeof === 'bigint'
16+
17+
export const BIGINT_EXPECTATION = `BigInt('9007199254740991')`;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* typeof === 'boolean'
3+
* instanceof Boolean === false
4+
* instanceof Object === false
5+
*/
6+
export const FALSE = false;
7+
8+
/**
9+
* typeof === 'boolean'
10+
* instanceof Boolean === false
11+
* instanceof Object === false
12+
*/
13+
export const TRUE = true;
14+
15+
/**
16+
* typeof === 'boolean'
17+
* instanceof Boolean === true
18+
* instanceof Object === true
19+
*/
20+
export const FALSE_INSTANCE: Boolean = new Boolean(FALSE); // instanceof Boolean
21+
export const TRUE_INSTANCE: Boolean = new Boolean(TRUE); // instanceof Boolean
22+
23+
export const FALSE_EXPECTATION = `new Boolean(${FALSE})`;
24+
export const TRUE_EXPECTATION = `new Boolean(${TRUE})`;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { NUMBER } from './number.const';
2+
import { STRING } from './string.const';
3+
import { SYMBOL_STRING, SYMBOL_NUMBER } from './symbol.const';
4+
5+
/**
6+
* typeof === 'function'
7+
* instanceof Class === false
8+
* instanceof Function === true
9+
* instanceof Object === true
10+
*/
11+
export class Class {
12+
13+
1030405027 = 'my new number';
14+
5 = 'my number';
15+
16+
firstName = 'My name';
17+
surname = 'Surname';
18+
19+
x = NUMBER;
20+
y = STRING;
21+
22+
get [NUMBER](): number {
23+
return this.x;
24+
}
25+
get [STRING](): string {
26+
return this.y;
27+
}
28+
29+
get [SYMBOL_NUMBER](): number {
30+
return this.x;
31+
}
32+
33+
get [SYMBOL_STRING](): string {
34+
return this.y;
35+
}
36+
}
37+
38+
/**
39+
* typeof === 'object'
40+
* instanceof Class === true
41+
* instanceof Function === false
42+
* instanceof Object === true
43+
*/
44+
export const CLASS = new Class();
45+
46+
export class Person {
47+
firstName = '';
48+
surname = '';
49+
age = 15;
50+
}
51+
52+
export class PersonCopy {
53+
firstName = '';
54+
surname = '';
55+
age = 15;
56+
}
57+
58+
export const PERSON: Person = new Person();
59+
export const PERSON_COPY: PersonCopy = new PersonCopy();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Func } from '../../../type/func.type';
2+
/**
3+
* typeof === 'function'
4+
* instanceof Function === true
5+
* instanceof Object === true
6+
*/
7+
export const FUNCTION: Func = (x: number, y: string): any => x + y;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export let notDefined: undefined; // typeof === 'undefined'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @example https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null
3+
*/
4+
/**
5+
* typeof === 'object'
6+
* instanceof Function === false
7+
* instanceof Number === false
8+
* instanceof Object === false
9+
*/
10+
export const NULL: null = null;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
/**
3+
* @example https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
4+
*/
5+
6+
/**
7+
* typeof === 'number'
8+
* instanceof Function === false
9+
* instanceof Number === false
10+
* instanceof Object === false
11+
*/
12+
export const NUMBER = 10304050;
13+
14+
/**
15+
* typeof === 'number'
16+
* instanceof Function === false
17+
* instanceof Number === false
18+
* instanceof Object === false
19+
*/
20+
export const NUMBER_INSTANCE: Number = Number(NUMBER);
21+
22+
/**
23+
* typeof === 'number'
24+
* instanceof Function === false
25+
* instanceof Number === true
26+
* instanceof Object === true
27+
*/
28+
export const NUMBER_NEW_INSTANCE: Number = new Number(NUMBER);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { SYMBOL_NUMBER, SYMBOL_STRING } from './symbol.const';
2+
import { STRING } from './string.const';
3+
import { NUMBER } from './number.const';
4+
export interface ObjectOne {
5+
'key as string'?: boolean;
6+
1030405027?: string;
7+
5?: string;
8+
[NUMBER]: string;
9+
[SYMBOL_NUMBER]?: string;
10+
[SYMBOL_STRING]?: number;
11+
x: number;
12+
}
13+
export interface ObjectTwo { x: string; y: number; }
14+
/**
15+
* @example https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects
16+
*/
17+
/**
18+
* typeof === 'object'
19+
* instanceof Boolean === false
20+
* instanceof Function === false
21+
* instanceof Number === false
22+
* instanceof Object === true
23+
* instanceof String === false
24+
* instanceof Symbol === false
25+
*/
26+
export const OBJECT_ONE: ObjectOne = {
27+
'key as string': true,
28+
1030405027: 'key is number',
29+
5: 'key is also number',
30+
[NUMBER]: 'key is number',
31+
[STRING]: 'key is string',
32+
[SYMBOL_NUMBER]: 'key is symbol number',
33+
[SYMBOL_STRING]: 6,
34+
x: 3000
35+
};
36+
37+
/**
38+
* typeof === 'object'
39+
* instanceof Boolean === false
40+
* instanceof Function === false
41+
* instanceof Number === false
42+
* instanceof Object === true
43+
* instanceof String === false
44+
* instanceof Symbol === false
45+
*/
46+
export const OBJECT_TWO: ObjectTwo = { x: 'One Two Three', y: 10000 };
47+
48+
/**
49+
* typeof === 'object'
50+
* instanceof Boolean === false
51+
* instanceof Function === false
52+
* instanceof Number === false
53+
* instanceof Object === true
54+
* instanceof String === false
55+
* instanceof Symbol === false
56+
*/
57+
export const OBJECT_ONE_NEW: Object = new Object(OBJECT_ONE);
58+
59+
/**
60+
* typeof === 'object'
61+
* instanceof Boolean === false
62+
* instanceof Function === false
63+
* instanceof Number === false
64+
* instanceof Object === true
65+
* instanceof String === false
66+
* instanceof Symbol === false
67+
*/
68+
export const OBJECT_TWO_NEW: Object = new Object(OBJECT_TWO);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @example https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
3+
*/
4+
/**
5+
* typeof === 'string'
6+
* instanceof Function === false
7+
* instanceof Object === false
8+
* instanceof String === false
9+
*/
10+
export const STRING: string = '!@#$%^&*()abcdefghijklmnoprstuwyz';
11+
12+
/**
13+
* typeof === 'string'
14+
* instanceof Function === false
15+
* instanceof Object === false
16+
* instanceof String === false
17+
*/
18+
export const STRING_INSTANCE: String = String(STRING);
19+
20+
/**
21+
* typeof === 'string'
22+
* instanceof Function === false
23+
* instanceof Object === true
24+
* instanceof String === true
25+
*/
26+
export const STRING_NEW_INSTANCE: String = new String(STRING);

0 commit comments

Comments
 (0)