From 9fa68f2b0c2d106389080c681ef31b94015c6c7c Mon Sep 17 00:00:00 2001 From: Fernando Dodino Date: Mon, 4 Dec 2023 00:33:48 -0300 Subject: [PATCH] fix #185 avoid test same name (#194) Co-authored-by: Nahuel Palumbo --- src/validator.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/validator.ts b/src/validator.ts index 8506046f..46267462 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -137,9 +137,9 @@ export const shouldHaveCatchOrAlways = error(node => notEmpty(node.catches) || notEmpty(node.always.sentences) ) -export const methodShouldHaveDifferentSignature = error(node => { - return node.parent.methods.every(other => node === other || !other.matchesSignature(node.name, node.parameters.length)) -}) +export const methodShouldHaveDifferentSignature = error(node => + node.parent.methods.every(other => node === other || !other.matchesSignature(node.name, node.parameters.length)) +) export const shouldNotOnlyCallToSuper = warning(node => { const callsSuperWithSameArgs = (sentence?: Sentence) => sentence?.is(Super) && sentence.args.every((arg, index) => arg.is(Reference) && arg.target === node.parameters[index]) @@ -511,6 +511,15 @@ export const shouldNotUseVoidMethodAsValue = error(node => { return !method || method.isNative() || method.isAbstract() || returnsValue(method) }) +export const shouldHaveDifferentName = error(node => { + const tests: List = match(node.parent)( + when(Describe)(describe => describe.tests), + when(Package)(module => module.members.filter(member => member.is(Test)) as unknown as List), + when(Node)(_ => []), + ) + return !tests || tests.every(other => node === other || other.name !== node.name) +}) + // ══════════════════════════════════════════════════════════════════════════════════════════════════════════════════ // HELPER FUNCTIONS // ══════════════════════════════════════════════════════════════════════════════════════════════════════════════════ @@ -780,7 +789,7 @@ const validationsByKind = (node: Node): Record> => match when(Catch)(() => ({ shouldCatchUsingExceptionHierarchy, catchShouldBeReachable })), when(Package)(() => ({ shouldNotDuplicatePackageName })), when(Program)(() => ({ nameShouldNotBeKeyword, shouldNotUseReservedWords, shouldMatchFileExtension, shouldNotDuplicateEntities })), - when(Test)(() => ({ shouldHaveNonEmptyName, shouldNotMarkMoreThanOneOnlyTest, shouldHaveAssertInTest, shouldMatchFileExtension })), + when(Test)(() => ({ shouldHaveNonEmptyName, shouldNotMarkMoreThanOneOnlyTest, shouldHaveAssertInTest, shouldMatchFileExtension, shouldHaveDifferentName })), when(Class)(() => ({ nameShouldBeginWithUppercase, nameShouldNotBeKeyword, shouldNotHaveLoopInHierarchy, linearizationShouldNotRepeatNamedArguments, shouldNotDefineMoreThanOneSuperclass, superclassShouldBeLastInLinearization, shouldNotDuplicateGlobalDefinitions, shouldNotDuplicateVariablesInLinearization, shouldImplementAllMethodsInHierarchy, shouldNotUseReservedWords, shouldNotDuplicateEntities })), when(Singleton)(() => ({ nameShouldBeginWithLowercase, inlineSingletonShouldBeAnonymous, topLevelSingletonShouldHaveAName, nameShouldNotBeKeyword, shouldInitializeInheritedAttributes, linearizationShouldNotRepeatNamedArguments, shouldNotDefineMoreThanOneSuperclass, superclassShouldBeLastInLinearization, shouldNotDuplicateGlobalDefinitions, shouldNotDuplicateVariablesInLinearization, shouldImplementInheritedAbstractMethods, shouldImplementAllMethodsInHierarchy, shouldNotUseReservedWords, shouldNotDuplicateEntities })), when(Mixin)(() => ({ nameShouldBeginWithUppercase, shouldNotHaveLoopInHierarchy, shouldOnlyInheritFromMixin, shouldNotDuplicateGlobalDefinitions, shouldNotDuplicateVariablesInLinearization, shouldNotDuplicateEntities })),