Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20738 dictionarystore string generates incorrect source code when a negative number is in values #538

Merged
merged 2 commits into from Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Collections-Support/WeakKeyAssociation.class.st
Expand Up @@ -113,7 +113,7 @@ WeakKeyAssociation >> printOn: aStream [

{ #category : #printing }
WeakKeyAssociation >> storeOn: aStream [
"Store in the format (key->value)"
"Store in the format (WeakKeyAssociation key: theKey value: theValue)"
aStream
nextPut: $(;
nextPutAll: self class name.
Expand Down
19 changes: 19 additions & 0 deletions src/Collections-Tests/AssociationTest.class.st
Expand Up @@ -55,3 +55,22 @@ AssociationTest >> testIsSelfEvaluating [
description: 'a self evaluating should evaluate as self'].

]

{ #category : #tests }
AssociationTest >> testStoreOnNegativeInteger [
| association storeString |
association := 'a'-> -1.

storeString := String streamContents: [ :s | association storeOn: s ].

self assert: storeString equals: '(''a''-> -1)'
]

{ #category : #tests }
AssociationTest >> testStoreOnPositiveInteger [
| association storeString |
association := 'a'-> 1.
storeString := String streamContents: [ :s | association storeOn: s ].

self assert: storeString equals: '(''a''->1)'
]
10 changes: 10 additions & 0 deletions src/Collections-Tests/DictionaryTest.class.st
Expand Up @@ -719,6 +719,16 @@ DictionaryTest >> testSelectIsNotShallowCopy [
description: 'modifying a selection should not modify the original'
]

{ #category : #'tests - printing' }
DictionaryTest >> testStoreOnWithNegativeInteger [
| dictionary |
dictionary := { 'x' -> -1 } as: self classToBeTested.

self
assert: (String streamContents: [ :s | dictionary storeOn: s ])
equals: '((',self classToBeTested name,' new) add: (''x''-> -1); yourself)'
]

{ #category : #requirements }
DictionaryTest >> valueNotIn [
" return a value not included in nonEmpty "
Expand Down
2 changes: 1 addition & 1 deletion src/Collections-Tests/SmallDictionaryTest.class.st
Expand Up @@ -23,5 +23,5 @@ SmallDictionaryTest >> classToBeTested [
SmallDictionaryTest >> testStoreOn [
"self debug: #testStoreOn"

self assert: self nonEmptyDict storeString = ('((', self nonEmptyDict class printString , ' new) add: (#a->1); add: (#b->30); add: (#c->1); add: (#d->-2); yourself)')
self assert: self nonEmptyDict storeString = ('((', self nonEmptyDict class printString , ' new) add: (#a->1); add: (#b->30); add: (#c->1); add: (#d-> -2); yourself)')
]
10 changes: 10 additions & 0 deletions src/Collections-Tests/WeakKeyDictionaryTest.class.st
Expand Up @@ -114,3 +114,13 @@ WeakKeyDictionaryTest >> testGrow [
"Keys are gone but not yet finalized."
dict grow.
]

{ #category : #'tests - printing' }
WeakKeyDictionaryTest >> testStoreOnWithNegativeInteger [
| dictionary |
dictionary := { 'x' -> -1 } as: self classToBeTested.

self
assert: (String streamContents: [ :s | dictionary storeOn: s ])
equals: '((',self classToBeTested name,' new) add: (WeakKeyAssociation key: ''x'' value: -1); yourself)'
]
24 changes: 24 additions & 0 deletions src/Kernel-Tests-WithCompiler/AssociationTest.extension.st
@@ -0,0 +1,24 @@
Extension { #name : #AssociationTest }

{ #category : #'*Kernel-Tests-WithCompiler' }
AssociationTest >> testStoreOnNegativeIntegerRoundtrip [
| association storeString evaluated |
association := 'a'-> -1.

storeString := String streamContents: [ :s | association storeOn: s ].

evaluated := Compiler evaluate: storeString.

self assert: association equals: evaluated
]

{ #category : #'*Kernel-Tests-WithCompiler' }
AssociationTest >> testStoreOnPositiveIntegerRoundtrip [
| association storeString evaluated |
association := 'a'-> 1.
storeString := String streamContents: [ :s | association storeOn: s ].

evaluated := Compiler evaluate: storeString.

self assert: association equals: evaluated
]
15 changes: 15 additions & 0 deletions src/Kernel-Tests-WithCompiler/SmallDictionaryTest.extension.st
@@ -0,0 +1,15 @@
Extension { #name : #SmallDictionaryTest }

{ #category : #'*Kernel-Tests-WithCompiler' }
SmallDictionaryTest >> testStoreOnRoundTrip [
| dictionary storeString evalutated |
dictionary := self classToBeTested new.
dictionary
add: #a -> 1;
add: #b -> 30;
add: #c -> 1;
add: #d -> -2.
storeString := String streamContents: [ :s | dictionary storeOn: s ].
evalutated := Compiler evaluate: storeString.
self assert: dictionary equals: evalutated
]
12 changes: 12 additions & 0 deletions src/Kernel-Tests/FloatTest.class.st
Expand Up @@ -960,6 +960,18 @@ FloatTest >> testStoreBase16 [
description: 'the radix prefix should not be omitted, except in base 10'
]

{ #category : #'tests - printing' }
FloatTest >> testStoreOn [
| float |
float := -1.2.

self assert: (String streamContents: [ :s | float storeOn: s ]) equals: ' -1.2'.

float := 1.2.

self assert: (String streamContents: [ :s | float storeOn: s ]) equals: '1.2'
]

{ #category : #'tests - conversion' }
FloatTest >> testStringAsNumber [
"This covers parsing in Number>>readFrom:"
Expand Down
12 changes: 12 additions & 0 deletions src/Kernel-Tests/IntegerTest.class.st
Expand Up @@ -1535,6 +1535,18 @@ IntegerTest >> testSqrtFloor [

]

{ #category : #'tests - printing' }
IntegerTest >> testStoreOn [
| integer |
integer := 42.

self assert: (String streamContents: [ :s | integer storeOn: s ]) equals: '42'.

integer := -42.

self assert: (String streamContents: [ :s | integer storeOn: s ]) equals: ' -42'.
]

{ #category : #'tests - instance creation' }
IntegerTest >> testStringAsNumber [
"This covers parsing in Number>>readFrom:
Expand Down
9 changes: 9 additions & 0 deletions src/Kernel-Tests/LargeNegativeIntegerTest.class.st
Expand Up @@ -17,3 +17,12 @@ LargeNegativeIntegerTest >> testEmptyTemplate [
self assert: i printString = '-0'.
self assert: i normalize = 0
]

{ #category : #'tests-printing' }
LargeNegativeIntegerTest >> testStoreOn [
| integer |
integer := -1073741825.
self
assert: integer class equals: LargeNegativeInteger;
assert: (String streamContents: [ :s | integer storeOn: s ]) equals: ' -1073741825'.
]
9 changes: 9 additions & 0 deletions src/Kernel-Tests/LargePositiveIntegerTest.class.st
Expand Up @@ -65,3 +65,12 @@ LargePositiveIntegerTest >> testNormalize [
self should: ((SmallInteger minVal - 1 + 1) == SmallInteger minVal).
self assert: (SmallInteger minVal - 3 + 6) == (SmallInteger minVal+3).
]

{ #category : #'tests-printing' }
LargePositiveIntegerTest >> testStoreOn [
| integer |
integer := 1073741824.
self
assert: integer class equals: LargePositiveInteger;
assert: (String streamContents: [ :s | integer storeOn: s ]) equals: '1073741824'.
]
2 changes: 1 addition & 1 deletion src/Kernel/Float.class.st
Expand Up @@ -1404,7 +1404,7 @@ Float >> storeOn: aStream [
Float >> storeOn: aStream base: base [
"Print the Number exactly so it can be interpreted back unchanged"
self isFinite
ifTrue: [self signBit = 1 ifTrue: [aStream nextPutAll: '-'].
ifTrue: [self signBit = 1 ifTrue: [aStream nextPutAll: ' -'].
base = 10 ifFalse: [aStream print: base; nextPut: $r].
self = 0.0
ifTrue: [aStream nextPutAll: '0.0']
Expand Down
8 changes: 8 additions & 0 deletions src/Kernel/Integer.class.st
Expand Up @@ -2038,6 +2038,14 @@ Integer >> sqrtFloor [
^guess
]

{ #category : #printing }
Integer >> storeOn: aStream [
self < 0
ifTrue: [ aStream space ].

super storeOn: aStream.
]

{ #category : #'printing-numerative' }
Integer >> storeOn: aStream base: base [
"Print a representation of the receiver on the stream
Expand Down