assertTrue(a==77,'string.byte() should return the numerical code for the first character in the first returned item')
assertTrue(b==nil,'string.byte() should return only one item when no length is given [1]')
locala,b=string.byte('Mo0',2)
assertTrue(a==111,'string.byte() should return the numerical code for the nth character in the first returned item, when n is specified in the second argument [1]')
assertTrue(b==nil,'string.byte() should return only one item when no length is given [2]')
locala,b,c=string.byte('Mo0',2,3)
assertTrue(a==111,'string.byte() should return the numerical code for the nth character in the first returned item, when n is specified in the second argument [2]')
assertTrue(b==48,'string.byte() should return the numerical code for the nth character in the first returned item, when n is specified in the second argument [3]')
assertTrue(c==nil,'string.byte() should return only the number of items specified in the length argument or the up to the end of the string, whichever is encountered first [1]')
locala,b,c=string.byte('Mo0',3,20)
assertTrue(a==48,'string.byte() should return the numerical code for the nth character in the first returned item, when n is specified in the second argument [4]')
assertTrue(b==nil,'string.byte() should return only the number of items specified in the length argument or the up to the end of the string, whichever is encountered first [2]')
assertTrue(a=='','string.byte() should return an empty string when called with no arguments')
assertTrue(b=='testicles','string.byte() should return a string comprising of characters representing by the value each of the arguments passed')
-- -- dump
-- local f = function () end
-- local a = string.dump(f)
-- assertTrue (type(a) == 'string', 'string.dump() should return a string when called with a function')
-- local s = string.dump(function () return 'bar' end)
-- f = load(s)
-- assertTrue (type(f) == 'function', 'load() should create a function from the output of string.dump() [1]')
-- result = f()
-- assertTrue (result == 'bar', 'The result of load(string.dump(f)) should behave the same as f() [1]')
-- function namedFuncWithParams (a, b)
-- return a..b
-- end
-- s = string.dump(namedFuncWithParams)
-- f = load(s)
-- assertTrue (type(f) == 'function', 'load() should create a function from the output of string.dump() [2]')
-- result = f('hel','lo')
-- assertTrue (result == 'hello', 'The result of load(string.dump(f)) should behave the same as f() [2]')
-- find
locala='The quick brown fox'
localb=string.find(a,'quick');
localc=string.find(a,'fox');
locald=string.find(a,'kipper');
locale=string.find(a,'');
localf=string.find(a,'quick',8);
localg=string.find(a,'fox',8);
assertTrue(b==5,'string.find() should return the location of the first occurrence of the second argument within the first, if it is present [1]')
assertTrue(c==17,'string.find() should return the location of the first occurrence of the second argument within the first, if it is present [2]')
assertTrue(d==nil,'string.find() should return nil if the second argument is not contained within the first [1]')
assertTrue(e==1,'string.find() should return return 1 if the second argument is an empty string')
assertTrue(f==nil,'string.find() should return nil if the second argument is not contained within the first after the index specified by the third argument')
assertTrue(g==17,'string.find() should return the location of the second argument if it is contained within the first after the index specified by the third argument')
localb,c,d,e=string.find(a,'q(.)(.)');
assertEqual(b,5,'string.find() should return the location of the first occurrence of the second argument within the first, if it is present [3]')
assertEqual(c,7,'string.find() should return the location of the last character of the first occurrence of the second argument within the first, if it is present')
assertEqual(d,'u','string.find() should return the groups that are specified in the regex. [1]')
assertEqual(e,'i','string.find() should return the groups that are specified in the regex. [2]')
b=string.find('[','[_%w]')
assertTrue(b==nil,'string.find() should not return the location of special syntax [ and ].')
locala=[[Thequick
brownfox]]
b=string.find(a,'The .* fox')
assertTrue(b==1,'The dot pattern should match across lines in string.find()')
assertTrue(c=='moo<my-xml></my-xml>','string.gsub() should replace the matched part of the string[1]')
-- Not even scraping the surface
a='%%1'
b='Hello %1'
c=string.gsub(b,a,'world')
assertTrue(c=='Hello world','string.gsub() should replace the matched part of the string[2]')
a='%d'
b='ab5kfd8scf4lll'
c=function(x)return'('..x..')'end
d=string.gsub(b,a,c,2)
assertTrue(d=='ab(5)kfd(8)scf4lll','string.gsub() should replace the matched part of the string with the value returned from the given map function')
a="[^:]+"
b=":aa:bbb:cccc:ddddd:eee:"
c=function(subStr)end
d=string.gsub(b,a,c)
assertTrue(d==':aa:bbb:cccc:ddddd:eee:','string.gsub() should not replace the matched part of the string if the value returned from the map function is nil')
c=function(subStr)return'X'end
d=string.gsub(b,a,c)
assertTrue(d==':X:X:X:X:X:','string.gsub() should replace the matched part of the string if the value returned from the map function is not nil')
c=string.gsub(';a;','a*','ITEM')
assertTrue(c=='ITEM;ITEMITEM;ITEM','string.gsub() should replace the matched part of the string[2]')
a='abc\\def'
b=string.gsub(a,'\\','\\\\')
assertEqual(b,'abc\\\\def','string.gsub() should allow backslashes')
a="a = 'a', b = 'b', c = 'c',"
b=string.gsub(a,",$","")
assertEqual(b,"a = 'a', b = 'b', c = 'c'",'string.gsub() should match $ with end of string')
-- len
locala='McLaren Mercedes'
localb=string.len('');
localc=string.len(a);
assertTrue(b==0,'string.len() should return 0 if passed an empty string')
assertTrue(c==16,'string.len() should return the length of the string in the first argument')
-- lower
locala='McLaren Mercedes'
localb=string.lower('');
localc=string.lower(a);
assertTrue(b=='','string.lower() should return an empty string if passed an empty string')
assertTrue(c=='mclaren mercedes','string.lower() should return the string in the first argument with all character in lower case')
assertEqual(a,'test-123_test.2@a-b_c.movie','string.match() should flatten nested groups.')
locala=('-=[]\';'):match("%W")
assertEqual(a,'-','string.match() match non-word chars.')
-- rep
locala='Ho'
localb=string.rep(a,0);
localc=string.rep(a,1);
locald=string.rep(a,3);
assertTrue(b=='','string.rep() should return an empty string if the second argument is 0')
assertTrue(c=='Ho','string.rep() should return the first argument if the second argument is 1')
assertTrue(d=='HoHoHo','string.rep() should return a string containing the first argument repeated the second argument number of times')
-- reverse
locala=string.reverse('');
localb=string.reverse('x');
localc=string.reverse('tpircSavaJ');
assertTrue(a=='','string.reverse() should return an empty string if passed an empty string')
assertTrue(b=='x','string.reverse() should return the first argument if its length is 1')
assertTrue(c=='JavaScript','string.reverse() should return a string containing the first argument reversed')
-- sub
locala='Pub Standards'
localb=string.sub(a,1)
localc=string.sub(a,5)
locald=string.sub(a,-4)
locale=string.sub(a,1,3)
localf=string.sub(a,7,9)
localg=string.sub(a,-4,-2)
localh=string.sub(a,5,-2)
locali=string.sub(a,0)
assertTrue(b=='Pub Standards','string.sub() should return the first argument if the second argument is 1')
assertTrue(c=='Standards','string.sub() should return a subset of the first argument from the nth character onwards, when n is the second argument and positive')
assertTrue(d=='ards','string.sub() should return the last n characters of the first argument, where n is the absolute value of the second argument and the second argument is negative')
assertTrue(e=='Pub','string.sub() should return the first n characters of the first argument when the second argument is one and n is the third argument')
assertTrue(f=='and','string.sub() should return a subset of the first argument from the nth character to the mth character, when n is the second argument and positive and m is the third argument and negative')
assertTrue(h=='Standard','string.sub() should return a subset of the first argument from the nth character to the last but mth character, when n is the second argument and positive and m is the third argument and negative')
assertTrue(i=='Pub Standards','string.sub() should return a subset of the first argument from the last but nth character to the last but mth character, when n is the second argument and negative and m is the third argument and negative')
-- upper
locala=string.upper('');
localb=string.upper('JavaScript');
assertTrue(a=='','string.upper() should return an empty string if passed an empty string')
assertTrue(b=='JAVASCRIPT','string.upper() should return the first argument in uppercase')
-- `string` lib as metatable of strings.
localstrMeta=getmetatable('')
assertEqual(strMeta.__index,string,'String lib should be metamethod of string instances.')
a=('Hey'):lower()
assertEqual(a,'hey','String lib should be metamethod of string instances.')