feat: tests

This commit is contained in:
2023-04-21 12:08:35 +02:00
parent 8cb9285462
commit d8c79256c9
140 changed files with 2100 additions and 2693 deletions

View File

@@ -0,0 +1,70 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
// @ts-expect-error unused type
type TestTypeAlias = number | string;
// @ts-expect-error unused type
enum TestEnum {
Foo,
Bar,
}
export const testConfig: EasyAstSpecType = {
testName: `should resolve alias-likes`,
expected: {
TestTypeAlias: {
name: 'TestTypeAlias',
kind: LightweightDefinitionKind.ALIAS_LIKE,
modifiers: ['type'],
type: {
flags: 1_048_576,
specificationTypes: [
{
value: 'string',
flags: 4,
},
{
value: 'number',
flags: 8,
},
],
},
},
TestEnum: {
name: 'TestEnum',
kind: LightweightDefinitionKind.ALIAS_LIKE,
modifiers: ['enum'],
type: {
flags: 1_048_576,
specificationTypes: [
{
referenceName: 'Foo',
value: 0,
flags: 1280,
},
{
referenceName: 'Bar',
value: 1,
flags: 1280,
},
],
},
},
},
};

View File

@@ -0,0 +1,79 @@
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-interface */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
interface Random {}
// @ts-expect-error unused type
type TestArrayGeneric = Array<string>;
// @ts-expect-error unused type
type TestArrayLiteral = number[];
// @ts-expect-error unused type
type TestArrayReferenceGeneric = Array<Random>;
// @ts-expect-error unused type
type TestArrayReferenceLiteral = Random[];
export const testConfig: EasyAstSpecType = {
testName: `should resolve array-likes`,
expected: {
TestArrayGeneric: {
name: 'TestArrayGeneric',
kind: LightweightDefinitionKind.ALIAS_LIKE,
modifiers: ['type'],
type: {
value: 'string',
flags: 4,
isArray: true,
},
},
TestArrayLiteral: {
name: 'TestArrayLiteral',
kind: LightweightDefinitionKind.ALIAS_LIKE,
modifiers: ['type'],
type: {
value: 'number',
flags: 8,
isArray: true,
},
},
TestArrayReferenceGeneric: {
name: 'TestArrayReferenceGeneric',
kind: LightweightDefinitionKind.ALIAS_LIKE,
modifiers: ['type'],
type: {
referenceName: 'Random',
flags: 524_288,
isArray: true,
},
},
TestArrayReferenceLiteral: {
name: 'TestArrayReferenceLiteral',
kind: LightweightDefinitionKind.ALIAS_LIKE,
modifiers: ['type'],
type: {
referenceName: 'Random',
flags: 524_288,
isArray: true,
},
},
Random: {
name: 'Random',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
},
},
};

View File

@@ -0,0 +1,61 @@
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/no-inferrable-types */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
// @ts-expect-error unused type
interface TestInterface {
foo: number;
}
// @ts-expect-error unused type
class TestClass {
bar: string = 'test';
}
export const testConfig: EasyAstSpecType = {
testName: `should resolve class-likes`,
expected: {
TestInterface: {
name: 'TestInterface',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
properties: {
foo: {
name: 'foo',
type: {
value: 'number',
flags: 8,
},
},
},
},
TestClass: {
name: 'TestClass',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['class'],
properties: {
bar: {
name: 'bar',
type: {
value: 'string',
flags: 4,
},
},
},
},
},
};

View File

@@ -0,0 +1,164 @@
/* eslint-disable @typescript-eslint/no-unused-vars,jsdoc/check-tag-names */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
/**
* Class comment
*
* Class description
*
* More description
*
* @classTag classParameter1 classParameter2
*/
// @ts-expect-error unused type
interface TestInterface {
/**
* Property comment
*
* Property description
*
* More description
*
* @propertyTag propertyParameter1 propertyParameter2
*/
foo: string;
}
/**
* Class comment
*
* Class description
*
* More description
*
* @classTag classParameter1 classParameter2
*/
// @ts-expect-error unused type
class TestClass {
/**
* Property comment
*
* Property description
*
* More description
*
* @propertyTag propertyParameter1 propertyParameter2
*/
foo = 1;
}
/**
* Enum comment
*
* Enum description
*
* More description
*
* @enumTag enumParameter1
*/
// @ts-expect-error unused type
enum TestAlias {}
export const testConfig: EasyAstSpecType = {
testName: `should resolve comments`,
expected: {
TestInterface: {
comment: {
shortSummary: 'Class comment',
description: 'Class description\n\nMore description',
tags: [
{
name: 'classTag',
parameters: ['classParameter1', 'classParameter2'],
},
],
},
name: 'TestInterface',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
properties: {
foo: {
comment: {
shortSummary: 'Property comment',
description: 'Property description\n\nMore description',
tags: [
{
name: 'propertyTag',
parameters: ['propertyParameter1', 'propertyParameter2'],
},
],
},
name: 'foo',
type: {
value: 'string',
flags: 4,
},
},
},
},
TestClass: {
comment: {
shortSummary: 'Class comment',
description: 'Class description\n\nMore description',
tags: [
{
name: 'classTag',
parameters: ['classParameter1', 'classParameter2'],
},
],
},
name: 'TestClass',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['class'],
properties: {
foo: {
comment: {
shortSummary: 'Property comment',
description: 'Property description\n\nMore description',
tags: [
{
name: 'propertyTag',
parameters: ['propertyParameter1', 'propertyParameter2'],
},
],
},
name: 'foo',
type: {
value: 'number',
flags: 8,
},
},
},
},
TestAlias: {
comment: {
shortSummary: 'Enum comment',
description: 'Enum description\n\nMore description',
tags: [
{
name: 'enumTag',
parameters: ['enumParameter1'],
},
],
},
name: 'TestAlias',
kind: LightweightDefinitionKind.ALIAS_LIKE,
modifiers: ['enum'],
},
},
};

View File

@@ -0,0 +1,67 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
interface Test1<T = number> {
foo: T;
}
// @ts-expect-error unused type
interface Test2 {
bar: Test1;
}
export const testConfig: EasyAstSpecType = {
testName: `should resolve default generics`,
expected: {
Test1: {
name: 'Test1',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
typeParameters: ['T'],
properties: {
foo: {
name: 'foo',
type: {
referenceName: 'T',
flags: 262_144,
},
},
},
},
Test2: {
name: 'Test2',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
properties: {
bar: {
name: 'bar',
type: {
referenceName: 'Test1',
flags: 524_288,
genericsTypes: [
{
value: 'number',
flags: 8,
},
],
},
},
},
},
},
};

View File

@@ -0,0 +1,75 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
// @ts-expect-error unused type
enum TestAuto {
Foo,
Bar,
}
// @ts-expect-error unused type
enum TestSpecified {
YES = 'yes',
NO = 'no',
}
export const testConfig: EasyAstSpecType = {
testName: `should resolve auto and specified enums`,
expected: {
TestAuto: {
name: 'TestAuto',
kind: LightweightDefinitionKind.ALIAS_LIKE,
modifiers: ['enum'],
type: {
flags: 1_048_576,
specificationTypes: [
{
referenceName: 'Foo',
value: 0,
flags: 1280,
},
{
referenceName: 'Bar',
value: 1,
flags: 1280,
},
],
},
},
TestSpecified: {
name: 'TestSpecified',
kind: LightweightDefinitionKind.ALIAS_LIKE,
modifiers: ['enum'],
type: {
flags: 1_048_576,
specificationTypes: [
{
referenceName: 'YES',
value: 'yes',
flags: 1152,
},
{
referenceName: 'NO',
value: 'no',
flags: 1152,
},
],
},
},
},
};

View File

@@ -0,0 +1,81 @@
/* eslint-disable @typescript-eslint/no-empty-interface,@typescript-eslint/no-unused-vars */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
interface $Random {}
// @ts-expect-error unused type
interface Generics {
baz: Foo<number, $Random>;
}
interface Foo<T, S> {
foo: T;
bar: S;
}
export const testConfig: EasyAstSpecType = {
testName: `should resolve generics`,
expected: {
Generics: {
name: 'Generics',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
properties: {
baz: {
name: 'baz',
type: {
referenceName: 'Foo',
flags: 524_288,
genericsTypes: [
{
value: 'number',
flags: 8,
},
{
referenceName: '$Random',
flags: 524_288,
},
],
},
},
},
},
Foo: {
name: 'Foo',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
typeParameters: ['T', 'S'],
properties: {
foo: {
name: 'foo',
type: {
referenceName: 'T',
flags: 262_144,
},
},
bar: {
name: 'bar',
type: {
referenceName: 'S',
flags: 262_144,
},
},
},
},
},
};

View File

@@ -0,0 +1,71 @@
/* eslint-disable @typescript-eslint/no-empty-interface,@typescript-eslint/no-unused-vars */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
interface $Random {}
// @ts-expect-error unused
interface IndexSignatureObject {
[key: string]: $Random;
}
// @ts-expect-error unused
interface IndexSignaturePrimitive {
[key: string]: number;
}
export const testConfig: EasyAstSpecType = {
testName: `should resolve index signatures`,
expected: {
IndexSignatureObject: {
name: 'IndexSignatureObject',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
indexSignatures: {
key: {
name: 'key',
indexSignatureType: {
value: 'string',
flags: 4,
},
type: {
referenceName: '$Random',
flags: 524_288,
},
},
},
},
IndexSignaturePrimitive: {
name: 'IndexSignaturePrimitive',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
indexSignatures: {
key: {
name: 'key',
indexSignatureType: {
value: 'string',
flags: 4,
},
type: {
value: 'number',
flags: 8,
},
},
},
},
},
};

View File

@@ -0,0 +1,83 @@
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/no-inferrable-types */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
interface $BaseInterface<T> {
foo: T;
}
interface $BaseInterface2 {
bar: string;
}
class $BaseClass {}
// @ts-expect-error unused
class InheritingClass extends $BaseClass implements $BaseInterface<number>, $BaseInterface2 {
bar: string = '';
foo: number = 1;
}
export const testConfig: EasyAstSpecType = {
testName: `inheritance`,
expected: {
InheritingClass: {
name: 'InheritingClass',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['class'],
implementedDefinitions: [
{
referenceName: '$BaseInterface',
genericsTypes: [
{
value: 'number',
flags: 8,
},
],
flags: 524_288,
},
{
referenceName: '$BaseInterface2',
flags: 524_288,
},
],
extendedDefinitions: [
{
referenceName: '$BaseClass',
flags: 524_288,
},
],
properties: {
foo: {
name: 'foo',
type: {
value: 'number',
flags: 8,
},
},
bar: {
name: 'bar',
type: {
value: 'string',
flags: 4,
},
},
},
},
},
};

View File

@@ -0,0 +1,62 @@
/* eslint-disable @typescript-eslint/no-empty-interface,@typescript-eslint/no-unused-vars */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
// @ts-expect-error unused
interface NestedObject {
nested: {
deeplyNested: {
aNumber: number;
};
};
}
export const testConfig: EasyAstSpecType = {
testName: `should handle nested/type literals`,
expected: {
NestedObject: {
name: 'NestedObject',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
properties: {
nested: {
name: 'nested',
type: {
flags: 524_288,
},
properties: {
deeplyNested: {
name: 'deeplyNested',
type: {
flags: 524_288,
},
properties: {
aNumber: {
name: 'aNumber',
type: {
flags: 8,
value: 'number',
},
},
},
},
},
},
},
},
},
};

View File

@@ -0,0 +1,100 @@
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/no-explicit-any */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
// @ts-expect-error unused
interface Test {
number_type: number;
string_type: string;
boolean_type: boolean;
any_type: any;
unknown_type: unknown;
null_type: null;
undefined_type: undefined;
}
export const testConfig: EasyAstSpecType = {
testName: `should interpret primitive types correctly`,
expected: {
Test: {
name: 'Test',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
properties: {
number_type: {
name: 'number_type',
type: {
value: 'number',
flags: 8,
},
},
string_type: {
name: 'string_type',
type: {
value: 'string',
flags: 4,
},
},
boolean_type: {
name: 'boolean_type',
type: {
value: 'boolean',
flags: 1_048_592,
specificationTypes: [
{
value: 'false',
flags: 512,
},
{
value: 'true',
flags: 512,
},
],
},
},
any_type: {
name: 'any_type',
type: {
value: 'any',
flags: 1,
},
},
unknown_type: {
name: 'unknown_type',
type: {
value: 'unknown',
flags: 2,
},
},
null_type: {
name: 'null_type',
type: {
value: 'null',
flags: 65_536,
},
},
undefined_type: {
name: 'undefined_type',
type: {
value: 'undefined',
flags: 32_768,
},
},
},
},
},
};

View File

@@ -0,0 +1,62 @@
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/no-explicit-any */
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
// @ts-expect-error unused
interface Foo<T extends Bar<string>> {
bar: T;
}
interface Bar<T> {
foo: T;
}
export const testConfig: EasyAstSpecType = {
testName: `should ignore type constraints`,
expected: {
Foo: {
name: 'Foo',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
typeParameters: ['T'],
properties: {
bar: {
name: 'bar',
type: {
referenceName: 'T',
flags: 262_144,
},
},
},
},
Bar: {
name: 'Bar',
kind: LightweightDefinitionKind.CLASS_LIKE,
modifiers: ['interface'],
typeParameters: ['T'],
properties: {
foo: {
name: 'foo',
type: {
referenceName: 'T',
flags: 262_144,
},
},
},
},
},
};