Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion .smalltalk_gemstone.ston
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
SmalltalkCISpec {
#name : 'NeoJSON for GemStone',
#loading : [
SCIMetacelloLoadSpec {
#baseline : 'NeoJSON',
#directory : 'filetree',
#load : [ 'Core', 'Tests' ],
#platforms : [ #gemstone ]
#onConflict : #useIncoming,
#onWarningLog : true,
#platforms : [ #gemstone ],
#repository : 'https://github.com/GsDevKit/NeoJSON',
#useLatestMetacello : true
}
]
}
}
32 changes: 16 additions & 16 deletions .smalltalkci/.unit-tests.ston
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
SmalltalkCISpec {
#loading : [
SCIMetacelloLoadSpec {
#baseline : 'NeoJSON',
#directory : '../repository',
#load : [ 'build' ],
#platforms : [ #pharo ]
}
],
#testing : {
#coverage : {
#packages : [ 'Neo-JSON*' ],
#format: #lcov
}
}
}
SmalltalkCISpec {
#loading : [
SCIMetacelloLoadSpec {
#baseline : 'NeoJSON',
#directory : '../repository',
#load : [ 'build' ],
#platforms : [ #pharo ]
}
],
#testing : {
#coverage : {
#packages : [ 'Neo-JSON*' ],
#format: #lcov
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ baseline: spec
group: 'Examples' with: #('Neo-JSON-Pharo-Examples') ].
spec
for: #gemstone
do: [ spec
do: [
spec
baseline: 'OrderedDictionary'
with: [ spec
loads: #('Core');
repository: 'github://GsDevKit/OrderedDictionary:master/repository' ].
spec
package: 'Neo-JSON-GemStone-Core' with: [ spec requires: #('Neo-JSON-Core') ];
package: 'Neo-JSON-GemStone-Tests' with: [ spec requires: #('Neo-JSON-Tests') ];
package: 'Neo-JSON-GemStone-Examples' with: [ spec requires: #('Neo-JSON-Core') ];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*neo-json-pharo-core
*neo-json-core
neoJsonOn: neoJSONWriter
neoJSONWriter writeMap: self
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ decimalDigitLength
"100000000 decimalDigitLength >>> 9"
"SmallInteger maxVal decimalDigitLength >>> 19"

self negative ifTrue: [^self negated decimalDigitLength].
self negative ifTrue: [ ^ self negated decimalDigitLength ].
^self < 10000
ifTrue:
[self < 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ numberOfDigitsInBase: b
Mostly same as super but an optimized version for base 10 case"

self < 0 ifTrue: [^self negated numberOfDigitsInBase: b].
^super numberOfDigitsInBase: b
^ super numberOfDigitsInBase: b
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"category" : "Neo-JSON-Gemstone-Examples",
"category" : "Neo-JSON-GemStone-Examples",
"classinstvars" : [
],
"classvars" : [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"category" : "Neo-JSON-Gemstone-Examples",
"category" : "Neo-JSON-GemStone-Examples",
"classinstvars" : [
],
"classvars" : [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"category" : "Neo-JSON-Gemstone-Examples",
"category" : "Neo-JSON-GemStone-Examples",
"classinstvars" : [
],
"classvars" : [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"category" : "Neo-JSON-Gemstone-Examples",
"category" : "Neo-JSON-GemStone-Examples",
"classinstvars" : [
],
"classvars" : [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
testing
testFindPaths
| json paths testingArray |
| json paths |
json := self class exampleJSONSchema.
testingArray := #((#'properties' #'street_address') (#'$defs' #'country')).

paths := json findPaths: [ :object | object isDictionary and: [ object includesKey: #'$anchor' ] ].
self deny: paths isEmpty.
(paths asArray) do: [ :eachArray |
self assert: (testingArray includes: eachArray) ].
paths := json findPaths: [ :object | object isDictionary and: [ (object at: #'$anchor') = 'street_address' ] ].
self assert: (testingArray includes: paths flattened).
paths := json findPaths: [ :object | object isDictionary and: [ (object at: #'$anchor') = 'country' ] ].
self assert: (testingArray includes: paths flattened).

self assert: paths asArray equals: #((properties street_address) (#'$defs' #'country')).
self assert: ((json atPath: paths first) at: #'$anchor') equals: 'street_address'.
self assert: ((json atPath: paths second) at: #'$anchor') equals: 'country'.

paths := json findPaths: [ :object | object isDictionary and: [ (object at: #'foo') = 'bar' ] ].
self assert: paths isEmpty.

Expand Down
15 changes: 15 additions & 0 deletions repository/BaselineOfNeoJSON/BaselineOfNeoJSON.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,19 @@ BaselineOfNeoJSON >> baseline: spec [
group: 'Core' with: #('Neo-JSON-Core' 'Neo-JSON-Pharo-Core');
group: 'Tests' with: #('Neo-JSON-Tests' 'Neo-JSON-Pharo-Tests');
group: 'Examples' with: #('Neo-JSON-Pharo-Examples') ].
spec
for: #gemstone
do: [
spec
baseline: 'OrderedDictionary'
with: [ spec
loads: #('Core');
repository: 'github://GsDevKit/OrderedDictionary:master/repository' ].
spec
package: 'Neo-JSON-GemStone-Core' with: [ spec requires: #('Neo-JSON-Core') ];
package: 'Neo-JSON-GemStone-Tests' with: [ spec requires: #('Neo-JSON-Tests') ];
package: 'Neo-JSON-GemStone-Examples' with: [ spec requires: #('Neo-JSON-Core') ];
group: 'Core' with: #('Neo-JSON-Core' 'Neo-JSON-GemStone-Core');
group: 'Tests' with: #('Neo-JSON-Tests' 'Neo-JSON-GemStone-Tests');
group: 'Examples' with: #('Neo-JSON-GemStone-Examples') ].
]
6 changes: 6 additions & 0 deletions repository/Neo-JSON-Core/OrderedDictionary.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #OrderedDictionary }

{ #category : #'*neo-json-core' }
OrderedDictionary >> neoJsonOn: neoJSONWriter [
neoJSONWriter writeMap: self
]
25 changes: 25 additions & 0 deletions repository/Neo-JSON-GemStone-Core/BinaryFloat.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Extension { #name : #'BinaryFloat' }

{ #category : #'*neo-json-gemstone-core' }
BinaryFloat class >> negativeInfinity [

^ self fromString: #'MinusInfinity'
]

{ #category : #'*neo-json-gemstone-core' }
BinaryFloat class >> zero [

^ 0.0
]

{ #category : #'*neo-json-gemstone-core' }
BinaryFloat >> isFinite [

^(self - self) = 0.0
]

{ #category : #'*neo-json-gemstone-core' }
BinaryFloat >> isZero [

^ self = 0.0
]
85 changes: 85 additions & 0 deletions repository/Neo-JSON-GemStone-Core/Integer.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
Extension { #name : #'Integer' }

{ #category : #'*neo-json-gemstone-core' }
Integer >> asCharacterDigit [

^ Character digitValue: self
]

{ #category : #'*neo-json-gemstone-core' }
Integer >> digitAt: anExponent base: base [

^ self // (base raisedToInteger: anExponent - 1) \\ base

]

{ #category : #'*neo-json-gemstone-core' }
Integer >> isPowerOfTwo [
"Return true if the receiver is an integral power of two."
^ self ~= 0 and: [ (self bitAnd: self-1) = 0 ]
]

{ #category : #'*neo-json-gemstone-core' }
Integer >> numberOfDigitsInBase: b [
"Return how many digits are necessary to print this number in base b.
This does not count any place for minus sign, radix prefix or whatever.
Note that this algorithm may cost a few operations on LargeInteger."

| nDigits q total |
self negative ifTrue: [^self negated numberOfDigitsInBase: b].
self < b ifTrue: [^1].
b isPowerOfTwo ifTrue: [^self highBit + b highBit - 2 quo: b highBit - 1].

"A conversion from base 2 to base b has to be performed.
This algorithm avoids Float computations like (self log: b) floor + 1,
1) because they are inexact
2) because LargeInteger might overflow
3) because this algorithm might be cheaper than conversion"

q := self.
total := 0.
["Make an initial nDigits guess that is lower than or equal to required number of digits"
nDigits := b = 10
ifTrue: [((q highBit - 1) * 1233 >> 12) + 1. "This is because (2 log)/(10 log)*4096 is slightly greater than 1233"]
ifFalse: [q highBit quo: b highBit].
total := total + nDigits.

"See how many digits remains above these first nDigits guess"
(q := q quo: (b raisedToInteger: nDigits)) < b] whileFalse.
^q = 0
ifTrue: [total]
ifFalse: [total + 1]
]

{ #category : #'*neo-json-gemstone-core' }
Integer >> print: positiveNumberString on: aStream prefix: prefix length: minimum padded: zeroFlag [
"Return a String based on concatenation of positiveNumberString with prefix then padded by 0 is zeroFlag is set for a minimum length."

"(String streamContents: [ :s | 10 print: '10' on: s prefix: 'zz' length: 4 padded: true ] ) >>> 'zz10'"

| padLength |
padLength := minimum - positiveNumberString size - prefix size.
padLength > 0
ifTrue: [ zeroFlag
ifTrue: [ aStream nextPutAll: prefix; nextPutAll: (String new: padLength withAll: $0) ]
ifFalse: [ aStream nextPutAll: (String new: padLength withAll: Character space); nextPutAll: prefix ] ]
ifFalse: [ aStream nextPutAll: prefix ].
aStream nextPutAll: positiveNumberString
]

{ #category : #'*neo-json-gemstone-core' }
Integer >> printOn: aStream base: base length: minimum padded: zeroFlag [
"Return a String representation of this number in base b with a minimum length and padded by 0 if zeroFlag is set"

"(String streamContents: [ :s | 10 printOn: s base: 10 length: 4 padded: true] ) >>> '0010'"
"(String streamContents: [ :s | -10 printOn: s base: 10 length: 4 padded: true] ) >>> '-010'"

| prefix |
prefix := self negative ifTrue: ['-'] ifFalse: [ '' ].
self
print: (self abs printStringBase: base)
on: aStream
prefix: prefix
length: minimum
padded: zeroFlag
]
21 changes: 21 additions & 0 deletions repository/Neo-JSON-GemStone-Core/KeyValueDictionary.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Extension { #name : #'KeyValueDictionary' }

{ #category : #'*neo-json-gemstone-core' }
KeyValueDictionary class >> newFromPairs: anArray [
"Answer an instance of me associating (anArray at:i) to (anArray at: i+i)
for each odd i. anArray must have an even number of entries.
Dictionary newFromPairs: {'Red' . Color red . 'Blue' . Color blue . 'Green' . Color green}. "
| newDictionary |

newDictionary := self new: (anArray size/2).
1 to: (anArray size-1) by: 2 do: [ :i|
newDictionary at: (anArray at: i) put: (anArray at: i+1).
].
^ newDictionary

]

{ #category : #'*neo-json-gemstone-core' }
KeyValueDictionary >> neoJsonOn: neoJSONWriter [
neoJSONWriter writeMap: self
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #'MultiByteString' }

{ #category : #'*neo-json-gemstone-core' }
MultiByteString >> neoJsonOn: neoJSONWriter [
neoJSONWriter writeString: self
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #'OrderedDictionary' }

{ #category : #'*neo-json-gemstone-core' }
OrderedDictionary >> neoJsonOn: neoJSONWriter [
neoJSONWriter writeMap: self
]
Loading
Loading