Skip to content

Commit 81ab994

Browse files
committed
Fix bug in assert statements.
It can have multiple expression, not just one
1 parent 5acf9c1 commit 81ab994

6 files changed

Lines changed: 109 additions & 47 deletions

File tree

‎src/FAST-Python-Model-Generator/FASTPythonMetamodelGenerator.class.st‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
358358
complex --|> literal.
359359
complex --|> tNumericalLiteral.
360360

361+
concatenatedString --|> expression.
362+
361363
conditionalExpression --|> expression.
362364
conditionalExpression --|> tWithCondition.
363365
conditionalExpression --|> tSliceContent.
@@ -536,8 +538,8 @@ FASTPythonMetamodelGenerator >> defineRelations [
536538
((attribute property: #attribute) comment: 'The variable been accessed')
537539
<>- ((variable property: #attributeOwner) comment: 'The attribute access accessing me (if it''s the case)').
538540

539-
((assertStatement property: #expression) comment: 'The expression asserted')
540-
<>- ((expression property: #assertOwner) comment: 'The assert statement that own the expression (if it''s the case)').
541+
((assertStatement property: #expressions) comment: 'The expressions asserted')
542+
<>-* ((expression property: #parentAssertStatement) comment: 'The assert statement that own the expression (if it''s the case)').
541543

542544
(await property: #expression) <>- (expression property: #parentAwait).
543545

‎src/FAST-Python-Model/FASTPyAssertStatement.class.st‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
### Children
66
| Relation | Origin | Opposite | Type | Comment |
77
|---|
8-
| `expression` | `FASTPyAssertStatement` | `assertOwner` | `FASTPyExpression` | The expression asserted|
8+
| `expressions` | `FASTPyAssertStatement` | `parentAssertStatement` | `FASTPyExpression` | The expressions asserted|
99
1010
1111
@@ -14,7 +14,7 @@ Class {
1414
#name : 'FASTPyAssertStatement',
1515
#superclass : 'FASTPyStatement',
1616
#instVars : [
17-
'#expression => FMOne type: #FASTPyExpression opposite: #assertOwner'
17+
'#expressions => FMMany type: #FASTPyExpression opposite: #parentAssertStatement'
1818
],
1919
#category : 'FAST-Python-Model-Entities',
2020
#package : 'FAST-Python-Model',
@@ -30,25 +30,32 @@ FASTPyAssertStatement class >> annotation [
3030
^ self
3131
]
3232

33+
{ #category : 'adding' }
34+
FASTPyAssertStatement >> addExpression: anObject [
35+
<generated>
36+
^ self expressions add: anObject
37+
]
38+
3339
{ #category : 'accessing' }
34-
FASTPyAssertStatement >> expression [
35-
"Relation named: #expression type: #FASTPyExpression opposite: #assertOwner"
40+
FASTPyAssertStatement >> expressions [
41+
"Relation named: #expressions type: #FASTPyExpression opposite: #parentAssertStatement"
3642

3743
<generated>
38-
<FMComment: 'The expression asserted'>
39-
^ expression
44+
<FMComment: 'The expressions asserted'>
45+
<derived>
46+
^ expressions
4047
]
4148

4249
{ #category : 'accessing' }
43-
FASTPyAssertStatement >> expression: anObject [
50+
FASTPyAssertStatement >> expressions: anObject [
4451

4552
<generated>
46-
expression := anObject
53+
expressions value: anObject
4754
]
4855

4956
{ #category : 'navigation' }
50-
FASTPyAssertStatement >> expressionGroup [
57+
FASTPyAssertStatement >> expressionsGroup [
5158
<generated>
52-
<navigation: 'Expression'>
53-
^ MooseSpecializedGroup with: self expression
59+
<navigation: 'Expressions'>
60+
^ MooseSpecializedGroup withAll: self expressions asSet
5461
]

‎src/FAST-Python-Model/FASTPyConcatenatedString.class.st‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"
1313
Class {
1414
#name : 'FASTPyConcatenatedString',
15-
#superclass : 'FASTPyEntity',
15+
#superclass : 'FASTPyExpression',
1616
#instVars : [
1717
'#strings => FMMany type: #FASTPyString opposite: #parentConcatenatedString'
1818
],
@@ -24,7 +24,7 @@ Class {
2424
{ #category : 'meta' }
2525
FASTPyConcatenatedString class >> annotation [
2626

27-
<FMClass: #ConcatenatedString super: #FASTPyEntity>
27+
<FMClass: #ConcatenatedString super: #FASTPyExpression>
2828
<package: #'FAST-Python-Model'>
2929
<generated>
3030
^ self

‎src/FAST-Python-Model/FASTPyExpression.class.st‎

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
| Relation | Origin | Opposite | Type | Comment |
77
|---|
88
| `argumentOwner` | `FASTTExpression` | `arguments` | `FASTTWithArguments` | my owner|
9-
| `assertOwner` | `FASTPyExpression` | `expression` | `FASTPyAssertStatement` | The assert statement that own the expression (if it's the case)|
109
| `assignedIn` | `FASTTExpression` | `expression` | `FASTTAssignment` | Optional assignment where this expression is used|
1110
| `attributeObjectOwner` | `FASTPyExpression` | `object` | `FASTPyAttributeAccess` | My parent if I define the object of an attribute access (if it's the case).|
1211
| `caller` | `FASTPyExpression` | `callee` | `FASTPyCall` | The call entity calling me (if it's the case)|
@@ -28,6 +27,7 @@
2827
| `listSplatOwner` | `FASTPyExpression` | `iterable` | `FASTPyListSplat` | List splat unpacking me (if it's the case)|
2928
| `pairKeyOwner` | `FASTTExpression` | `key` | `FASTPyPair` | |
3029
| `pairValueOwner` | `FASTTExpression` | `value` | `FASTPyPair` | |
30+
| `parentAssertStatement` | `FASTPyExpression` | `expressions` | `FASTPyAssertStatement` | The assert statement that own the expression (if it's the case)|
3131
| `parentAwait` | `FASTPyExpression` | `expression` | `FASTPyAwait` | |
3232
| `parentComparisonOperator` | `FASTPyExpression` | `operands` | `FASTPyComparisonOperator` | Parent comparison expression of which I am.|
3333
| `parentConditional` | `FASTTExpression` | `condition` | `FASTTWithCondition` | Optional condition statement/expression where this expression is used|
@@ -58,7 +58,6 @@ Class {
5858
#traits : 'FASTTExpression',
5959
#classTraits : 'FASTTExpression classTrait',
6060
#instVars : [
61-
'#assertOwner => FMOne type: #FASTPyAssertStatement opposite: #expression',
6261
'#attributeObjectOwner => FMOne type: #FASTPyAttributeAccess opposite: #object',
6362
'#caller => FMOne type: #FASTPyCall opposite: #callee',
6463
'#collectionInitializer => FMOne type: #FASTPyCollectionInitializer opposite: #initializers',
@@ -76,6 +75,7 @@ Class {
7675
'#keywordArgumentOwner => FMOne type: #FASTPyKeywordArgument opposite: #value',
7776
'#lambdaOwner => FMOne type: #FASTPyLambda opposite: #expression',
7877
'#listSplatOwner => FMOne type: #FASTPyListSplat opposite: #iterable',
78+
'#parentAssertStatement => FMOne type: #FASTPyAssertStatement opposite: #expressions',
7979
'#parentAwait => FMOne type: #FASTPyAwait opposite: #expression',
8080
'#parentComparisonOperator => FMOne type: #FASTPyComparisonOperator opposite: #operands',
8181
'#parentInterpolation => FMOne type: #FASTPyInterpolation opposite: #expression',
@@ -99,31 +99,6 @@ FASTPyExpression class >> annotation [
9999
^ self
100100
]
101101

102-
{ #category : 'accessing' }
103-
FASTPyExpression >> assertOwner [
104-
"Relation named: #assertOwner type: #FASTPyAssertStatement opposite: #expression"
105-
106-
<generated>
107-
<FMComment: 'The assert statement that own the expression (if it''s the case)'>
108-
<container>
109-
<derived>
110-
^ assertOwner
111-
]
112-
113-
{ #category : 'accessing' }
114-
FASTPyExpression >> assertOwner: anObject [
115-
116-
<generated>
117-
assertOwner := anObject
118-
]
119-
120-
{ #category : 'navigation' }
121-
FASTPyExpression >> assertOwnerGroup [
122-
<generated>
123-
<navigation: 'AssertOwner'>
124-
^ MooseSpecializedGroup with: self assertOwner
125-
]
126-
127102
{ #category : 'accessing' }
128103
FASTPyExpression >> attributeObjectOwner [
129104
"Relation named: #attributeObjectOwner type: #FASTPyAttributeAccess opposite: #object"
@@ -537,6 +512,30 @@ FASTPyExpression >> listSplatOwnerGroup [
537512
^ MooseSpecializedGroup with: self listSplatOwner
538513
]
539514

515+
{ #category : 'accessing' }
516+
FASTPyExpression >> parentAssertStatement [
517+
"Relation named: #parentAssertStatement type: #FASTPyAssertStatement opposite: #expressions"
518+
519+
<generated>
520+
<FMComment: 'The assert statement that own the expression (if it''s the case)'>
521+
<container>
522+
^ parentAssertStatement
523+
]
524+
525+
{ #category : 'accessing' }
526+
FASTPyExpression >> parentAssertStatement: anObject [
527+
528+
<generated>
529+
parentAssertStatement := anObject
530+
]
531+
532+
{ #category : 'navigation' }
533+
FASTPyExpression >> parentAssertStatementGroup [
534+
<generated>
535+
<navigation: 'ParentAssertStatement'>
536+
^ MooseSpecializedGroup with: self parentAssertStatement
537+
]
538+
540539
{ #category : 'accessing' }
541540
FASTPyExpression >> parentAwait [
542541
"Relation named: #parentAwait type: #FASTPyAwait opposite: #expression"

‎src/FAST-Python-Tools-Tests/FASTPythonImporterTest.class.st‎

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ FASTPythonImporterTest >> testAssertStatement [
170170
self assert: self topEntity sourceCode equals: 'assert b != 0'.
171171
self assert: (self topEntity isOfType: FASTPyAssertStatement).
172172

173-
"Testing value of monovalue relation expression"
174-
self assert: self topEntity expression isNotNil.
175-
176-
stack push: self topEntity expression.
173+
"Testing value of multivalued relation expressions"
174+
self assert: self topEntity expressions size equals: 1.
175+
176+
stack push: (stack top expressions at: 1).
177177
self assert: self topEntity sourceCode equals: 'b != 0'.
178178
self assert: (self topEntity isOfType: FASTPyComparisonOperator).
179179

@@ -194,6 +194,58 @@ FASTPythonImporterTest >> testAssertStatement [
194194
self assert: self topEntity operators equals: #('!=')
195195
]
196196

197+
{ #category : 'tests - statements' }
198+
FASTPythonImporterTest >> testAssertStatementWithConcatenatedString [
199+
<generated>
200+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
201+
Regenerate executing: self regenerateTest: #testAssertStatementWithConcatenatedString "
202+
203+
self parse: 'assert 0, "Could not find method in self.functions and no "\
204+
"instance installed"'.
205+
206+
self assert: (fast allWithType: FASTPyAssertStatement) size equals: 1.
207+
self assert: (fast allWithType: FASTPyConcatenatedString) size equals: 1.
208+
self assert: (fast allWithType: FASTPyInteger) size equals: 1.
209+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
210+
self assert: (fast allWithType: FASTPyString) size equals: 2.
211+
212+
stack push: fast rootEntities anyOne containedEntities first.
213+
self assert: self topEntity sourceCode equals: 'assert 0, "Could not find method in self.functions and no "\
214+
"instance installed"' withPlatformLineEndings.
215+
self assert: (self topEntity isOfType: FASTPyAssertStatement).
216+
217+
"Testing value of multivalued relation expressions"
218+
self assert: self topEntity expressions size equals: 2.
219+
220+
stack push: (stack top expressions at: 1).
221+
self assert: self topEntity sourceCode equals: '0'.
222+
self assert: (self topEntity isOfType: FASTPyInteger).
223+
self assert: (self topEntity isOfType: FASTTLiteral).
224+
self assert: (self topEntity isOfType: FASTTNumericalLiteral).
225+
stack pop.
226+
227+
stack push: (stack top expressions at: 2).
228+
self assert: self topEntity sourceCode equals: '"Could not find method in self.functions and no "\
229+
"instance installed"' withPlatformLineEndings.
230+
self assert: (self topEntity isOfType: FASTPyConcatenatedString).
231+
232+
"Testing value of multivalued relation strings"
233+
self assert: self topEntity strings size equals: 2.
234+
235+
stack push: (stack top strings at: 1).
236+
self assert: self topEntity sourceCode equals: '"Could not find method in self.functions and no "'.
237+
self assert: (self topEntity isOfType: FASTPyString).
238+
self assert: (self topEntity isOfType: FASTTLiteral).
239+
self assert: (self topEntity isOfType: FASTTStringLiteral).
240+
stack pop.
241+
242+
stack push: (stack top strings at: 2).
243+
self assert: self topEntity sourceCode equals: '"instance installed"'.
244+
self assert: (self topEntity isOfType: FASTPyString).
245+
self assert: (self topEntity isOfType: FASTTLiteral).
246+
self assert: (self topEntity isOfType: FASTTStringLiteral)
247+
]
248+
197249
{ #category : 'tests' }
198250
FASTPythonImporterTest >> testAssignment [
199251

‎src/FAST-Python-Tools/TSFASTPythonImporter.class.st‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ TSFASTPythonImporter >> visitArgumentList: aTSNode [
5454
{ #category : 'visiting' }
5555
TSFASTPythonImporter >> visitAssertStatement: aTSNode [
5656

57-
^ self visitStatement: aTSNode
57+
self onNextContextDo: [ :entry | entry add: #expressions asAliasOfField: '<unnamedChild>' ].
58+
59+
^ self handleNode: aTSNode kind: FASTPyAssertStatement
5860
]
5961

6062
{ #category : 'visiting' }

0 commit comments

Comments
 (0)