From 768bece65eebaef655c1cc9d17ff276a65fb1322 Mon Sep 17 00:00:00 2001 From: anquetil Date: Sun, 10 Nov 2024 18:49:04 +0100 Subject: [PATCH] correcting errors in FASTCopyVisitorCodeGeneratorTest (+ adding tests) --- .../FASTCopyVisitorCodeGeneratorTest.class.st | 62 +++++++++++++++---- .../FASTVisitorCodeGenerator.class.st | 4 +- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/FAST-Core-Tools-Tests/FASTCopyVisitorCodeGeneratorTest.class.st b/src/FAST-Core-Tools-Tests/FASTCopyVisitorCodeGeneratorTest.class.st index 88e26eb..e40c44e 100644 --- a/src/FAST-Core-Tools-Tests/FASTCopyVisitorCodeGeneratorTest.class.st +++ b/src/FAST-Core-Tools-Tests/FASTCopyVisitorCodeGeneratorTest.class.st @@ -29,12 +29,21 @@ FASTCopyVisitorCodeGeneratorTest >> setUp [ generator := FASTCopyVisitorCodeGenerator new. visitorClass := Mock named: 'visitor'. - visitorMethods := OrderedCollection new. + visitorClass stub package willReturn: (self class package). + + visitorMethods := OrderedCollection new. (visitorClass stub compile: Any classified: Any) will: [ :method :category | visitorMethods add: method -> category ] ] +{ #category : 'running' } +FASTCopyVisitorCodeGeneratorTest >> tearDown [ + super tearDown. + + self class package extensionMethods do: #removeFromSystem +] + { #category : 'tests' } FASTCopyVisitorCodeGeneratorTest >> testGenerateCopyMethod [ @@ -45,39 +54,66 @@ FASTCopyVisitorCodeGeneratorTest >> testGenerateCopyMethod [ ] { #category : 'tests' } -FASTCopyVisitorCodeGeneratorTest >> testShouldCopyPropertyFor [ +FASTCopyVisitorCodeGeneratorTest >> testShouldCopyMultiValuedDerivedProperty [ + + | property | + + property := FmxTraitsTestGenerateAccessorBClassB asMooseDescription + allProperties detect: [ :prop | prop name = 'relationToA' ]. + + self assert: property isDerived. + self assert: (generator shouldCopyProperty: property) +] + +{ #category : 'tests' } +FASTCopyVisitorCodeGeneratorTest >> testShouldCopyNotMultiValuedProperty [ + + | property | + + property := FmxTraitsTestGenerateAccessorBClassB asMooseDescription + allProperties detect: [ :prop | prop name = 'relationToA' ]. + + self deny: property isMultivalued. + self assert: (generator shouldCopyProperty: property) +] + +{ #category : 'tests' } +FASTCopyVisitorCodeGeneratorTest >> testShouldCopyPropertyToOtherEntity [ | property | property := FmxTraitsTestGenerateAccessorBClassA asMooseDescription allProperties detect: [ :prop | prop name = 'relationToB' ]. - generator package: (FmxTraitsTestGenerateAccessorBClassA metamodel packages detect: [ :p | p name = 'Famix-MetamodelBuilder-TestsTraitsResources-A' ]). self assert: (generator shouldCopyProperty: property). ] { #category : 'tests' } -FASTCopyVisitorCodeGeneratorTest >> testShouldNotCopyDerivedProperty [ +FASTCopyVisitorCodeGeneratorTest >> testShouldNotCopyMultivaluedDerivedProperty [ | property | property := FmxTraitsTestGenerateAccessorBClassB asMooseDescription allProperties detect: [ :prop | prop name = 'relationToA' ]. - - self assert: property isDerived. + + "focing it to be multivalued" + property isMultivalued: true. + self assert: property isMultivalued. self deny: (generator shouldCopyProperty: property) ] { #category : 'tests' } -FASTCopyVisitorCodeGeneratorTest >> testShouldNotCopyPropertyFromOtherPackage [ - +FASTCopyVisitorCodeGeneratorTest >> testShouldNotCopyPropertyParent [ + "property pointing to parent should not be copied" | property | - property := FmxTraitsTestGenerateAccessorBClassB asMooseDescription - allProperties detect: [ :prop | prop name = 'relationToA' ]. - - generator package: (FmxTraitsTestGenerateAccessorBClassA metamodel packages detect: [ :p | p name = 'Famix-MetamodelBuilder-TestsTraitsResources-B' ]). - self assert: (generator shouldCopyProperty: property) + property := FmxTraitsTestGenerateAccessorBClassA asMooseDescription + allProperties detect: [ :prop | prop name = 'relationToB' ]. + + "forcing it to be to parent" + property isContainer: true. + self assert: property isContainer. + self deny: (generator shouldCopyProperty: property) ] diff --git a/src/FAST-Core-Tools/FASTVisitorCodeGenerator.class.st b/src/FAST-Core-Tools/FASTVisitorCodeGenerator.class.st index 0aa227e..40063a4 100644 --- a/src/FAST-Core-Tools/FASTVisitorCodeGenerator.class.st +++ b/src/FAST-Core-Tools/FASTVisitorCodeGenerator.class.st @@ -64,7 +64,9 @@ FASTVisitorCodeGenerator >> generateAccept: modelClass [ { #category : 'code generation' } FASTVisitorCodeGenerator >> generateAcceptSelectorOn: stream [ - stream << 'accept: aVisitor' + stream + << 'accept: aVisitor' ; + cr ] { #category : 'code generation' }