Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DifferentialComparator now also compared on some properties values #36

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 76 additions & 21 deletions src/FAST-Core-Tools/FASTDifferentialValidator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,40 @@ Class {
#category : #'FAST-Core-Tools'
}

{ #category : #utilities }
FASTDifferentialValidator >> acceptableAST: ast1 differentFrom: ast2 [
{ #category : #comparison }
FASTDifferentialValidator >> ast: node1 acceptableDifferenceTo: node2 [
"In non strict mode, some differences could be accepted"

^false
]

{ #category : #utilities }
FASTDifferentialValidator >> ast: ast1 differ: ast2 [
{ #category : #comparison }
FASTDifferentialValidator >> ast: node1 acceptableDifferenceTo: node2 property: property [

^#(startPos endPos) includes: property
]

{ #category : #comparison }
FASTDifferentialValidator >> ast: node1 differ: node2 [

self strict ifTrue: [ Exception signal: 'ASTs differ' ].

(self acceptableAST: ast1 differentFrom: ast2)
(self ast: node1 acceptableDifferenceTo: node2)
ifTrue: [
(' ** difference in ignored, position in source: ' , ast1 startPos asString)
(' ** difference in ignored, position in source: ' , node1 startPos asString)
traceCr.
Notification signal
]
ifFalse: [ Exception signal: 'ASTs differ' ]
]

{ #category : #comparison }
FASTDifferentialValidator >> ast: node1 differ: node2 property: property [

(self ast: node1 acceptableDifferenceTo: node2 property: property)
ifFalse: [ Exception signal: 'ASTs differ on property: ' , property implementingSelector ]
]

{ #category : #configuration }
FASTDifferentialValidator >> beStrict [

Expand All @@ -68,30 +81,62 @@ FASTDifferentialValidator >> childrenNodes: astNode [

]

{ #category : #utilities }
FASTDifferentialValidator >> compare: ast1 to: ast2 [
"comparing the two lists of children may seem a bit complicate, but it is trying
to give more info on when the children starts to differ"
{ #category : #comparison }
FASTDifferentialValidator >> compare: node1 to: node2 [
"check the two nodes have the same class
then check they have the same properties (attributes with primitive types)
then check recursively that they ahev the same sub-nodes"

| children1 children2 size1 size2 |
self compareClasses: node1 to: node2.
self compareProperties: node1 to: node2.
self compareChildren: node1 to: node2
]

(ast1 class = ast2 class)
ifFalse: [ self ast: ast1 differ: ast2 ].
{ #category : #comparison }
FASTDifferentialValidator >> compareChildren: node1 to: node2 [
"comparing the two lists of children may seem a bit complicate, but it is trying
to give more info when the children starts to differ
For example comparing using #with:collect: gives very little information if the two lists
differ in size"

children1 := self childrenNodes: ast1.
children2 := self childrenNodes: ast2.
| size1 children1 size2 children2 |
children1 := self childrenNodes: node1.
children2 := self childrenNodes: node2.

size1 := children1 size.
size2 := children2 size.

1 to: size1 do: [ :i |
(size2 < i)
size2 < i
ifTrue: [ self ast: (children1 at: i) differ: nil ]
ifFalse: [ self compare: (children1 at: i) to: (children2 at: i) ]
].
ifFalse: [ self compare: (children1 at: i) to: (children2 at: i) ] ].

children2 size > children1 size ifTrue: [
self ast: nil differ: (children2 at: children1 size + 1) ]
]

{ #category : #comparison }
FASTDifferentialValidator >> compareClasses: node1 to: node2 [

node1 class = node2 class ifFalse: [
self ast: node1 differ: node2 ]
]

{ #category : #comparison }
FASTDifferentialValidator >> compareProperties: node1 to: node2 [
"compare the values of the 'properties' (attributes with primitive types) of the two nodes
since the two nodes should be the same class, they have the same properties"

(node1 class mooseDescription allPrimitiveProperties) do: [ :property || value1 value2 |
(self propertyToCompare: property) ifTrue: [
value1 := node1 perform: property implementingSelector.
value2 := node2 perform: property implementingSelector.

(value1 = value2) ifFalse: [
self ast: node1 differ: node2 property: property
]]
]

(children2 size > children1 size)
ifTrue: [self ast: nil differ: (children2 at: (children1 size + 1)) ]
]

{ #category : #utilities }
Expand Down Expand Up @@ -128,7 +173,7 @@ FASTDifferentialValidator >> initialize [
super initialize.

strict := false.
skipPaths := #()
skipPaths := #().
]

{ #category : #testing }
Expand All @@ -143,6 +188,16 @@ FASTDifferentialValidator >> on: aDirectoryName [
self runOnFileReference: aDirectoryName asFileReference
]

{ #category : #testing }
FASTDifferentialValidator >> propertyToCompare: aFMProperty [
"do not compare on derived (ie. computed) properties, only those with a stored value
do not compare on startPos/endPos as they are not meaningfull"

aFMProperty isDerived ifTrue: [^false].
(#(startPos endPos) includes: aFMProperty implementingSelector) ifTrue: [^false].
^true
]

{ #category : #utilities }
FASTDifferentialValidator >> reExportAST: ast [

Expand Down
Loading