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

test[m8n] 60 String

-- setup
test = "test"


-- instantiation
if (not test:isString()) then error("Must be aString") end
if (not test=="test") then error("Must be test String") end
test=smalltalk.String:new()
if (not test:isString()) then error("Must instatiate a String") end
if (not test=="") then error("Must instatiate the empty String") end
test=smalltalk.String:fromString_("hello")
if (not test:isString()) then error("Must be a String") end
if (not test=="hello") then error("Must be hello") end
test=smalltalk.String:_at("hello")
if (not test=="hello") then error("Must return hello") end
test=smalltalk.String:_at(nil)
if (not test==nil) then error("Must return nil") end
test=smalltalk.String:fromCharCode_(smalltalk.Array:with_with_with_(65,66,67))
if (not test=="ABC") then error("Must return ABC") end
test=smalltalk.String:fromCharCode_(65)
if (not test=="A") then error("Must return ABC") end
test=smalltalk.String:fromString_("hello")
if (not test=="hello") then error("Must return hello") end
test=smalltalk.String:fromString_(nil)
if (not test=="nil") then error("Must return 'nil'") end
test=smalltalk.String:fromString_(77)
if (not test=="77") then error("Must return '77'") end

-- constants
if (smalltalk.String:cr()~="\r") then error("Must return cr") end
if (smalltalk.String:lf()~="\n") then error("Must return lf") end
if (smalltalk.String:space()~=" ") then error("Must return space") end
if (smalltalk.String:tab()~="\t") then error("Must return tab") end
if (smalltalk.String:zero()~="\0") then error("Must return zero") end
if (smalltalk.String:crlf()~="\r\n") then error("Must return crlf") end
if (smalltalk.String:doItSelector()~="s8DoIt") then error("Must return cr") end
if (not smalltalk.String:reservedWords():includes_("for")) then error("Note, it should include #for keyword") end
if (not smalltalk.String:reservedLuaWords():includes_("for")) then error("Note, it should include #for keyword") end

-- class messages
if (smalltalk.String:with_("A")~="A") then error("Must return A") end
if (smalltalk.String:with_with_("A","B")~="AB") then error("Must return AB") end
if (smalltalk.String:with_with_with_("A","B","C")~="ABC") then error("Must return ABC") end
if (smalltalk.String:with_with_with_with_("A","B","C","D")~="ABCD") then error("Must return ABCD") end


-- instance composing
test="test"
if (not ("a"):_comma("b")=="ab") then error("Must return 'ab'") end
if (not ("a"):_comma(nil)=="anil") then error("Must return 'anil'") end
if (not ("a"):_comma(77)=="a77") then error("Must return 'a77'") end

-- instance magnitude
test="test"
if (not ("a"):_lt("b")) then error("a must be less than b") end
if (not ("a"):_lt_eq("b")) then error("a must be <= than b") end
if (("a"):_eq("b")) then error("Equality test failed") end
if (("a"):_eq(nil)) then error("Equality test failed") end
if (("a"):_eq(77)) then error("Equality test failed") end
if (("77"):_eq(77)) then error("Equality test failed") end
if (not ("a"):_eq("a")) then error("Equality test failed") end
if (("a"):_gt("b")) then error("b must be greater than a") end
if (("a"):_gt_eq("b")) then error("b must be >= than a") end

-- matching
if (("yourself"):argumentCount()~=0) then error("Must return 0") end
if (("+"):argumentCount()~=1) then error("Must return 1") end
if ((">>"):argumentCount()~=1) then error("Must return 1") end
if (("between:and:"):argumentCount()~=2) then error("Must return 2") end
if ((""):argumentCount()~=0) then error("Must return 0") end
if (("hello little world"):asArrayOfSubstrings():size()~=3) then error("Must be 3 parts") end
if (("hello+my+little+pony"):asArrayOfSubstringsSeparatedBy_("+"):size()~=4) then error("Must be 4 parts") end
if (not ("hello+my+little+pony"):includes_("tt")) then error("Must be included") end
if (not ("hello+my+little+pony"):indexOf_("tt")==12) then error("Must return 12") end
if (not ("hello+my+little+pony"):indexOf_("t-t")==0) then error("Must return 0") end
if (not ("hello+my+little+pony"):indexOf_startingAt_("+",12)==16) then error("Must return 16") end

--query
if (not ("2"):isCharacter()) then error("Must return true") end
if ("22"):isCharacter() then error("Must return false") end
if (not ("2"):isAlphaNumeric()) then error("Must return true") end
if ("22"):isAlphaNumeric() then error("Must return false") end
if ("+"):isAlphaNumeric() then error("Must return false") end
if (not ("2"):isDigit()) then error("Must return true") end
if ("o"):isDigit() then error("Must return false") end
if (not ("f"):isLetter()) then error("Must return true") end
if ("4"):isLetter() then error("Must return false") end
if (not ("yourself"):isLiteral()) then error("Must return true") end
if ("+"):isLiteral() then error("Must return false") end
if (not ("your_self"):isLiteral()) then error("Must return true") end
if (not ("add:"):isLiteral()) then error("Must return true") end
if (not ("between:and:"):isLiteral()) then error("Must return true") end
if (not ("_hello_123"):isLiteral()) then error("Must return true") end
if (not ("123"):isLiteral()) then error("Must return true") end
if ("1*1"):isLiteral() then error("Must return false") end

if (not ("abc"):isLowercase()) then error("Must return true") end
if ("ABC"):isLowerCase() then error("Must return false") end


--indexing, copying and replacing
if (not ("ABC"):second()=="B") then error("Must return $B") end
if (not ("A"):second()=="") then error("Must return the empty string") end
if (not ("U"):between_and_("A","Z")) then error("Must be true") end
if (not ("ABCDE"):copyFrom_to_(1,3)=="ABC") then error("Must return ABC") end
if (not ("ABCDE"):copyWithout_("CD")=="ABE") then error("Must return ABE") end
if (not ("ABCDE"):replace_with_("CD","XX")=="ABXXE") then error("Must return ABXXE") end
if (not ("ABCDEABCDE"):replace_with_("CD","xx")=="ABxxEABxxE") then error("Must return ABxxEABxxE") end
if (not (" my 1111 my 22"):fromLast_("my ")=="22") then error("Must return 22") end

-- converting
if (("hello"):asGlobalName()~="Hello") then error("Must return Hello") end
if (not ("Hello"):asLocalName()=="hello") then error("Wrong local name") end
if (not ("hello"):asLiteral()=="#hello") then error("Must return #hello") end
if (not ("Hello World"):asLowercase()=="hello world") then error("Must return hello world") end
if (not ("Hello World"):asUppercase()=="HELLO WORLD") then error("Must return HELLO WORLD") end
if (not ("4"):digitValue()==4) then error("Must return 4") end
if (not ("F"):digitValue()==15) then error("Must return 15") end
if (not ('012'):asArray():_eq(smalltalk.Array:with_with_with_("0","1","2"))) then error("Wrong result") end

-- split
if (not ("hello my little world"):asArrayOfSubstringsSeparatedBy_(" "):size()==4) then error("Must return an array of size 4") end
if (not ("hello my little world"):asArrayOfSubstringsSeparatedBy_(" "):second()=="my") then error("Must return 'my'") end

--searching
if (not ("hello"):lastIndexOf_("l")==4) then error("Must return 4") end
if (not ("hello"):occurrencesOf_("l")==2) then error("Must return 2") end
if (not ("hello"):occurrencesOf_("2")==0) then error("Must return 0") end
if ("hello"):startsWith_("3") then error("Must return false") end
if ("hello"):startsWith_("hello world") then error("Must return false") end
if (not ("hello"):startsWith_("hel")) then error("Must return true") end
if (not ("   hello \t\n "):trimBlanks()=="hello") then error("Must return true") end


Uploaded Image: needsWork.png
-- URI
("toDo"):asDecodedURI()
("toDo"):asEncodedURI()

-- clear
test = nil