[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[jl8] 01

.
self running: 'Literals'
'hello word' isLiteral not
#x isLiteral
#x asLiteral = '#x'

self running: 'access to native language'
self nativeLanguage = #jl or: [ self nativeLanguage = #py ]
#(jl py) includes: self nativeLanguage

self running: 'instVarAt tests'
Point instVarNames first isString
(Point zero instVarAt: #x) = 0
| p | p := Point new. p instVarAt: #x put: 77. ^p x = 77

self running: #kernelInlines
"self halt
12 toString = #12
#hello toString = #hello
nil toString = #nil
(self toString: 12) = #12
(self toString: #hello) = #hello
(self toString: nil) = #nil

self running: '#isObject: tests'
(self isObject: Smalltalk current newHash) not
self isObject: self
self isObject: 12
self isObject: #hello
self isObject: Point zero
self isObject: 0
self isObject: nil
self isObject: true
self isObject: false

self running: '#typeOf: tests'
(self typeOf: #hello asParameter) = (self nativeLanguage = #py ifTrue: [#str] ifFalse: [#{String}])
(self typeOf: 123 asParameter) = (self nativeLanguage = #py ifTrue: [#int] ifFalse: [#{Int64}])
(self typeOf: 123.8 asParameter) = (self nativeLanguage = #py ifTrue: [#float] ifFalse: [#{Float64}])
| f | f := self callableOf: [ true ]. self nativeLanguage = #py ifTrue: [ ^{'__0__.f()'} ] ifFalse: [ ^{'f()'} ]
| j | j := Point zero asJSONObject. ^(self isObject: j) not

self running: '#perform... tests'
(Point zero perform: #x) = 0
| p | p := Point zero. p perform: #x: with: 7. ^p x = 7
(Array perform: #with:with: withArguments: (Array with: 1 with: 2)) first = 1
[ ^true ] perform: #value

self perform: #isObject: with: #( #(123) )
self perform: #isObject: with: #( 123 )
self perform: #isObject: with: #( #123 )

self running: 'Smalltalk... tests'
Smalltalk current includesKey: #Object
(Smalltalk current includesKey: #the-thing) not
(Smalltalk current includesKey: 123) not
(Smalltalk current includesKey: Point zero) not
(Smalltalk current includesKey: nil) not
(Smalltalk current includesKey: true) not
(Smalltalk current includesKey: [ #hello ]) not
(Smalltalk current includesKey: #(1 2 3 4)) not
(Smalltalk current eval: 'return 3+4') = 7 asParameter
self nativeLanguage ~= #py or: [ (Smalltalk current eval: 'return smalltalk.classes()') = Smalltalk current classes ]
self nativeLanguage ~= #jl or: [ (Smalltalk current eval: 'return classes(smalltalk)') = Smalltalk current classes ]
Smalltalk classes = Smalltalk current classes
(Smalltalk at: #Object ifAbsent: []) notNil
Smalltalk includesKey: #Object

Smalltalk global notNil
(self isObject: Smalltalk global) not
Smalltalk gc. ^true

self running: 'Behavior tests'
Object basicNew class == Object
Object basicNew isMemberOf: Object
Point basicNew isMemberOf: Point
Point basicNew isKindOf: Point
Point basicNew isKindOf: Object
Class basicNew isKindOf: Class
#(1 2 3) isKindOf: Array
#(1 2 3) isKindOf: Collection
#(1 2 3) isKindOf: Object
Class basicNew isClass
Metaclass basicNew isKindOf: Metaclass
Array basicNew isEmpty
Point new isMemberOf: Point
Object selectors includes: #yourself
Point class selectors includes: #zero
Point new x isNil

self running: 'CompiledMethod tests'
"??? #asClosure

self running: 'Boolean tests'
true not not
true = true
false = false
true ~= false
true == true
false==false
true ~~ false
true == false not
false == true not

self running: 'Number tests'
1 = 1
3 > 2
3 >= 2
3 >= -3
-3 <= 3
3 + 4 = 7
3 * 4 = 12
128.99 truncated = 128
128.99 rounded = 129
12 isNumber
Number pi isNumber
Number pi truncated = 3
"toDo...
true isNumber not
false isNumber not

self running: 'BlockClosure tests'
[:x :y :z| self ] argumentCount = 3

self running: '#evaluate & #value'
[ true ] notNil
[ true ] value
[ true ] evaluate
true evaluate
[:what| what ] value: true
[:x :y :z| x + y - z = 0 ] value: 1 value: 2 value: 3
[:what| what ] evaluateWithArguments: (Array with: true)
true evaluateWithArguments: #(1 2 3 4 5)
[:x| x = 1 ] evaluateWithArguments: #(1 2 3 4 5)

self running: 'UndefinedObject tests'
nil asJSONObject isNil

self running: 'Collection & SequenceableCollection tests'
(#(1 2 3 4 5 6 7 8 9) indexOf: 5) = 5
| a t | a := #(). t := #(1 2 3 4 5). t do: [:x| a add: x ]. ^t = a
(#(1 2 3 4 5 6 7 8 9) detect: [:x| x >= 3] ifNone: []) = 3
#(1 2 3 4 5 6 7 8 9) detect: [:x| x >= 300] ifNone: [^true]. ^false
(#(1 2 3 4 5 6 7 8 9) detect: [:x| x >= 300] ifNone: [true]) = true
#(1 2 3 4 5 6 7 8 9) reversed = #(9 8 7 6 5 4 3 2 1)
#() isEmpty
#(1) notEmpty
(Array new: 123) notEmpty
(Array new: 123) size = 123
((Array new: 123) occurrencesOf: nil) = 123
#(1 2 3) removeAll; isEmpty
| a t | a := #(). t := #(1 2 3 4 5). t reverseDo: [:x| a add: x ]. ^t = a reversed
#(1 2 3 4 5 6 7 8 9) includes: 5
(#(1 2 3 4 5 6 7 8 9) includes: nil) not
(#(1 2 3 4 5 6 7 8 9) occurrencesOf: nil) = 0
(#(1 2 3 4 5 6 7 8 9) occurrencesOf: 5) = 1
(#(1 5 3 5 6 5 8 5) occurrencesOf: 5) = 4
(#(1 5 3 5 6 5 8 5) select: [:x| x = 5 ]) = #(5 5 5 5)
nil == #( nil ) first

self running: 'String tests'
(#hello includes: 5) not
#hello includes: $l
#hello includes: $h
#hello includes: $o
#hello size = 5
#hello first = $h
#hello last = #o
#hello isLiteral
(#hello occurrencesOf: $l) = 2
(#hello occurrencesOf: Point zero) = 0
(#hello occurrencesOf: nil) = 0
(#hello occurrencesOf: $x) = 0
#hello startsWith: #he
#hello ,#world = #helloworld
#hello ,nil = #hello
(#12334533673389 asArrayOfSubstringsSeparatedBy: #33) = #(#12 #45 #67 #89)
$A isLetter
$6 isLetter not
$A isDigit not
$6 isDigit
$A isUppercase
$a isLowercase
$a asUppercase = $A
#HELLO asLowercase = #hello
#hallo < #hello
#hello > #any
#hello isCharacter not
' ' isSeparator
'	' isSeparator
String cr isSeparator
'hello word' isLiteral not
#x isLiteral
#x asLiteral = '#x'

self running: 'Array tests'
(Array new: 12) size = 12
(Array with: 123) first = 123
(Array withAll: #(1 2 3 4)) size = 4
(Array withAll: #hello) size = 5
((#12334533673389 asArrayOfSubstringsSeparatedBy: #33) join: '') = #12456789

#(1 #(2 3 4) 5 6 7) second = #(2 3 4)
| a b | a := #(1 2 3). b := #(2 3 4).  a at: 2 put: b. ^a second = b
(#(1 2 3 4 5 6 7 8 9) indexOf: 5) = 5
(#(1 2 #(3 4 5) 6 7 8 9) indexOf: #(3 4 5)) = 3
| a b | a :=#(1 2 #(3 4 5) 6 7 8 9). b := a detect: [:each| each = #(3 4 5) ] ifNone: []. ^b = #(3 4 5)

#(1 2 3 4) removeAll; isEmpty
(#(1 2 3 4) atAllPut: 3; occurrencesOf: 3) = 4
(#(1 2 3 4)  removeFirst; yourself) = #(2 3 4)
(#(1 2 3 4)  removeLast; yourself) = #(1 2 3)
(#(1 2 3 4)  removeIndex: 2; yourself) = #(1 3 4)

self running: 'Exception tests'
[ self error: #hello. false ] on: Exception do: [:ex| true ]
[ #hey blablabla ] on: Exception do: [:ex| true ]
[ #hey blablabla ] on: Exception do: [:ex| ^true ]. ^false

self running: 'StringStream tests'
#hello stream peek = $h
'' stream peek isNil
#hello stream peekForAll: #hello
#hello stream next;peekForAll: #ello
(#hello stream next; position) = 1
(#hello stream nextLine; peek) isNil
#hello stream nextLine; atEnd

self running: 'Random tests'
Random new next isNumber
Random new next between: 0 and: 1

self running: 'DateTime tests'
DateTime today notNil
DateTime now notNil
DateTime msNow isNumber

self running: 'ClassBuilder tests'
"toDo...

self running: 'Native objects tests'
NativeObject undefined isNil
(NativeHandle support @ (#hello -> 1 ,(#world -> 2)) json) ownPropertyNames sorted = #(hello world)

self running: 'toolsInlines'
self running: 'String tests'
self running: 'MethodReferences tests'

self running: 'snapshotInlines'
Snapshot new bootHeader isString
Snapshot new bootFooter isString
Snapshot new launchExpression isString

self running: 'otherInlines'
"nothing
self nativeLanguage ~= #py or: [ String reservedPythonWords includes: #True ]
self nativeLanguage ~= #jl or: [ String reservedJuliaWords includes: #true ]
"self nativeLanguage ~= #py or: [ String forbiddenPythonSelectors includes: #class ]
self nativeLanguage ~= #jl or: [ String forbiddenJuliaSelectors includes: #smalltalk ]

self running: 'printing classes'
Array printString = #Array
Array class printString = 'Array class'
PPNotParser printString = #PPNotParser
Dictionary printString = #Dictionary
Array asLiteral = #Array
"((Array basicAt: #printString) basicAt: #__method__) = (Class>>#printString)

self running: 'rootClasses & classes'
Smalltalk current rootClasses = (Array with: Object)
Smalltalk classes detect: [:one| one isKindOf: Metaclass ] ifNone: [^true]. ^false

self running: 'sorting Arrays'
#(a b c z x y w) sorted = #(a b c w x y z)
(#(1 2 20 10 5 50 70) sorted: [:x :y| x > y ]) = #(70 50 20 10 5 2 1)
#(hello 1 2 3 four) sorted = #(1 2 3 #four #hello)

self running: 'Block arguments'
^([:x| x + x ] value: 1) = 2
^([:x| x + x ] evaluateWith: 1) = 2
^([:x| x + x ] evaluateWithArguments: #(1 2 3 4)) = 2
^([:x :y| y notNil ifTrue: [x + x] ] evaluateWithArguments: #(1 2)) = 2
^([:x :y| y notNil ifTrue: [x + x] ] value: 1 value: nil) isNil
^([:x :y| y notNil ifTrue: [x + x] ] value: 7) isNil