'From Squeak3.8alpha of ''17 July 2004'' [latest update: #6281] on 1 October 2004 at 10:04:30 am'! "Change Set: AbstractStringAsIntegerTweak-laza Date: 1 October 2004 Author: Alexander@Lazarevic.de Moves asInteger from String up the hierarchy to AbstractString (again) and replaces it wit a simpler version."! ClassTestCase subclass: #MultiStringTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Collections-Text-Tests'! !MultiStringTest commentStamp: '' prior: 0! This is the unit test for the class String. Unit tests are a good way to exercise the functionality of your system in a repeatable and automatic manner. They are therefore recommended if you plan to release anything. For more information, see: - http://www.c2.com/cgi/wiki?UnitTest - http://minnow.cc.gatech.edu/squeak/1547 - the sunit class category! !AbstractString methodsFor: 'converting' stamp: 'laza 10/1/2004 09:55'! asInteger ^self asSignedInteger ! ! !AbstractString methodsFor: 'converting' stamp: 'laza 10/1/2004 09:54'! asSignedInteger "Returns the first signed integer it can find or nil." | start stream | start := self findFirst: [:char | char isDigit]. start isZero ifTrue: [^nil]. stream := (ReadStream on: self) position: start. stream back = $- ifTrue: [stream back]. ^Integer readFrom: stream! ! !AbstractString methodsFor: 'converting' stamp: 'laza 10/1/2004 10:02'! asUnsignedInteger "Returns the first integer it can find or nil." | start stream | start := self findFirst: [:char | char isDigit]. start isZero ifTrue: [^nil]. stream := (ReadStream on: self) position: start - 1. ^Integer readFrom: stream! ! !MultiStringTest methodsFor: 'testing - converting' stamp: 'laza 10/1/2004 09:58'! testAsInteger self assert: '1796exportFixes-tkMX' asMultiString asInteger = 1796. self assert: 'donald' asMultiString asInteger isNil. self assert: 'abc234def567' asMultiString asInteger = 234. self assert: '-94' asMultiString asInteger = -94. self assert: 'foo-bar-92' asMultiString asInteger = -92. self assert: '1796exportFixes-tkMX' asMultiString asSignedInteger = 1796. self assert: 'donald' asMultiString asSignedInteger isNil. self assert: 'abc234def567' asMultiString asSignedInteger = 234. self assert: '-94' asMultiString asSignedInteger = -94. self assert: 'foo-bar-92' asMultiString asSignedInteger = -92. self assert: '1796exportFixes-tkMX' asMultiString asUnsignedInteger = 1796. self assert: 'donald' asMultiString asUnsignedInteger isNil. self assert: 'abc234def567' asMultiString asUnsignedInteger = 234. self assert: '-94' asMultiString asUnsignedInteger = 94. self assert: 'foo-bar-92' asMultiString asUnsignedInteger = 92! ! String removeSelector: #asInteger! String removeSelector: #asSignedInteger!