Skip to content

Commit e808008

Browse files
authored
Add #ifNotNil:ifNil: to Nil and Object (#123)
2 parents f11313b + 7b843e1 commit e808008

File tree

9 files changed

+45
-34
lines changed

9 files changed

+45
-34
lines changed

Examples/Benchmarks/TestSuite/Reflection2Test.som

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Reflection2Test = TestCase (
7878
testSelectors = (
7979
| sels |
8080
sels := Object selectors.
81-
self assert: 32 equals: sels length.
81+
self assert: 33 equals: sels length.
8282

8383
sels contains: #=.
8484
self assert: (Object hasMethod: #=).

Examples/Benchmarks/TestSuite/Reflection3Test.som

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Reflection3Test = TestCase (
7878
testSelectors = (
7979
| sels |
8080
sels := Object selectors.
81-
self assert: 32 equals: sels length.
81+
self assert: 33 equals: sels length.
8282

8383
sels contains: #=.
8484
self assert: (Object hasMethod: #=).

Examples/Benchmarks/TestSuite/Reflection4Test.som

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Reflection4Test = TestCase (
7878
testSelectors = (
7979
| sels |
8080
sels := Object selectors.
81-
self assert: 32 equals: sels length.
81+
self assert: 33 equals: sels length.
8282

8383
sels contains: #=.
8484
self assert: (Object hasMethod: #=).

Examples/Benchmarks/TestSuite/Reflection5Test.som

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Reflection5Test = TestCase (
7878
testSelectors = (
7979
| sels |
8080
sels := Object selectors.
81-
self assert: 32 equals: sels length.
81+
self assert: 33 equals: sels length.
8282

8383
sels contains: #=.
8484
self assert: (Object hasMethod: #=).

Examples/Benchmarks/TestSuite/ReflectionTest.som

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ ReflectionTest = TestCase (
7878
testSelectors = (
7979
| sels |
8080
sels := Object selectors.
81-
self assert: 32 equals: sels length.
81+
self assert: 33 equals: sels length.
8282

8383
sels contains: #=.
8484
self assert: (Object hasMethod: #=).

Smalltalk/Nil.som

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Nil = (
2727

2828
"Converting"
2929
asString = ( ^'nil' )
30-
30+
3131
"Comparing"
3232
isNil = ( ^true )
3333
notNil = ( ^false )
@@ -36,5 +36,5 @@ Nil = (
3636
ifNil: aBlock = (^aBlock value)
3737
ifNotNil: aBlock = (^self)
3838
ifNil: goBlock ifNotNil: noGoBlock = (^goBlock value)
39-
39+
ifNotNil: noGoBlock ifNil: goBlock = (^goBlock value)
4040
)

Smalltalk/Object.som

+15-14
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ THE SOFTWARE.
2626
Object = nil (
2727
class = primitive
2828
objectSize = primitive "size in bytes"
29-
29+
3030
"Comparing"
3131

3232
" If you override =, you MUST override hashcode as well. The rule
@@ -38,48 +38,49 @@ Object = nil (
3838
~= other = (^ (self == other) not )
3939
isNil = ( ^false )
4040
notNil = ( ^true )
41-
41+
4242
"Converting"
4343
asString = ( ^'instance of ' + (self class) )
4444
, element = ( ^(Vector new append: self) append: element )
4545
hashcode = primitive
46-
46+
4747
"Evaluating"
4848
value = ( ^self )
49-
49+
5050
"Convenience"
5151
ifNil: aBlock = (^self)
5252
ifNotNil: aBlock = (^aBlock value)
5353
ifNil: noGoBlock ifNotNil: goBlock = (^goBlock value)
54-
54+
ifNotNil: goBlock ifNil: noGoBlock = (^goBlock value)
55+
5556
"Printing"
5657
print = ( self asString print )
5758
println = ( self print. system printNewline )
5859

5960
"Debugging"
6061
inspect = primitive
6162
halt = primitive
62-
63+
6364
"Error handling"
6465
error: string = ( '' println. ('ERROR: ' + string) println. system exit: 1 )
65-
66+
6667
"Abstract method support"
6768
subclassResponsibility = (
6869
self error: 'This method is abstract and should be overridden'
6970
)
70-
71+
7172
"Error recovering"
7273
doesNotUnderstand: selector arguments: arguments = (
7374
self error:
7475
('Method ' + selector + ' not found in class ' + self class name)
7576
)
76-
77+
7778
escapedBlock: block = (
7879
self error: 'Block has escaped and cannot be executed'
7980
)
80-
81+
8182
unknownGlobal: name = ( ^system resolve: name )
82-
83+
8384
"Reflection"
8485
respondsTo: aSymbol = (
8586
(self class hasMethod: aSymbol)
@@ -92,13 +93,13 @@ Object = nil (
9293
ifFalse: [ cls := cls superclass ] ].
9394
^ false ]
9495
)
95-
96+
9697
perform: aSymbol = primitive
9798
perform: aSymbol withArguments: args = primitive
98-
99+
99100
perform: aSymbol inSuperclass: cls = primitive
100101
perform: aSymbol withArguments: args inSuperclass: cls = primitive
101-
102+
102103
instVarAt: idx = primitive
103104
instVarAt: idx put: obj = primitive
104105
instVarNamed: sym = primitive

TestSuite/BooleanTest.som

+10
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,14 @@ BooleanTest = TestCase (
172172
self assert: (nil ifNotNil: [ #notExec ]) is: nil.
173173
self assert: (nil ifNotNil: [ #notExec ]) is: nil.
174174
)
175+
176+
testIfNilIfNotNil = (
177+
self assert: (nil ifNil: [ #exec ] ifNotNil: [ #notExec ]) is: #exec.
178+
self assert: (self ifNil: [ #notExec ] ifNotNil: [ #exec ]) is: #exec.
179+
)
180+
181+
testIfNotNilIfNil = (
182+
self assert: (nil ifNotNil: [ #exec ] ifNil: [ #notExec ]) is: #notExec.
183+
self assert: (self ifNotNil: [ #exec ] ifNil: [ #notExec ]) is: #exec.
184+
)
175185
)

TestSuite/ReflectionTest.som

+13-13
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ReflectionTest = TestCase (
3131
self assert: (23 respondsTo: #isNil).
3232
self assert: (23 respondsTo: #+).
3333
)
34-
34+
3535
testMethods = (
3636
"First method in Object should be #class."
3737
self assert: #class equals: (Object methods at: 1) signature.
@@ -42,50 +42,50 @@ ReflectionTest = TestCase (
4242
| o |
4343
self assert: Integer equals: (23 perform: #class).
4444
self assert: (23 perform: #between:and: withArguments: (Array with: 22 with: 24)).
45-
45+
4646
o := SuperTest new.
4747
self assert: #super equals: (o perform: #something inSuperclass: SuperTestSuperClass).
48-
48+
4949
"Trying to see whether the stack in bytecode-based SOMs works properly"
5050
self assert: #a equals: ((23 perform: #class) = Integer ifTrue: [#a] ifFalse: [#b]).
5151

5252
self assert: 28 equals: 5 + (23 perform: #value).
5353
)
54-
54+
5555
testInstVarAtAndPut = (
5656
| tmp |
5757
"Testing #at: and #at:put:"
5858
tmp := Pair withKey: 3 andValue: 42.
59-
59+
6060
self assert: tmp key equals: (tmp instVarAt: 1).
61-
61+
6262
tmp instVarAt: 1 put: #foo.
6363
self assert: #foo equals: tmp key.
6464
)
65-
65+
6666
testName = (
6767
self assert: #Object equals: Object name.
6868
self assert: #'Object class' equals: Object class name.
6969
self assert: #Integer equals: 1 class name.
7070
)
71-
71+
7272
testAsString = (
7373
self assert: 'Object' equals: Object asString.
7474
self assert: 'Object class' equals: Object class asString.
7575
self assert: 'Integer' equals: 1 class asString.
7676
)
77-
77+
7878
testSelectors = (
7979
| sels |
8080
sels := Object selectors.
81-
self assert: 32 equals: sels length.
82-
81+
self assert: 33 equals: sels length.
82+
8383
sels contains: #=.
8484
self assert: (Object hasMethod: #=).
85-
85+
8686
sels contains: #value.
8787
self assert: (Object hasMethod: #value).
88-
88+
8989
sels contains: #notNil.
9090
self assert: (Object hasMethod: #notNil).
9191
)

0 commit comments

Comments
 (0)