diff --git a/src/BaselineOfBlocSerialization/BaselineOfBlocSerialization.class.st b/src/BaselineOfBlocSerialization/BaselineOfBlocSerialization.class.st index 97e0774..33eaffe 100644 --- a/src/BaselineOfBlocSerialization/BaselineOfBlocSerialization.class.st +++ b/src/BaselineOfBlocSerialization/BaselineOfBlocSerialization.class.st @@ -8,25 +8,25 @@ Class { BaselineOfBlocSerialization >> baseline: spec [ - spec for: #common do: [ - - "dependencies" + spec for: #common do: [ "dependencies" spec baseline: 'Ston' with: [ spec repository: 'github://svenvc/ston/repository' ]. + spec + baseline: 'StashSerialization' + with: [ spec repository: 'github://Nyan11/Stash/src' ]. + spec baseline: 'Bloc' with: [ spec repository: 'github://pharo-graphics/Bloc:master/src' ]. "project packages" spec package: 'Bloc-Serialization-STON'. - spec - package: 'Bloc-Serialization' - with: [ spec requires: #( 'Bloc' 'Bloc-Serialization-STON' 'Ston' ) ]. + spec package: 'Bloc-Serialization' with: [ + spec requires: #( 'Bloc' 'Bloc-Serialization-STON' + 'Ston' 'StashSerialization' ) ]. spec package: 'Bloc-Serialization-Tests' - with: [ spec requires: #( 'Bloc-Serialization' ) ]. - - ] + with: [ spec requires: #( 'Bloc-Serialization' ) ] ] ] diff --git a/src/Bloc-Serialization-Tests/BlElementSerializationTests.class.st b/src/Bloc-Serialization-Tests/BlElementSerializationTests.class.st index 308fb21..d47239c 100644 --- a/src/Bloc-Serialization-Tests/BlElementSerializationTests.class.st +++ b/src/Bloc-Serialization-Tests/BlElementSerializationTests.class.st @@ -19,7 +19,7 @@ BlElementSerializationTests >> testSerializeThenMaterialize [ element := BlElement new. newElement := element serializeThenMaterialize. - self assert: element class equals: newElement class. + self assert: element class equals: newElement class ] { #category : #tests } @@ -27,5 +27,5 @@ BlElementSerializationTests >> testShouldSerializedChildren [ | element | element := BlElement new. - self assert: element shouldSerializedChildren. + self assert: element shouldSerializedChildren ] diff --git a/src/Bloc-Serialization-Tests/BlFakeSerializer.class.st b/src/Bloc-Serialization-Tests/BlFakeSerializer.class.st new file mode 100644 index 0000000..f290b13 --- /dev/null +++ b/src/Bloc-Serialization-Tests/BlFakeSerializer.class.st @@ -0,0 +1,26 @@ +Class { + #name : #BlFakeSerializer, + #superclass : #Object, + #classInstVars : [ + 'counter' + ], + #category : #'Bloc-Serialization-Tests-Core' +} + +{ #category : #initialization } +BlFakeSerializer class >> materialize: anObject [ + + counter := counter + 1 +] + +{ #category : #initialization } +BlFakeSerializer class >> materializeCount [ + + ^ counter +] + +{ #category : #initialization } +BlFakeSerializer class >> resetForTest [ + + counter := 0. +] diff --git a/src/Bloc-Serialization-Tests/BlSerializerTest.class.st b/src/Bloc-Serialization-Tests/BlSerializerTest.class.st index 34614ac..8f53501 100644 --- a/src/Bloc-Serialization-Tests/BlSerializerTest.class.st +++ b/src/Bloc-Serialization-Tests/BlSerializerTest.class.st @@ -7,6 +7,20 @@ Class { #category : #'Bloc-Serialization-Tests-Core' } +{ #category : #tests } +BlSerializerTest >> testMaterialize [ + + | error blElement | + error := nil. + + BlFakeSerializer resetForTest. + self assert: BlFakeSerializer materializeCount equals: 0. + [ blElement := BlSerializer materialize: '"BlFakeSerializer"' ] onErrorDo: [ :e | + error := e ]. + self assert: BlFakeSerializer materializeCount equals: 1. + self assert: error equals: nil. +] + { #category : #tests } BlSerializerTest >> testMaterializeEmptyString [ @@ -59,7 +73,6 @@ BlSerializerTest >> testSerializeBlElementCollection [ error := nil. result := nil. [ result := BlSerializer serialize: OrderedCollection new ] onErrorDo: [ :e | error := e ]. self deny: (error isKindOf: BlocSerializationError). "this test is ok because of a empty string is an empty collection" - self assert: result equals: 'OrderedCollection [ ]'. error := nil. result := nil. oc := OrderedCollection new. diff --git a/src/Bloc-Serialization-Tests/BlocSerializationTests.class.st b/src/Bloc-Serialization-Tests/BlocSerializationTests.class.st index b25e213..3a4b725 100644 --- a/src/Bloc-Serialization-Tests/BlocSerializationTests.class.st +++ b/src/Bloc-Serialization-Tests/BlocSerializationTests.class.st @@ -10,18 +10,39 @@ BlocSerializationTests >> serializeThenMaterialize: aBlElement [ ^ BlSerializer materialize: (BlSerializer serialize: aBlElement) ] +{ #category : #utilities } +BlocSerializationTests >> serializeThenMaterialize: aBlElement withSerializer: aBlSerializer [ + + ^ aBlSerializer materialize: (aBlSerializer serialize: aBlElement) +] + +{ #category : #'as yet unclassified' } +BlocSerializationTests >> serializersToTest [ + + ^ TBlSerializer users +] + { #category : #utilities } BlocSerializationTests >> test: aBlElement on: aTestBloc [ "This method take a blElement, execute a Bloc with assertions inside (from test implementation) for this blElement. The blElement is serialized and rebuild, the new blElement rebuild is re-tested by the Bloc with assertions to confirm the good serialization process " | newBlElement | - "Execute the test bloc with the BlElement before serialization" aTestBloc value: aBlElement. + + self serializersToTest do: [ :each | + "Serialize the blElement for building a new blElement which should be with same properties" + newBlElement := self serializeThenMaterialize: aBlElement withSerializer: each. + + "Re-execute the test bloc with the new BlElement after materialization to confirm that the new object have same properties than the previous" + aTestBloc value: newBlElement ] + - "Serialize the blElement for building a new blElement which should be with same properties" - newBlElement := self serializeThenMaterialize: aBlElement. + + +] - "Re-execute the test bloc with the new BlElement after materialization to confirm that the new object have same properties than the previous" - aTestBloc value: newBlElement +{ #category : #utilities } +BlocSerializationTests >> testNotEmptyTesting [ + self assert: self serializersToTest isNotEmpty ] diff --git a/src/Bloc-Serialization/Array.extension.st b/src/Bloc-Serialization/Array.extension.st new file mode 100644 index 0000000..56df231 --- /dev/null +++ b/src/Bloc-Serialization/Array.extension.st @@ -0,0 +1,7 @@ +Extension { #name : #Array } + +{ #category : #'*Bloc-Serialization' } +Array >> materializeAsBlElement [ + + ^ self +] diff --git a/src/Bloc-Serialization/BlSerializer.class.st b/src/Bloc-Serialization/BlSerializer.class.st index 375a12c..a2f5319 100644 --- a/src/Bloc-Serialization/BlSerializer.class.st +++ b/src/Bloc-Serialization/BlSerializer.class.st @@ -4,57 +4,57 @@ Serailizer class for Bloc Class { #name : #BlSerializer, #superclass : #Object, + #traits : 'TBlSerializer', + #classTraits : 'TBlSerializer classTrait', + #classInstVars : [ + 'serializer' + ], #category : #'Bloc-Serialization-Core' } { #category : #serialization } BlSerializer class >> materialize: aString [ "Materialize a String into a BlElement and return it. Default materializer is STON." - | blElement | - aString isString not ifTrue:[ BlocMaterializationError signal: 'Cannot materialize a no String object into BlElement' ]. - "Try to materialize and catch an error into a BlocMaterialization error" - [ blElement := STON fromString: aString ] onErrorDo: [ :e | BlocMaterializationError signal: 'Cannot support Bloc materialization of this String (', e asString, ')' ]. - blElement ifNil:[ BlocMaterializationError signal: 'Bloc materialization result is nil' ]. - ^ blElement + | serializerClassName serializerClass | + aString ifEmpty: [ ^ BlocMaterializationError new signal ]. + aString first = $" ifFalse: [ + ^ BlStonSerializer materialize: aString ]. + serializerClassName := aString lines first allButFirst allButLast. + serializerClass := Smalltalk environment classNamed: + serializerClassName. + ^ serializerClass materialize: ('' join: aString lines allButFirst) +] + +{ #category : #initialization } +BlSerializer class >> reset [ + +