Skip to content

Commit

Permalink
Merge pull request #30 from guillep/harvest-p9
Browse files Browse the repository at this point in the history
Harvest changes done in Pharo9
  • Loading branch information
svenvc authored Jul 12, 2021
2 parents 4c34015 + 3fa5d6f commit c5f69da
Show file tree
Hide file tree
Showing 55 changed files with 149 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*STON-Core
fromSton: stonReader
"Read a map representation containing element/occurences pairs"
"Read a map representation containing element/occurrences pairs"

| bag |
bag := self new.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*STON-Core
stonOn: stonWriter
"Use a map with element-occurences pairs as representation"
"Use a map with element-occurrences pairs as representation"

stonWriter
writeObject: self
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*ston-core
stonContainSubObjects
^ false
4 changes: 2 additions & 2 deletions repository/STON-Core.package/STON.class/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ STON is more or less a superset of JSON and is backwards compatible with JSON wh

- class information (except for lists (Array) and maps (Dictionary))
- proper handling of shared and circular references
- more Smalltalk like syntax (Symbols with #, single qouted Strings, nil instead of null)
- more Smalltalk like syntax (Symbols with #, single quoted Strings, nil instead of null)
- more defined special types (Date, Time, DataAndTime, ByteArray, Point)

Parsing JSON is done using #fromString: or #fromStream: with the results being composed of Arrays and Dictionaries.
Expand All @@ -45,7 +45,7 @@ For a much more sophisticated JSON parser/writer implementation, have a look at

Like JSON, STON does not allow for comments. However, a preprocessor option can skip C style comments before parsing.

I also define some contants used in the implementation: the class used as list, map and association, as well as the optional class name key (used when reading objects using an unknown class).
I also define some constants used in the implementation: the class used as list, map and association, as well as the optional class name key (used when reading objects using an unknown class).


I m p l e m e n t a t i o n
Expand Down
2 changes: 1 addition & 1 deletion repository/STON-Core.package/STON.class/properties.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "SvenVanCaekenberghe 10/9/2018 21:14",
"commentStamp" : "",
"super" : "Object",
"category" : "STON-Core-Facade",
"classinstvars" : [ ],
Expand Down
2 changes: 1 addition & 1 deletion repository/STON-Core.package/STONJSON.class/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ STON is more or less a superset of JSON and is backwards compatible with JSON wh

- class information (except for lists (Array) and maps (Dictionary))
- proper handling of shared and circular references
- more Smalltalk like syntax (Symbols with #, single qouted Strings, nil instead of null)
- more Smalltalk like syntax (Symbols with #, single quoted Strings, nil instead of null)
- more defined special types (Date, Time, DataAndTime, ByteArray, Point)

Parsing JSON is done using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ initialize-release
convertNewLines: boolean
"When true, any newline CR, LF or CRLF read unescaped inside strings or symbols
will be converted to the newline convention chosen, see #newLine:
The default is false, not doing any convertions."
The default is false, not doing any conversions."

convertNewLines := boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*ston-core
stonContainSubObjects
^ false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*ston-core
stonContainSubObjects
^ false
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
tests
testOrderedDictionary
| odictClass odict json dict |

odictClass := self environment at: #OrderedDictionary ifAbsent: [ ^ self skip ].

odict := odictClass newFrom: {
'a' -> 42 . 'b' -> 1. 'aa' -> 4. 'c' -> 23
}.

"assert that the order is not equal in the dictionary hash table".
self

odict := odictClass newFrom: {('a' -> 42) . ('b' -> 1) . ('aa' -> 4) . ('c' -> 23)}.

"assert that the order is not equal in the dictionary hash table"
self
assertCollection: odict asArray hasSameElements: odict dictionary asArray;
deny: odict asArray equals: odict dictionary asArray.

"ordered presevered when encoding:"
json := STONJSON toString: odict.
self assert: json equals: '{"a":42,"b":1,"aa":4,"c":23}'.

"lost when decoding"
dict := STONJSON fromString: json.

self
self
assertCollection: dict asArray hasSameElements: odict asArray;
assert: dict equals: odict dictionary;
deny: dict asArray equals: odict asArray
deny: dict asArray equals: odict asArray
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
private
materialize: string
^ STON reader
on: string readStream;
optimizeForLargeStructures;
next
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
tests
testAssociation
self assert: (self materialize: '''foo'':1') equals: ('foo' -> 1).
self assert: (self materialize: '#bar:2') equals: (#bar -> 2).
self assert: (self materialize: '''foo bar'':#ok') equals: ('foo bar' -> #ok).
self assert: (self materialize: '123:456') equals: (123 -> 456).
self assert: (self materialize: '''foo'' : 1') equals: ('foo' -> 1).
self assert: (self materialize: '#bar : 2') equals: (#bar -> 2).
self assert: (self materialize: '''foo bar'' : #ok') equals: ('foo bar' -> #ok).
self assert: (self materialize: '123 : -456') equals: (123 -> -456).
self assert: (self materialize: '#foo : 1 : 2') equals: (#foo -> (1 -> 2))
self assert: (self materialize: '''foo'':1') equals: 'foo' -> 1.
self assert: (self materialize: '#bar:2') equals: #bar -> 2.
self assert: (self materialize: '''foo bar'':#ok') equals: 'foo bar' -> #ok.
self assert: (self materialize: '123:456') equals: 123 -> 456.

self assert: (self materialize: '''foo'' : 1') equals: 'foo' -> 1.
self assert: (self materialize: '#bar : 2') equals: #bar -> 2.
self assert: (self materialize: '''foo bar'' : #ok') equals: 'foo bar' -> #ok.
self assert: (self materialize: '123 : -456') equals: 123 -> -456.

self assert: (self materialize: '#foo : 1 : 2') equals: #foo -> (1 -> 2)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tests
testByteArray
self assert: (self materialize: 'ByteArray[''010203'']') equals: #(1 2 3) asByteArray
self assert: (self materialize: 'ByteArray[''010203'']') equals: #(1 2 3) asByteArray
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tests
testCharacter
self assert: (self materialize: 'Character[''A'']') identicalTo: $A.
self assert: (self materialize: 'Character[''A'']') identicalTo: $A
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
tests
testDateAndTime
| dateAndTime |
dateAndTime := DateAndTime year: 2012 month: 1 day: 1 hour: 6 minute: 30 second: 15 offset: 1 hour.
dateAndTime := DateAndTime
year: 2012
month: 1
day: 1
hour: 6
minute: 30
second: 15
offset: 1 hour.
self assert: (self materialize: 'DateAndTime[''2012-01-01T06:30:15+01:00'']') equals: dateAndTime
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
tests
testDictionary
| collection |
collection := STON mapClass new at: 1 put: 1; at: 2 put: 2; yourself.
collection := STON mapClass new
at: 1 put: 1;
at: 2 put: 2;
yourself.
self assert: (self materialize: '{1:1,2:2}') equals: collection.
self assert: (self materialize: '{}') equals: STON mapClass new.
self assert: (self materialize: '{}') equals: STON mapClass new
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
tests
testDictionaryWithComplexKeys
| collection reader |
collection := STON mapClass new at: true put: 1; at: #(foo) put: 2; yourself.
collection := STON mapClass new
at: true put: 1;
at: #(foo) put: 2;
yourself.
"allowing complex map keys used to be optional, now it is always the default"
reader := STONReader on: '{true:1,[#foo]:2}' readStream.
self assert: reader next equals: collection
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
tests
testIdentityDictionary
| collection |
collection := IdentityDictionary new at: 1 put: 1; at: 2 put: 2; yourself.
collection := IdentityDictionary new
at: 1 put: 1;
at: 2 put: 2;
yourself.
self assert: (self materialize: 'IdentityDictionary{1:1,2:2}') equals: collection.
self assert: (self materialize: 'IdentityDictionary{}') equals: IdentityDictionary new.
self assert: (self materialize: 'IdentityDictionary{}') equals: IdentityDictionary new
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
tests
testJsonString
"Allow double quotes for backwards JSON compatibility"

| string |
self assert: (self materialize: '"foo"') equals: 'foo'.
self assert: (self materialize: '"FOO"') equals: 'FOO'.
self assert: (self materialize: '"\u00E9l\u00E8ve en Fran\u00E7ais"') equals: 'élève en Français'.
string := String withAll: {
$". $'. $\. Character tab. Character cr. Character lf. Character newPage. Character backspace }.
self assert: (self materialize: '"\"\''\\\t\r\n\f\b"') equals: string.
string := String withAll: {$" . $' . $\ . Character tab . Character cr . Character lf . Character newPage . Character backspace}.
self assert: (self materialize: '"\"\''\\\t\r\n\f\b"') equals: string
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
tests
testMap
self assert: (self materialize: '{#foo:1}') equals: (STON mapClass new at: #foo put: 1; yourself).
self
assert: (self materialize: '{#foo:1}')
equals:
(STON mapClass new
at: #foo put: 1;
yourself).
self assert: (self materialize: '{}') equals: STON mapClass new
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests
testObject
self assert: (self materialize: 'Point[1,2]') equals: (1@2).
self assert: (self materialize: 'Point[1.5,-0.5]') equals: (1.5 @ -0.5).
self assert: (self materialize: 'Point[1,2]') equals: 1 @ 2.
self assert: (self materialize: 'Point[1.5,-0.5]') equals: 1.5 @ -0.5
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ testOrderedCollection
| collection |
collection := OrderedCollection with: 1 with: 2 with: 3.
self assert: (self materialize: 'OrderedCollection[1,2,3]') equals: collection.
self assert: (self materialize: 'OrderedCollection[]') equals: OrderedCollection new.
self assert: (self materialize: 'OrderedCollection[]') equals: OrderedCollection new
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tests
testPoint
self assert: (self materialize: 'Point[1,2]') equals: (1@2)
self assert: (self materialize: 'Point[1,2]') equals: 1 @ 2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests
testReferenceCycle
| array |
array := (self materialize: '[1,@1]').
array := self materialize: '[1,@1]'.
self assert: array class equals: STON listClass.
self assert: array size equals: 2.
self assert: array first equals: 1.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
tests
testReferenceSharing
| one array |
one := { #one }.
array := (self materialize: '[[#one],@2,@2]').
self assert: array = (STON listClass with: one with: one with: one).
one := {#one}.
array := self materialize: '[[#one],@2,@2]'.
self assert: array equals: (STON listClass with: one with: one with: one).
self assert: array first identicalTo: array second.
self assert: array first identicalTo: array third
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ testString
self assert: (self materialize: '''foo''') equals: 'foo'.
self assert: (self materialize: '''FOO''') equals: 'FOO'.
self assert: (self materialize: '''\u00E9l\u00E8ve en Fran\u00E7ais''') equals: 'élève en Français'.
string := String withAll: {
$". $'. $\. $/. Character tab. Character cr. Character lf. Character newPage. Character backspace }.
self assert: (self materialize: '''\"\''\\\/\t\r\n\f\b''') equals: string.
string := String withAll: {$" . $' . $\ . $/ . Character tab . Character cr . Character lf . Character newPage . Character backspace}.
self assert: (self materialize: '''\"\''\\\/\t\r\n\f\b''') equals: string
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
tests
testWhitespace
| whitespace |
whitespace := { Character space. Character tab. Character cr. Character lf }.
self assert: (self materialize: whitespace, '123') equals: 123

whitespace := {Character space . Character tab . Character cr . Character lf}.
self assert: (self materialize: whitespace , '123') equals: 123
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests
testFromString
| object |
object := STON listClass withAll: { 1. 0. -1. true. false. nil }.
object := STON listClass withAll: {1 . 0 . -1 . true . false . nil}.
self assert: (STON fromString: '[1,0,-1,true,false,nil]') equals: object
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ testRoomExitCycles
self assert: ((object first at: #exit) at: #destination) identicalTo: object second.
self assert: ((object second at: #exit) at: #origin) identicalTo: object second.
self assert: ((object second at: #exit) at: #destination) identicalTo: object first.
"Try writing again the parse model"
"Try writing again the parse model"
self assert: (STON toString: object) equals: ston
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests
testToString
| object |
object := STON listClass withAll: { 1. 0. -1. true. false. nil }.
object := STON listClass withAll: {1 . 0 . -1 . true . false . nil}.
self assert: (STON toString: object) equals: '[1,0,-1,true,false,nil]'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
acccessing
accessing
addKnownObject: object
^ self knownObjects addIfNotPresent: object
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
instance creation
fromId: idString
"Given id, return a matching instance of me, either by returning an existing known instance or by creating a new one (that is automtically added to the known instances)"
"Given id, return a matching instance of me, either by returning an existing known instance or by creating a new one (that is automatically added to the known instances)"

| uuid |
uuid := UUID fromString: idString.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
acccessing
accessing
knownObjects
^ KnownObjects ifNil: [ KnownObjects := OrderedCollection new ]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
acccessing
accessing
resetKnownObjects
KnownObjects ifNotNil: [ :collection | collection removeAll ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
private
materialize: string
^ STON reader
on: (STONCStyleCommentsSkipStream on: string readStream);
optimizeForLargeStructures;
next
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
private
materialize: string
^ (self reader: string) next
^ STON reader
on: string readStream;
next
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ testKnownObjects
self assert: object identicalTo: knownObject.
"not just the id is equal, but the rest of the object too"
self assert: object description equals: knownObject description.
STONTestKnownObject resetKnownObjects.

STONTestKnownObject resetKnownObjects
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "SvenVanCaekenberghe 10/8/2018 16:52",
"commentStamp" : "",
"super" : "TestCase",
"category" : "STON-Tests-Write-Read",
"classinstvars" : [ ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ testAssociation
self assert: (self serialize: 'foo' -> 1) equals: '''foo'':1'.
self assert: (self serialize: #bar -> 2) equals: '#bar:2'.
self assert: (self serialize: 'foo bar' -> #ok) equals: '''foo bar'':#ok'.
self assert: (self serialize: 123 -> 456) equals: '123:456'
self assert: (self serialize: 123 -> 456) equals: '123:456'
Loading

0 comments on commit c5f69da

Please sign in to comment.