Skip to content

Commit

Permalink
Merge pull request #13 from Nyan11/better_traits_tests
Browse files Browse the repository at this point in the history
Change traits methods to serialize
  • Loading branch information
Nyan11 authored Oct 1, 2024
2 parents eea79a4 + 9348c40 commit 7f86385
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 262 deletions.
30 changes: 18 additions & 12 deletions src/Stash-Serialization/BlockClosure.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ Extension { #name : #BlockClosure }
{ #category : #'*Stash-Serialization' }
BlockClosure >> asStashConstructor [

| variables props temps |
| variables props |
variables := (self sourceNode variableNodes collect: #name) asSet.

((variables select: [ :each | each first isUppercase ]) allSatisfy: [ :each | Smalltalk environment at: each ifPresent: [ true ] ifAbsent: [ false ] ]) ifFalse: [ StashCannotSerializeBlockClosure new
context: self;
signal:
'The BlockClosure reference a global variable that as not been found on the image. It cannot be serialize without risk.'
].
variables := variables reject:[ :each | each first isUppercase ].
props := self sourceNode allArgumentVariables, self sourceNode allTemporaryVariables.

((variables select: [ :each | each first isUppercase ]) allSatisfy: [
:each |
Smalltalk environment
at: each
ifPresent: [ true ]
ifAbsent: [ false ] ]) ifFalse: [
StashCannotSerializeBlockClosure new
context: self;
signal:
'The BlockClosure reference a global variable that as not been found on the image. It cannot be serialize without risk.' ].
variables := variables reject: [ :each | each first isUppercase ].
props := self sourceNode allArgumentVariables
, self sourceNode allTemporaryVariables.
(props size >= variables size and: [ props includesAll: variables ])
ifFalse: [
^ StashCannotSerializeBlockClosure new
context: self;
signal:
'The BlockClosure reference an outer context. It cannot be serialize without risk.' ].
context: self;
signal:
'The BlockClosure reference an outer context. It cannot be serialize without risk.' ].
^ self printString
]
16 changes: 0 additions & 16 deletions src/Stash-Serialization/Object.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@ Object >> allSetterAndGettersForMyStash [
^ pragmas flatCollect: [ :p | p method receiver: self withArguments: #( ) executeMethod: p method ].
]

{ #category : #'*Stash-Serialization' }
Object >> allSetterAndGettersForMyStashForMyTraits [

<stashAccessors>
| traits |
traits := Set new.
traits addAll: self class allTraits.
self class allSuperclassesDo: [ :class | traits addAll: class allTraits].
^ traits flatCollect: [ :trait |
trait localMethodDict
at: #allSetterAndGettersOfTraitForMyStash:
ifPresent: [ :method |
method valueWithReceiver: self arguments: { self } ]
ifAbsent: [ { } ] ]
]

{ #category : #'*Stash-Serialization' }
Object >> asStashConstructor [

Expand Down
18 changes: 0 additions & 18 deletions src/Stash-Serialization/StashSetterGetterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,6 @@ StashSetterGetterTest >> testObject1 [
self assert: newObject name equals: 'test1'
]

{ #category : #tests }
StashSetterGetterTest >> testObject10 [

| object source newObject |
object := StashTestSetterGetter4 new
name: 'test1';
yourself.
source := Stash new serialize: object.
self assert: source equals: 'StashTestSetterGetter4 new
name: ''test1'';
yourself'.

newObject := self class compiler
source: source;
evaluate.
self assert: newObject name equals: 'test1'
]

{ #category : #tests }
StashSetterGetterTest >> testObject2 [

Expand Down
15 changes: 8 additions & 7 deletions src/Stash-Serialization/StashTestOnlySet1.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ Class {
#category : #'Stash-Serialization-test-cases'
}

{ #category : #initialization }
StashTestOnlySet1 >> initialize [

state := false
]

{ #category : #'as yet unclassified' }
StashTestOnlySet1 >> allSetterAndGettersForMyStash [
StashTestOnlySet1 >> stashAccessors [

<stashAccessors>
^ { ([ :testObject |
testObject state
ifTrue: [ #stateTrue ]
ifFalse: [ #stateFalse ] ] -> self) onlySetOnStash }
]

{ #category : #initialization }
StashTestOnlySet1 >> initialize [

state := false
]

{ #category : #accessing }
StashTestOnlySet1 >> state [

Expand Down
22 changes: 12 additions & 10 deletions src/Stash-Serialization/StashTestOnlySet2.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ Class {
#category : #'Stash-Serialization-test-cases'
}

{ #category : #'as yet unclassified' }
StashTestOnlySet2 >> allSetterAndGettersForMyStash [

self state ifFalse: [ ^ { } ].
^ { [ :testObject |
testObject state
ifTrue: [ #stateTrue ]
ifFalse: [ #stateFalse ] ] onlySetOnStash }
]

{ #category : #initialization }
StashTestOnlySet2 >> initialize [

state := false.
]

{ #category : #'as yet unclassified' }
StashTestOnlySet2 >> stashAccessors [

<stashAccessors>

self state ifFalse: [ ^ { } ].
^ { [ :testObject |
testObject state
ifTrue: [ #stateTrue ]
ifFalse: [ #stateFalse ] ] onlySetOnStash }
]

{ #category : #accessing }
StashTestOnlySet2 >> state [

Expand Down
16 changes: 9 additions & 7 deletions src/Stash-Serialization/StashTestOnlySet3.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ Class {
#category : #'Stash-Serialization-test-cases'
}

{ #category : #initialization }
StashTestOnlySet3 >> initialize [

state := false.
]

{ #category : #'as yet unclassified' }
StashTestOnlySet3 >> allSetterAndGettersForMyStash [
StashTestOnlySet3 >> stashAccessors [

<stashAccessors>

self state ifFalse: [ ^ { } ].
self state ifTrue: [ ^ { #stateTrue onlySetOnStash } ].
Expand All @@ -18,12 +26,6 @@ StashTestOnlySet3 >> allSetterAndGettersForMyStash [
ifFalse: [ #stateFalse ] ] onlySetOnStash }
]

{ #category : #initialization }
StashTestOnlySet3 >> initialize [

state := false.
]

{ #category : #accessing }
StashTestOnlySet3 >> state [

Expand Down
14 changes: 8 additions & 6 deletions src/Stash-Serialization/StashTestSetterGetter1.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ Class {
#category : #'Stash-Serialization-test-cases'
}

{ #category : #'as yet unclassified' }
StashTestSetterGetter1 >> allSetterAndGettersForMyStash [

^ { #name: -> #name }
]

{ #category : #accessing }
StashTestSetterGetter1 >> name [

Expand All @@ -24,3 +18,11 @@ StashTestSetterGetter1 >> name: anObject [

name := anObject
]

{ #category : #'as yet unclassified' }
StashTestSetterGetter1 >> stashAccessors [

<stashAccessors>

^ { (#name: -> #name) }
]
14 changes: 8 additions & 6 deletions src/Stash-Serialization/StashTestSetterGetter2.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ Class {
#category : #'Stash-Serialization-test-cases'
}

{ #category : #'as yet unclassified' }
StashTestSetterGetter2 >> allSetterAndGettersForMyStash [

^ { #name }
]

{ #category : #accessing }
StashTestSetterGetter2 >> name [

Expand All @@ -24,3 +18,11 @@ StashTestSetterGetter2 >> name: anObject [

name := anObject
]

{ #category : #'as yet unclassified' }
StashTestSetterGetter2 >> stashAccessors [

<stashAccessors>

^ { #name }
]
14 changes: 8 additions & 6 deletions src/Stash-Serialization/StashTestSetterGetter3.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ Class {
#category : #'Stash-Serialization-test-cases'
}

{ #category : #'as yet unclassified' }
StashTestSetterGetter3 >> allSetterAndGettersForMyStash [

^ { (#name: -> [ :obj | obj name ]) }
]

{ #category : #accessing }
StashTestSetterGetter3 >> name [

Expand All @@ -24,3 +18,11 @@ StashTestSetterGetter3 >> name: anObject [

name := anObject
]

{ #category : #'as yet unclassified' }
StashTestSetterGetter3 >> stashAccessors [

<stashAccessors>

^ { (#name: -> [ :obj | obj name ]) }
]
27 changes: 0 additions & 27 deletions src/Stash-Serialization/StashTestSetterGetter4.class.st

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
Class {
#name : #StashTestTraits2,
#name : #StashTestTraits,
#superclass : #Object,
#traits : 'TStashTest4',
#classTraits : 'TStashTest4 classTrait',
#traits : 'TStashTest',
#classTraits : 'TStashTest classTrait',
#instVars : [
'model4'
],
#category : #'Stash-Serialization-test-cases'
}

{ #category : #initialization }
StashTestTraits2 >> initialize [
StashTestTraits >> initialize [

model4 := StashTestTraitsModel new.
]

{ #category : #'as yet unclassified' }
StashTestTraits2 >> model4 [
StashTestTraits >> model4 [

^ model4
]
30 changes: 0 additions & 30 deletions src/Stash-Serialization/StashTestTraits1.class.st

This file was deleted.

5 changes: 0 additions & 5 deletions src/Stash-Serialization/StashTestTraits1SubClass.class.st

This file was deleted.

5 changes: 0 additions & 5 deletions src/Stash-Serialization/StashTestTraits2SubClass.class.st

This file was deleted.

5 changes: 5 additions & 0 deletions src/Stash-Serialization/StashTestTraitsSubClass.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Class {
#name : #StashTestTraitsSubClass,
#superclass : #StashTestTraits,
#category : #'Stash-Serialization-test-cases'
}
Loading

0 comments on commit 7f86385

Please sign in to comment.