12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323 |
- {
- This file is part of the Free Component Library (FCL)
- Copyright (c) 2014 by Michael Van Canneyt
- Unit tests for Pascal-to-Javascript converter class.
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************
- Examples:
- ./testpas2js --suite=TTestModule.TestEmptyProgram
- ./testpas2js --suite=TTestModule.TestEmptyUnit
- }
- unit tcmodules;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, fpcunit, testregistry, contnrs, fppas2js,
- pastree, PScanner, PasResolver, PParser, jstree, jswriter, jsbase;
- const
- po_pas2js = [po_asmwhole,po_resolvestandardtypes];
- type
- { TTestPasParser }
- TTestPasParser = Class(TPasParser)
- end;
- TOnFindUnit = function(const aUnitName: String): TPasModule of object;
- { TTestEnginePasResolver }
- TTestEnginePasResolver = class(TPas2JsResolver)
- private
- FFilename: string;
- FModule: TPasModule;
- FOnFindUnit: TOnFindUnit;
- FParser: TTestPasParser;
- FResolver: TStreamResolver;
- FScanner: TPascalScanner;
- FSource: string;
- procedure SetModule(AValue: TPasModule);
- public
- destructor Destroy; override;
- function FindModule(const AName: String): TPasModule; override;
- property OnFindUnit: TOnFindUnit read FOnFindUnit write FOnFindUnit;
- property Filename: string read FFilename write FFilename;
- property Resolver: TStreamResolver read FResolver write FResolver;
- property Scanner: TPascalScanner read FScanner write FScanner;
- property Parser: TTestPasParser read FParser write FParser;
- property Source: string read FSource write FSource;
- property Module: TPasModule read FModule write SetModule;
- end;
- { TCustomTestModule }
- TCustomTestModule = Class(TTestCase)
- private
- FConverter: TPasToJSConverter;
- FEngine: TTestEnginePasResolver;
- FExpectedErrorClass: ExceptClass;
- FExpectedErrorMsg: string;
- FExpectedErrorNumber: integer;
- FFilename: string;
- FFileResolver: TStreamResolver;
- FJSInitBody: TJSFunctionBody;
- FJSInterfaceUses: TJSArrayLiteral;
- FJSModule: TJSSourceElements;
- FJSModuleSrc: TJSSourceElements;
- FJSSource: TStringList;
- FModule: TPasModule;
- FJSModuleCallArgs: TJSArguments;
- FModules: TObjectList;// list of TTestEnginePasResolver
- FParser: TTestPasParser;
- FPasProgram: TPasProgram;
- FJSRegModuleCall: TJSCallExpression;
- FScanner: TPascalScanner;
- FSkipTests: boolean;
- FSource: TStringList;
- FFirstPasStatement: TPasImplBlock;
- function GetModuleCount: integer;
- function GetModules(Index: integer): TTestEnginePasResolver;
- function OnPasResolverFindUnit(const aUnitName: String): TPasModule;
- protected
- procedure SetUp; override;
- procedure TearDown; override;
- Procedure Add(Line: string); virtual;
- Procedure StartParsing; virtual;
- procedure ParseModule; virtual;
- procedure ParseProgram; virtual;
- procedure ParseUnit; virtual;
- protected
- function FindModuleWithFilename(aFilename: string): TTestEnginePasResolver; virtual;
- function AddModule(aFilename: string): TTestEnginePasResolver; virtual;
- function AddModuleWithSrc(aFilename, Src: string): TTestEnginePasResolver; virtual;
- function AddModuleWithIntfImplSrc(aFilename, InterfaceSrc,
- ImplementationSrc: string): TTestEnginePasResolver; virtual;
- procedure AddSystemUnit; virtual;
- procedure StartProgram(NeedSystemUnit: boolean); virtual;
- procedure StartUnit(NeedSystemUnit: boolean); virtual;
- Procedure ConvertModule; virtual;
- Procedure ConvertProgram; virtual;
- Procedure ConvertUnit; virtual;
- procedure CheckDottedIdentifier(Msg: string; El: TJSElement; DottedName: string);
- function GetDottedIdentifier(El: TJSElement): string;
- procedure CheckSource(Msg,Statements, InitStatements: string); virtual;
- procedure CheckDiff(Msg, Expected, Actual: string); virtual;
- procedure SetExpectedPasResolverError(Msg: string; MsgNumber: integer);
- procedure SetExpectedConverterError(Msg: string; MsgNumber: integer);
- function IsErrorExpected(E: Exception): boolean;
- procedure HandleScannerError(E: EScannerError);
- procedure HandleParserError(E: EParserError);
- procedure HandlePasResolveError(E: EPasResolve);
- procedure HandlePas2JSError(E: EPas2JS);
- procedure HandleException(E: Exception);
- procedure RaiseException(E: Exception);
- procedure WriteSources(const aFilename: string; aRow, aCol: integer);
- property PasProgram: TPasProgram Read FPasProgram;
- property Modules[Index: integer]: TTestEnginePasResolver read GetModules;
- property ModuleCount: integer read GetModuleCount;
- property Engine: TTestEnginePasResolver read FEngine;
- property Filename: string read FFilename;
- Property Module: TPasModule Read FModule;
- property FirstPasStatement: TPasImplBlock read FFirstPasStatement;
- property Converter: TPasToJSConverter read FConverter;
- property JSSource: TStringList read FJSSource;
- property JSModule: TJSSourceElements read FJSModule;
- property JSRegModuleCall: TJSCallExpression read FJSRegModuleCall;
- property JSModuleCallArgs: TJSArguments read FJSModuleCallArgs;
- property JSInterfaceUses: TJSArrayLiteral read FJSInterfaceUses;
- property JSModuleSrc: TJSSourceElements read FJSModuleSrc;
- property JSInitBody: TJSFunctionBody read FJSInitBody;
- property ExpectedErrorClass: ExceptClass read FExpectedErrorClass write FExpectedErrorClass;
- property ExpectedErrorMsg: string read FExpectedErrorMsg write FExpectedErrorMsg;
- property ExpectedErrorNumber: integer read FExpectedErrorNumber write FExpectedErrorNumber;
- property SkipTests: boolean read FSkipTests write FSkipTests;
- public
- property Source: TStringList read FSource;
- property FileResolver: TStreamResolver read FFileResolver;
- property Scanner: TPascalScanner read FScanner;
- property Parser: TTestPasParser read FParser;
- end;
- { TTestModule }
- TTestModule = class(TCustomTestModule)
- Published
- // modules
- Procedure TestEmptyProgram;
- Procedure TestEmptyProgramUseStrict;
- Procedure TestEmptyUnit;
- Procedure TestEmptyUnitUseStrict;
- // vars/const
- Procedure TestVarInt;
- Procedure TestVarBaseTypes;
- Procedure TestConstBaseTypes;
- Procedure TestUnitImplVars;
- Procedure TestUnitImplConsts;
- Procedure TestUnitImplRecord;
- Procedure TestRenameJSNameConflict;
- Procedure TestLocalConst;
- Procedure TestVarExternal;
- Procedure TestVarExternalOtherUnit;
- // strings
- Procedure TestCharConst;
- Procedure TestChar_Compare;
- Procedure TestChar_Ord;
- Procedure TestChar_Chr;
- Procedure TestStringConst;
- Procedure TestString_Length;
- Procedure TestString_Compare;
- Procedure TestString_SetLength;
- Procedure TestString_CharAt;
- Procedure TestStr;
- Procedure TestAnsiStringFail;
- // alias types
- Procedure TestAliasTypeRef;
- Procedure TestTypeCast_BaseTypes;
- Procedure TestTypeCast_AliasBaseTypes;
- // functions
- Procedure TestEmptyProc;
- Procedure TestProcOneParam;
- Procedure TestFunctionWithoutParams;
- Procedure TestProcedureWithoutParams;
- Procedure TestPrgProcVar;
- Procedure TestProcTwoArgs;
- Procedure TestProc_DefaultValue;
- Procedure TestUnitProcVar;
- Procedure TestImplProc;
- Procedure TestFunctionResult;
- Procedure TestNestedProc;
- Procedure TestForwardProc;
- Procedure TestNestedForwardProc;
- Procedure TestAssignFunctionResult;
- Procedure TestFunctionResultInCondition;
- Procedure TestExit;
- Procedure TestBreak;
- Procedure TestContinue;
- Procedure TestProcedureExternal;
- Procedure TestProcedureExternalOtherUnit;
- Procedure TestProcedureAsm;
- Procedure TestProcedureAssembler;
- Procedure TestProcedure_VarParam;
- Procedure TestProcedureOverload;
- Procedure TestProcedureOverloadForward;
- Procedure TestProcedureOverloadUnit;
- Procedure TestProcedureOverloadNested;
- Procedure TestProc_Varargs;
- // enums, sets
- Procedure TestEnumName;
- Procedure TestEnumNumber;
- Procedure TestEnumFunctions;
- Procedure TestSet;
- Procedure TestSetOperators;
- Procedure TestSetFunctions;
- Procedure TestSet_PassAsArgClone;
- Procedure TestEnum_AsParams;
- Procedure TestSet_AsParams;
- Procedure TestSet_Property;
- // statements
- Procedure TestNestBegin;
- Procedure TestIncDec;
- Procedure TestAssignments;
- Procedure TestArithmeticOperators1;
- Procedure TestLogicalOperators;
- Procedure TestBitwiseOperators;
- Procedure TestFunctionInt;
- Procedure TestFunctionString;
- Procedure TestForLoop;
- Procedure TestForLoopInFunction;
- Procedure TestForLoop_ReadVarAfter;
- Procedure TestForLoop_Nested;
- Procedure TestRepeatUntil;
- Procedure TestAsmBlock;
- Procedure TestTryFinally;
- Procedure TestTryExcept;
- Procedure TestCaseOf;
- Procedure TestCaseOf_UseSwitch;
- Procedure TestCaseOfNoElse;
- Procedure TestCaseOfNoElse_UseSwitch;
- Procedure TestCaseOfRange;
- // arrays
- Procedure TestArray_Dynamic;
- Procedure TestArray_Dynamic_Nil;
- Procedure TestArray_DynMultiDimensional;
- Procedure TestArrayOfRecord;
- Procedure TestArray_AsParams;
- Procedure TestArrayElement_AsParams;
- Procedure TestArrayElementFromFuncResult_AsParams;
- Procedure TestArrayEnumTypeRange;
- Procedure TestArray_SetLengthProperty;
- Procedure TestArray_OpenArrayOfString;
- // ToDo: const array
- // ToDo: SetLength(array of static array)
- // record
- Procedure TestRecord_Var;
- Procedure TestWithRecordDo;
- Procedure TestRecord_Assign;
- Procedure TestRecord_PassAsArgClone;
- Procedure TestRecord_AsParams;
- Procedure TestRecordElement_AsParams;
- Procedure TestRecordElementFromFuncResult_AsParams;
- Procedure TestRecordElementFromWith_AsParams;
- Procedure TestRecord_Equal;
- // ToDo: const record
- // classes
- Procedure TestClass_TObjectDefaultConstructor;
- Procedure TestClass_TObjectConstructorWithParams;
- Procedure TestClass_Var;
- Procedure TestClass_Method;
- Procedure TestClass_Inheritance;
- Procedure TestClass_AbstractMethod;
- Procedure TestClass_CallInherited_NoParams;
- Procedure TestClass_CallInherited_WithParams;
- Procedure TestClasS_CallInheritedConstructor;
- Procedure TestClass_ClassVar;
- Procedure TestClass_CallClassMethod;
- Procedure TestClass_Property;
- Procedure TestClass_Property_ClassMethod;
- Procedure TestClass_Property_Index;
- Procedure TestClass_PropertyOfTypeArray;
- Procedure TestClass_PropertyDefault;
- Procedure TestClass_PropertyOverride;
- Procedure TestClass_Assigned;
- Procedure TestClass_WithClassDoCreate;
- Procedure TestClass_WithClassInstDoProperty;
- Procedure TestClass_WithClassInstDoPropertyWithParams;
- Procedure TestClass_WithClassInstDoFunc;
- Procedure TestClass_TypeCast;
- Procedure TestClass_TypeCastUntypedParam;
- Procedure TestClass_Overloads;
- Procedure TestClass_OverloadsAncestor;
- Procedure TestClass_OverloadConstructor;
- Procedure TestClass_ReintroducedVar;
- Procedure TestClass_RaiseDescendant;
- Procedure TestClass_ExternalMethod;
- Procedure TestClass_ExternalVirtualNameMismatchFail;
- Procedure TestClass_ExternalOverrideFail;
- Procedure TestClass_ExternalVar;
- // class of
- Procedure TestClassOf_Create;
- Procedure TestClassOf_Call;
- Procedure TestClassOf_Assign;
- Procedure TestClassOf_Is;
- Procedure TestClassOf_Compare;
- Procedure TestClassOf_ClassVar;
- Procedure TestClassOf_ClassMethod;
- Procedure TestClassOf_ClassProperty;
- Procedure TestClassOf_ClassMethodSelf;
- Procedure TestClassOf_TypeCast;
- Procedure TestClassOf_ImplicitFunctionCall;
- // external class
- Procedure TestExternalClass_Var;
- // ToDo TestExternalClass_Const
- Procedure TestExternalClass_DuplicateVarFail;
- Procedure TestExternalClass_Method;
- Procedure TestExternalClass_NonExternalOverride;
- Procedure TestExternalClass_Property;
- Procedure TestExternalClass_ClassProperty;
- Procedure TestExternalClass_ClassOf;
- Procedure TestExternalClass_ClassOtherUnit;
- Procedure TestExternalClass_Is;
- Procedure TestExternalClass_As;
- Procedure TestExternalClass_DestructorFail;
- Procedure TestExternalClass_New;
- Procedure TestExternalClass_ClassOf_New;
- Procedure TestExternalClass_FuncClassOf_New;
- Procedure TestExternalClass_LocalConstSameName;
- Procedure TestExternalClass_ReintroduceOverload;
- Procedure TestExternalClass_Inherited;
- Procedure TestExternalClass_NewInstance;
- Procedure TestExternalClass_NewInstance_NonVirtualFail;
- Procedure TestExternalClass_NewInstance_FirstParamNotString_Fail;
- Procedure TestExternalClass_NewInstance_SecondParamTyped_Fail;
- Procedure TestExternalClass_TypeCastToRootClass;
- // proc types
- Procedure TestProcType;
- Procedure TestProcType_FunctionFPC;
- Procedure TestProcType_FunctionDelphi;
- Procedure TestProcType_AsParam;
- Procedure TestProcType_MethodFPC;
- Procedure TestProcType_MethodDelphi;
- Procedure TestProcType_PropertyFPC;
- Procedure TestProcType_PropertyDelphi;
- Procedure TestProcType_WithClassInstDoPropertyFPC;
- // jsvalue
- Procedure TestJSValue_AssignToJSValue;
- Procedure TestJSValue_TypeCastToBaseType;
- Procedure TestJSValue_Enum;
- Procedure TestJSValue_ClassInstance;
- Procedure TestJSValue_ClassOf;
- Procedure TestJSValue_ArrayOfJSValue;
- Procedure TestJSValue_Params;
- Procedure TestJSValue_UntypedParam;
- Procedure TestJSValue_FuncType;
- end;
- function LinesToStr(Args: array of const): string;
- function ExtractFileUnitName(aFilename: string): string;
- function JSToStr(El: TJSElement): string;
- implementation
- function LinesToStr(Args: array of const): string;
- var
- s: String;
- i: Integer;
- begin
- s:='';
- for i:=Low(Args) to High(Args) do
- case Args[i].VType of
- vtChar: s += Args[i].VChar+LineEnding;
- vtString: s += Args[i].VString^+LineEnding;
- vtPChar: s += Args[i].VPChar+LineEnding;
- vtWideChar: s += AnsiString(Args[i].VWideChar)+LineEnding;
- vtPWideChar: s += AnsiString(Args[i].VPWideChar)+LineEnding;
- vtAnsiString: s += AnsiString(Args[i].VAnsiString)+LineEnding;
- vtWidestring: s += AnsiString(WideString(Args[i].VWideString))+LineEnding;
- vtUnicodeString:s += AnsiString(UnicodeString(Args[i].VUnicodeString))+LineEnding;
- end;
- Result:=s;
- end;
- function ExtractFileUnitName(aFilename: string): string;
- var
- p: Integer;
- begin
- Result:=ExtractFileName(aFilename);
- if Result='' then exit;
- for p:=length(Result) downto 1 do
- case Result[p] of
- '/','\': exit;
- '.':
- begin
- Delete(Result,p,length(Result));
- exit;
- end;
- end;
- end;
- function JSToStr(El: TJSElement): string;
- var
- aWriter: TBufferWriter;
- aJSWriter: TJSWriter;
- begin
- aWriter:=TBufferWriter.Create(1000);
- try
- aJSWriter:=TJSWriter.Create(aWriter);
- aJSWriter.IndentSize:=2;
- aJSWriter.WriteJS(El);
- Result:=aWriter.AsAnsistring;
- finally
- aWriter.Free;
- end;
- end;
- { TTestEnginePasResolver }
- procedure TTestEnginePasResolver.SetModule(AValue: TPasModule);
- begin
- if FModule=AValue then Exit;
- if Module<>nil then
- Module.Release;
- FModule:=AValue;
- if Module<>nil then
- Module.AddRef;
- end;
- destructor TTestEnginePasResolver.Destroy;
- begin
- FreeAndNil(FResolver);
- Module:=nil;
- FreeAndNil(FParser);
- FreeAndNil(FScanner);
- FreeAndNil(FResolver);
- inherited Destroy;
- end;
- function TTestEnginePasResolver.FindModule(const AName: String): TPasModule;
- begin
- Result:=nil;
- if Assigned(OnFindUnit) then
- Result:=OnFindUnit(AName);
- end;
- { TCustomTestModule }
- function TCustomTestModule.GetModuleCount: integer;
- begin
- Result:=FModules.Count;
- end;
- function TCustomTestModule.GetModules(Index: integer
- ): TTestEnginePasResolver;
- begin
- Result:=TTestEnginePasResolver(FModules[Index]);
- end;
- function TCustomTestModule.OnPasResolverFindUnit(const aUnitName: String
- ): TPasModule;
- var
- i: Integer;
- CurEngine: TTestEnginePasResolver;
- CurUnitName: String;
- begin
- //writeln('TTestModule.OnPasResolverFindUnit START Unit="',aUnitName,'"');
- Result:=nil;
- for i:=0 to ModuleCount-1 do
- begin
- CurEngine:=Modules[i];
- CurUnitName:=ExtractFileUnitName(CurEngine.Filename);
- //writeln('TTestModule.OnPasResolverFindUnit Checking ',i,'/',ModuleCount,' ',CurEngine.Filename,' ',CurUnitName);
- if CompareText(aUnitName,CurUnitName)=0 then
- begin
- Result:=CurEngine.Module;
- if Result<>nil then exit;
- //writeln('TTestModule.OnPasResolverFindUnit PARSING unit "',CurEngine.Filename,'"');
- FileResolver.FindSourceFile(aUnitName);
- CurEngine.Resolver:=TStreamResolver.Create;
- CurEngine.Resolver.OwnsStreams:=True;
- //writeln('TTestResolver.OnPasResolverFindUnit SOURCE=',CurEngine.Source);
- CurEngine.Resolver.AddStream(CurEngine.FileName,TStringStream.Create(CurEngine.Source));
- CurEngine.Scanner:=TPascalScanner.Create(CurEngine.Resolver);
- CurEngine.Parser:=TTestPasParser.Create(CurEngine.Scanner,CurEngine.Resolver,CurEngine);
- CurEngine.Parser.Options:=CurEngine.Parser.Options+po_pas2js;
- if CompareText(CurUnitName,'System')=0 then
- CurEngine.Parser.ImplicitUses.Clear;
- CurEngine.Scanner.OpenFile(CurEngine.Filename);
- try
- CurEngine.Parser.NextToken;
- CurEngine.Parser.ParseUnit(CurEngine.FModule);
- except
- on E: EParserError do
- HandleParserError(E);
- on E: EPasResolve do
- HandlePasResolveError(E);
- on E: Exception do
- HandleException(E);
- end;
- //writeln('TTestModule.OnPasResolverFindUnit END ',CurUnitName);
- Result:=CurEngine.Module;
- exit;
- end;
- end;
- writeln('TTestModule.OnPasResolverFindUnit missing unit "',aUnitName,'"');
- Fail('can''t find unit "'+aUnitName+'"');
- end;
- procedure TCustomTestModule.SetUp;
- begin
- inherited SetUp;
- FSkipTests:=false;
- FSource:=TStringList.Create;
- FModules:=TObjectList.Create(true);
- FFilename:='test1.pp';
- FFileResolver:=TStreamResolver.Create;
- FFileResolver.OwnsStreams:=True;
- FScanner:=TPascalScanner.Create(FFileResolver);
- FEngine:=AddModule(Filename);
- FParser:=TTestPasParser.Create(FScanner,FFileResolver,FEngine);
- Parser.Options:=Parser.Options+po_pas2js;
- FModule:=Nil;
- FConverter:=TPasToJSConverter.Create;
- FConverter.UseLowerCase:=false;
- FExpectedErrorClass:=nil;
- end;
- procedure TCustomTestModule.TearDown;
- begin
- FSkipTests:=false;
- FJSModule:=nil;
- FJSRegModuleCall:=nil;
- FJSModuleCallArgs:=nil;
- FJSInterfaceUses:=nil;
- FJSModuleSrc:=nil;
- FJSInitBody:=nil;
- FreeAndNil(FJSSource);
- FreeAndNil(FJSModule);
- FreeAndNil(FConverter);
- Engine.Clear;
- if Assigned(FModule) then
- begin
- FModule.Release;
- FModule:=nil;
- end;
- FreeAndNil(FSource);
- FreeAndNil(FParser);
- FreeAndNil(FScanner);
- FreeAndNil(FFileResolver);
- if FModules<>nil then
- begin
- FreeAndNil(FModules);
- FEngine:=nil;
- end;
- inherited TearDown;
- end;
- procedure TCustomTestModule.Add(Line: string);
- begin
- Source.Add(Line);
- end;
- procedure TCustomTestModule.StartParsing;
- var
- Src: String;
- begin
- Src:=Source.Text;
- FEngine.Source:=Src;
- FileResolver.AddStream(FileName,TStringStream.Create(Src));
- Scanner.OpenFile(FileName);
- Writeln('// Test : ',Self.TestName);
- Writeln(Src);
- end;
- procedure TCustomTestModule.ParseModule;
- begin
- if SkipTests then exit;
- FFirstPasStatement:=nil;
- try
- StartParsing;
- Parser.ParseMain(FModule);
- except
- on E: EParserError do
- HandleParserError(E);
- on E: EPasResolve do
- HandlePasResolveError(E);
- on E: EPas2JS do
- HandlePas2JSError(E);
- on E: Exception do
- HandleException(E);
- end;
- if SkipTests then exit;
- AssertNotNull('Module resulted in Module',FModule);
- AssertEquals('modulename',lowercase(ChangeFileExt(FFileName,'')),lowercase(Module.Name));
- TAssert.AssertSame('Has resolver',Engine,Parser.Engine);
- end;
- procedure TCustomTestModule.ParseProgram;
- begin
- if SkipTests then exit;
- ParseModule;
- if SkipTests then exit;
- AssertEquals('Has program',TPasProgram,Module.ClassType);
- FPasProgram:=TPasProgram(Module);
- AssertNotNull('Has program section',PasProgram.ProgramSection);
- AssertNotNull('Has initialization section',PasProgram.InitializationSection);
- if (PasProgram.InitializationSection.Elements.Count>0) then
- if TObject(PasProgram.InitializationSection.Elements[0]) is TPasImplBlock then
- FFirstPasStatement:=TPasImplBlock(PasProgram.InitializationSection.Elements[0]);
- end;
- procedure TCustomTestModule.ParseUnit;
- begin
- if SkipTests then exit;
- ParseModule;
- if SkipTests then exit;
- AssertEquals('Has unit (TPasModule)',TPasModule,Module.ClassType);
- AssertNotNull('Has interface section',Module.InterfaceSection);
- AssertNotNull('Has implementation section',Module.ImplementationSection);
- if (Module.InitializationSection<>nil)
- and (Module.InitializationSection.Elements.Count>0)
- and (TObject(Module.InitializationSection.Elements[0]) is TPasImplBlock) then
- FFirstPasStatement:=TPasImplBlock(Module.InitializationSection.Elements[0]);
- end;
- function TCustomTestModule.FindModuleWithFilename(aFilename: string
- ): TTestEnginePasResolver;
- var
- i: Integer;
- begin
- for i:=0 to ModuleCount-1 do
- if CompareText(Modules[i].Filename,aFilename)=0 then
- exit(Modules[i]);
- Result:=nil;
- end;
- function TCustomTestModule.AddModule(aFilename: string
- ): TTestEnginePasResolver;
- begin
- //writeln('TTestModuleConverter.AddModule ',aFilename);
- if FindModuleWithFilename(aFilename)<>nil then
- Fail('TTestModuleConverter.AddModule: file "'+aFilename+'" already exists');
- Result:=TTestEnginePasResolver.Create;
- Result.Filename:=aFilename;
- Result.AddObjFPCBuiltInIdentifiers([btChar,btString,btLongint,btInt64,btBoolean,btDouble]);
- Result.OnFindUnit:=@OnPasResolverFindUnit;
- FModules.Add(Result);
- end;
- function TCustomTestModule.AddModuleWithSrc(aFilename, Src: string
- ): TTestEnginePasResolver;
- begin
- Result:=AddModule(aFilename);
- Result.Source:=Src;
- end;
- function TCustomTestModule.AddModuleWithIntfImplSrc(aFilename, InterfaceSrc,
- ImplementationSrc: string): TTestEnginePasResolver;
- var
- Src: String;
- begin
- Src:='unit '+ExtractFileUnitName(aFilename)+';'+LineEnding;
- Src+=LineEnding;
- Src+='interface'+LineEnding;
- Src+=LineEnding;
- Src+=InterfaceSrc;
- Src+='implementation'+LineEnding;
- Src+=LineEnding;
- Src+=ImplementationSrc;
- Src+='end.'+LineEnding;
- Result:=AddModuleWithSrc(aFilename,Src);
- end;
- procedure TCustomTestModule.AddSystemUnit;
- begin
- AddModuleWithIntfImplSrc('system.pp',
- // interface
- LinesToStr([
- 'type',
- ' integer=longint;',
- 'var',
- ' ExitCode: Longint;',
- ''
- // implementation
- ]),LinesToStr([
- ''
- ]));
- end;
- procedure TCustomTestModule.StartProgram(NeedSystemUnit: boolean);
- begin
- if NeedSystemUnit then
- AddSystemUnit
- else
- Parser.ImplicitUses.Clear;
- Add('program test1;');
- Add('');
- end;
- procedure TCustomTestModule.StartUnit(NeedSystemUnit: boolean);
- begin
- if NeedSystemUnit then
- AddSystemUnit
- else
- Parser.ImplicitUses.Clear;
- Add('unit Test1;');
- Add('');
- end;
- procedure TCustomTestModule.ConvertModule;
- var
- ModuleNameExpr: TJSLiteral;
- FunDecl, InitFunction: TJSFunctionDeclarationStatement;
- FunDef: TJSFuncDef;
- InitAssign: TJSSimpleAssignStatement;
- FunBody: TJSFunctionBody;
- InitName: String;
- begin
- if SkipTests then exit;
- try
- FJSModule:=FConverter.ConvertPasElement(Module,Engine) as TJSSourceElements;
- except
- on E: EScannerError do
- HandleScannerError(E);
- on E: EParserError do
- HandleParserError(E);
- on E: EPasResolve do
- HandlePasResolveError(E);
- on E: EPas2JS do
- HandlePas2JSError(E);
- on E: Exception do
- HandleException(E);
- end;
- if SkipTests then exit;
- if ExpectedErrorClass<>nil then
- Fail('Missing '+ExpectedErrorClass.ClassName+' error {'+ExpectedErrorMsg+'} ('+IntToStr(ExpectedErrorNumber)+')');
- FJSSource:=TStringList.Create;
- FJSSource.Text:=JSToStr(JSModule);
- {$IFDEF VerbosePas2JS}
- writeln('TTestModule.ConvertModule JS:');
- write(FJSSource.Text);
- {$ENDIF}
- // rtl.module(...
- AssertEquals('jsmodule has one statement - the call',1,JSModule.Statements.Count);
- AssertNotNull('register module call',JSModule.Statements.Nodes[0].Node);
- AssertEquals('register module call',TJSCallExpression,JSModule.Statements.Nodes[0].Node.ClassType);
- FJSRegModuleCall:=JSModule.Statements.Nodes[0].Node as TJSCallExpression;
- AssertNotNull('register module rtl.module expr',JSRegModuleCall.Expr);
- AssertNotNull('register module rtl.module args',JSRegModuleCall.Args);
- AssertEquals('rtl.module args',TJSArguments,JSRegModuleCall.Args.ClassType);
- FJSModuleCallArgs:=JSRegModuleCall.Args as TJSArguments;
- AssertEquals('rtl.module args.count',3,JSModuleCallArgs.Elements.Count);
- // parameter 'unitname'
- AssertNotNull('module name param',JSModuleCallArgs.Elements.Elements[0].Expr);
- ModuleNameExpr:=JSModuleCallArgs.Elements.Elements[0].Expr as TJSLiteral;
- AssertEquals('module name param is string',ord(jstString),ord(ModuleNameExpr.Value.ValueType));
- if Module is TPasProgram then
- AssertEquals('module name','program',String(ModuleNameExpr.Value.AsString))
- else
- AssertEquals('module name',Module.Name,String(ModuleNameExpr.Value.AsString));
- // main uses section
- AssertNotNull('interface uses section',JSModuleCallArgs.Elements.Elements[1].Expr);
- AssertEquals('interface uses section type',TJSArrayLiteral,JSModuleCallArgs.Elements.Elements[1].Expr.ClassType);
- FJSInterfaceUses:=JSModuleCallArgs.Elements.Elements[1].Expr as TJSArrayLiteral;
- // function()
- AssertNotNull('module function',JSModuleCallArgs.Elements.Elements[2].Expr);
- AssertEquals('module function type',TJSFunctionDeclarationStatement,JSModuleCallArgs.Elements.Elements[2].Expr.ClassType);
- FunDecl:=JSModuleCallArgs.Elements.Elements[2].Expr as TJSFunctionDeclarationStatement;
- AssertNotNull('module function def',FunDecl.AFunction);
- FunDef:=FunDecl.AFunction as TJSFuncDef;
- AssertEquals('module function name','',String(FunDef.Name));
- AssertNotNull('module function body',FunDef.Body);
- FunBody:=FunDef.Body as TJSFunctionBody;
- FJSModuleSrc:=FunBody.A as TJSSourceElements;
- // init this.$main - the last statement
- if Module is TPasProgram then
- begin
- InitName:='$main';
- AssertEquals('this.'+InitName+' function 1',true,JSModuleSrc.Statements.Count>0);
- end
- else
- InitName:='$init';
- FJSInitBody:=nil;
- if JSModuleSrc.Statements.Count>0 then
- begin
- InitAssign:=JSModuleSrc.Statements.Nodes[JSModuleSrc.Statements.Count-1].Node as TJSSimpleAssignStatement;
- if GetDottedIdentifier(InitAssign.LHS)='this.'+InitName then
- begin
- InitFunction:=InitAssign.Expr as TJSFunctionDeclarationStatement;
- FJSInitBody:=InitFunction.AFunction.Body as TJSFunctionBody;
- end
- else if Module is TPasProgram then
- CheckDottedIdentifier('init function',InitAssign.LHS,'this.'+InitName);
- end;
- end;
- procedure TCustomTestModule.ConvertProgram;
- begin
- Add('end.');
- ParseProgram;
- ConvertModule;
- end;
- procedure TCustomTestModule.ConvertUnit;
- begin
- Add('end.');
- ParseUnit;
- ConvertModule;
- end;
- procedure TCustomTestModule.CheckDottedIdentifier(Msg: string; El: TJSElement;
- DottedName: string);
- begin
- if DottedName='' then
- begin
- AssertNull(Msg,El);
- end
- else
- begin
- AssertNotNull(Msg,El);
- AssertEquals(Msg,DottedName,GetDottedIdentifier(El));
- end;
- end;
- function TCustomTestModule.GetDottedIdentifier(El: TJSElement): string;
- begin
- if El=nil then
- Result:=''
- else if El is TJSPrimaryExpressionIdent then
- Result:=String(TJSPrimaryExpressionIdent(El).Name)
- else if El is TJSDotMemberExpression then
- Result:=GetDottedIdentifier(TJSDotMemberExpression(El).MExpr)+'.'+String(TJSDotMemberExpression(El).Name)
- else
- AssertEquals('GetDottedIdentifier',TJSPrimaryExpressionIdent,El.ClassType);
- end;
- procedure TCustomTestModule.CheckSource(Msg, Statements, InitStatements: string);
- var
- ActualSrc, ExpectedSrc, InitName: String;
- begin
- ActualSrc:=JSToStr(JSModuleSrc);
- ExpectedSrc:=Statements;
- if Module is TPasProgram then
- InitName:='$main'
- else
- InitName:='$init';
- if (Module is TPasProgram) or (InitStatements<>'') then
- ExpectedSrc:=ExpectedSrc+LineEnding
- +'this.'+InitName+' = function () {'+LineEnding
- +InitStatements
- +'};'+LineEnding;
- //writeln('TTestModule.CheckSource InitStatements="',InitStatements,'"');
- CheckDiff(Msg,ExpectedSrc,ActualSrc);
- end;
- procedure TCustomTestModule.CheckDiff(Msg, Expected, Actual: string);
- // search diff, ignore changes in spaces
- const
- SpaceChars = [#9,#10,#13,' '];
- var
- ExpectedP, ActualP: PChar;
- function FindLineEnd(p: PChar): PChar;
- begin
- Result:=p;
- while not (Result^ in [#0,#10,#13]) do inc(Result);
- end;
- function FindLineStart(p, MinP: PChar): PChar;
- begin
- while (p>MinP) and not (p[-1] in [#10,#13]) do dec(p);
- Result:=p;
- end;
- procedure DiffFound;
- var
- ActLineStartP, ActLineEndP, p, StartPos: PChar;
- ExpLine, ActLine: String;
- i: Integer;
- begin
- writeln('Diff found "',Msg,'". Lines:');
- // write correct lines
- p:=PChar(Expected);
- repeat
- StartPos:=p;
- while not (p^ in [#0,#10,#13]) do inc(p);
- ExpLine:=copy(Expected,StartPos-PChar(Expected)+1,p-StartPos);
- if p^ in [#10,#13] then begin
- if (p[1] in [#10,#13]) and (p^<>p[1]) then
- inc(p,2)
- else
- inc(p);
- end;
- if p<=ExpectedP then begin
- writeln('= ',ExpLine);
- end else begin
- // diff line
- // write actual line
- ActLineStartP:=FindLineStart(ActualP,PChar(Actual));
- ActLineEndP:=FindLineEnd(ActualP);
- ActLine:=copy(Actual,ActLineStartP-PChar(Actual)+1,ActLineEndP-ActLineStartP);
- writeln('- ',ActLine);
- // write expected line
- writeln('+ ',ExpLine);
- // write empty line with pointer ^
- for i:=1 to 2+ExpectedP-StartPos do write(' ');
- writeln('^');
- AssertEquals(Msg,ExpLine,ActLine);
- break;
- end;
- until p^=#0;
- raise Exception.Create('diff found, but lines are the same, internal error');
- end;
- var
- IsSpaceNeeded: Boolean;
- LastChar: Char;
- begin
- if Expected='' then Expected:=' ';
- if Actual='' then Actual:=' ';
- ExpectedP:=PChar(Expected);
- ActualP:=PChar(Actual);
- repeat
- //writeln('TTestModule.CheckDiff Exp="',ExpectedP^,'" Act="',ActualP^,'"');
- case ExpectedP^ of
- #0:
- begin
- // check that rest of Actual has only spaces
- while ActualP^ in SpaceChars do inc(ActualP);
- if ActualP^<>#0 then
- DiffFound;
- exit;
- end;
- ' ',#9,#10,#13:
- begin
- // skip space in Expected
- IsSpaceNeeded:=false;
- if ExpectedP>PChar(Expected) then
- LastChar:=ExpectedP[-1]
- else
- LastChar:=#0;
- while ExpectedP^ in SpaceChars do inc(ExpectedP);
- if (LastChar in ['a'..'z','A'..'Z','0'..'9','_','$'])
- and (ExpectedP^ in ['a'..'z','A'..'Z','0'..'9','_','$']) then
- IsSpaceNeeded:=true;
- if IsSpaceNeeded and (not (ActualP^ in SpaceChars)) then
- DiffFound;
- while ActualP^ in SpaceChars do inc(ActualP);
- end;
- else
- while ActualP^ in SpaceChars do inc(ActualP);
- if ExpectedP^<>ActualP^ then
- DiffFound;
- inc(ExpectedP);
- inc(ActualP);
- end;
- until false;
- end;
- procedure TCustomTestModule.SetExpectedPasResolverError(Msg: string;
- MsgNumber: integer);
- begin
- ExpectedErrorClass:=EPasResolve;
- ExpectedErrorMsg:=Msg;
- ExpectedErrorNumber:=MsgNumber;
- end;
- procedure TCustomTestModule.SetExpectedConverterError(Msg: string;
- MsgNumber: integer);
- begin
- ExpectedErrorClass:=EPas2JS;
- ExpectedErrorMsg:=Msg;
- ExpectedErrorNumber:=MsgNumber;
- end;
- function TCustomTestModule.IsErrorExpected(E: Exception): boolean;
- var
- MsgNumber: Integer;
- begin
- Result:=false;
- if (ExpectedErrorClass=nil) or (ExpectedErrorClass<>E.ClassType) then exit;
- if E is EPas2JS then
- MsgNumber:=EPas2JS(E).MsgNumber
- else if E is EPasResolve then
- MsgNumber:=EPasResolve(E).MsgNumber
- else
- MsgNumber:=0;
- Result:=(MsgNumber=ExpectedErrorNumber) and (E.Message=ExpectedErrorMsg);
- if Result then
- SkipTests:=true;
- end;
- procedure TCustomTestModule.HandleScannerError(E: EScannerError);
- begin
- if IsErrorExpected(E) then exit;
- WriteSources(Scanner.CurFilename,Scanner.CurRow,Scanner.CurColumn);
- writeln('ERROR: TCustomTestModule.HandleScannerError '+E.ClassName+':'+E.Message
- +' '+Scanner.CurFilename
- +'('+IntToStr(Scanner.CurRow)+','+IntToStr(Scanner.CurColumn)+')');
- RaiseException(E);
- end;
- procedure TCustomTestModule.HandleParserError(E: EParserError);
- begin
- if IsErrorExpected(E) then exit;
- WriteSources(E.Filename,E.Row,E.Column);
- writeln('ERROR: TCustomTestModule.HandleParserError '+E.ClassName+':'+E.Message
- +' '+E.Filename+'('+IntToStr(E.Row)+','+IntToStr(E.Column)+')'
- +' Line="'+Scanner.CurLine+'"'
- );
- RaiseException(E);
- end;
- procedure TCustomTestModule.HandlePasResolveError(E: EPasResolve);
- var
- Row, Col: integer;
- begin
- if IsErrorExpected(E) then exit;
- Engine.UnmangleSourceLineNumber(E.PasElement.SourceLinenumber,Row,Col);
- WriteSources(E.PasElement.SourceFilename,Row,Col);
- writeln('ERROR: TCustomTestModule.HandlePasResolveError '+E.ClassName+':'+E.Message
- +' '+E.PasElement.SourceFilename
- +'('+IntToStr(Row)+','+IntToStr(Col)+')');
- RaiseException(E);
- end;
- procedure TCustomTestModule.HandlePas2JSError(E: EPas2JS);
- var
- Row, Col: integer;
- begin
- if IsErrorExpected(E) then exit;
- Engine.UnmangleSourceLineNumber(E.PasElement.SourceLinenumber,Row,Col);
- WriteSources(E.PasElement.SourceFilename,Row,Col);
- writeln('ERROR: TCustomTestModule.HandlePas2JSError '+E.ClassName+':'+E.Message
- +' '+E.PasElement.SourceFilename
- +'('+IntToStr(Row)+','+IntToStr(Col)+')');
- RaiseException(E);
- end;
- procedure TCustomTestModule.HandleException(E: Exception);
- begin
- if IsErrorExpected(E) then exit;
- WriteSources('',0,0);
- writeln('ERROR: TCustomTestModule.HandleException '+E.ClassName+':'+E.Message);
- RaiseException(E);
- end;
- procedure TCustomTestModule.RaiseException(E: Exception);
- var
- MsgNumber: Integer;
- begin
- if ExpectedErrorClass<>nil then begin
- if FExpectedErrorClass=E.ClassType then begin
- if E is EPas2JS then
- MsgNumber:=EPas2JS(E).MsgNumber
- else if E is EPasResolve then
- MsgNumber:=EPasResolve(E).MsgNumber
- else
- MsgNumber:=0;
- AssertEquals('Expected error message ('+IntToStr(ExpectedErrorNumber)+')','{'+ExpectedErrorMsg+'}','{'+E.Message+'}');
- AssertEquals('Expected {'+ExpectedErrorMsg+'}, but got msg {'+E.Message+'} number',
- ExpectedErrorNumber,MsgNumber);
- end else begin
- AssertEquals('Wrong exception class',ExpectedErrorClass.ClassName,E.ClassName);
- end;
- end;
- Fail(E.Message);
- end;
- procedure TCustomTestModule.WriteSources(const aFilename: string; aRow,
- aCol: integer);
- var
- IsSrc: Boolean;
- i, j: Integer;
- SrcLines: TStringList;
- Line: string;
- aModule: TTestEnginePasResolver;
- begin
- for i:=0 to ModuleCount-1 do
- begin
- aModule:=Modules[i];
- SrcLines:=TStringList.Create;
- try
- SrcLines.Text:=aModule.Source;
- IsSrc:=ExtractFilename(aModule.Filename)=ExtractFileName(aFilename);
- writeln('Testcode:-File="',aModule.Filename,'"----------------------------------:');
- for j:=1 to SrcLines.Count do
- begin
- Line:=SrcLines[j-1];
- if IsSrc and (j=aRow) then
- begin
- write('*');
- Line:=LeftStr(Line,aCol-1)+'|'+copy(Line,aCol,length(Line));
- end;
- writeln(Format('%:4d: ',[j]),Line);
- end;
- finally
- SrcLines.Free;
- end;
- end;
- end;
- { TTestModule }
- procedure TTestModule.TestEmptyProgram;
- begin
- StartProgram(false);
- Add('begin');
- ConvertProgram;
- CheckSource('TestEmptyProgram','','');
- end;
- procedure TTestModule.TestEmptyProgramUseStrict;
- begin
- Converter.Options:=Converter.Options+[coUseStrict];
- StartProgram(false);
- Add('begin');
- ConvertProgram;
- CheckSource('TestEmptyProgramUseStrict','"use strict";','');
- end;
- procedure TTestModule.TestEmptyUnit;
- begin
- StartUnit(false);
- Add('interface');
- Add('implementation');
- ConvertUnit;
- CheckSource('TestEmptyUnit',
- LinesToStr([
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;'
- ]),
- '');
- end;
- procedure TTestModule.TestEmptyUnitUseStrict;
- begin
- Converter.Options:=Converter.Options+[coUseStrict];
- StartUnit(false);
- Add('interface');
- Add('implementation');
- ConvertUnit;
- CheckSource('TestEmptyUnitUseStrict',
- LinesToStr([
- '"use strict";',
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;'
- ]),
- '');
- end;
- procedure TTestModule.TestVarInt;
- begin
- StartProgram(false);
- Add('var MyI: longint;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestVarInt','this.MyI=0;','');
- end;
- procedure TTestModule.TestVarBaseTypes;
- begin
- StartProgram(false);
- Add('var');
- Add(' i: longint;');
- Add(' s: string;');
- Add(' c: char;');
- Add(' b: boolean;');
- Add(' d: double;');
- Add(' i2: longint = 3;');
- Add(' s2: string = ''foo'';');
- Add(' c2: char = ''4'';');
- Add(' b2: boolean = true;');
- Add(' d2: double = 5.6;');
- Add(' i3: longint = $707;');
- Add(' i4: int64 = 4503599627370495;');
- Add(' i5: int64 = -4503599627370496;');
- Add(' i6: int64 = $fffffffffffff;');
- Add(' i7: int64 = -$10000000000000;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestVarBaseTypes',
- LinesToStr([
- 'this.i=0;',
- 'this.s="";',
- 'this.c="";',
- 'this.b=false;',
- 'this.d=0.0;',
- 'this.i2=3;',
- 'this.s2="foo";',
- 'this.c2="4";',
- 'this.b2=true;',
- 'this.d2=5.6;',
- 'this.i3=0x707;',
- 'this.i4= 4503599627370495;',
- 'this.i5= -4503599627370496;',
- 'this.i6= 0xfffffffffffff;',
- 'this.i7=-0x10000000000000;'
- ]),
- '');
- end;
- procedure TTestModule.TestConstBaseTypes;
- begin
- StartProgram(false);
- Add('const');
- Add(' i: longint = 3;');
- Add(' s: string = ''foo'';');
- Add(' c: char = ''4'';');
- Add(' b: boolean = true;');
- Add(' d: double = 5.6;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestVarBaseTypes',
- LinesToStr([
- 'this.i=3;',
- 'this.s="foo";',
- 'this.c="4";',
- 'this.b=true;',
- 'this.d=5.6;'
- ]),
- '');
- end;
- procedure TTestModule.TestAliasTypeRef;
- begin
- StartProgram(false);
- Add('type');
- Add(' a=longint;');
- Add(' b=a;');
- Add('var');
- Add(' c: A;');
- Add(' d: B;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestAliasTypeRef',
- LinesToStr([ // statements
- 'this.c = 0;',
- 'this.d = 0;'
- ]),
- LinesToStr([ // this.$main
- ''
- ]));
- end;
- procedure TTestModule.TestTypeCast_BaseTypes;
- begin
- StartProgram(false);
- Add('var');
- Add(' i: longint;');
- Add(' b: boolean;');
- Add(' d: double;');
- Add(' s: string;');
- Add(' c: char;');
- Add('begin');
- Add(' i:=longint(i);');
- Add(' i:=longint(b);');
- Add(' b:=boolean(b);');
- Add(' b:=boolean(i);');
- Add(' d:=double(d);');
- Add(' d:=double(i);');
- Add(' s:=string(s);');
- Add(' s:=string(c);');
- Add(' c:=char(c);');
- ConvertProgram;
- CheckSource('TestAliasTypeRef',
- LinesToStr([ // statements
- 'this.i = 0;',
- 'this.b = false;',
- 'this.d = 0.0;',
- 'this.s = "";',
- 'this.c = "";',
- '']),
- LinesToStr([ // this.$main
- 'this.i = this.i;',
- 'this.i = (this.b ? 1 : 0);',
- 'this.b = this.b;',
- 'this.b = this.i != 0;',
- 'this.d = this.d;',
- 'this.d = this.i;',
- 'this.s = this.s;',
- 'this.s = this.c;',
- 'this.c = this.c;',
- '']));
- end;
- procedure TTestModule.TestTypeCast_AliasBaseTypes;
- begin
- StartProgram(false);
- Add('type');
- Add(' integer = longint;');
- Add(' TYesNo = boolean;');
- Add(' TFloat = double;');
- Add(' TCaption = string;');
- Add(' TChar = char;');
- Add('var');
- Add(' i: integer;');
- Add(' b: TYesNo;');
- Add(' d: TFloat;');
- Add(' s: TCaption;');
- Add(' c: TChar;');
- Add('begin');
- Add(' i:=integer(i);');
- Add(' i:=integer(b);');
- Add(' b:=TYesNo(b);');
- Add(' b:=TYesNo(i);');
- Add(' d:=TFloat(d);');
- Add(' d:=TFloat(i);');
- Add(' s:=TCaption(s);');
- Add(' s:=TCaption(c);');
- Add(' c:=TChar(c);');
- ConvertProgram;
- CheckSource('TestAliasTypeRef',
- LinesToStr([ // statements
- 'this.i = 0;',
- 'this.b = false;',
- 'this.d = 0.0;',
- 'this.s = "";',
- 'this.c = "";',
- '']),
- LinesToStr([ // this.$main
- 'this.i = this.i;',
- 'this.i = (this.b ? 1 : 0);',
- 'this.b = this.b;',
- 'this.b = this.i != 0;',
- 'this.d = this.d;',
- 'this.d = this.i;',
- 'this.s = this.s;',
- 'this.s = this.c;',
- 'this.c = this.c;',
- '']));
- end;
- procedure TTestModule.TestEmptyProc;
- begin
- StartProgram(false);
- Add('procedure Test;');
- Add('begin');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestEmptyProc',
- LinesToStr([ // statements
- 'this.Test = function () {',
- '};'
- ]),
- LinesToStr([ // this.$main
- ''
- ]));
- end;
- procedure TTestModule.TestProcOneParam;
- begin
- StartProgram(false);
- Add('procedure ProcA(i: longint);');
- Add('begin');
- Add('end;');
- Add('begin');
- Add(' PROCA(3);');
- ConvertProgram;
- CheckSource('TestProcOneParam',
- LinesToStr([ // statements
- 'this.ProcA = function (i) {',
- '};'
- ]),
- LinesToStr([ // this.$main
- 'this.ProcA(3);'
- ]));
- end;
- procedure TTestModule.TestFunctionWithoutParams;
- begin
- StartProgram(false);
- Add('function FuncA: longint;');
- Add('begin');
- Add('end;');
- Add('var i: longint;');
- Add('begin');
- Add(' I:=FUNCA();');
- Add(' I:=FUNCA;');
- Add(' FUNCA();');
- Add(' FUNCA;');
- ConvertProgram;
- CheckSource('TestProcWithoutParams',
- LinesToStr([ // statements
- 'this.FuncA = function () {',
- ' var Result = 0;',
- ' return Result;',
- '};',
- 'this.i=0;'
- ]),
- LinesToStr([ // this.$main
- 'this.i=this.FuncA();',
- 'this.i=this.FuncA();',
- 'this.FuncA();',
- 'this.FuncA();'
- ]));
- end;
- procedure TTestModule.TestProcedureWithoutParams;
- begin
- StartProgram(false);
- Add('procedure ProcA;');
- Add('begin');
- Add('end;');
- Add('begin');
- Add(' PROCA();');
- Add(' PROCA;');
- ConvertProgram;
- CheckSource('TestProcWithoutParams',
- LinesToStr([ // statements
- 'this.ProcA = function () {',
- '};'
- ]),
- LinesToStr([ // this.$main
- 'this.ProcA();',
- 'this.ProcA();'
- ]));
- end;
- procedure TTestModule.TestIncDec;
- begin
- StartProgram(false);
- Add('var');
- Add(' Bar: longint;');
- Add('begin');
- Add(' inc(bar);');
- Add(' inc(bar,2);');
- Add(' dec(bar);');
- Add(' dec(bar,3);');
- ConvertProgram;
- CheckSource('TestIncDec',
- LinesToStr([ // statements
- 'this.Bar = 0;'
- ]),
- LinesToStr([ // this.$main
- 'this.Bar+=1;',
- 'this.Bar+=2;',
- 'this.Bar-=1;',
- 'this.Bar-=3;'
- ]));
- end;
- procedure TTestModule.TestAssignments;
- begin
- StartProgram(false);
- Parser.Options:=Parser.Options+[po_cassignments];
- Add('var');
- Add(' Bar:longint;');
- Add('begin');
- Add(' bar:=3;');
- Add(' bar+=4;');
- Add(' bar-=5;');
- Add(' bar*=6;');
- ConvertProgram;
- CheckSource('TestAssignments',
- LinesToStr([ // statements
- 'this.Bar = 0;'
- ]),
- LinesToStr([ // this.$main
- 'this.Bar=3;',
- 'this.Bar+=4;',
- 'this.Bar-=5;',
- 'this.Bar*=6;'
- ]));
- end;
- procedure TTestModule.TestArithmeticOperators1;
- begin
- StartProgram(false);
- Add('var');
- Add(' vA,vB,vC:longint;');
- Add('begin');
- Add(' va:=1;');
- Add(' vb:=va+va;');
- Add(' vb:=va div vb;');
- Add(' vb:=va mod vb;');
- Add(' vb:=va+va*vb+va div vb;');
- Add(' vc:=-va;');
- Add(' va:=va-vb;');
- Add(' vb:=va;');
- Add(' if va<vb then vc:=va else vc:=vb;');
- ConvertProgram;
- CheckSource('TestArithmeticOperators1',
- LinesToStr([ // statements
- 'this.vA = 0;',
- 'this.vB = 0;',
- 'this.vC = 0;'
- ]),
- LinesToStr([ // this.$main
- 'this.vA = 1;',
- 'this.vB = this.vA + this.vA;',
- 'this.vB = Math.floor(this.vA / this.vB);',
- 'this.vB = this.vA % this.vB;',
- 'this.vB = (this.vA + (this.vA * this.vB)) + Math.floor(this.vA / this.vB);',
- 'this.vC = -this.vA;',
- 'this.vA = this.vA - this.vB;',
- 'this.vB = this.vA;',
- 'if (this.vA < this.vB){ this.vC = this.vA } else this.vC = this.vB;'
- ]));
- end;
- procedure TTestModule.TestLogicalOperators;
- begin
- StartProgram(false);
- Add('var');
- Add(' vA,vB,vC:boolean;');
- Add('begin');
- Add(' va:=vb and vc;');
- Add(' va:=vb or vc;');
- Add(' va:=true and vc;');
- Add(' va:=(vb and vc) or (va and vb);');
- Add(' va:=not vb;');
- ConvertProgram;
- CheckSource('TestLogicalOperators',
- LinesToStr([ // statements
- 'this.vA = false;',
- 'this.vB = false;',
- 'this.vC = false;'
- ]),
- LinesToStr([ // this.$main
- 'this.vA = this.vB && this.vC;',
- 'this.vA = this.vB || this.vC;',
- 'this.vA = true && this.vC;',
- 'this.vA = (this.vB && this.vC) || (this.vA && this.vB);',
- 'this.vA = !this.vB;'
- ]));
- end;
- procedure TTestModule.TestBitwiseOperators;
- begin
- StartProgram(false);
- Add('var');
- Add(' vA,vB,vC:longint;');
- Add('begin');
- Add(' va:=vb and vc;');
- Add(' va:=vb or vc;');
- Add(' va:=vb xor vc;');
- Add(' va:=vb shl vc;');
- Add(' va:=vb shr vc;');
- Add(' va:=3 and vc;');
- Add(' va:=(vb and vc) or (va and vb);');
- Add(' va:=not vb;');
- ConvertProgram;
- CheckSource('TestBitwiseOperators',
- LinesToStr([ // statements
- 'this.vA = 0;',
- 'this.vB = 0;',
- 'this.vC = 0;'
- ]),
- LinesToStr([ // this.$main
- 'this.vA = this.vB & this.vC;',
- 'this.vA = this.vB | this.vC;',
- 'this.vA = this.vB ^ this.vC;',
- 'this.vA = this.vB << this.vC;',
- 'this.vA = this.vB >>> this.vC;',
- 'this.vA = 3 & this.vC;',
- 'this.vA = (this.vB & this.vC) | (this.vA & this.vB);',
- 'this.vA = ~this.vB;'
- ]));
- end;
- procedure TTestModule.TestPrgProcVar;
- begin
- StartProgram(false);
- Add('procedure Proc1;');
- Add('type');
- Add(' t1=longint;');
- Add('var');
- Add(' vA:t1;');
- Add('begin');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestPrgProcVar',
- LinesToStr([ // statements
- 'this.Proc1 = function () {',
- ' var vA=0;',
- '};'
- ]),
- LinesToStr([ // this.$main
- ''
- ]));
- end;
- procedure TTestModule.TestUnitProcVar;
- begin
- StartUnit(false);
- Add('interface');
- Add('');
- Add('type tA=string; // unit scope');
- Add('procedure Proc1;');
- Add('');
- Add('implementation');
- Add('');
- Add('procedure Proc1;');
- Add('type tA=longint; // local proc scope');
- Add('var v1:tA; // using local tA');
- Add('begin');
- Add('end;');
- Add('var v2:tA; // using interface tA');
- ConvertUnit;
- CheckSource('TestUnitProcVar',
- LinesToStr([ // statements
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;',
- 'this.Proc1 = function () {',
- ' var v1 = 0;',
- '};',
- '$impl.v2 = "";'
- ]),
- '' // this.$init
- );
- end;
- procedure TTestModule.TestImplProc;
- begin
- StartUnit(false);
- Add('interface');
- Add('');
- Add('procedure Proc1;');
- Add('');
- Add('implementation');
- Add('');
- Add('procedure Proc1; begin end;');
- Add('procedure Proc2; begin end;');
- Add('initialization');
- Add(' Proc1;');
- Add(' Proc2;');
- ConvertUnit;
- CheckSource('TestImplProc',
- LinesToStr([ // statements
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;',
- 'this.Proc1 = function () {',
- '};',
- '$impl.Proc2 = function () {',
- '};',
- '']),
- LinesToStr([ // this.$init
- 'this.Proc1();',
- '$impl.Proc2();',
- '']));
- end;
- procedure TTestModule.TestFunctionResult;
- begin
- StartProgram(false);
- Add('function Func1: longint;');
- Add('begin');
- Add(' Result:=3;');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestFunctionResult',
- LinesToStr([ // statements
- 'this.Func1 = function () {',
- ' var Result = 0;',
- ' Result = 3;',
- ' return Result;',
- '};'
- ]),
- '');
- end;
- procedure TTestModule.TestNestedProc;
- begin
- StartProgram(false);
- Add('function DoIt(pA,pD: longint): longint;');
- Add('var');
- Add(' vB: longint;');
- Add(' vC: longint;');
- Add(' function Nesty(pA: longint): longint; ');
- Add(' var vB: longint;');
- Add(' begin');
- Add(' Result:=pa+vb+vc+pd;');
- Add(' end;');
- Add('begin');
- Add(' Result:=pa+vb+vc;');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestNestedProc',
- LinesToStr([ // statements
- 'this.DoIt = function (pA, pD) {',
- ' var Result = 0;',
- ' var vB = 0;',
- ' var vC = 0;',
- ' function Nesty(pA) {',
- ' var Result = 0;',
- ' var vB = 0;',
- ' Result = ((pA + vB) + vC) + pD;',
- ' return Result;',
- ' };',
- ' Result = (pA + vB) + vC;',
- ' return Result;',
- '};'
- ]),
- '');
- end;
- procedure TTestModule.TestForwardProc;
- begin
- StartProgram(false);
- Add('procedure FuncA(Bar: longint); forward;');
- Add('procedure FuncB(Bar: longint);');
- Add('begin');
- Add(' funca(bar);');
- Add('end;');
- Add('procedure funca(bar: longint);');
- Add('begin');
- Add(' if bar=3 then ;');
- Add('end;');
- Add('begin');
- Add(' funca(4);');
- Add(' funcb(5);');
- ConvertProgram;
- CheckSource('TestForwardProc',
- LinesToStr([ // statements'
- 'this.FuncB = function (Bar) {',
- ' this.FuncA(Bar);',
- '};',
- 'this.FuncA = function (Bar) {',
- ' if (Bar == 3);',
- '};'
- ]),
- LinesToStr([
- 'this.FuncA(4);',
- 'this.FuncB(5);'
- ])
- );
- end;
- procedure TTestModule.TestNestedForwardProc;
- begin
- StartProgram(false);
- Add('procedure FuncA;');
- Add(' procedure FuncB(i: longint); forward;');
- Add(' procedure FuncC(i: longint);');
- Add(' begin');
- Add(' funcb(i);');
- Add(' end;');
- Add(' procedure FuncB(i: longint);');
- Add(' begin');
- Add(' if i=3 then ;');
- Add(' end;');
- Add('begin');
- Add(' funcc(4)');
- Add('end;');
- Add('begin');
- Add(' funca;');
- ConvertProgram;
- CheckSource('TestNestedForwardProc',
- LinesToStr([ // statements'
- 'this.FuncA = function () {',
- ' function FuncC(i) {',
- ' FuncB(i);',
- ' };',
- ' function FuncB(i) {',
- ' if (i == 3);',
- ' };',
- ' FuncC(4);',
- '};'
- ]),
- LinesToStr([
- 'this.FuncA();'
- ])
- );
- end;
- procedure TTestModule.TestAssignFunctionResult;
- begin
- StartProgram(false);
- Add('function Func1: longint;');
- Add('begin');
- Add('end;');
- Add('var i: longint;');
- Add('begin');
- Add(' i:=func1();');
- Add(' i:=func1()+func1();');
- ConvertProgram;
- CheckSource('TestAssignFunctionResult',
- LinesToStr([ // statements
- 'this.Func1 = function () {',
- ' var Result = 0;',
- ' return Result;',
- '};',
- 'this.i = 0;'
- ]),
- LinesToStr([
- 'this.i = this.Func1();',
- 'this.i = this.Func1() + this.Func1();'
- ]));
- end;
- procedure TTestModule.TestFunctionResultInCondition;
- begin
- StartProgram(false);
- Add('function Func1: longint;');
- Add('begin');
- Add('end;');
- Add('function Func2: boolean;');
- Add('begin');
- Add('end;');
- Add('var i: longint;');
- Add('begin');
- Add(' if func2 then ;');
- Add(' if i=func1() then ;');
- Add(' if i=func1 then ;');
- ConvertProgram;
- CheckSource('TestFunctionResultInCondition',
- LinesToStr([ // statements
- 'this.Func1 = function () {',
- ' var Result = 0;',
- ' return Result;',
- '};',
- 'this.Func2 = function () {',
- ' var Result = false;',
- ' return Result;',
- '};',
- 'this.i = 0;'
- ]),
- LinesToStr([
- 'if (this.Func2());',
- 'if (this.i == this.Func1());',
- 'if (this.i == this.Func1());'
- ]));
- end;
- procedure TTestModule.TestExit;
- begin
- StartProgram(false);
- Add('procedure ProcA;');
- Add('begin');
- Add(' exit;');
- Add('end;');
- Add('function FuncB: longint;');
- Add('begin');
- Add(' exit;');
- Add(' exit(3);');
- Add('end;');
- Add('function FuncC: string;');
- Add('begin');
- Add(' exit;');
- Add(' exit(''a'');');
- Add(' exit(''abc'');');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestExit',
- LinesToStr([ // statements
- 'this.ProcA = function () {',
- ' return;',
- '};',
- 'this.FuncB = function () {',
- ' var Result = 0;',
- ' return Result;',
- ' return 3;',
- ' return Result;',
- '};',
- 'this.FuncC = function () {',
- ' var Result = "";',
- ' return Result;',
- ' return "a";',
- ' return "abc";',
- ' return Result;',
- '};'
- ]),
- '');
- end;
- procedure TTestModule.TestBreak;
- begin
- StartProgram(false);
- Add('var i: longint;');
- Add('begin');
- Add(' repeat');
- Add(' break;');
- Add(' until true;');
- Add(' while true do');
- Add(' break;');
- Add(' for i:=1 to 2 do');
- Add(' break;');
- ConvertProgram;
- CheckSource('TestBreak',
- LinesToStr([ // statements
- 'this.i = 0;'
- ]),
- LinesToStr([
- 'do {',
- ' break;',
- '} while (!true);',
- 'while (true) break;',
- 'var $loopend1 = 2;',
- 'for (this.i = 1; this.i <= $loopend1; this.i++) break;',
- 'if (this.i > $loopend1) this.i--;'
- ]));
- end;
- procedure TTestModule.TestContinue;
- begin
- StartProgram(false);
- Add('var i: longint;');
- Add('begin');
- Add(' repeat');
- Add(' continue;');
- Add(' until true;');
- Add(' while true do');
- Add(' continue;');
- Add(' for i:=1 to 2 do');
- Add(' continue;');
- ConvertProgram;
- CheckSource('TestContinue',
- LinesToStr([ // statements
- 'this.i = 0;'
- ]),
- LinesToStr([
- 'do {',
- ' continue;',
- '} while (!true);',
- 'while (true) continue;',
- 'var $loopend1 = 2;',
- 'for (this.i = 1; this.i <= $loopend1; this.i++) continue;',
- 'if (this.i > $loopend1) this.i--;'
- ]));
- end;
- procedure TTestModule.TestProcedureExternal;
- begin
- StartProgram(false);
- Add('procedure Foo; external name ''console.log'';');
- Add('function Bar: longint; external name ''get.item'';');
- Add('function Bla(s: string): longint; external name ''apply.something'';');
- Add('var');
- Add(' i: longint;');
- Add('begin');
- Add(' Foo;');
- Add(' i:=Bar;');
- Add(' i:=Bla(''abc'');');
- ConvertProgram;
- CheckSource('TestProcedureExternal',
- LinesToStr([ // statements
- 'this.i = 0;'
- ]),
- LinesToStr([
- 'console.log();',
- 'this.i = get.item();',
- 'this.i = apply.something("abc");'
- ]));
- end;
- procedure TTestModule.TestProcedureExternalOtherUnit;
- begin
- AddModuleWithIntfImplSrc('unit2.pas',
- LinesToStr([
- 'procedure Now; external name ''Date.now'';',
- 'procedure DoIt;'
- ]),
- 'procedure doit; begin end;');
- StartUnit(true);
- Add('interface');
- Add('uses unit2;');
- Add('implementation');
- Add('begin');
- Add(' now;');
- Add(' now();');
- Add(' uNit2.now;');
- Add(' uNit2.now();');
- Add(' test1.now;');
- Add(' test1.now();');
- Add(' doit;');
- Add(' uNit2.doit;');
- Add(' test1.doit;');
- ConvertUnit;
- CheckSource('TestProcedureExternalOtherUnit',
- LinesToStr([
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;'
- ]),
- LinesToStr([
- 'Date.now();',
- 'Date.now();',
- 'Date.now();',
- 'Date.now();',
- 'Date.now();',
- 'Date.now();',
- 'pas.unit2.DoIt();',
- 'pas.unit2.DoIt();',
- 'pas.unit2.DoIt();'
- ]));
- end;
- procedure TTestModule.TestProcedureAsm;
- begin
- StartProgram(false);
- Add('function DoIt: longint;');
- Add('begin;');
- Add(' asm');
- Add(' { a:{ b:{}, c:[]}, d:''1'' };');
- Add(' end;');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestProcedureAsm',
- LinesToStr([ // statements
- 'this.DoIt = function () {',
- ' var Result = 0;',
- ' { a:{ b:{}, c:[]}, d:''1'' };',
- ' return Result;',
- '};'
- ]),
- LinesToStr([
- ''
- ]));
- end;
- procedure TTestModule.TestProcedureAssembler;
- begin
- StartProgram(false);
- Add('function DoIt: longint; assembler;');
- Add('asm');
- Add('{ a:{ b:{}, c:[]}, d:''1'' };');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestProcedureAssembler',
- LinesToStr([ // statements
- 'this.DoIt = function () {',
- ' { a:{ b:{}, c:[]}, d:''1'' };',
- '};'
- ]),
- LinesToStr([
- ''
- ]));
- end;
- procedure TTestModule.TestProcedure_VarParam;
- begin
- StartProgram(false);
- Add('type integer = longint;');
- Add('procedure DoIt(vG: integer; const vH: integer; var vI: integer);');
- Add('var vJ: integer;');
- Add('begin');
- Add(' vg:=vg+1;');
- Add(' vj:=vh+2;');
- Add(' vi:=vi+3;');
- Add(' doit(vg,vg,vg);');
- Add(' doit(vh,vh,vj);');
- Add(' doit(vi,vi,vi);');
- Add(' doit(vj,vj,vj);');
- Add('end;');
- Add('var i: integer;');
- Add('begin');
- Add(' doit(i,i,i);');
- ConvertProgram;
- CheckSource('TestProcedure_VarParam',
- LinesToStr([ // statements
- 'this.DoIt = function (vG,vH,vI) {',
- ' var vJ = 0;',
- ' vG = vG + 1;',
- ' vJ = vH + 2;',
- ' vI.set(vI.get()+3);',
- ' this.DoIt(vG, vG, {',
- ' get: function () {',
- ' return vG;',
- ' },',
- ' set: function (v) {',
- ' vG = v;',
- ' }',
- ' });',
- ' this.DoIt(vH, vH, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- ' this.DoIt(vI.get(), vI.get(), vI);',
- ' this.DoIt(vJ, vJ, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- '};',
- 'this.i = 0;'
- ]),
- LinesToStr([
- 'this.DoIt(this.i,this.i,{',
- ' p: this,',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});'
- ]));
- end;
- procedure TTestModule.TestProcedureOverload;
- begin
- StartProgram(false);
- Add('procedure DoIt(vI: longint); begin end;');
- Add('procedure DoIt(vI, vJ: longint); begin end;');
- Add('procedure DoIt(vD: double); begin end;');
- Add('begin');
- Add(' DoIt(1);');
- Add(' DoIt(2,3);');
- Add(' DoIt(4.5);');
- ConvertProgram;
- CheckSource('TestProcedureOverload',
- LinesToStr([ // statements
- 'this.DoIt = function (vI) {',
- '};',
- 'this.DoIt$1 = function (vI, vJ) {',
- '};',
- 'this.DoIt$2 = function (vD) {',
- '};',
- '']),
- LinesToStr([
- 'this.DoIt(1);',
- 'this.DoIt$1(2, 3);',
- 'this.DoIt$2(4.5);',
- '']));
- end;
- procedure TTestModule.TestProcedureOverloadForward;
- begin
- StartProgram(false);
- Add('procedure DoIt(vI: longint); forward;');
- Add('procedure DoIt(vI, vJ: longint); begin end;');
- Add('procedure doit(vi: longint); begin end;');
- Add('begin');
- Add(' doit(1);');
- Add(' doit(2,3);');
- ConvertProgram;
- CheckSource('TestProcedureOverloadForward',
- LinesToStr([ // statements
- 'this.DoIt$1 = function (vI, vJ) {',
- '};',
- 'this.DoIt = function (vI) {',
- '};',
- '']),
- LinesToStr([
- 'this.DoIt(1);',
- 'this.DoIt$1(2, 3);',
- '']));
- end;
- procedure TTestModule.TestProcedureOverloadUnit;
- begin
- StartUnit(false);
- Add('interface');
- Add('procedure DoIt(vI: longint);');
- Add('procedure DoIt(vI, vJ: longint);');
- Add('implementation');
- Add('procedure DoIt(vI, vJ, vK, vL, vM: longint); forward;');
- Add('procedure DoIt(vI, vJ, vK: longint); begin end;');
- Add('procedure DoIt(vi: longint); begin end;');
- Add('procedure DoIt(vI, vJ, vK, vL: longint); begin end;');
- Add('procedure DoIt(vi, vj: longint); begin end;');
- Add('procedure DoIt(vi, vj, vk, vl, vm: longint); begin end;');
- Add('begin');
- Add(' doit(1);');
- Add(' doit(2,3);');
- Add(' doit(4,5,6);');
- Add(' doit(7,8,9,10);');
- Add(' doit(11,12,13,14,15);');
- ConvertUnit;
- CheckSource('TestProcedureOverloadUnit',
- LinesToStr([ // statements
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;',
- 'this.DoIt = function (vI) {',
- '};',
- 'this.DoIt$1 = function (vI, vJ) {',
- '};',
- '$impl.DoIt$3 = function (vI, vJ, vK) {',
- '};',
- '$impl.DoIt$4 = function (vI, vJ, vK, vL) {',
- '};',
- '$impl.DoIt$2 = function (vI, vJ, vK, vL, vM) {',
- '};',
- '']),
- LinesToStr([
- 'this.DoIt(1);',
- 'this.DoIt$1(2, 3);',
- '$impl.DoIt$3(4,5,6);',
- '$impl.DoIt$4(7,8,9,10);',
- '$impl.DoIt$2(11,12,13,14,15);',
- '']));
- end;
- procedure TTestModule.TestProcedureOverloadNested;
- begin
- StartProgram(false);
- Add('procedure DoIt(vA: longint); forward;');
- Add('procedure DoIt(vB, vC: longint);');
- Add('begin // 2 param overload');
- Add(' doit(1);');
- Add(' doit(1,2);');
- Add('end;');
- Add('procedure doit(vA: longint);');
- Add(' procedure DoIt(vA, vB, vC: longint); forward;');
- Add(' procedure DoIt(vA, vB, vC, vD: longint);');
- Add(' begin // 4 param overload');
- Add(' doit(1);');
- Add(' doit(1,2);');
- Add(' doit(1,2,3);');
- Add(' doit(1,2,3,4);');
- Add(' end;');
- Add(' procedure doit(vA, vB, vC: longint);');
- Add(' procedure DoIt(vA, vB, vC, vD, vE: longint); forward;');
- Add(' procedure DoIt(vA, vB, vC, vD, vE, vF: longint);');
- Add(' begin // 6 param overload');
- Add(' doit(1);');
- Add(' doit(1,2);');
- Add(' doit(1,2,3);');
- Add(' doit(1,2,3,4);');
- Add(' doit(1,2,3,4,5);');
- Add(' doit(1,2,3,4,5,6);');
- Add(' end;');
- Add(' procedure doit(vA, vB, vC, vD, vE: longint);');
- Add(' begin // 5 param overload');
- Add(' doit(1);');
- Add(' doit(1,2);');
- Add(' doit(1,2,3);');
- Add(' doit(1,2,3,4);');
- Add(' doit(1,2,3,4,5);');
- Add(' doit(1,2,3,4,5,6);');
- Add(' end;');
- Add(' begin // 3 param overload');
- Add(' doit(1);');
- Add(' doit(1,2);');
- Add(' doit(1,2,3);');
- Add(' doit(1,2,3,4);');
- Add(' doit(1,2,3,4,5);');
- Add(' doit(1,2,3,4,5,6);');
- Add(' end;');
- Add('begin // 1 param overload');
- Add(' doit(1);');
- Add(' doit(1,2);');
- Add(' doit(1,2,3);');
- Add(' doit(1,2,3,4);');
- Add('end;');
- Add('begin // main');
- Add(' doit(1);');
- Add(' doit(1,2);');
- ConvertProgram;
- CheckSource('TestProcedureOverloadNested',
- LinesToStr([ // statements
- 'this.DoIt$1 = function (vB, vC) {',
- ' this.DoIt(1);',
- ' this.DoIt$1(1, 2);',
- '};',
- 'this.DoIt = function (vA) {',
- ' function DoIt$3(vA, vB, vC, vD) {',
- ' this.DoIt(1);',
- ' this.DoIt$1(1, 2);',
- ' DoIt$2(1, 2, 3);',
- ' DoIt$3(1, 2, 3, 4);',
- ' };',
- ' function DoIt$2(vA, vB, vC) {',
- ' function DoIt$5(vA, vB, vC, vD, vE, vF) {',
- ' this.DoIt(1);',
- ' this.DoIt$1(1, 2);',
- ' DoIt$2(1, 2, 3);',
- ' DoIt$3(1, 2, 3, 4);',
- ' DoIt$4(1, 2, 3, 4, 5);',
- ' DoIt$5(1, 2, 3, 4, 5, 6);',
- ' };',
- ' function DoIt$4(vA, vB, vC, vD, vE) {',
- ' this.DoIt(1);',
- ' this.DoIt$1(1, 2);',
- ' DoIt$2(1, 2, 3);',
- ' DoIt$3(1, 2, 3, 4);',
- ' DoIt$4(1, 2, 3, 4, 5);',
- ' DoIt$5(1, 2, 3, 4, 5, 6);',
- ' };',
- ' this.DoIt(1);',
- ' this.DoIt$1(1, 2);',
- ' DoIt$2(1, 2, 3);',
- ' DoIt$3(1, 2, 3, 4);',
- ' DoIt$4(1, 2, 3, 4, 5);',
- ' DoIt$5(1, 2, 3, 4, 5, 6);',
- ' };',
- ' this.DoIt(1);',
- ' this.DoIt$1(1, 2);',
- ' DoIt$2(1, 2, 3);',
- ' DoIt$3(1, 2, 3, 4);',
- '};',
- '']),
- LinesToStr([
- 'this.DoIt(1);',
- 'this.DoIt$1(1, 2);',
- '']));
- end;
- procedure TTestModule.TestProc_Varargs;
- begin
- StartProgram(false);
- Add('procedure ProcA(i:longint); varargs; external name ''ProcA'';');
- Add('procedure ProcB; varargs; external name ''ProcB'';');
- Add('procedure ProcC(i: longint = 17); varargs; external name ''ProcC'';');
- Add('function GetIt: longint; begin end;');
- Add('begin');
- Add(' ProcA(1);');
- Add(' ProcA(1,2);');
- Add(' ProcA(1,2.0);');
- Add(' ProcA(1,2,3);');
- Add(' ProcA(1,''2'');');
- Add(' ProcA(2,'''');');
- Add(' ProcA(3,false);');
- Add(' ProcB;');
- Add(' ProcB();');
- Add(' ProcB(4);');
- Add(' ProcB(''foo'');');
- Add(' ProcC;');
- Add(' ProcC();');
- Add(' ProcC(4);');
- Add(' ProcC(5,''foo'');');
- Add(' ProcB(GetIt);');
- Add(' ProcB(GetIt());');
- Add(' ProcB(GetIt,GetIt());');
- ConvertProgram;
- CheckSource('TestProc_Varargs',
- LinesToStr([ // statements
- 'this.GetIt = function () {',
- ' var Result = 0;',
- ' return Result;',
- '};',
- '']),
- LinesToStr([
- 'ProcA(1);',
- 'ProcA(1, 2);',
- 'ProcA(1, 2.0);',
- 'ProcA(1, 2, 3);',
- 'ProcA(1, "2");',
- 'ProcA(2, "");',
- 'ProcA(3, false);',
- 'ProcB();',
- 'ProcB();',
- 'ProcB(4);',
- 'ProcB("foo");',
- 'ProcC(17);',
- 'ProcC(17);',
- 'ProcC(4);',
- 'ProcC(5, "foo");',
- 'ProcB(this.GetIt());',
- 'ProcB(this.GetIt());',
- 'ProcB(this.GetIt(), this.GetIt());',
- '']));
- end;
- procedure TTestModule.TestEnumName;
- begin
- StartProgram(false);
- Add('type TMyEnum = (Red, Green, Blue);');
- Add('var e: TMyEnum;');
- Add('var f: TMyEnum = Blue;');
- Add('begin');
- Add(' e:=green;');
- ConvertProgram;
- CheckSource('TestEnumName',
- LinesToStr([ // statements
- 'this.TMyEnum = {',
- ' "0":"Red",',
- ' Red:0,',
- ' "1":"Green",',
- ' Green:1,',
- ' "2":"Blue",',
- ' Blue:2',
- ' };',
- 'this.e = 0;',
- 'this.f = this.TMyEnum.Blue;'
- ]),
- LinesToStr([
- 'this.e=this.TMyEnum.Green;'
- ]));
- end;
- procedure TTestModule.TestEnumNumber;
- begin
- Converter.Options:=Converter.Options+[coEnumNumbers];
- StartProgram(false);
- Add('type TMyEnum = (Red, Green);');
- Add('var');
- Add(' e: TMyEnum;');
- Add(' f: TMyEnum = Green;');
- Add('begin');
- Add(' e:=green;');
- ConvertProgram;
- CheckSource('TestEnumNumber',
- LinesToStr([ // statements
- 'this.TMyEnum = {',
- ' "0":"Red",',
- ' Red:0,',
- ' "1":"Green",',
- ' Green:1',
- ' };',
- 'this.e = 0;',
- 'this.f = 1;'
- ]),
- LinesToStr([
- 'this.e=1;'
- ]));
- end;
- procedure TTestModule.TestEnumFunctions;
- begin
- StartProgram(false);
- Add('type TMyEnum = (Red, Green);');
- Add('var');
- Add(' e: TMyEnum;');
- Add(' i: longint;');
- Add(' s: string;');
- Add('begin');
- Add(' i:=ord(red);');
- Add(' i:=ord(green);');
- Add(' i:=ord(e);');
- Add(' e:=low(tmyenum);');
- Add(' e:=low(e);');
- Add(' e:=high(tmyenum);');
- Add(' e:=high(e);');
- Add(' e:=pred(green);');
- Add(' e:=pred(e);');
- Add(' e:=succ(red);');
- Add(' e:=succ(e);');
- Add(' e:=tmyenum(1);');
- Add(' e:=tmyenum(i);');
- Add(' s:=str(e);');
- Add(' str(e,s)');
- Add(' s:=str(e:3);');
- ConvertProgram;
- CheckSource('TestEnumNumber',
- LinesToStr([ // statements
- 'this.TMyEnum = {',
- ' "0":"Red",',
- ' Red:0,',
- ' "1":"Green",',
- ' Green:1',
- ' };',
- 'this.e = 0;',
- 'this.i = 0;',
- 'this.s = "";'
- ]),
- LinesToStr([
- 'this.i=this.TMyEnum.Red;',
- 'this.i=this.TMyEnum.Green;',
- 'this.i=this.e;',
- 'this.e=this.TMyEnum.Red;',
- 'this.e=this.TMyEnum.Red;',
- 'this.e=this.TMyEnum.Green;',
- 'this.e=this.TMyEnum.Green;',
- 'this.e=this.TMyEnum.Green-1;',
- 'this.e=this.e-1;',
- 'this.e=this.TMyEnum.Red+1;',
- 'this.e=this.e+1;',
- 'this.e=1;',
- 'this.e=this.i;',
- 'this.s = this.TMyEnum[this.e];',
- 'this.s = this.TMyEnum[this.e];',
- 'this.s = rtl.spaceLeft(this.TMyEnum[this.e], 3);',
- '']));
- end;
- procedure TTestModule.TestSet;
- begin
- StartProgram(false);
- Add('type');
- Add(' TColor = (Red, Green, Blue);');
- Add(' TColors = set of TColor;');
- Add('var');
- Add(' c: TColor;');
- Add(' s: TColors;');
- Add(' t: TColors = [];');
- Add(' u: TColors = [Red];');
- Add('begin');
- Add(' s:=[];');
- Add(' s:=[Green];');
- Add(' s:=[Green,Blue];');
- Add(' s:=[Red..Blue];');
- Add(' s:=[Red,Green..Blue];');
- Add(' s:=[Red,c];');
- Add(' s:=t;');
- ConvertProgram;
- CheckSource('TestEnumName',
- LinesToStr([ // statements
- 'this.TColor = {',
- ' "0":"Red",',
- ' Red:0,',
- ' "1":"Green",',
- ' Green:1,',
- ' "2":"Blue",',
- ' Blue:2',
- ' };',
- 'this.c = 0;',
- 'this.s = {};',
- 'this.t = {};',
- 'this.u = rtl.createSet(this.TColor.Red);'
- ]),
- LinesToStr([
- 'this.s={};',
- 'this.s=rtl.createSet(this.TColor.Green);',
- 'this.s=rtl.createSet(this.TColor.Green,this.TColor.Blue);',
- 'this.s=rtl.createSet(null,this.TColor.Red,this.TColor.Blue);',
- 'this.s=rtl.createSet(this.TColor.Red,null,this.TColor.Green,this.TColor.Blue);',
- 'this.s=rtl.createSet(this.TColor.Red,this.c);',
- 'this.s=rtl.refSet(this.t);',
- '']));
- end;
- procedure TTestModule.TestSetOperators;
- begin
- StartProgram(false);
- Add('type');
- Add(' TColor = (Red, Green, Blue);');
- Add(' TColors = set of tcolor;');
- Add('var');
- Add(' vC: TColor;');
- Add(' vS: TColors;');
- Add(' vT: TColors;');
- Add(' vU: TColors;');
- Add(' B: boolean;');
- Add('begin');
- Add(' include(vs,green);');
- Add(' exclude(vs,vc);');
- Add(' vs:=vt+vu;');
- Add(' vs:=vt+[red];');
- Add(' vs:=[red]+vt;');
- Add(' vs:=[red]+[green];');
- Add(' vs:=vt-vu;');
- Add(' vs:=vt-[red];');
- Add(' vs:=[red]-vt;');
- Add(' vs:=[red]-[green];');
- Add(' vs:=vt*vu;');
- Add(' vs:=vt*[red];');
- Add(' vs:=[red]*vt;');
- Add(' vs:=[red]*[green];');
- Add(' vs:=vt><vu;');
- Add(' vs:=vt><[red];');
- Add(' vs:=[red]><vt;');
- Add(' vs:=[red]><[green];');
- Add(' b:=vt=vu;');
- Add(' b:=vt=[red];');
- Add(' b:=[red]=vt;');
- Add(' b:=[red]=[green];');
- Add(' b:=vt<>vu;');
- Add(' b:=vt<>[red];');
- Add(' b:=[red]<>vt;');
- Add(' b:=[red]<>[green];');
- Add(' b:=vt<=vu;');
- Add(' b:=vt<=[red];');
- Add(' b:=[red]<=vt;');
- Add(' b:=[red]<=[green];');
- Add(' b:=vt>=vu;');
- Add(' b:=vt>=[red];');
- Add(' b:=[red]>=vt;');
- Add(' b:=[red]>=[green];');
- Add(' b:=Red in vt;');
- Add(' b:=vc in vt;');
- Add(' b:=Green in [Red..Blue];');
- Add(' b:=vc in [Red..Blue];');
- ConvertProgram;
- CheckSource('TestEnumName',
- LinesToStr([ // statements
- 'this.TColor = {',
- ' "0":"Red",',
- ' Red:0,',
- ' "1":"Green",',
- ' Green:1,',
- ' "2":"Blue",',
- ' Blue:2',
- ' };',
- 'this.vC = 0;',
- 'this.vS = {};',
- 'this.vT = {};',
- 'this.vU = {};',
- 'this.B = false;'
- ]),
- LinesToStr([
- 'this.vS = rtl.includeSet(this.vS,this.TColor.Green);',
- 'this.vS = rtl.excludeSet(this.vS,this.vC);',
- 'this.vS = rtl.unionSet(this.vT, this.vU);',
- 'this.vS = rtl.unionSet(this.vT, rtl.createSet(this.TColor.Red));',
- 'this.vS = rtl.unionSet(rtl.createSet(this.TColor.Red), this.vT);',
- 'this.vS = rtl.unionSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));',
- 'this.vS = rtl.diffSet(this.vT, this.vU);',
- 'this.vS = rtl.diffSet(this.vT, rtl.createSet(this.TColor.Red));',
- 'this.vS = rtl.diffSet(rtl.createSet(this.TColor.Red), this.vT);',
- 'this.vS = rtl.diffSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));',
- 'this.vS = rtl.intersectSet(this.vT, this.vU);',
- 'this.vS = rtl.intersectSet(this.vT, rtl.createSet(this.TColor.Red));',
- 'this.vS = rtl.intersectSet(rtl.createSet(this.TColor.Red), this.vT);',
- 'this.vS = rtl.intersectSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));',
- 'this.vS = rtl.symDiffSet(this.vT, this.vU);',
- 'this.vS = rtl.symDiffSet(this.vT, rtl.createSet(this.TColor.Red));',
- 'this.vS = rtl.symDiffSet(rtl.createSet(this.TColor.Red), this.vT);',
- 'this.vS = rtl.symDiffSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));',
- 'this.B = rtl.eqSet(this.vT, this.vU);',
- 'this.B = rtl.eqSet(this.vT, rtl.createSet(this.TColor.Red));',
- 'this.B = rtl.eqSet(rtl.createSet(this.TColor.Red), this.vT);',
- 'this.B = rtl.eqSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));',
- 'this.B = rtl.neSet(this.vT, this.vU);',
- 'this.B = rtl.neSet(this.vT, rtl.createSet(this.TColor.Red));',
- 'this.B = rtl.neSet(rtl.createSet(this.TColor.Red), this.vT);',
- 'this.B = rtl.neSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));',
- 'this.B = rtl.leSet(this.vT, this.vU);',
- 'this.B = rtl.leSet(this.vT, rtl.createSet(this.TColor.Red));',
- 'this.B = rtl.leSet(rtl.createSet(this.TColor.Red), this.vT);',
- 'this.B = rtl.leSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));',
- 'this.B = rtl.geSet(this.vT, this.vU);',
- 'this.B = rtl.geSet(this.vT, rtl.createSet(this.TColor.Red));',
- 'this.B = rtl.geSet(rtl.createSet(this.TColor.Red), this.vT);',
- 'this.B = rtl.geSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));',
- 'this.B = this.vT[this.TColor.Red];',
- 'this.B = this.vT[this.vC];',
- 'this.B = rtl.createSet(null, this.TColor.Red, this.TColor.Blue)[this.TColor.Green];',
- 'this.B = rtl.createSet(null, this.TColor.Red, this.TColor.Blue)[this.vC];',
- '']));
- end;
- procedure TTestModule.TestSetFunctions;
- begin
- StartProgram(false);
- Add('type');
- Add(' TMyEnum = (Red, Green);');
- Add(' TMyEnums = set of TMyEnum;');
- Add('var');
- Add(' e: TMyEnum;');
- Add(' s: TMyEnums;');
- Add('begin');
- Add(' e:=Low(TMyEnums);');
- Add(' e:=Low(s);');
- Add(' e:=High(TMyEnums);');
- Add(' e:=High(s);');
- ConvertProgram;
- CheckSource('TestSetFunctions',
- LinesToStr([ // statements
- 'this.TMyEnum = {',
- ' "0":"Red",',
- ' Red:0,',
- ' "1":"Green",',
- ' Green:1',
- ' };',
- 'this.e = 0;',
- 'this.s = {};'
- ]),
- LinesToStr([
- 'this.e=this.TMyEnum.Red;',
- 'this.e=this.TMyEnum.Red;',
- 'this.e=this.TMyEnum.Green;',
- 'this.e=this.TMyEnum.Green;',
- '']));
- end;
- procedure TTestModule.TestSet_PassAsArgClone;
- begin
- StartProgram(false);
- Add('type');
- Add(' TMyEnum = (Red, Green);');
- Add(' TMyEnums = set of TMyEnum;');
- Add('procedure DoDefault(s: tmyenums); begin end;');
- Add('procedure DoConst(const s: tmyenums); begin end;');
- Add('var');
- Add(' aSet: tmyenums;');
- Add('begin');
- Add(' dodefault(aset);');
- Add(' doconst(aset);');
- ConvertProgram;
- CheckSource('TestSetFunctions',
- LinesToStr([ // statements
- 'this.TMyEnum = {',
- ' "0":"Red",',
- ' Red:0,',
- ' "1":"Green",',
- ' Green:1',
- ' };',
- 'this.DoDefault = function (s) {',
- '};',
- 'this.DoConst = function (s) {',
- '};',
- 'this.aSet = {};'
- ]),
- LinesToStr([
- 'this.DoDefault(rtl.refSet(this.aSet));',
- 'this.DoConst(this.aSet);',
- '']));
- end;
- procedure TTestModule.TestEnum_AsParams;
- begin
- StartProgram(false);
- Add('type TEnum = (Red,Blue);');
- Add('procedure DoIt(vG: TEnum; const vH: TEnum; var vI: TEnum);');
- Add('var vJ: TEnum;');
- Add('begin');
- Add(' vg:=vg;');
- Add(' vj:=vh;');
- Add(' vi:=vi;');
- Add(' doit(vg,vg,vg);');
- Add(' doit(vh,vh,vj);');
- Add(' doit(vi,vi,vi);');
- Add(' doit(vj,vj,vj);');
- Add('end;');
- Add('var i: TEnum;');
- Add('begin');
- Add(' doit(i,i,i);');
- ConvertProgram;
- CheckSource('TestEnum_AsParams',
- LinesToStr([ // statements
- 'this.TEnum = {',
- ' "0": "Red",',
- ' Red: 0,',
- ' "1": "Blue",',
- ' Blue: 1',
- '};',
- 'this.DoIt = function (vG,vH,vI) {',
- ' var vJ = 0;',
- ' vG = vG;',
- ' vJ = vH;',
- ' vI.set(vI.get());',
- ' this.DoIt(vG, vG, {',
- ' get: function () {',
- ' return vG;',
- ' },',
- ' set: function (v) {',
- ' vG = v;',
- ' }',
- ' });',
- ' this.DoIt(vH, vH, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- ' this.DoIt(vI.get(), vI.get(), vI);',
- ' this.DoIt(vJ, vJ, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- '};',
- 'this.i = 0;'
- ]),
- LinesToStr([
- 'this.DoIt(this.i,this.i,{',
- ' p: this,',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});'
- ]));
- end;
- procedure TTestModule.TestSet_AsParams;
- begin
- StartProgram(false);
- Add('type TEnum = (Red,Blue);');
- Add('type TEnums = set of TEnum;');
- Add('procedure DoIt(vG: TEnums; const vH: TEnums; var vI: TEnums);');
- Add('var vJ: TEnums;');
- Add('begin');
- Add(' vg:=vg;');
- Add(' vj:=vh;');
- Add(' vi:=vi;');
- Add(' doit(vg,vg,vg);');
- Add(' doit(vh,vh,vj);');
- Add(' doit(vi,vi,vi);');
- Add(' doit(vj,vj,vj);');
- Add('end;');
- Add('var i: TEnums;');
- Add('begin');
- Add(' doit(i,i,i);');
- ConvertProgram;
- CheckSource('TestSet_AsParams',
- LinesToStr([ // statements
- 'this.TEnum = {',
- ' "0": "Red",',
- ' Red: 0,',
- ' "1": "Blue",',
- ' Blue: 1',
- '};',
- 'this.DoIt = function (vG,vH,vI) {',
- ' var vJ = {};',
- ' vG = rtl.refSet(vG);',
- ' vJ = rtl.refSet(vH);',
- ' vI.set(rtl.refSet(vI.get()));',
- ' this.DoIt(rtl.refSet(vG), vG, {',
- ' get: function () {',
- ' return vG;',
- ' },',
- ' set: function (v) {',
- ' vG = v;',
- ' }',
- ' });',
- ' this.DoIt(rtl.refSet(vH), vH, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- ' this.DoIt(rtl.refSet(vI.get()), vI.get(), vI);',
- ' this.DoIt(rtl.refSet(vJ), vJ, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- '};',
- 'this.i = {};'
- ]),
- LinesToStr([
- 'this.DoIt(rtl.refSet(this.i),this.i,{',
- ' p: this,',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});'
- ]));
- end;
- procedure TTestModule.TestSet_Property;
- begin
- StartProgram(false);
- Add('type');
- Add(' TEnum = (Red,Blue);');
- Add(' TEnums = set of TEnum;');
- Add(' TObject = class');
- Add(' function GetColors: TEnums; external name ''GetColors'';');
- Add(' procedure SetColors(const Value: TEnums); external name ''SetColors'';');
- Add(' property Colors: TEnums read GetColors write SetColors;');
- Add(' end;');
- Add('procedure DoIt(i: TEnums; const j: TEnums; var k: TEnums; out l: TEnums);');
- Add('begin end;');
- Add('var Obj: TObject;');
- Add('begin');
- Add(' Include(Obj.Colors,Red);');
- Add(' Exclude(Obj.Colors,Red);');
- //Add(' DoIt(Obj.Colors,Obj.Colors,Obj.Colors,Obj.Colors);');
- ConvertProgram;
- CheckSource('TestSet_Property',
- LinesToStr([ // statements
- 'this.TEnum = {',
- ' "0": "Red",',
- ' Red: 0,',
- ' "1": "Blue",',
- ' Blue: 1',
- '};',
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'this.DoIt = function (i, j, k, l) {',
- '};',
- 'this.Obj = null;',
- '']),
- LinesToStr([
- 'this.Obj.SetColors(rtl.includeSet(this.Obj.GetColors(), this.TEnum.Red));',
- 'this.Obj.SetColors(rtl.excludeSet(this.Obj.GetColors(), this.TEnum.Red));',
- '']));
- end;
- procedure TTestModule.TestNestBegin;
- begin
- StartProgram(false);
- Add('begin');
- Add(' begin');
- Add(' begin');
- Add(' end;');
- Add(' begin');
- Add(' if true then ;');
- Add(' end;');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestNestBegin',
- '',
- 'if (true) ;');
- end;
- procedure TTestModule.TestUnitImplVars;
- begin
- StartUnit(false);
- Add('interface');
- Add('implementation');
- Add('var');
- Add(' V1:longint;');
- Add(' V2:longint = 3;');
- Add(' V3:string = ''abc'';');
- ConvertUnit;
- CheckSource('TestUnitImplVars',
- LinesToStr([ // statements
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;',
- '$impl.V1 = 0;',
- '$impl.V2 = 3;',
- '$impl.V3 = "abc";'
- ]),
- '');
- end;
- procedure TTestModule.TestUnitImplConsts;
- begin
- StartUnit(false);
- Add('interface');
- Add('implementation');
- Add('const');
- Add(' v1 = 3;');
- Add(' v2:longint = 4;');
- Add(' v3:string = ''abc'';');
- ConvertUnit;
- CheckSource('TestUnitImplConsts',
- LinesToStr([ // statements
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;',
- '$impl.v1 = 3;',
- '$impl.v2 = 4;',
- '$impl.v3 = "abc";'
- ]),
- '');
- end;
- procedure TTestModule.TestUnitImplRecord;
- begin
- StartUnit(false);
- Add('interface');
- Add('implementation');
- Add('type');
- Add(' TMyRecord = record');
- Add(' i: longint;');
- Add(' end;');
- Add('var aRec: TMyRecord;');
- Add('initialization');
- Add(' arec.i:=3;');
- ConvertUnit;
- CheckSource('TestUnitImplRecord',
- LinesToStr([ // statements
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;',
- '$impl.TMyRecord = function (s) {',
- ' if (s) {',
- ' this.i = s.i;',
- ' } else {',
- ' this.i = 0;',
- ' };',
- ' this.$equal = function (b) {',
- ' return this.i == b.i;',
- ' };',
- '};',
- '$impl.aRec = new $impl.TMyRecord();'
- ]),
- '$impl.aRec.i = 3;'
- );
- end;
- procedure TTestModule.TestRenameJSNameConflict;
- begin
- StartProgram(false);
- Add('var apply: longint;');
- Add('var bind: longint;');
- Add('var call: longint;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestRenameJSNameConflict',
- LinesToStr([ // statements
- 'this.Apply = 0;',
- 'this.Bind = 0;',
- 'this.Call = 0;'
- ]),
- LinesToStr([ // this.$main
- ''
- ]));
- end;
- procedure TTestModule.TestLocalConst;
- begin
- StartProgram(false);
- Add('procedure DoIt;');
- Add('const');
- Add(' cA: longint = 1;');
- Add(' cB = 2;');
- Add(' procedure Sub;');
- Add(' const');
- Add(' csA = 3;');
- Add(' cB: double = 4;');
- Add(' begin');
- Add(' cb:=cb+csa;');
- Add(' ca:=ca+csa+5;');
- Add(' end;');
- Add('begin');
- Add(' ca:=ca+cb+6;');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestLocalConst',
- LinesToStr([
- 'var cA = 1;',
- 'var cB = 2;',
- 'var csA = 3;',
- 'var cB$1 = 4;',
- 'this.DoIt = function () {',
- ' function Sub() {',
- ' cB$1 = cB$1 + csA;',
- ' cA = (cA + csA) + 5;',
- ' };',
- ' cA = (cA + cB) + 6;',
- '};'
- ]),
- LinesToStr([
- ]));
- end;
- procedure TTestModule.TestVarExternal;
- begin
- StartProgram(false);
- Add('var');
- Add(' NaN: double; external name ''Global.NaN'';');
- Add(' d: double;');
- Add('begin');
- Add(' d:=NaN;');
- ConvertProgram;
- CheckSource('TestVarExternal',
- LinesToStr([
- 'this.d = 0.0;'
- ]),
- LinesToStr([
- 'this.d = Global.NaN;'
- ]));
- end;
- procedure TTestModule.TestVarExternalOtherUnit;
- begin
- AddModuleWithIntfImplSrc('unit2.pas',
- LinesToStr([
- 'var NaN: double; external name ''Global.NaN'';',
- 'var iV: longint;'
- ]),
- '');
- StartUnit(true);
- Add('interface');
- Add('uses unit2;');
- Add('implementation');
- Add('var');
- Add(' d: double;');
- Add(' i: longint;');
- Add('begin');
- Add(' d:=nan;');
- Add(' d:=uNit2.nan;');
- Add(' d:=test1.nan;');
- Add(' i:=iv;');
- Add(' i:=uNit2.iv;');
- Add(' i:=test1.iv;');
- ConvertUnit;
- CheckSource('TestVarExternalOtherUnit',
- LinesToStr([
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;',
- '$impl.d = 0.0;',
- '$impl.i = 0;',
- '']),
- LinesToStr([
- '$impl.d = Global.NaN;',
- '$impl.d = Global.NaN;',
- '$impl.d = Global.NaN;',
- '$impl.i = pas.unit2.iV;',
- '$impl.i = pas.unit2.iV;',
- '$impl.i = pas.unit2.iV;',
- '']));
- end;
- procedure TTestModule.TestCharConst;
- begin
- StartProgram(false);
- Add('const');
- Add(' c: char = ''1'';');
- Add('begin');
- Add(' c:=#0;');
- Add(' c:=#1;');
- Add(' c:=#9;');
- Add(' c:=#10;');
- Add(' c:=#13;');
- Add(' c:=#31;');
- Add(' c:=#32;');
- Add(' c:=#$A;');
- Add(' c:=#$0A;');
- Add(' c:=#$b;');
- Add(' c:=#$0b;');
- Add(' c:=^A;');
- Add(' c:=''"'';');
- ConvertProgram;
- CheckSource('TestCharConst',
- LinesToStr([
- 'this.c="1";'
- ]),
- LinesToStr([
- 'this.c="\x00";',
- 'this.c="\x01";',
- 'this.c="\t";',
- 'this.c="\n";',
- 'this.c="\r";',
- 'this.c="\x1F";',
- 'this.c=" ";',
- 'this.c="\n";',
- 'this.c="\n";',
- 'this.c="\x0B";',
- 'this.c="\x0B";',
- 'this.c="\x01";',
- 'this.c=''"'';'
- ]));
- end;
- procedure TTestModule.TestChar_Compare;
- begin
- StartProgram(false);
- Add('var');
- Add(' c: char;');
- Add(' b: boolean;');
- Add('begin');
- Add(' b:=c=''1'';');
- Add(' b:=''2''=c;');
- Add(' b:=''3''=''4'';');
- Add(' b:=c<>''5'';');
- Add(' b:=''6''<>c;');
- Add(' b:=c>''7'';');
- Add(' b:=''8''>c;');
- Add(' b:=c>=''9'';');
- Add(' b:=''A''>=c;');
- Add(' b:=c<''B'';');
- Add(' b:=''C''<c;');
- Add(' b:=c<=''D'';');
- Add(' b:=''E''<=c;');
- ConvertProgram;
- CheckSource('TestChar_Compare',
- LinesToStr([
- 'this.c="";',
- 'this.b = false;'
- ]),
- LinesToStr([
- 'this.b = this.c == "1";',
- 'this.b = "2" == this.c;',
- 'this.b = "3" == "4";',
- 'this.b = this.c != "5";',
- 'this.b = "6" != this.c;',
- 'this.b = this.c > "7";',
- 'this.b = "8" > this.c;',
- 'this.b = this.c >= "9";',
- 'this.b = "A" >= this.c;',
- 'this.b = this.c < "B";',
- 'this.b = "C" < this.c;',
- 'this.b = this.c <= "D";',
- 'this.b = "E" <= this.c;',
- '']));
- end;
- procedure TTestModule.TestChar_Ord;
- begin
- StartProgram(false);
- Add('var');
- Add(' c: char;');
- Add(' i: longint;');
- Add('begin');
- Add(' i:=ord(c);');
- ConvertProgram;
- CheckSource('TestChar_Ord',
- LinesToStr([
- 'this.c = "";',
- 'this.i = 0;'
- ]),
- LinesToStr([
- 'this.i = this.c.charCodeAt();',
- '']));
- end;
- procedure TTestModule.TestChar_Chr;
- begin
- StartProgram(false);
- Add('var');
- Add(' c: char;');
- Add(' i: longint;');
- Add('begin');
- Add(' c:=chr(i);');
- ConvertProgram;
- CheckSource('TestChar_Chr',
- LinesToStr([
- 'this.c = "";',
- 'this.i = 0;'
- ]),
- LinesToStr([
- 'this.c = String.fromCharCode(this.i);',
- '']));
- end;
- procedure TTestModule.TestStringConst;
- begin
- StartProgram(false);
- Add('var');
- Add(' s: string = ''abc'';');
- Add('begin');
- Add(' s:='''';');
- Add(' s:=#13#10;');
- Add(' s:=#9''foo'';');
- Add(' s:=#$A9;');
- Add(' s:=''foo''#13''bar'';');
- Add(' s:=''"'';');
- Add(' s:=''"''''"'';');
- ConvertProgram;
- CheckSource('TestStringConst',
- LinesToStr([
- 'this.s="abc";'
- ]),
- LinesToStr([
- 'this.s="";',
- 'this.s="\r\n";',
- 'this.s="\tfoo";',
- 'this.s="©";',
- 'this.s="foo\rbar";',
- 'this.s=''"'';',
- 'this.s=''"\''"'';'
- ]));
- end;
- procedure TTestModule.TestString_Length;
- begin
- StartProgram(false);
- Add('const c = ''foo'';');
- Add('var');
- Add(' s: string;');
- Add(' i: longint;');
- Add('begin');
- Add(' i:=length(s);');
- Add(' i:=length(s+s);');
- Add(' i:=length(''abc'');');
- Add(' i:=length(c);');
- ConvertProgram;
- CheckSource('TestString_Length',
- LinesToStr([
- 'this.c = "foo";',
- 'this.s = "";',
- 'this.i = 0;',
- '']),
- LinesToStr([
- 'this.i = this.s.length;',
- 'this.i = (this.s+this.s).length;',
- 'this.i = "abc".length;',
- 'this.i = this.c.length;',
- '']));
- end;
- procedure TTestModule.TestString_Compare;
- begin
- StartProgram(false);
- Add('var');
- Add(' s, t: string;');
- Add(' b: boolean;');
- Add('begin');
- Add(' b:=s=t;');
- Add(' b:=s<>t;');
- Add(' b:=s>t;');
- Add(' b:=s>=t;');
- Add(' b:=s<t;');
- Add(' b:=s<=t;');
- ConvertProgram;
- CheckSource('TestString_Compare',
- LinesToStr([ // statements
- 'this.s = "";',
- 'this.t = "";',
- 'this.b =false;'
- ]),
- LinesToStr([ // this.$main
- 'this.b = this.s == this.t;',
- 'this.b = this.s != this.t;',
- 'this.b = this.s > this.t;',
- 'this.b = this.s >= this.t;',
- 'this.b = this.s < this.t;',
- 'this.b = this.s <= this.t;',
- '']));
- end;
- procedure TTestModule.TestString_SetLength;
- begin
- StartProgram(false);
- Add('var s: string;');
- Add('begin');
- Add(' SetLength(s,3);');
- ConvertProgram;
- CheckSource('TestString_SetLength',
- LinesToStr([ // statements
- 'this.s = "";'
- ]),
- LinesToStr([ // this.$main
- 'this.s.length = 3;'
- ]));
- end;
- procedure TTestModule.TestString_CharAt;
- begin
- StartProgram(false);
- Add('var');
- Add(' s: string;');
- Add(' c: char;');
- Add(' b: boolean;');
- Add('begin');
- Add(' b:= s[1] = c;');
- Add(' b:= c = s[1];');
- Add(' b:= c <> s[1];');
- Add(' b:= c > s[1];');
- Add(' b:= c >= s[1];');
- Add(' b:= c < s[1];');
- Add(' b:= c <= s[1];');
- Add(' s[1] := c;');
- ConvertProgram;
- CheckSource('TestString_CharAt',
- LinesToStr([ // statements
- 'this.s = "";',
- 'this.c = "";',
- 'this.b = false;'
- ]),
- LinesToStr([ // this.$main
- 'this.b = this.s.charAt(1-1) == this.c;',
- 'this.b = this.c == this.s.charAt(1 - 1);',
- 'this.b = this.c != this.s.charAt(1 - 1);',
- 'this.b = this.c > this.s.charAt(1 - 1);',
- 'this.b = this.c >= this.s.charAt(1 - 1);',
- 'this.b = this.c < this.s.charAt(1 - 1);',
- 'this.b = this.c <= this.s.charAt(1 - 1);',
- 'this.s = rtl.setCharAt(this.s, 1, this.c);',
- '']));
- end;
- procedure TTestModule.TestStr;
- begin
- StartProgram(false);
- Add('var');
- Add(' b: boolean;');
- Add(' i: longint;');
- Add(' d: double;');
- Add(' s: string;');
- Add('begin');
- Add(' str(b,s);');
- Add(' str(i,s);');
- Add(' str(d,s);');
- Add(' str(i:3,s);');
- Add(' str(d:3:2,s);');
- Add(' s:=str(b);');
- Add(' s:=str(i);');
- Add(' s:=str(d);');
- Add(' s:=str(i,i);');
- Add(' s:=str(i:3);');
- Add(' s:=str(d:3:2);');
- Add(' s:=str(i:4,i);');
- Add(' s:=str(i,i:5);');
- Add(' s:=str(i:4,i:5);');
- Add(' s:=str(s,s);');
- Add(' s:=str(s,''foo'');');
- ConvertProgram;
- CheckSource('TestStr',
- LinesToStr([ // statements
- 'this.b = false;',
- 'this.i = 0;',
- 'this.d = 0.0;',
- 'this.s = "";',
- '']),
- LinesToStr([ // this.$main
- 'this.s = ""+this.b;',
- 'this.s = ""+this.i;',
- 'this.s = ""+this.d;',
- 'this.s = rtl.spaceLeft(""+this.i,3);',
- 'this.s = rtl.spaceLeft(this.d.toFixed(2),3);',
- 'this.s = ""+this.b;',
- 'this.s = ""+this.i;',
- 'this.s = ""+this.d;',
- 'this.s = (""+this.i)+this.i;',
- 'this.s = rtl.spaceLeft(""+this.i,3);',
- 'this.s = rtl.spaceLeft(this.d.toFixed(2),3);',
- 'this.s = rtl.spaceLeft("" + this.i, 4) + this.i;',
- 'this.s = ("" + this.i) + rtl.spaceLeft("" + this.i, 5);',
- 'this.s = rtl.spaceLeft("" + this.i, 4) + rtl.spaceLeft("" + this.i, 5);',
- 'this.s = this.s + this.s;',
- 'this.s = this.s + "foo";',
- '']));
- end;
- procedure TTestModule.TestAnsiStringFail;
- begin
- StartProgram(false);
- Add('var s: AnsiString');
- Add('begin');
- SetExpectedPasResolverError('foo',123);
- end;
- procedure TTestModule.TestProcTwoArgs;
- begin
- StartProgram(false);
- Add('procedure Test(a,b: longint);');
- Add('begin');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestProcTwoArgs',
- LinesToStr([ // statements
- 'this.Test = function (a,b) {',
- '};'
- ]),
- LinesToStr([ // this.$main
- ''
- ]));
- end;
- procedure TTestModule.TestProc_DefaultValue;
- begin
- StartProgram(false);
- Add('procedure p1(i: longint = 1);');
- Add('begin');
- Add('end;');
- Add('procedure p2(i: longint = 1; c: char = ''a'');');
- Add('begin');
- Add('end;');
- Add('procedure p3(d: double = 1.0; b: boolean = false; s: string = ''abc'');');
- Add('begin');
- Add('end;');
- Add('begin');
- Add(' p1;');
- Add(' p1();');
- Add(' p1(11);');
- Add(' p2;');
- Add(' p2();');
- Add(' p2(12);');
- Add(' p2(13,''b'');');
- Add(' p3();');
- ConvertProgram;
- CheckSource('TestProc_DefaultValue',
- LinesToStr([ // statements
- 'this.p1 = function (i) {',
- '};',
- 'this.p2 = function (i,c) {',
- '};',
- 'this.p3 = function (d,b,s) {',
- '};'
- ]),
- LinesToStr([ // this.$main
- ' this.p1(1);',
- ' this.p1(1);',
- ' this.p1(11);',
- ' this.p2(1,"a");',
- ' this.p2(1,"a");',
- ' this.p2(12,"a");',
- ' this.p2(13,"b");',
- ' this.p3(1.0,false,"abc");'
- ]));
- end;
- procedure TTestModule.TestFunctionInt;
- begin
- StartProgram(false);
- Add('function MyTest(Bar: longint): longint;');
- Add('begin');
- Add(' Result:=2*bar');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestFunctionInt',
- LinesToStr([ // statements
- 'this.MyTest = function (Bar) {',
- ' var Result = 0;',
- ' Result = 2*Bar;',
- ' return Result;',
- '};'
- ]),
- LinesToStr([ // this.$main
- ''
- ]));
- end;
- procedure TTestModule.TestFunctionString;
- begin
- StartProgram(false);
- Add('function Test(Bar: string): string;');
- Add('begin');
- Add(' Result:=bar+BAR');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestFunctionString',
- LinesToStr([ // statements
- 'this.Test = function (Bar) {',
- ' var Result = "";',
- ' Result = Bar+Bar;',
- ' return Result;',
- '};'
- ]),
- LinesToStr([ // this.$main
- ''
- ]));
- end;
- procedure TTestModule.TestForLoop;
- begin
- StartProgram(false);
- Add('var');
- Add(' vI, vJ, vN: longint;');
- Add('begin');
- Add(' VJ:=0;');
- Add(' VN:=3;');
- Add(' for VI:=1 to VN do');
- Add(' begin');
- Add(' VJ:=VJ+VI;');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestForLoop',
- LinesToStr([ // statements
- 'this.vI = 0;',
- 'this.vJ = 0;',
- 'this.vN = 0;'
- ]),
- LinesToStr([ // this.$main
- ' this.vJ = 0;',
- ' this.vN = 3;',
- ' var $loopend1 = this.vN;',
- ' for (this.vI = 1; this.vI <= $loopend1; this.vI++) {',
- ' this.vJ = this.vJ + this.vI;',
- ' };',
- ' if (this.vI > $loopend1) this.vI--;'
- ]));
- end;
- procedure TTestModule.TestForLoopInFunction;
- begin
- StartProgram(false);
- Add('function SumNumbers(Count: longint): longint;');
- Add('var');
- Add(' vI, vJ: longint;');
- Add('begin');
- Add(' vj:=0;');
- Add(' for vi:=1 to count do');
- Add(' begin');
- Add(' vj:=vj+vi;');
- Add(' end;');
- Add('end;');
- Add('begin');
- Add(' sumnumbers(3);');
- ConvertProgram;
- CheckSource('TestForLoopInFunction',
- LinesToStr([ // statements
- 'this.SumNumbers = function (Count) {',
- ' var Result = 0;',
- ' var vI = 0;',
- ' var vJ = 0;',
- ' vJ = 0;',
- ' var $loopend1 = Count;',
- ' for (vI = 1; vI <= $loopend1; vI++) {',
- ' vJ = vJ + vI;',
- ' };',
- ' return Result;',
- '};'
- ]),
- LinesToStr([ // this.$main
- ' this.SumNumbers(3);'
- ]));
- end;
- procedure TTestModule.TestForLoop_ReadVarAfter;
- begin
- StartProgram(false);
- Add('var');
- Add(' vI: longint;');
- Add('begin');
- Add(' for vi:=1 to 2 do ;');
- Add(' if vi=3 then ;');
- ConvertProgram;
- CheckSource('TestForLoop',
- LinesToStr([ // statements
- 'this.vI = 0;'
- ]),
- LinesToStr([ // this.$main
- ' var $loopend1 = 2;',
- ' for (this.vI = 1; this.vI <= $loopend1; this.vI++);',
- ' if(this.vI>$loopend1)this.vI--;',
- ' if (this.vI==3) ;'
- ]));
- end;
- procedure TTestModule.TestForLoop_Nested;
- begin
- StartProgram(false);
- Add('function SumNumbers(Count: longint): longint;');
- Add('var');
- Add(' vI, vJ, vK: longint;');
- Add('begin');
- Add(' VK:=0;');
- Add(' for VI:=1 to count do');
- Add(' begin');
- Add(' for vj:=1 to vi do');
- Add(' begin');
- Add(' vk:=VK+VI;');
- Add(' end;');
- Add(' end;');
- Add('end;');
- Add('begin');
- Add(' sumnumbers(3);');
- ConvertProgram;
- CheckSource('TestForLoopInFunction',
- LinesToStr([ // statements
- 'this.SumNumbers = function (Count) {',
- ' var Result = 0;',
- ' var vI = 0;',
- ' var vJ = 0;',
- ' var vK = 0;',
- ' vK = 0;',
- ' var $loopend1 = Count;',
- ' for (vI = 1; vI <= $loopend1; vI++) {',
- ' var $loopend2 = vI;',
- ' for (vJ = 1; vJ <= $loopend2; vJ++) {',
- ' vK = vK + vI;',
- ' };',
- ' };',
- ' return Result;',
- '};'
- ]),
- LinesToStr([ // this.$main
- ' this.SumNumbers(3);'
- ]));
- end;
- procedure TTestModule.TestRepeatUntil;
- begin
- StartProgram(false);
- Add('var');
- Add(' vI, vJ, vN: longint;');
- Add('begin');
- Add(' vn:=3;');
- Add(' vj:=0;');
- Add(' VI:=0;');
- Add(' repeat');
- Add(' VI:=vi+1;');
- Add(' vj:=VJ+vI;');
- Add(' until vi>=vn');
- ConvertProgram;
- CheckSource('TestRepeatUntil',
- LinesToStr([ // statements
- 'this.vI = 0;',
- 'this.vJ = 0;',
- 'this.vN = 0;'
- ]),
- LinesToStr([ // this.$main
- ' this.vN = 3;',
- ' this.vJ = 0;',
- ' this.vI = 0;',
- ' do{',
- ' this.vI = this.vI + 1;',
- ' this.vJ = this.vJ + this.vI;',
- ' }while(!(this.vI>=this.vN));'
- ]));
- end;
- procedure TTestModule.TestAsmBlock;
- begin
- StartProgram(false);
- Add('var');
- Add(' vI: longint;');
- Add('begin');
- Add(' vi:=1;');
- Add(' asm');
- Add(' if (vI==1) {');
- Add(' vI=2;');
- Add(' }');
- Add(' if (vI==2){ vI=3; }');
- Add(' end;');
- Add(' VI:=4;');
- ConvertProgram;
- CheckSource('TestAsmBlock',
- LinesToStr([ // statements
- 'this.vI = 0;'
- ]),
- LinesToStr([ // this.$main
- 'this.vI = 1;',
- 'if (vI==1) {',
- ' vI=2;',
- '}',
- 'if (vI==2){ vI=3; }',
- ';',
- 'this.vI = 4;'
- ]));
- end;
- procedure TTestModule.TestTryFinally;
- begin
- StartProgram(false);
- Add('var i: longint;');
- Add('begin');
- Add(' try');
- Add(' i:=0; i:=2 div i;');
- Add(' finally');
- Add(' i:=3');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestTryFinally',
- LinesToStr([ // statements
- 'this.i = 0;'
- ]),
- LinesToStr([ // this.$main
- 'try {',
- ' this.i = 0;',
- ' this.i = Math.floor(2 / this.i);',
- '} finally {',
- ' this.i = 3;',
- '};'
- ]));
- end;
- procedure TTestModule.TestTryExcept;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class end;');
- Add(' Exception = class Msg: string; end;');
- Add(' EInvalidCast = class(Exception) end;');
- Add('var vI: longint;');
- Add('begin');
- Add(' try');
- Add(' vi:=1;');
- Add(' except');
- Add(' vi:=2');
- Add(' end;');
- Add(' try');
- Add(' vi:=3;');
- Add(' except');
- Add(' raise;');
- Add(' end;');
- Add(' try');
- Add(' VI:=4;');
- Add(' except');
- Add(' on einvalidcast do');
- Add(' raise;');
- Add(' on E: exception do');
- Add(' if e.msg='''' then');
- Add(' raise e;');
- Add(' else');
- Add(' vi:=5');
- Add(' end;');
- Add(' try');
- Add(' VI:=6;');
- Add(' except');
- Add(' on einvalidcast do ;');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestTryExcept',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'rtl.createClass(this, "Exception", this.TObject, function () {',
- ' this.$init = function () {',
- ' pas.program.TObject.$init.call(this);',
- ' this.Msg = "";',
- ' };',
- '});',
- 'rtl.createClass(this, "EInvalidCast", this.Exception, function () {',
- '});',
- 'this.vI = 0;'
- ]),
- LinesToStr([ // this.$main
- 'try {',
- ' this.vI = 1;',
- '} catch {',
- ' this.vI = 2;',
- '};',
- 'try {',
- ' this.vI = 3;',
- '} catch ($e) {',
- ' throw $e;',
- '};',
- 'try {',
- ' this.vI = 4;',
- '} catch ($e) {',
- ' if (this.EInvalidCast.isPrototypeOf($e)){',
- ' throw $e',
- ' } else if (this.Exception.isPrototypeOf($e)) {',
- ' var E = $e;',
- ' if (E.Msg == "") throw E;',
- ' } else {',
- ' this.vI = 5;',
- ' }',
- '};',
- 'try {',
- ' this.vI = 6;',
- '} catch ($e) {',
- ' if (this.EInvalidCast.isPrototypeOf($e)){' ,
- ' } else throw $e',
- '};',
- '']));
- end;
- procedure TTestModule.TestCaseOf;
- begin
- StartProgram(false);
- Add('var vI: longint;');
- Add('begin');
- Add(' case vi of');
- Add(' 1: ;');
- Add(' 2: vi:=3;');
- Add(' else');
- Add(' VI:=4');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestCaseOf',
- LinesToStr([ // statements
- 'this.vI = 0;'
- ]),
- LinesToStr([ // this.$main
- 'var $tmp1 = this.vI;',
- 'if ($tmp1 == 1) {} else if ($tmp1 == 2){ this.vI = 3 }else {',
- ' this.vI = 4;',
- '};'
- ]));
- end;
- procedure TTestModule.TestCaseOf_UseSwitch;
- begin
- StartProgram(false);
- Converter.UseSwitchStatement:=true;
- Add('var Vi: longint;');
- Add('begin');
- Add(' case vi of');
- Add(' 1: ;');
- Add(' 2: VI:=3;');
- Add(' else');
- Add(' vi:=4');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestCaseOf_UseSwitch',
- LinesToStr([ // statements
- 'this.Vi = 0;'
- ]),
- LinesToStr([ // this.$main
- 'switch (this.Vi) {',
- 'case 1:',
- ' break;',
- 'case 2:',
- ' this.Vi = 3;',
- ' break;',
- 'default:',
- ' this.Vi = 4;',
- '};'
- ]));
- end;
- procedure TTestModule.TestCaseOfNoElse;
- begin
- StartProgram(false);
- Add('var Vi: longint;');
- Add('begin');
- Add(' case vi of');
- Add(' 1: begin vi:=2; VI:=3; end;');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestCaseOfNoElse',
- LinesToStr([ // statements
- 'this.Vi = 0;'
- ]),
- LinesToStr([ // this.$main
- 'var $tmp1 = this.Vi;',
- 'if ($tmp1 == 1) {',
- ' this.Vi = 2;',
- ' this.Vi = 3;',
- '};'
- ]));
- end;
- procedure TTestModule.TestCaseOfNoElse_UseSwitch;
- begin
- StartProgram(false);
- Converter.UseSwitchStatement:=true;
- Add('var vI: longint;');
- Add('begin');
- Add(' case vi of');
- Add(' 1: begin VI:=2; vi:=3; end;');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestCaseOfNoElse_UseSwitch',
- LinesToStr([ // statements
- 'this.vI = 0;'
- ]),
- LinesToStr([ // this.$main
- 'switch (this.vI) {',
- 'case 1:',
- ' this.vI = 2;',
- ' this.vI = 3;',
- ' break;',
- '};'
- ]));
- end;
- procedure TTestModule.TestCaseOfRange;
- begin
- StartProgram(false);
- Add('var vI: longint;');
- Add('begin');
- Add(' case vi of');
- Add(' 1..3: vi:=14;');
- Add(' 4,5: vi:=16;');
- Add(' 6..7,9..10: ;');
- Add(' else ;');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestCaseOfRange',
- LinesToStr([ // statements
- 'this.vI = 0;'
- ]),
- LinesToStr([ // this.$main
- 'var $tmp1 = this.vI;',
- 'if (($tmp1 >= 1) && ($tmp1 <= 3)){',
- ' this.vI = 14',
- '} else if (($tmp1 == 4) || ($tmp1 == 5)){',
- ' this.vI = 16',
- '} else if ((($tmp1 >= 6) && ($tmp1 <= 7)) || (($tmp1 >= 9) && ($tmp1 <= 10))) ;'
- ]));
- end;
- procedure TTestModule.TestArray_Dynamic;
- begin
- StartProgram(false);
- Add('type');
- Add(' TArrayInt = array of longint;');
- Add('var');
- Add(' Arr: TArrayInt;');
- Add(' i: longint;');
- Add(' b: boolean;');
- Add('begin');
- Add(' SetLength(arr,3);');
- Add(' arr[0]:=4;');
- Add(' arr[1]:=length(arr)+arr[0];');
- Add(' arr[i]:=5;');
- Add(' arr[arr[i]]:=arr[6];');
- Add(' i:=low(arr);');
- Add(' i:=high(arr);');
- Add(' b:=Assigned(arr);');
- ConvertProgram;
- CheckSource('TestArray_Dynamic',
- LinesToStr([ // statements
- 'this.Arr = [];',
- 'this.i = 0;',
- 'this.b = false;'
- ]),
- LinesToStr([ // this.$main
- 'this.Arr = rtl.arraySetLength(this.Arr,3,0);',
- 'this.Arr[0] = 4;',
- 'this.Arr[1] = this.Arr.length + this.Arr[0];',
- 'this.Arr[this.i] = 5;',
- 'this.Arr[this.Arr[this.i]] = this.Arr[6];',
- 'this.i = 0;',
- 'this.i = this.Arr.length - 1;',
- 'this.b = this.Arr.length > 0;',
- '']));
- end;
- procedure TTestModule.TestArray_Dynamic_Nil;
- begin
- StartProgram(false);
- Add('type');
- Add(' TArrayInt = array of longint;');
- Add('var');
- Add(' Arr: TArrayInt;');
- Add('procedure DoIt(const i: TArrayInt; j: TArrayInt); begin end;');
- Add('begin');
- Add(' arr:=nil;');
- Add(' if arr=nil then;');
- Add(' if nil=arr then;');
- Add(' DoIt(nil,nil);');
- ConvertProgram;
- CheckSource('TestArray_Dynamic',
- LinesToStr([ // statements
- 'this.Arr = [];',
- 'this.DoIt = function(i,j){',
- '};'
- ]),
- LinesToStr([ // this.$main
- 'this.Arr = [];',
- 'if (this.Arr.length == 0);',
- 'if (0 == this.Arr.length);',
- 'this.DoIt([],[]);',
- '']));
- end;
- procedure TTestModule.TestArray_DynMultiDimensional;
- begin
- StartProgram(false);
- Add('type');
- Add(' TArrayInt = array of longint;');
- Add(' TArrayArrayInt = array of TArrayInt;');
- Add('var');
- Add(' Arr: TArrayInt;');
- Add(' Arr2: TArrayArrayInt;');
- Add(' i: longint;');
- Add('begin');
- Add(' arr2:=nil;');
- Add(' if arr2=nil then;');
- Add(' if nil=arr2 then;');
- Add(' i:=low(arr2);');
- Add(' i:=low(arr2[1]);');
- Add(' i:=high(arr2);');
- Add(' i:=high(arr2[2]);');
- Add(' arr2[3]:=arr;');
- Add(' arr2[4][5]:=i;');
- Add(' i:=arr2[6][7];');
- Add(' arr2[8,9]:=i;');
- Add(' i:=arr2[10,11];');
- Add(' SetLength(arr2,14);');
- Add(' SetLength(arr2[15],16);');
- ConvertProgram;
- CheckSource('TestArray_Dynamic',
- LinesToStr([ // statements
- 'this.Arr = [];',
- 'this.Arr2 = [];',
- 'this.i = 0;'
- ]),
- LinesToStr([ // this.$main
- 'this.Arr2 = [];',
- 'if (this.Arr2.length == 0);',
- 'if (0 == this.Arr2.length);',
- 'this.i = 0;',
- 'this.i = 0;',
- 'this.i = this.Arr2.length-1;',
- 'this.i = this.Arr2[2].length-1;',
- 'this.Arr2[3] = this.Arr;',
- 'this.Arr2[4][5] = this.i;',
- 'this.i = this.Arr2[6][7];',
- 'this.Arr2[8][9] = this.i;',
- 'this.i = this.Arr2[10][11];',
- 'this.Arr2 = rtl.arraySetLength(this.Arr2, 14, []);',
- 'this.Arr2[15] = rtl.arraySetLength(this.Arr2[15], 16, 0);',
- '']));
- end;
- procedure TTestModule.TestArrayOfRecord;
- begin
- StartProgram(false);
- Add('type');
- Add(' TRec = record');
- Add(' Int: longint;');
- Add(' end;');
- Add(' TArrayRec = array of TRec;');
- Add('var');
- Add(' Arr: TArrayRec;');
- Add(' r: TRec;');
- Add(' i: longint;');
- Add('begin');
- Add(' SetLength(arr,3);');
- Add(' arr[0].int:=4;');
- Add(' arr[1].int:=length(arr)+arr[2].int;');
- Add(' arr[arr[i].int].int:=arr[5].int;');
- Add(' arr[7]:=r;');
- Add(' r:=arr[8];');
- Add(' i:=low(arr);');
- Add(' i:=high(arr);');
- ConvertProgram;
- CheckSource('TestArrayOfRecord',
- LinesToStr([ // statements
- 'this.TRec = function (s) {',
- ' if (s) {',
- ' this.Int = s.Int;',
- ' } else {',
- ' this.Int = 0;',
- ' };',
- ' this.$equal = function (b) {',
- ' return this.Int == b.Int;',
- ' };',
- '};',
- 'this.Arr = [];',
- 'this.r = new this.TRec();',
- 'this.i = 0;'
- ]),
- LinesToStr([ // this.$main
- 'this.Arr = rtl.arraySetLength(this.Arr,3, this.TRec);',
- 'this.Arr[0].Int = 4;',
- 'this.Arr[1].Int = this.Arr.length+this.Arr[2].Int;',
- 'this.Arr[this.Arr[this.i].Int].Int = this.Arr[5].Int;',
- 'this.Arr[7] = new this.TRec(this.r);',
- 'this.r = new this.TRec(this.Arr[8]);',
- 'this.i = 0;',
- 'this.i = this.Arr.length-1;',
- '']));
- end;
- procedure TTestModule.TestArray_AsParams;
- begin
- StartProgram(false);
- Add('type integer = longint;');
- Add('type TArrInt = array of integer;');
- Add('procedure DoIt(vG: TArrInt; const vH: TArrInt; var vI: TArrInt);');
- Add('var vJ: TArrInt;');
- Add('begin');
- Add(' vg:=vg;');
- Add(' vj:=vh;');
- Add(' vi:=vi;');
- Add(' doit(vg,vg,vg);');
- Add(' doit(vh,vh,vj);');
- Add(' doit(vi,vi,vi);');
- Add(' doit(vj,vj,vj);');
- Add('end;');
- Add('var i: TArrInt;');
- Add('begin');
- Add(' doit(i,i,i);');
- ConvertProgram;
- CheckSource('TestArray_AsParams',
- LinesToStr([ // statements
- 'this.DoIt = function (vG,vH,vI) {',
- ' var vJ = [];',
- ' vG = vG;',
- ' vJ = vH;',
- ' vI.set(vI.get());',
- ' this.DoIt(vG, vG, {',
- ' get: function () {',
- ' return vG;',
- ' },',
- ' set: function (v) {',
- ' vG = v;',
- ' }',
- ' });',
- ' this.DoIt(vH, vH, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- ' this.DoIt(vI.get(), vI.get(), vI);',
- ' this.DoIt(vJ, vJ, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- '};',
- 'this.i = [];'
- ]),
- LinesToStr([
- 'this.DoIt(this.i,this.i,{',
- ' p: this,',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});'
- ]));
- end;
- procedure TTestModule.TestArrayElement_AsParams;
- begin
- StartProgram(false);
- Add('type integer = longint;');
- Add('type TArrayInt = array of integer;');
- Add('procedure DoIt(vG: Integer; const vH: Integer; var vI: Integer);');
- Add('var vJ: tarrayint;');
- Add('begin');
- Add(' vi:=vi;');
- Add(' doit(vi,vi,vi);');
- Add(' doit(vj[1+1],vj[1+2],vj[1+3]);');
- Add('end;');
- Add('var a: TArrayInt;');
- Add('begin');
- Add(' doit(a[1+4],a[1+5],a[1+6]);');
- ConvertProgram;
- CheckSource('TestArrayElement_AsParams',
- LinesToStr([ // statements
- 'this.DoIt = function (vG,vH,vI) {',
- ' var vJ = [];',
- ' vI.set(vI.get());',
- ' this.DoIt(vI.get(), vI.get(), vI);',
- ' this.DoIt(vJ[1+1], vJ[1+2], {',
- ' a:1+3,',
- ' p:vJ,',
- ' get: function () {',
- ' return this.p[this.a];',
- ' },',
- ' set: function (v) {',
- ' this.p[this.a] = v;',
- ' }',
- ' });',
- '};',
- 'this.a = [];'
- ]),
- LinesToStr([
- 'this.DoIt(this.a[1+4],this.a[1+5],{',
- ' a: 1+6,',
- ' p: this.a,',
- ' get: function () {',
- ' return this.p[this.a];',
- ' },',
- ' set: function (v) {',
- ' this.p[this.a] = v;',
- ' }',
- '});'
- ]));
- end;
- procedure TTestModule.TestArrayElementFromFuncResult_AsParams;
- begin
- StartProgram(false);
- Add('type Integer = longint;');
- Add('type TArrayInt = array of integer;');
- Add('function GetArr(vB: integer = 0): tarrayint;');
- Add('begin');
- Add('end;');
- Add('procedure DoIt(vG: integer; const vH: integer; var vI: integer);');
- Add('begin');
- Add('end;');
- Add('begin');
- Add(' doit(getarr[1+1],getarr[1+2],getarr[1+3]);');
- Add(' doit(getarr()[2+1],getarr()[2+2],getarr()[2+3]);');
- Add(' doit(getarr(7)[3+1],getarr(8)[3+2],getarr(9)[3+3]);');
- ConvertProgram;
- CheckSource('TestArrayElementFromFuncResult_AsParams',
- LinesToStr([ // statements
- 'this.GetArr = function (vB) {',
- ' var Result = [];',
- ' return Result;',
- '};',
- 'this.DoIt = function (vG,vH,vI) {',
- '};'
- ]),
- LinesToStr([
- 'this.DoIt(this.GetArr(0)[1+1],this.GetArr(0)[1+2],{',
- ' a: 1+3,',
- ' p: this.GetArr(0),',
- ' get: function () {',
- ' return this.p[this.a];',
- ' },',
- ' set: function (v) {',
- ' this.p[this.a] = v;',
- ' }',
- '});',
- 'this.DoIt(this.GetArr(0)[2+1],this.GetArr(0)[2+2],{',
- ' a: 2+3,',
- ' p: this.GetArr(0),',
- ' get: function () {',
- ' return this.p[this.a];',
- ' },',
- ' set: function (v) {',
- ' this.p[this.a] = v;',
- ' }',
- '});',
- 'this.DoIt(this.GetArr(7)[3+1],this.GetArr(8)[3+2],{',
- ' a: 3+3,',
- ' p: this.GetArr(9),',
- ' get: function () {',
- ' return this.p[this.a];',
- ' },',
- ' set: function (v) {',
- ' this.p[this.a] = v;',
- ' }',
- '});',
- '']));
- end;
- procedure TTestModule.TestArrayEnumTypeRange;
- begin
- StartProgram(false);
- Add('type');
- Add(' TEnum = (red,blue);');
- Add(' TEnumArray = array[TEnum] of longint;');
- Add('var');
- Add(' e: TEnum;');
- Add(' i: longint;');
- Add(' a: TEnumArray;');
- Add(' numbers: TEnumArray = (1,2);');
- Add(' names: array[TEnum] of string = (''red'',''blue'');');
- Add('begin');
- Add(' e:=low(a);');
- Add(' e:=high(a);');
- Add(' i:=a[red]+length(a);');
- Add(' a[e]:=a[e];');
- ConvertProgram;
- CheckSource('TestArrayEnumTypeRange',
- LinesToStr([ // statements
- ' this.TEnum = {',
- ' "0": "red",',
- ' red: 0,',
- ' "1": "blue",',
- ' blue: 1',
- '};',
- 'this.e = 0;',
- 'this.i = 0;',
- 'this.a = rtl.arrayNewMultiDim([2],0);',
- 'this.numbers = [1, 2];',
- 'this.names = ["red", "blue"];',
- '']),
- LinesToStr([ // this.$main
- 'this.e = this.TEnum.red;',
- 'this.e = this.TEnum.blue;',
- 'this.i = this.a[this.TEnum.red]+2;',
- 'this.a[this.e] = this.a[this.e];',
- '']));
- end;
- procedure TTestModule.TestArray_SetLengthProperty;
- begin
- StartProgram(false);
- Add('type');
- Add(' TArrInt = array of longint;');
- Add(' TObject = class');
- Add(' function GetColors: TArrInt; external name ''GetColors'';');
- Add(' procedure SetColors(const Value: TArrInt); external name ''SetColors'';');
- Add(' property Colors: TArrInt read GetColors write SetColors;');
- Add(' end;');
- Add('var Obj: TObject;');
- Add('begin');
- Add(' SetLength(Obj.Colors,2);');
- ConvertProgram;
- CheckSource('TestArray_SetLengthProperty',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'this.Obj = null;',
- '']),
- LinesToStr([
- 'this.Obj.SetColors(rtl.arraySetLength(this.Obj.GetColors(), 2, 0));',
- '']));
- end;
- procedure TTestModule.TestArray_OpenArrayOfString;
- begin
- StartProgram(false);
- Add('procedure DoIt(const a: array of String);');
- Add('var');
- Add(' i: longint;');
- Add(' s: string;');
- Add('begin');
- Add(' for i:=low(a) to high(a) do s:=a[length(a)-i-1];');
- Add('end;');
- Add('var s: string;');
- Add('begin');
- Add(' DoIt([]);');
- Add(' DoIt([s,''foo'','''',s+s]);');
- ConvertProgram;
- CheckSource('TestArray_OpenArrayOfString',
- LinesToStr([ // statements
- 'this.DoIt = function (a) {',
- ' var i = 0;',
- ' var s = "";',
- ' var $loopend1 = a.length - 1;',
- ' for (i = 0; i <= $loopend1; i++) s = a[(a.length - i) - 1];',
- '};',
- 'this.s = "";',
- '']),
- LinesToStr([
- 'this.DoIt([]);',
- 'this.DoIt([this.s, "foo", "", this.s + this.s]);',
- '']));
- end;
- procedure TTestModule.TestRecord_Var;
- begin
- StartProgram(false);
- Add('type');
- Add(' TRecA = record');
- Add(' Bold: longint;');
- Add(' end;');
- Add('var Rec: TRecA;');
- Add('begin');
- Add(' rec.bold:=123');
- ConvertProgram;
- CheckSource('TestRecord_Var',
- LinesToStr([ // statements
- 'this.TRecA = function (s) {',
- ' if (s) {',
- ' this.Bold = s.Bold;',
- ' } else {',
- ' this.Bold = 0;',
- ' };',
- ' this.$equal = function (b) {',
- ' return this.Bold == b.Bold;',
- ' };',
- '};',
- 'this.Rec = new this.TRecA();'
- ]),
- LinesToStr([ // this.$main
- 'this.Rec.Bold = 123;'
- ]));
- end;
- procedure TTestModule.TestWithRecordDo;
- begin
- StartProgram(false);
- Add('type');
- Add(' TRec = record');
- Add(' vI: longint;');
- Add(' end;');
- Add('var');
- Add(' Int: longint;');
- Add(' r: TRec;');
- Add('begin');
- Add(' with r do');
- Add(' int:=vi;');
- Add(' with r do begin');
- Add(' int:=vi;');
- Add(' vi:=int;');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestWithRecordDo',
- LinesToStr([ // statements
- 'this.TRec = function (s) {',
- ' if (s) {',
- ' this.vI = s.vI;',
- ' } else {',
- ' this.vI = 0;',
- ' };',
- ' this.$equal = function (b) {',
- ' return this.vI == b.vI;',
- ' };',
- '};',
- 'this.Int = 0;',
- 'this.r = new this.TRec();'
- ]),
- LinesToStr([ // this.$main
- 'var $with1 = this.r;',
- 'this.Int = $with1.vI;',
- 'var $with2 = this.r;',
- 'this.Int = $with2.vI;',
- '$with2.vI = this.Int;'
- ]));
- end;
- procedure TTestModule.TestRecord_Assign;
- begin
- StartProgram(false);
- Add('type');
- Add(' TEnum = (red,green);');
- Add(' TEnums = set of TEnum;');
- Add(' TSmallRec = record');
- Add(' N: longint;');
- Add(' end;');
- Add(' TBigRec = record');
- Add(' Int: longint;');
- Add(' D: double;');
- Add(' Arr: array of longint;');
- Add(' Small: TSmallRec;');
- Add(' Enums: TEnums;');
- Add(' end;');
- Add('var');
- Add(' r, s: TBigRec;');
- Add('begin');
- Add(' r:=s;');
- ConvertProgram;
- CheckSource('TestRecord_Assign',
- LinesToStr([ // statements
- 'this.TEnum = {',
- ' "0": "red",',
- ' red: 0,',
- ' "1": "green",',
- ' green: 1',
- '};',
- 'this.TSmallRec = function (s) {',
- ' if(s){',
- ' this.N = s.N;',
- ' } else {',
- ' this.N = 0;',
- ' };',
- ' this.$equal = function (b) {',
- ' return this.N == b.N;',
- ' };',
- '};',
- 'this.TBigRec = function (s) {',
- ' if(s){',
- ' this.Int = s.Int;',
- ' this.D = s.D;',
- ' this.Arr = s.Arr;',
- ' this.Small = new pas.program.TSmallRec(s.Small);',
- ' this.Enums = rtl.refSet(s.Enums);',
- ' } else {',
- ' this.Int = 0;',
- ' this.D = 0.0;',
- ' this.Arr = [];',
- ' this.Small = new pas.program.TSmallRec();',
- ' this.Enums = {};',
- ' };',
- ' this.$equal = function (b) {',
- ' return (this.Int == b.Int) && ((this.D == b.D) && ((this.Arr == b.Arr)',
- ' && (this.Small.$equal(b.Small) && rtl.eqSet(this.Enums, b.Enums))));',
- ' };',
- '};',
- 'this.r = new this.TBigRec();',
- 'this.s = new this.TBigRec();'
- ]),
- LinesToStr([ // this.$main
- 'this.r = new this.TBigRec(this.s);',
- '']));
- end;
- procedure TTestModule.TestRecord_PassAsArgClone;
- begin
- StartProgram(false);
- Add('type');
- Add(' TRecA = record');
- Add(' Bold: longint;');
- Add(' end;');
- Add('procedure DoDefault(r: treca); begin end;');
- Add('procedure DoConst(const r: treca); begin end;');
- Add('var Rec: treca;');
- Add('begin');
- Add(' dodefault(rec);');
- Add(' doconst(rec);');
- ConvertProgram;
- CheckSource('TestRecord_PassAsArgClone',
- LinesToStr([ // statements
- 'this.TRecA = function (s) {',
- ' if (s) {',
- ' this.Bold = s.Bold;',
- ' } else {',
- ' this.Bold = 0;',
- ' };',
- ' this.$equal = function (b) {',
- ' return this.Bold == b.Bold;',
- ' };',
- '};',
- 'this.DoDefault = function (r) {',
- '};',
- 'this.DoConst = function (r) {',
- '};',
- 'this.Rec = new this.TRecA();'
- ]),
- LinesToStr([ // this.$main
- 'this.DoDefault(new this.TRecA(this.Rec));',
- 'this.DoConst(this.Rec);',
- '']));
- end;
- procedure TTestModule.TestRecord_AsParams;
- begin
- StartProgram(false);
- Add('type');
- Add(' integer = longint;');
- Add(' TRecord = record');
- Add(' i: integer;');
- Add(' end;');
- Add('procedure DoIt(vG: TRecord; const vH: TRecord; var vI: TRecord);');
- Add('var vJ: TRecord;');
- Add('begin');
- Add(' vg:=vg;');
- Add(' vj:=vh;');
- Add(' vi:=vi;');
- Add(' doit(vg,vg,vg);');
- Add(' doit(vh,vh,vj);');
- Add(' doit(vi,vi,vi);');
- Add(' doit(vj,vj,vj);');
- Add('end;');
- Add('var i: TRecord;');
- Add('begin');
- Add(' doit(i,i,i);');
- ConvertProgram;
- CheckSource('TestRecord_AsParams',
- LinesToStr([ // statements
- 'this.TRecord = function (s) {',
- ' if (s) {',
- ' this.i = s.i;',
- ' } else {',
- ' this.i = 0;',
- ' };',
- ' this.$equal = function (b) {',
- ' return this.i == b.i;',
- ' };',
- '};',
- 'this.DoIt = function (vG,vH,vI) {',
- ' var vJ = new this.TRecord();',
- ' vG = new this.TRecord(vG);',
- ' vJ = new this.TRecord(vH);',
- ' vI.set(new this.TRecord(vI.get()));',
- ' this.DoIt(new this.TRecord(vG), vG, {',
- ' get: function () {',
- ' return vG;',
- ' },',
- ' set: function (v) {',
- ' vG = v;',
- ' }',
- ' });',
- ' this.DoIt(new this.TRecord(vH), vH, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- ' this.DoIt(new this.TRecord(vI.get()), vI.get(), vI);',
- ' this.DoIt(new this.TRecord(vJ), vJ, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- '};',
- 'this.i = new this.TRecord();'
- ]),
- LinesToStr([
- 'this.DoIt(new this.TRecord(this.i),this.i,{',
- ' p: this,',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});'
- ]));
- end;
- procedure TTestModule.TestRecordElement_AsParams;
- begin
- StartProgram(false);
- Add('type');
- Add(' integer = longint;');
- Add(' TRecord = record');
- Add(' i: integer;');
- Add(' end;');
- Add('procedure DoIt(vG: integer; const vH: integer; var vI: integer);');
- Add('var vJ: TRecord;');
- Add('begin');
- Add(' doit(vj.i,vj.i,vj.i);');
- Add('end;');
- Add('var r: TRecord;');
- Add('begin');
- Add(' doit(r.i,r.i,r.i);');
- ConvertProgram;
- CheckSource('TestRecordElement_AsParams',
- LinesToStr([ // statements
- 'this.TRecord = function (s) {',
- ' if (s) {',
- ' this.i = s.i;',
- ' } else {',
- ' this.i = 0;',
- ' };',
- ' this.$equal = function (b) {',
- ' return this.i == b.i;',
- ' };',
- '};',
- 'this.DoIt = function (vG,vH,vI) {',
- ' var vJ = new this.TRecord();',
- ' this.DoIt(vJ.i, vJ.i, {',
- ' p: vJ,',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- ' });',
- '};',
- 'this.r = new this.TRecord();'
- ]),
- LinesToStr([
- 'this.DoIt(this.r.i,this.r.i,{',
- ' p: this.r,',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});'
- ]));
- end;
- procedure TTestModule.TestRecordElementFromFuncResult_AsParams;
- begin
- StartProgram(false);
- Add('type');
- Add(' integer = longint;');
- Add(' TRecord = record');
- Add(' i: integer;');
- Add(' end;');
- Add('function GetRec(vB: integer = 0): TRecord;');
- Add('begin');
- Add('end;');
- Add('procedure DoIt(vG: integer; const vH: integer; var vI: integer);');
- Add('begin');
- Add('end;');
- Add('begin');
- Add(' doit(getrec.i,getrec.i,getrec.i);');
- Add(' doit(getrec().i,getrec().i,getrec().i);');
- Add(' doit(getrec(1).i,getrec(2).i,getrec(3).i);');
- ConvertProgram;
- CheckSource('TestRecordElementFromFuncResult_AsParams',
- LinesToStr([ // statements
- 'this.TRecord = function (s) {',
- ' if (s) {',
- ' this.i = s.i;',
- ' } else {',
- ' this.i = 0;',
- ' };',
- ' this.$equal = function (b) {',
- ' return this.i == b.i;',
- ' };',
- '};',
- 'this.GetRec = function (vB) {',
- ' var Result = new this.TRecord();',
- ' return Result;',
- '};',
- 'this.DoIt = function (vG,vH,vI) {',
- '};'
- ]),
- LinesToStr([
- 'this.DoIt(this.GetRec(0).i,this.GetRec(0).i,{',
- ' p: this.GetRec(0),',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});',
- 'this.DoIt(this.GetRec(0).i,this.GetRec(0).i,{',
- ' p: this.GetRec(0),',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});',
- 'this.DoIt(this.GetRec(1).i,this.GetRec(2).i,{',
- ' p: this.GetRec(3),',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});',
- '']));
- end;
- procedure TTestModule.TestRecordElementFromWith_AsParams;
- begin
- StartProgram(false);
- Add('type');
- Add(' integer = longint;');
- Add(' TRecord = record');
- Add(' i: integer;');
- Add(' end;');
- Add('procedure DoIt(vG: integer; const vH: integer; var vI: integer);');
- Add('begin');
- Add('end;');
- Add('var r: trecord;');
- Add('begin');
- Add(' with r do ');
- Add(' doit(i,i,i);');
- ConvertProgram;
- CheckSource('TestRecordElementFromWith_AsParams',
- LinesToStr([ // statements
- 'this.TRecord = function (s) {',
- ' if (s) {',
- ' this.i = s.i;',
- ' } else {',
- ' this.i = 0;',
- ' };',
- ' this.$equal = function (b) {',
- ' return this.i == b.i;',
- ' };',
- '};',
- 'this.DoIt = function (vG,vH,vI) {',
- '};',
- 'this.r = new this.TRecord();'
- ]),
- LinesToStr([
- 'var $with1 = this.r;',
- 'this.DoIt($with1.i,$with1.i,{',
- ' p: $with1,',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});',
- '']));
- end;
- procedure TTestModule.TestRecord_Equal;
- begin
- StartProgram(false);
- Add('type');
- Add(' integer = longint;');
- Add(' TFlag = (red,blue);');
- Add(' TFlags = set of TFlag;');
- Add(' TProc = procedure;');
- Add(' TRecord = record');
- Add(' i: integer;');
- Add(' Event: TProc;');
- Add(' f: TFlags;');
- Add(' end;');
- Add(' TNested = record');
- Add(' r: TRecord;');
- Add(' end;');
- Add('var');
- Add(' b: boolean;');
- Add(' r,s: trecord;');
- Add('begin');
- Add(' b:=r=s;');
- Add(' b:=r<>s;');
- ConvertProgram;
- CheckSource('TestRecord_Equal',
- LinesToStr([ // statements
- 'this.TFlag = {',
- ' "0": "red",',
- ' red: 0,',
- ' "1": "blue",',
- ' blue: 1',
- '};',
- 'this.TRecord = function (s) {',
- ' if (s) {',
- ' this.i = s.i;',
- ' this.Event = s.Event;',
- ' this.f = rtl.refSet(s.f);',
- ' } else {',
- ' this.i = 0;',
- ' this.Event = null;',
- ' this.f = {};',
- ' };',
- ' this.$equal = function (b) {',
- ' return (this.i == b.i) && (rtl.eqCallback(this.Event, b.Event) && rtl.eqSet(this.f, b.f));',
- ' };',
- '};',
- 'this.TNested = function (s) {',
- ' if (s) {',
- ' this.r = new pas.program.TRecord(s.r);',
- ' } else {',
- ' this.r = new pas.program.TRecord();',
- ' };',
- ' this.$equal = function (b) {',
- ' return this.r.$equal(b.r);',
- ' };',
- '};',
- 'this.b = false;',
- 'this.r = new this.TRecord();',
- 'this.s = new this.TRecord();'
- ]),
- LinesToStr([
- 'this.b = this.r.$equal(this.s);',
- 'this.b = !this.r.$equal(this.s);',
- '']));
- end;
- procedure TTestModule.TestClass_TObjectDefaultConstructor;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' public');
- Add(' constructor Create;');
- Add(' destructor Destroy;');
- Add(' end;');
- Add('constructor tobject.create;');
- Add('begin end;');
- Add('destructor tobject.destroy;');
- Add('begin end;');
- Add('var Obj: tobject;');
- Add('begin');
- Add(' obj:=tobject.create;');
- Add(' obj.destroy;');
- ConvertProgram;
- CheckSource('TestClass_TObjectDefaultConstructor',
- LinesToStr([ // statements
- 'rtl.createClass(this,"TObject",null,function(){',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function(){',
- ' };',
- ' this.Destroy = function(){',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj = this.TObject.$create("Create");',
- 'this.Obj.$destroy("Destroy");',
- '']));
- end;
- procedure TTestModule.TestClass_TObjectConstructorWithParams;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' public');
- Add(' constructor Create(Par: longint);');
- Add(' end;');
- Add('constructor tobject.create(par: longint);');
- Add('begin end;');
- Add('var Obj: tobject;');
- Add('begin');
- Add(' obj:=tobject.create(3);');
- ConvertProgram;
- CheckSource('TestClass_TObjectConstructorWithParams',
- LinesToStr([ // statements
- 'rtl.createClass(this,"TObject",null,function(){',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function(Par){',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj = this.TObject.$create("Create",[3]);'
- ]));
- end;
- procedure TTestModule.TestClass_Var;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' public');
- Add(' vI: longint;');
- Add(' constructor Create(Par: longint);');
- Add(' end;');
- Add('constructor tobject.create(par: longint);');
- Add('begin');
- Add(' vi:=par+3');
- Add('end;');
- Add('var Obj: tobject;');
- Add('begin');
- Add(' obj:=tobject.create(4);');
- Add(' obj.vi:=obj.VI+5;');
- ConvertProgram;
- CheckSource('TestClass_Var',
- LinesToStr([ // statements
- 'rtl.createClass(this,"TObject",null,function(){',
- ' this.$init = function () {',
- ' this.vI = 0;',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function(Par){',
- ' this.vI = Par+3;',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj = this.TObject.$create("Create",[4]);',
- 'this.Obj.vI = this.Obj.vI + 5;'
- ]));
- end;
- procedure TTestModule.TestClass_Method;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' public');
- Add(' vI: longint;');
- Add(' Sub: TObject;');
- Add(' constructor Create;');
- Add(' function GetIt(Par: longint): tobject;');
- Add(' end;');
- Add('constructor tobject.create; begin end;');
- Add('function tobject.getit(par: longint): tobject;');
- Add('begin');
- Add(' Self.vi:=par+3;');
- Add(' Result:=self.sub;');
- Add('end;');
- Add('var Obj: tobject;');
- Add('begin');
- Add(' obj:=tobject.create;');
- Add(' obj.getit(4);');
- Add(' obj.sub.sub:=nil;');
- Add(' obj.sub.getit(5);');
- Add(' obj.sub.getit(6).SUB:=nil;');
- Add(' obj.sub.getit(7).GETIT(8);');
- Add(' obj.sub.getit(9).SuB.getit(10);');
- ConvertProgram;
- CheckSource('TestClass_Method',
- LinesToStr([ // statements
- 'rtl.createClass(this,"TObject",null,function(){',
- ' this.$init = function () {',
- ' this.vI = 0;',
- ' this.Sub = null;',
- ' };',
- ' this.$final = function () {',
- ' this.Sub = undefined;',
- ' };',
- ' this.Create = function(){',
- ' };',
- ' this.GetIt = function(Par){',
- ' var Result = null;',
- ' this.vI = Par + 3;',
- ' Result = this.Sub;',
- ' return Result;',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj = this.TObject.$create("Create");',
- 'this.Obj.GetIt(4);',
- 'this.Obj.Sub.Sub=null;',
- 'this.Obj.Sub.GetIt(5);',
- 'this.Obj.Sub.GetIt(6).Sub=null;',
- 'this.Obj.Sub.GetIt(7).GetIt(8);',
- 'this.Obj.Sub.GetIt(9).Sub.GetIt(10);'
- ]));
- end;
- procedure TTestModule.TestClass_Inheritance;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' public');
- Add(' constructor Create;');
- Add(' end;');
- Add(' TClassA = class');
- Add(' end;');
- Add(' TClassB = class(TObject)');
- Add(' procedure ProcB;');
- Add(' end;');
- Add('constructor tobject.create; begin end;');
- Add('procedure tclassb.procb; begin end;');
- Add('var');
- Add(' oO: TObject;');
- Add(' oA: TClassA;');
- Add(' oB: TClassB;');
- Add('begin');
- Add(' oO:=tobject.Create;');
- Add(' oA:=tclassa.Create;');
- Add(' ob:=tclassb.Create;');
- Add(' if oo is tclassa then ;');
- Add(' ob:=oo as tclassb;');
- Add(' (oo as tclassb).procb;');
- ConvertProgram;
- CheckSource('TestClass_Inheritance',
- LinesToStr([ // statements
- 'rtl.createClass(this,"TObject",null,function(){',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function () {',
- ' };',
- '});',
- 'rtl.createClass(this,"TClassA",this.TObject,function(){',
- '});',
- 'rtl.createClass(this,"TClassB",this.TObject,function(){',
- ' this.ProcB = function () {',
- ' };',
- '});',
- 'this.oO = null;',
- 'this.oA = null;',
- 'this.oB = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.oO = this.TObject.$create("Create");',
- 'this.oA = this.TClassA.$create("Create");',
- 'this.oB = this.TClassB.$create("Create");',
- 'if (this.TClassA.isPrototypeOf(this.oO));',
- 'this.oB = rtl.as(this.oO, this.TClassB);',
- 'rtl.as(this.oO, this.TClassB).ProcB();'
- ]));
- end;
- procedure TTestModule.TestClass_AbstractMethod;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' public');
- Add(' procedure DoIt; virtual; abstract;');
- Add(' end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestClass_AbstractMethod',
- LinesToStr([ // statements
- 'rtl.createClass(this,"TObject",null,function(){',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});'
- ]),
- LinesToStr([ // this.$main
- ''
- ]));
- end;
- procedure TTestModule.TestClass_CallInherited_NoParams;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' procedure DoAbstract; virtual; abstract;');
- Add(' procedure DoVirtual; virtual;');
- Add(' procedure DoIt;');
- Add(' end;');
- Add(' TA = class');
- Add(' procedure doabstract; override;');
- Add(' procedure dovirtual; override;');
- Add(' procedure DoSome;');
- Add(' end;');
- Add('procedure tobject.dovirtual;');
- Add('begin');
- Add(' inherited; // call non existing ancestor -> ignore silently');
- Add('end;');
- Add('procedure tobject.doit;');
- Add('begin');
- Add('end;');
- Add('procedure ta.doabstract;');
- Add('begin');
- Add(' inherited dovirtual; // call TObject.DoVirtual');
- Add('end;');
- Add('procedure ta.dovirtual;');
- Add('begin');
- Add(' inherited; // call TObject.DoVirtual');
- Add(' inherited dovirtual; // call TObject.DoVirtual');
- Add(' inherited dovirtual(); // call TObject.DoVirtual');
- Add(' doit;');
- Add(' doit();');
- Add('end;');
- Add('procedure ta.dosome;');
- Add('begin');
- Add(' inherited; // call non existing ancestor method -> silently ignore');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestClass_CallInherited_NoParams',
- LinesToStr([ // statements
- 'rtl.createClass(this,"TObject",null,function(){',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.DoVirtual = function () {',
- ' };',
- ' this.DoIt = function () {',
- ' };',
- '});',
- 'rtl.createClass(this, "TA", this.TObject, function () {',
- ' this.DoAbstract = function () {',
- ' pas.program.TObject.DoVirtual.call(this);',
- ' };',
- ' this.DoVirtual = function () {',
- ' pas.program.TObject.DoVirtual.apply(this, arguments);',
- ' pas.program.TObject.DoVirtual.call(this);',
- ' pas.program.TObject.DoVirtual.call(this);',
- ' this.DoIt();',
- ' this.DoIt();',
- ' };',
- ' this.DoSome = function () {',
- ' };',
- '});'
- ]),
- LinesToStr([ // this.$main
- ''
- ]));
- end;
- procedure TTestModule.TestClass_CallInherited_WithParams;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' procedure DoAbstract(pA: longint; pB: longint = 0); virtual; abstract;');
- Add(' procedure DoVirtual(pA: longint; pB: longint = 0); virtual;');
- Add(' procedure DoIt(pA: longint; pB: longint = 0);');
- Add(' procedure DoIt2(pA: longint = 1; pB: longint = 2);');
- Add(' end;');
- Add(' TClassA = class');
- Add(' procedure DoAbstract(pA: longint; pB: longint = 0); override;');
- Add(' procedure DoVirtual(pA: longint; pB: longint = 0); override;');
- Add(' end;');
- Add('procedure tobject.dovirtual(pa: longint; pb: longint = 0);');
- Add('begin');
- Add('end;');
- Add('procedure tobject.doit(pa: longint; pb: longint = 0);');
- Add('begin');
- Add('end;');
- Add('procedure tobject.doit2(pa: longint; pb: longint = 0);');
- Add('begin');
- Add('end;');
- Add('procedure tclassa.doabstract(pa: longint; pb: longint = 0);');
- Add('begin');
- Add(' inherited dovirtual(pa,pb); // call TObject.DoVirtual(pA,pB)');
- Add(' inherited dovirtual(pa); // call TObject.DoVirtual(pA,0)');
- Add('end;');
- Add('procedure tclassa.dovirtual(pa: longint; pb: longint = 0);');
- Add('begin');
- Add(' inherited; // call TObject.DoVirtual(pA,pB)');
- Add(' inherited dovirtual(pa,pb); // call TObject.DoVirtual(pA,pB)');
- Add(' inherited dovirtual(pa); // call TObject.DoVirtual(pA,0)');
- Add(' doit(pa,pb);');
- Add(' doit(pa);');
- Add(' doit2(pa);');
- Add(' doit2;');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestClass_CallInherited_WithParams',
- LinesToStr([ // statements
- 'rtl.createClass(this,"TObject",null,function(){',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.DoVirtual = function (pA,pB) {',
- ' };',
- ' this.DoIt = function (pA,pB) {',
- ' };',
- ' this.DoIt2 = function (pA,pB) {',
- ' };',
- '});',
- 'rtl.createClass(this, "TClassA", this.TObject, function () {',
- ' this.DoAbstract = function (pA,pB) {',
- ' pas.program.TObject.DoVirtual.call(this,pA,pB);',
- ' pas.program.TObject.DoVirtual.call(this,pA,0);',
- ' };',
- ' this.DoVirtual = function (pA,pB) {',
- ' pas.program.TObject.DoVirtual.apply(this, arguments);',
- ' pas.program.TObject.DoVirtual.call(this,pA,pB);',
- ' pas.program.TObject.DoVirtual.call(this,pA,0);',
- ' this.DoIt(pA,pB);',
- ' this.DoIt(pA,0);',
- ' this.DoIt2(pA,2);',
- ' this.DoIt2(1,2);',
- ' };',
- '});'
- ]),
- LinesToStr([ // this.$main
- ''
- ]));
- end;
- procedure TTestModule.TestClasS_CallInheritedConstructor;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' constructor Create; virtual;');
- Add(' constructor CreateWithB(b: boolean);');
- Add(' end;');
- Add(' TA = class');
- Add(' constructor Create; override;');
- Add(' constructor CreateWithC(c: char);');
- Add(' procedure DoIt;');
- Add(' class function DoSome: TObject;');
- Add(' end;');
- Add('constructor tobject.create;');
- Add('begin');
- Add(' inherited; // call non existing ancestor -> ignore silently');
- Add('end;');
- Add('constructor tobject.createwithb(b: boolean);');
- Add('begin');
- Add(' inherited; // call non existing ancestor -> ignore silently');
- Add(' create; // normal call');
- Add('end;');
- Add('constructor ta.create;');
- Add('begin');
- Add(' inherited; // normal call TObject.Create');
- Add(' inherited create; // normal call TObject.Create');
- Add(' inherited createwithb(false); // normal call TObject.CreateWithB');
- Add('end;');
- Add('constructor ta.createwithc(c: char);');
- Add('begin');
- Add(' inherited create; // call TObject.Create');
- Add(' inherited createwithb(true); // call TObject.CreateWithB');
- Add(' doit;');
- Add(' doit();');
- Add(' dosome;');
- Add('end;');
- Add('procedure ta.doit;');
- Add('begin');
- Add(' create; // normal call');
- Add(' createwithb(false); // normal call');
- Add(' createwithc(''c''); // normal call');
- Add('end;');
- Add('class function ta.dosome: TObject;');
- Add('begin');
- Add(' Result:=create; // constructor');
- Add(' Result:=createwithb(true); // constructor');
- Add(' Result:=createwithc(''c''); // constructor');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestClass_CallInheritedConstructor',
- LinesToStr([ // statements
- 'rtl.createClass(this,"TObject",null,function(){',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function () {',
- ' };',
- ' this.CreateWithB = function (b) {',
- ' this.Create();',
- ' };',
- '});',
- 'rtl.createClass(this, "TA", this.TObject, function () {',
- ' this.Create = function () {',
- ' pas.program.TObject.Create.apply(this, arguments);',
- ' pas.program.TObject.Create.call(this);',
- ' pas.program.TObject.CreateWithB.call(this, false);',
- ' };',
- ' this.CreateWithC = function (c) {',
- ' pas.program.TObject.Create.call(this);',
- ' pas.program.TObject.CreateWithB.call(this, true);',
- ' this.DoIt();',
- ' this.DoIt();',
- ' this.$class.DoSome();',
- ' };',
- ' this.DoIt = function () {',
- ' this.Create();',
- ' this.CreateWithB(false);',
- ' this.CreateWithC("c");',
- ' };',
- ' this.DoSome = function () {',
- ' var Result = null;',
- ' Result = this.$create("Create");',
- ' Result = this.$create("CreateWithB", [true]);',
- ' Result = this.$create("CreateWithC", ["c"]);',
- ' return Result;',
- ' };',
- '});'
- ]),
- LinesToStr([ // this.$main
- ''
- ]));
- end;
- procedure TTestModule.TestClass_ClassVar;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' public');
- Add(' class var vI: longint;');
- Add(' class var Sub: TObject;');
- Add(' constructor Create;');
- Add(' class function GetIt(Par: longint): tobject;');
- Add(' end;');
- Add('constructor tobject.create;');
- Add('begin');
- Add(' vi:=vi+1;');
- Add(' Self.vi:=Self.vi+1;');
- Add('end;');
- Add('class function tobject.getit(par: longint): tobject;');
- Add('begin');
- Add(' vi:=vi+par;');
- Add(' Self.vi:=Self.vi+par;');
- Add(' Result:=self.sub;');
- Add('end;');
- Add('var Obj: tobject;');
- Add('begin');
- Add(' obj:=tobject.create;');
- Add(' tobject.vi:=3;');
- Add(' if tobject.vi=4 then ;');
- Add(' tobject.sub:=nil;');
- Add(' obj.sub:=nil;');
- Add(' obj.sub.sub:=nil;');
- ConvertProgram;
- CheckSource('TestClass_ClassVar',
- LinesToStr([ // statements
- 'rtl.createClass(this,"TObject",null,function(){',
- ' this.vI = 0;',
- ' this.Sub = null;',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function(){',
- ' this.$class.vI = this.vI+1;',
- ' this.$class.vI = this.vI+1;',
- ' };',
- ' this.GetIt = function(Par){',
- ' var Result = null;',
- ' this.vI = this.vI + Par;',
- ' this.vI = this.vI + Par;',
- ' Result = this.Sub;',
- ' return Result;',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj = this.TObject.$create("Create");',
- 'this.TObject.vI = 3;',
- 'if (this.TObject.vI == 4);',
- 'this.TObject.Sub=null;',
- 'this.Obj.$class.Sub=null;',
- 'this.Obj.Sub.$class.Sub=null;',
- '']));
- end;
- procedure TTestModule.TestClass_CallClassMethod;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' public');
- Add(' class var vI: longint;');
- Add(' class var Sub: TObject;');
- Add(' constructor Create;');
- Add(' function GetMore(Par: longint): longint;');
- Add(' class function GetIt(Par: longint): tobject;');
- Add(' end;');
- Add('constructor tobject.create;');
- Add('begin');
- Add(' sub:=getit(3);');
- Add(' vi:=getmore(4);');
- Add(' sub:=Self.getit(5);');
- Add(' vi:=Self.getmore(6);');
- Add('end;');
- Add('function tobject.getmore(par: longint): longint;');
- Add('begin');
- Add(' sub:=getit(11);');
- Add(' vi:=getmore(12);');
- Add(' sub:=self.getit(13);');
- Add(' vi:=self.getmore(14);');
- Add('end;');
- Add('class function tobject.getit(par: longint): tobject;');
- Add('begin');
- Add(' sub:=getit(21);');
- Add(' vi:=sub.getmore(22);');
- Add(' sub:=self.getit(23);');
- Add(' vi:=self.sub.getmore(24);');
- Add('end;');
- Add('var Obj: tobject;');
- Add('begin');
- Add(' obj:=tobject.create;');
- Add(' tobject.getit(5);');
- Add(' obj.getit(6);');
- Add(' obj.sub.getit(7);');
- Add(' obj.sub.getit(8).SUB:=nil;');
- Add(' obj.sub.getit(9).GETIT(10);');
- Add(' obj.sub.getit(11).SuB.getit(12);');
- ConvertProgram;
- CheckSource('TestClass_CallClassMethod',
- LinesToStr([ // statements
- 'rtl.createClass(this,"TObject",null,function(){',
- ' this.vI = 0;',
- ' this.Sub = null;',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function(){',
- ' this.$class.Sub = this.$class.GetIt(3);',
- ' this.$class.vI = this.GetMore(4);',
- ' this.$class.Sub = this.$class.GetIt(5);',
- ' this.$class.vI = this.GetMore(6);',
- ' };',
- ' this.GetMore = function(Par){',
- ' var Result = 0;',
- ' this.$class.Sub = this.$class.GetIt(11);',
- ' this.$class.vI = this.GetMore(12);',
- ' this.$class.Sub = this.$class.GetIt(13);',
- ' this.$class.vI = this.GetMore(14);',
- ' return Result;',
- ' };',
- ' this.GetIt = function(Par){',
- ' var Result = null;',
- ' this.Sub = this.GetIt(21);',
- ' this.vI = this.Sub.GetMore(22);',
- ' this.Sub = this.GetIt(23);',
- ' this.vI = this.Sub.GetMore(24);',
- ' return Result;',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj = this.TObject.$create("Create");',
- 'this.TObject.GetIt(5);',
- 'this.Obj.$class.GetIt(6);',
- 'this.Obj.Sub.$class.GetIt(7);',
- 'this.Obj.Sub.$class.GetIt(8).$class.Sub=null;',
- 'this.Obj.Sub.$class.GetIt(9).$class.GetIt(10);',
- 'this.Obj.Sub.$class.GetIt(11).Sub.$class.GetIt(12);',
- '']));
- end;
- procedure TTestModule.TestClass_Property;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' Fx: longint;');
- Add(' Fy: longint;');
- Add(' function GetInt: longint;');
- Add(' procedure SetInt(Value: longint);');
- Add(' procedure DoIt;');
- Add(' property IntA: longint read Fx write Fy;');
- Add(' property IntB: longint read GetInt write SetInt;');
- Add(' end;');
- Add('function tobject.getint: longint;');
- Add('begin');
- Add(' result:=fx;');
- Add('end;');
- Add('procedure tobject.setint(value: longint);');
- Add('begin');
- Add(' if value=fy then exit;');
- Add(' fy:=value;');
- Add('end;');
- Add('procedure tobject.doit;');
- Add('begin');
- Add(' IntA:=IntA+1;');
- Add(' Self.IntA:=Self.IntA+1;');
- Add(' IntB:=IntB+1;');
- Add(' Self.IntB:=Self.IntB+1;');
- Add('end;');
- Add('var Obj: tobject;');
- Add('begin');
- Add(' obj.inta:=obj.inta+1;');
- Add(' if obj.intb=2 then;');
- Add(' obj.intb:=obj.intb+2;');
- Add(' obj.setint(obj.inta);');
- ConvertProgram;
- CheckSource('TestClass_Property',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.Fx = 0;',
- ' this.Fy = 0;',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.GetInt = function () {',
- ' var Result = 0;',
- ' Result = this.Fx;',
- ' return Result;',
- ' };',
- ' this.SetInt = function (Value) {',
- ' if (Value == this.Fy) return;',
- ' this.Fy = Value;',
- ' };',
- ' this.DoIt = function () {',
- ' this.Fy = this.Fx + 1;',
- ' this.Fy = this.Fx + 1;',
- ' this.SetInt(this.GetInt() + 1);',
- ' this.SetInt(this.GetInt() + 1);',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj.Fy = this.Obj.Fx + 1;',
- 'if (this.Obj.GetInt() == 2);',
- 'this.Obj.SetInt(this.Obj.GetInt() + 2);',
- 'this.Obj.SetInt(this.Obj.Fx);'
- ]));
- end;
- procedure TTestModule.TestClass_Property_ClassMethod;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' class var Fx: longint;');
- Add(' class var Fy: longint;');
- Add(' class function GetInt: longint;');
- Add(' class procedure SetInt(Value: longint);');
- Add(' class procedure DoIt;');
- Add(' class property IntA: longint read Fx write Fy;');
- Add(' class property IntB: longint read GetInt write SetInt;');
- Add(' end;');
- Add('class function tobject.getint: longint;');
- Add('begin');
- Add(' result:=fx;');
- Add('end;');
- Add('class procedure tobject.setint(value: longint);');
- Add('begin');
- Add('end;');
- Add('class procedure tobject.doit;');
- Add('begin');
- Add(' IntA:=IntA+1;');
- Add(' Self.IntA:=Self.IntA+1;');
- Add(' IntB:=IntB+1;');
- Add(' Self.IntB:=Self.IntB+1;');
- Add('end;');
- Add('var Obj: tobject;');
- Add('begin');
- Add(' tobject.inta:=tobject.inta+1;');
- Add(' if tobject.intb=2 then;');
- Add(' tobject.intb:=tobject.intb+2;');
- Add(' tobject.setint(tobject.inta);');
- Add(' obj.inta:=obj.inta+1;');
- Add(' if obj.intb=2 then;');
- Add(' obj.intb:=obj.intb+2;');
- Add(' obj.setint(obj.inta);');
- ConvertProgram;
- CheckSource('TestClass_Property_ClassMethod',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.Fx = 0;',
- ' this.Fy = 0;',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.GetInt = function () {',
- ' var Result = 0;',
- ' Result = this.Fx;',
- ' return Result;',
- ' };',
- ' this.SetInt = function (Value) {',
- ' };',
- ' this.DoIt = function () {',
- ' this.Fy = this.Fx + 1;',
- ' this.Fy = this.Fx + 1;',
- ' this.SetInt(this.GetInt() + 1);',
- ' this.SetInt(this.GetInt() + 1);',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.TObject.Fy = this.TObject.Fx + 1;',
- 'if (this.TObject.GetInt() == 2);',
- 'this.TObject.SetInt(this.TObject.GetInt() + 2);',
- 'this.TObject.SetInt(this.TObject.Fx);',
- 'this.Obj.$class.Fy = this.Obj.Fx + 1;',
- 'if (this.Obj.$class.GetInt() == 2);',
- 'this.Obj.$class.SetInt(this.Obj.$class.GetInt() + 2);',
- 'this.Obj.$class.SetInt(this.Obj.Fx);'
- ]));
- end;
- procedure TTestModule.TestClass_Property_Index;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' FItems: array of longint;');
- Add(' function GetItems(Index: longint): longint;');
- Add(' procedure SetItems(Index: longint; Value: longint);');
- Add(' procedure DoIt;');
- Add(' property Items[Index: longint]: longint read getitems write setitems;');
- Add(' end;');
- Add('function tobject.getitems(index: longint): longint;');
- Add('begin');
- Add(' Result:=fitems[index];');
- Add('end;');
- Add('procedure tobject.setitems(index: longint; value: longint);');
- Add('begin');
- Add(' fitems[index]:=value;');
- Add('end;');
- Add('procedure tobject.doit;');
- Add('begin');
- Add(' items[1]:=2;');
- Add(' items[3]:=items[4];');
- Add(' self.items[5]:=self.items[6];');
- Add(' items[items[7]]:=items[items[8]];');
- Add('end;');
- Add('var Obj: tobject;');
- Add('begin');
- Add(' obj.Items[11]:=obj.Items[12];');
- ConvertProgram;
- CheckSource('TestClass_Property_Index',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.FItems = [];',
- ' };',
- ' this.$final = function () {',
- ' this.FItems = undefined;',
- ' };',
- ' this.GetItems = function (Index) {',
- ' var Result = 0;',
- ' Result = this.FItems[Index];',
- ' return Result;',
- ' };',
- ' this.SetItems = function (Index, Value) {',
- ' this.FItems[Index] = Value;',
- ' };',
- ' this.DoIt = function () {',
- ' this.SetItems(1, 2);',
- ' this.SetItems(3,this.GetItems(4));',
- ' this.SetItems(5,this.GetItems(6));',
- ' this.SetItems(this.GetItems(7), this.GetItems(this.GetItems(8)));',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj.SetItems(11,this.Obj.GetItems(12));'
- ]));
- end;
- procedure TTestModule.TestClass_PropertyOfTypeArray;
- begin
- StartProgram(false);
- Add('type');
- Add(' TArray = array of longint;');
- Add(' TObject = class');
- Add(' FItems: TArray;');
- Add(' function GetItems: tarray;');
- Add(' procedure SetItems(Value: tarray);');
- Add(' property Items: tarray read getitems write setitems;');
- Add(' end;');
- Add('function tobject.getitems: tarray;');
- Add('begin');
- Add(' Result:=fitems;');
- Add('end;');
- Add('procedure tobject.setitems(value: tarray);');
- Add('begin');
- Add(' fitems:=value;');
- Add(' fitems:=nil;');
- Add(' Items:=nil;');
- Add(' Items:=Items;');
- Add(' Items[1]:=2;');
- Add(' fitems[3]:=Items[4];');
- Add(' Items[5]:=Items[6];');
- Add(' Self.Items[7]:=8;');
- Add(' Self.Items[9]:=Self.Items[10];');
- Add(' Items[Items[11]]:=Items[Items[12]];');
- Add('end;');
- Add('var Obj: tobject;');
- Add('begin');
- Add(' obj.items:=nil;');
- Add(' obj.items:=obj.items;');
- Add(' obj.items[11]:=obj.items[12];');
- ConvertProgram;
- CheckSource('TestClass_PropertyOfTypeArray',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.FItems = [];',
- ' };',
- ' this.$final = function () {',
- ' this.FItems = undefined;',
- ' };',
- ' this.GetItems = function () {',
- ' var Result = [];',
- ' Result = this.FItems;',
- ' return Result;',
- ' };',
- ' this.SetItems = function (Value) {',
- ' this.FItems = Value;',
- ' this.FItems = [];',
- ' this.SetItems([]);',
- ' this.SetItems(this.GetItems());',
- ' this.GetItems()[1] = 2;',
- ' this.FItems[3] = this.GetItems()[4];',
- ' this.GetItems()[5] = this.GetItems()[6];',
- ' this.GetItems()[7] = 8;',
- ' this.GetItems()[9] = this.GetItems()[10];',
- ' this.GetItems()[this.GetItems()[11]] = this.GetItems()[this.GetItems()[12]];',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj.SetItems([]);',
- 'this.Obj.SetItems(this.Obj.GetItems());',
- 'this.Obj.GetItems()[11] = this.Obj.GetItems()[12];'
- ]));
- end;
- procedure TTestModule.TestClass_PropertyDefault;
- begin
- StartProgram(false);
- Add('type');
- Add(' TArray = array of longint;');
- Add(' TObject = class');
- Add(' FItems: TArray;');
- Add(' function GetItems(Index: longint): longint;');
- Add(' procedure SetItems(Index, Value: longint);');
- Add(' property Items[Index: longint]: longint read getitems write setitems; default;');
- Add(' end;');
- Add('function tobject.getitems(index: longint): longint;');
- Add('begin');
- Add('end;');
- Add('procedure tobject.setitems(index, value: longint);');
- Add('begin');
- Add(' Self[1]:=2;');
- Add(' Self[3]:=Self[index];');
- Add(' Self[index]:=Self[Self[value]];');
- Add(' Self[Self[4]]:=value;');
- Add('end;');
- Add('var Obj: tobject;');
- Add('begin');
- Add(' obj[11]:=12;');
- Add(' obj[13]:=obj[14];');
- Add(' obj[obj[15]]:=obj[obj[15]];');
- ConvertProgram;
- CheckSource('TestClass_PropertyDefault',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.FItems = [];',
- ' };',
- ' this.$final = function () {',
- ' this.FItems = undefined;',
- ' };',
- ' this.GetItems = function (Index) {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- ' this.SetItems = function (Index, Value) {',
- ' this.SetItems(1, 2);',
- ' this.SetItems(3, this.GetItems(Index));',
- ' this.SetItems(Index, this.GetItems(this.GetItems(Value)));',
- ' this.SetItems(this.GetItems(4), Value);',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj.SetItems(11, 12);',
- 'this.Obj.SetItems(13, this.Obj.GetItems(14));',
- 'this.Obj.SetItems(this.Obj.GetItems(15), this.Obj.GetItems(this.Obj.GetItems(15)));'
- ]));
- end;
- procedure TTestModule.TestClass_PropertyOverride;
- begin
- StartProgram(false);
- Add('type');
- Add(' integer = longint;');
- Add(' TObject = class');
- Add(' FItem: integer;');
- Add(' function GetItem: integer; external name ''GetItem'';');
- Add(' procedure SetItem(Value: integer); external name ''SetItem'';');
- Add(' property Item: integer read getitem write setitem;');
- Add(' end;');
- Add(' TCar = class');
- Add(' FBag: integer;');
- Add(' function GetBag: integer; external name ''GetBag'';');
- Add(' property Item read getbag;');
- Add(' end;');
- Add('var');
- Add(' Obj: tobject;');
- Add(' Car: tcar;');
- Add('begin');
- Add(' Obj.Item:=Obj.Item;');
- Add(' Car.Item:=Car.Item;');
- ConvertProgram;
- CheckSource('TestClass_PropertyOverride',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.FItem = 0;',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'rtl.createClass(this, "TCar", this.TObject, function () {',
- ' this.$init = function () {',
- ' pas.program.TObject.$init.call(this);',
- ' this.FBag = 0;',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.Car = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.Obj.SetItem(this.Obj.GetItem());',
- 'this.Car.SetItem(this.Car.GetBag());',
- '']));
- end;
- procedure TTestModule.TestClass_Assigned;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' end;');
- Add('var');
- Add(' Obj: tobject;');
- Add(' b: boolean;');
- Add('begin');
- Add(' if Assigned(obj) then ;');
- Add(' b:=Assigned(obj) or false;');
- ConvertProgram;
- CheckSource('TestClass_Assigned',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.b = false;'
- ]),
- LinesToStr([ // this.$main
- 'if (this.Obj != null);',
- 'this.b = (this.Obj != null) || false;'
- ]));
- end;
- procedure TTestModule.TestClass_WithClassDoCreate;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' aBool: boolean;');
- Add(' Arr: array of boolean;');
- Add(' constructor Create;');
- Add(' end;');
- Add('constructor TObject.Create; begin end;');
- Add('var');
- Add(' Obj: tobject;');
- Add(' b: boolean;');
- Add('begin');
- Add(' with tobject.create do begin');
- Add(' b:=abool;');
- Add(' abool:=b;');
- Add(' b:=arr[1];');
- Add(' arr[2]:=b;');
- Add(' end;');
- Add(' with tobject do');
- Add(' obj:=create;');
- Add(' with obj do begin');
- Add(' create;');
- Add(' b:=abool;');
- Add(' abool:=b;');
- Add(' b:=arr[3];');
- Add(' arr[4]:=b;');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestClass_WithClassDoCreate',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.aBool = false;',
- ' this.Arr = [];',
- ' };',
- ' this.$final = function () {',
- ' this.Arr = undefined;',
- ' };',
- ' this.Create = function () {',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.b = false;'
- ]),
- LinesToStr([ // this.$main
- 'var $with1 = this.TObject.$create("Create");',
- 'this.b = $with1.aBool;',
- '$with1.aBool = this.b;',
- 'this.b = $with1.Arr[1];',
- '$with1.Arr[2] = this.b;',
- 'var $with2 = this.TObject;',
- 'this.Obj = $with2.$create("Create");',
- 'var $with3 = this.Obj;',
- '$with3.Create();',
- 'this.b = $with3.aBool;',
- '$with3.aBool = this.b;',
- 'this.b = $with3.Arr[3];',
- '$with3.Arr[4] = this.b;',
- '']));
- end;
- procedure TTestModule.TestClass_WithClassInstDoProperty;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' FInt: longint;');
- Add(' constructor Create;');
- Add(' function GetSize: longint;');
- Add(' procedure SetSize(Value: longint);');
- Add(' property Int: longint read FInt write FInt;');
- Add(' property Size: longint read GetSize write SetSize;');
- Add(' end;');
- Add('constructor TObject.Create; begin end;');
- Add('function TObject.GetSize: longint; begin; end;');
- Add('procedure TObject.SetSize(Value: longint); begin; end;');
- Add('var');
- Add(' Obj: tobject;');
- Add(' i: longint;');
- Add('begin');
- Add(' with TObject.Create do begin');
- Add(' i:=int;');
- Add(' int:=i;');
- Add(' i:=size;');
- Add(' size:=i;');
- Add(' end;');
- Add(' with obj do begin');
- Add(' i:=int;');
- Add(' int:=i;');
- Add(' i:=size;');
- Add(' size:=i;');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestClass_WithClassInstDoProperty',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.FInt = 0;',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function () {',
- ' };',
- ' this.GetSize = function () {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- ' this.SetSize = function (Value) {',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.i = 0;'
- ]),
- LinesToStr([ // this.$main
- 'var $with1 = this.TObject.$create("Create");',
- 'this.i = $with1.FInt;',
- '$with1.FInt = this.i;',
- 'this.i = $with1.GetSize();',
- '$with1.SetSize(this.i);',
- 'var $with2 = this.Obj;',
- 'this.i = $with2.FInt;',
- '$with2.FInt = this.i;',
- 'this.i = $with2.GetSize();',
- '$with2.SetSize(this.i);',
- '']));
- end;
- procedure TTestModule.TestClass_WithClassInstDoPropertyWithParams;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' constructor Create;');
- Add(' function GetItems(Index: longint): longint;');
- Add(' procedure SetItems(Index, Value: longint);');
- Add(' property Items[Index: longint]: longint read GetItems write SetItems;');
- Add(' end;');
- Add('constructor TObject.Create; begin end;');
- Add('function tobject.getitems(index: longint): longint; begin; end;');
- Add('procedure tobject.setitems(index, value: longint); begin; end;');
- Add('var');
- Add(' Obj: tobject;');
- Add(' i: longint;');
- Add('begin');
- Add(' with TObject.Create do begin');
- Add(' i:=Items[1];');
- Add(' Items[2]:=i;');
- Add(' end;');
- Add(' with obj do begin');
- Add(' i:=Items[3];');
- Add(' Items[4]:=i;');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestClass_WithClassInstDoPropertyWithParams',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function () {',
- ' };',
- ' this.GetItems = function (Index) {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- ' this.SetItems = function (Index, Value) {',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.i = 0;'
- ]),
- LinesToStr([ // this.$main
- 'var $with1 = this.TObject.$create("Create");',
- 'this.i = $with1.GetItems(1);',
- '$with1.SetItems(2, this.i);',
- 'var $with2 = this.Obj;',
- 'this.i = $with2.GetItems(3);',
- '$with2.SetItems(4, this.i);',
- '']));
- end;
- procedure TTestModule.TestClass_WithClassInstDoFunc;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' constructor Create;');
- Add(' function GetSize: longint;');
- Add(' procedure SetSize(Value: longint);');
- Add(' end;');
- Add('constructor TObject.Create; begin end;');
- Add('function TObject.GetSize: longint; begin; end;');
- Add('procedure TObject.SetSize(Value: longint); begin; end;');
- Add('var');
- Add(' Obj: tobject;');
- Add(' i: longint;');
- Add('begin');
- Add(' with TObject.Create do begin');
- Add(' i:=GetSize;');
- Add(' i:=GetSize();');
- Add(' SetSize(i);');
- Add(' end;');
- Add(' with obj do begin');
- Add(' i:=GetSize;');
- Add(' i:=GetSize();');
- Add(' SetSize(i);');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestClass_WithClassInstDoFunc',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function () {',
- ' };',
- ' this.GetSize = function () {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- ' this.SetSize = function (Value) {',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.i = 0;'
- ]),
- LinesToStr([ // this.$main
- 'var $with1 = this.TObject.$create("Create");',
- 'this.i = $with1.GetSize();',
- 'this.i = $with1.GetSize();',
- '$with1.SetSize(this.i);',
- 'var $with2 = this.Obj;',
- 'this.i = $with2.GetSize();',
- 'this.i = $with2.GetSize();',
- '$with2.SetSize(this.i);',
- '']));
- end;
- procedure TTestModule.TestClass_TypeCast;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' Next: TObject;');
- Add(' constructor Create;');
- Add(' end;');
- Add(' TControl = class(TObject)');
- Add(' Arr: array of TObject;');
- Add(' function GetIt(vI: longint = 0): TObject;');
- Add(' end;');
- Add('constructor tobject.create; begin end;');
- Add('function tcontrol.getit(vi: longint = 0): tobject; begin end;');
- Add('var');
- Add(' Obj: tobject;');
- Add('begin');
- Add(' obj:=tcontrol(obj).next;');
- Add(' tcontrol(obj):=nil;');
- Add(' obj:=tcontrol(obj);');
- Add(' tcontrol(obj):=tcontrol(tcontrol(obj).getit);');
- Add(' tcontrol(obj):=tcontrol(tcontrol(obj).getit());');
- Add(' tcontrol(obj):=tcontrol(tcontrol(obj).getit(1));');
- Add(' tcontrol(obj):=tcontrol(tcontrol(tcontrol(obj).getit).arr[2]);');
- ConvertProgram;
- CheckSource('TestClass_TypeCast',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.Next = null;',
- ' };',
- ' this.$final = function () {',
- ' this.Next = undefined;',
- ' };',
- ' this.Create = function () {',
- ' };',
- '});',
- 'rtl.createClass(this, "TControl", this.TObject, function () {',
- ' this.$init = function () {',
- ' pas.program.TObject.$init.call(this);',
- ' this.Arr = [];',
- ' };',
- ' this.$final = function () {',
- ' this.Arr = undefined;',
- ' pas.program.TObject.$final.call(this);',
- ' };',
- ' this.GetIt = function (vI) {',
- ' var Result = null;',
- ' return Result;',
- ' };',
- '});',
- 'this.Obj = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj = this.Obj.Next;',
- 'this.Obj = null;',
- 'this.Obj = this.Obj;',
- 'this.Obj = this.Obj.GetIt(0);',
- 'this.Obj = this.Obj.GetIt(0);',
- 'this.Obj = this.Obj.GetIt(1);',
- 'this.Obj = this.Obj.GetIt(0).Arr[2];',
- '']));
- end;
- procedure TTestModule.TestClass_TypeCastUntypedParam;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class end;');
- Add('procedure ProcA(var A);');
- Add('begin');
- Add(' TObject(A):=nil;');
- Add(' TObject(A):=TObject(A);');
- Add(' if TObject(A)=nil then ;');
- Add(' if nil=TObject(A) then ;');
- Add('end;');
- Add('procedure ProcB(out A);');
- Add('begin');
- Add(' TObject(A):=nil;');
- Add(' TObject(A):=TObject(A);');
- Add(' if TObject(A)=nil then ;');
- Add(' if nil=TObject(A) then ;');
- Add('end;');
- Add('procedure ProcC(const A);');
- Add('begin');
- Add(' if TObject(A)=nil then ;');
- Add(' if nil=TObject(A) then ;');
- Add('end;');
- Add('var o: TObject;');
- Add('begin');
- Add(' ProcA(o);');
- Add(' ProcB(o);');
- Add(' ProcC(o);');
- ConvertProgram;
- CheckSource('TestClass_TypeCastUntypedParam',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'this.ProcA = function (A) {',
- ' A.set(null);',
- ' A.set(A.get());',
- ' if (A.get() == null);',
- ' if (null == A.get());',
- '};',
- 'this.ProcB = function (A) {',
- ' A.set(null);',
- ' A.set(A.get());',
- ' if (A.get() == null);',
- ' if (null == A.get());',
- '};',
- 'this.ProcC = function (A) {',
- ' if (A == null);',
- ' if (null == A);',
- '};',
- 'this.o = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.ProcA({',
- ' p: this,',
- ' get: function () {',
- ' return this.p.o;',
- ' },',
- ' set: function (v) {',
- ' this.p.o = v;',
- ' }',
- '});',
- 'this.ProcB({',
- ' p: this,',
- ' get: function () {',
- ' return this.p.o;',
- ' },',
- ' set: function (v) {',
- ' this.p.o = v;',
- ' }',
- '});',
- 'this.ProcC(this.o);',
- '']));
- end;
- procedure TTestModule.TestClass_Overloads;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' procedure DoIt;');
- Add(' procedure DoIt(vI: longint);');
- Add(' end;');
- Add('procedure TObject.DoIt;');
- Add('begin');
- Add(' DoIt;');
- Add(' DoIt(1);');
- Add('end;');
- Add('procedure TObject.DoIt(vI: longint); begin end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestClass_Overloads',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.DoIt = function () {',
- ' this.DoIt();',
- ' this.DoIt$1(1);',
- ' };',
- ' this.DoIt$1 = function (vI) {',
- ' };',
- '});',
- '']),
- LinesToStr([ // this.$main
- '']));
- end;
- procedure TTestModule.TestClass_OverloadsAncestor;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' procedure DoIt(vA: longint);');
- Add(' procedure DoIt(vA, vB: longint);');
- Add(' end;');
- Add(' TCar = class');
- Add(' procedure DoIt(vA: longint);');
- Add(' procedure DoIt(vA, vB: longint);');
- Add(' end;');
- Add('procedure tobject.doit(va: longint);');
- Add('begin');
- Add(' doit(1);');
- Add(' doit(1,2);');
- Add('end;');
- Add('procedure tobject.doit(va, vb: longint); begin end;');
- Add('procedure tcar.doit(va: longint);');
- Add('begin');
- Add(' doit(1);');
- Add(' doit(1,2);');
- Add(' inherited doit(1);');
- Add(' inherited doit(1,2);');
- Add('end;');
- Add('procedure tcar.doit(va, vb: longint); begin end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestClass_OverloadsAncestor',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.DoIt = function (vA) {',
- ' this.DoIt(1);',
- ' this.DoIt$1(1,2);',
- ' };',
- ' this.DoIt$1 = function (vA, vB) {',
- ' };',
- '});',
- 'rtl.createClass(this, "TCar", this.TObject, function () {',
- ' this.DoIt$2 = function (vA) {',
- ' this.DoIt$2(1);',
- ' this.DoIt$3(1, 2);',
- ' pas.program.TObject.DoIt.call(this, 1);',
- ' pas.program.TObject.DoIt$1.call(this, 1, 2);',
- ' };',
- ' this.DoIt$3 = function (vA, vB) {',
- ' };',
- '});',
- '']),
- LinesToStr([ // this.$main
- '']));
- end;
- procedure TTestModule.TestClass_OverloadConstructor;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' constructor Create(vA: longint);');
- Add(' constructor Create(vA, vB: longint);');
- Add(' end;');
- Add(' TCar = class');
- Add(' constructor Create(vA: longint);');
- Add(' constructor Create(vA, vB: longint);');
- Add(' end;');
- Add('constructor tobject.create(va: longint);');
- Add('begin');
- Add(' create(1);');
- Add(' create(1,2);');
- Add('end;');
- Add('constructor tobject.create(va, vb: longint); begin end;');
- Add('constructor tcar.create(va: longint);');
- Add('begin');
- Add(' create(1);');
- Add(' create(1,2);');
- Add(' inherited create(1);');
- Add(' inherited create(1,2);');
- Add('end;');
- Add('constructor tcar.create(va, vb: longint); begin end;');
- Add('begin');
- Add(' tobject.create(1);');
- Add(' tobject.create(1,2);');
- Add(' tcar.create(1);');
- Add(' tcar.create(1,2);');
- ConvertProgram;
- CheckSource('TestClass_OverloadConstructor',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function (vA) {',
- ' this.Create(1);',
- ' this.Create$1(1,2);',
- ' };',
- ' this.Create$1 = function (vA, vB) {',
- ' };',
- '});',
- 'rtl.createClass(this, "TCar", this.TObject, function () {',
- ' this.Create$2 = function (vA) {',
- ' this.Create$2(1);',
- ' this.Create$3(1, 2);',
- ' pas.program.TObject.Create.call(this, 1);',
- ' pas.program.TObject.Create$1.call(this, 1, 2);',
- ' };',
- ' this.Create$3 = function (vA, vB) {',
- ' };',
- '});',
- '']),
- LinesToStr([ // this.$main
- 'this.TObject.$create("Create", [1]);',
- 'this.TObject.$create("Create$1", [1, 2]);',
- 'this.TCar.$create("Create$2", [1]);',
- 'this.TCar.$create("Create$3", [1, 2]);',
- '']));
- end;
- procedure TTestModule.TestClass_ReintroducedVar;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' strict private');
- Add(' Some: longint;');
- Add(' end;');
- Add(' TMobile = class');
- Add(' strict private');
- Add(' Some: string;');
- Add(' end;');
- Add(' TCar = class(tmobile)');
- Add(' procedure Some;');
- Add(' procedure Some(vA: longint);');
- Add(' end;');
- Add('procedure tcar.some;');
- Add('begin');
- Add(' Some;');
- Add(' Some(1);');
- Add('end;');
- Add('procedure tcar.some(va: longint); begin end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestClass_ReintroducedVar',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.Some = 0;',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'rtl.createClass(this, "TMobile", this.TObject, function () {',
- ' this.$init = function () {',
- ' pas.program.TObject.$init.call(this);',
- ' this.Some$1 = "";',
- ' };',
- '});',
- 'rtl.createClass(this, "TCar", this.TMobile, function () {',
- ' this.Some$2 = function () {',
- ' this.Some$2();',
- ' this.Some$3(1);',
- ' };',
- ' this.Some$3 = function (vA) {',
- ' };',
- '});',
- '']),
- LinesToStr([ // this.$main
- '']));
- end;
- procedure TTestModule.TestClass_RaiseDescendant;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' constructor Create(Msg: string);');
- Add(' end;');
- Add(' Exception = class');
- Add(' end;');
- Add(' EConvertError = class(Exception)');
- Add(' end;');
- Add('constructor TObject.Create(Msg: string); begin end;');
- Add('begin');
- Add(' raise Exception.Create(''Bar1'');');
- Add(' raise EConvertError.Create(''Bar2'');');
- ConvertProgram;
- CheckSource('TestClass_RaiseDescendant',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function (Msg) {',
- ' };',
- '});',
- 'rtl.createClass(this, "Exception", this.TObject, function () {',
- '});',
- 'rtl.createClass(this, "EConvertError", this.Exception, function () {',
- '});',
- '']),
- LinesToStr([ // this.$main
- 'throw this.Exception.$create("Create",["Bar1"]);',
- 'throw this.EConvertError.$create("Create",["Bar2"]);',
- '']));
- end;
- procedure TTestModule.TestClass_ExternalMethod;
- begin
- AddModuleWithIntfImplSrc('unit2.pas',
- LinesToStr([
- 'type',
- ' TObject = class',
- ' public',
- ' procedure Intern; external name ''$DoIntern'';',
- ' end;',
- '']),
- LinesToStr([
- '']));
- StartUnit(true);
- Add('interface');
- Add('uses unit2;');
- Add('type');
- Add(' TCar = class(TObject)');
- Add(' public');
- Add(' procedure Intern2; external name ''$DoIntern2'';');
- Add(' procedure DoIt;');
- Add(' end;');
- Add('implementation');
- Add('procedure tcar.doit;');
- Add('begin');
- Add(' Intern;');
- Add(' Intern();');
- Add(' Intern2;');
- Add(' Intern2();');
- Add('end;');
- Add('var Obj: TCar;');
- Add('begin');
- Add(' obj.intern;');
- Add(' obj.intern();');
- Add(' obj.intern2;');
- Add(' obj.intern2();');
- Add(' obj.doit;');
- Add(' obj.doit();');
- Add(' with obj do begin');
- Add(' Intern;');
- Add(' Intern();');
- Add(' Intern2;');
- Add(' Intern2();');
- Add(' end;');
- ConvertUnit;
- CheckSource('TestClass_ExternalMethod',
- LinesToStr([
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;',
- 'rtl.createClass(this, "TCar", pas.unit2.TObject, function () {',
- ' this.DoIt = function () {',
- ' this.$DoIntern();',
- ' this.$DoIntern();',
- ' this.$DoIntern2();',
- ' this.$DoIntern2();',
- ' };',
- ' });',
- '$impl.Obj = null;',
- '']),
- LinesToStr([
- '$impl.Obj.$DoIntern();',
- '$impl.Obj.$DoIntern();',
- '$impl.Obj.$DoIntern2();',
- '$impl.Obj.$DoIntern2();',
- '$impl.Obj.DoIt();',
- '$impl.Obj.DoIt();',
- 'var $with1 = $impl.Obj;',
- '$with1.$DoIntern();',
- '$with1.$DoIntern();',
- '$with1.$DoIntern2();',
- '$with1.$DoIntern2();',
- '']));
- end;
- procedure TTestModule.TestClass_ExternalVirtualNameMismatchFail;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' procedure DoIt; virtual; external name ''Foo'';');
- Add(' end;');
- Add('begin');
- SetExpectedPasResolverError('Virtual method name must match external',
- nVirtualMethodNameMustMatchExternal);
- ConvertProgram;
- end;
- procedure TTestModule.TestClass_ExternalOverrideFail;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' procedure DoIt; virtual; external name ''DoIt'';');
- Add(' end;');
- Add(' TCar = class');
- Add(' procedure DoIt; override; external name ''DoIt'';');
- Add(' end;');
- Add('begin');
- SetExpectedPasResolverError('Invalid procedure modifiers override,external',
- nInvalidProcModifiers);
- ConvertProgram;
- end;
- procedure TTestModule.TestClass_ExternalVar;
- begin
- AddModuleWithIntfImplSrc('unit2.pas',
- LinesToStr([
- '{$modeswitch externalclass}',
- 'type',
- ' TObject = class',
- ' public',
- ' Intern: longint external name ''$Intern'';',
- ' end;',
- '']),
- LinesToStr([
- '']));
- StartUnit(true);
- Add('interface');
- Add('uses unit2;');
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TCar = class(tobject)');
- Add(' public');
- Add(' Intern2: longint external name ''$Intern2'';');
- Add(' procedure DoIt;');
- Add(' end;');
- Add('implementation');
- Add('procedure tcar.doit;');
- Add('begin');
- Add(' Intern:=Intern+1;');
- Add(' Intern2:=Intern2+2;');
- Add('end;');
- Add('var Obj: TCar;');
- Add('begin');
- Add(' obj.intern:=obj.intern+1;');
- Add(' obj.intern2:=obj.intern2+2;');
- Add(' with obj do begin');
- Add(' intern:=intern+1;');
- Add(' intern2:=intern2+2;');
- Add(' end;');
- ConvertUnit;
- CheckSource('TestClass_ExternalVar',
- LinesToStr([
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;',
- 'rtl.createClass(this, "TCar", pas.unit2.TObject, function () {',
- ' this.DoIt = function () {',
- ' this.$Intern = this.$Intern + 1;',
- ' this.$Intern2 = this.$Intern2 + 2;',
- ' };',
- ' });',
- '$impl.Obj = null;',
- '']),
- LinesToStr([
- '$impl.Obj.$Intern = $impl.Obj.$Intern + 1;',
- '$impl.Obj.$Intern2 = $impl.Obj.$Intern2 + 2;',
- 'var $with1 = $impl.Obj;',
- '$with1.$Intern = $with1.$Intern + 1;',
- '$with1.$Intern2 = $with1.$Intern2 + 2;',
- '']));
- end;
- procedure TTestModule.TestClassOf_Create;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' constructor Create;');
- Add(' end;');
- Add(' TClass = class of TObject;');
- Add('constructor tobject.create; begin end;');
- Add('var');
- Add(' Obj: tobject;');
- Add(' C: tclass;');
- Add('begin');
- Add(' obj:=C.create;');
- Add(' with c do obj:=create;');
- ConvertProgram;
- CheckSource('TestClassOf_Create',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.Create = function () {',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.C = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj = this.C.$create("Create");',
- 'var $with1 = this.C;',
- 'this.Obj = $with1.$create("Create");',
- '']));
- end;
- procedure TTestModule.TestClassOf_Call;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' class procedure DoIt;');
- Add(' end;');
- Add(' TClass = class of TObject;');
- Add('class procedure tobject.doit; begin end;');
- Add('var');
- Add(' C: tclass;');
- Add('begin');
- Add(' c.doit;');
- Add(' with c do doit;');
- ConvertProgram;
- CheckSource('TestClassOf_Call',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.DoIt = function () {',
- ' };',
- '});',
- 'this.C = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.C.DoIt();',
- 'var $with1 = this.C;',
- '$with1.DoIt();',
- '']));
- end;
- procedure TTestModule.TestClassOf_Assign;
- begin
- StartProgram(false);
- Add('type');
- Add(' TClass = class of TObject;');
- Add(' TObject = class');
- Add(' ClassType: TClass; ');
- Add(' end;');
- Add('var');
- Add(' Obj: tobject;');
- Add(' C: tclass;');
- Add('begin');
- Add(' c:=nil;');
- Add(' c:=obj.classtype;');
- ConvertProgram;
- CheckSource('TestClassOf_Assign',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.ClassType = null;',
- ' };',
- ' this.$final = function () {',
- ' this.ClassType = undefined;',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.C = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.C = null;',
- 'this.C = this.Obj.ClassType;',
- '']));
- end;
- procedure TTestModule.TestClassOf_Is;
- begin
- StartProgram(false);
- Add('type');
- Add(' TClass = class of TObject;');
- Add(' TObject = class');
- Add(' end;');
- Add(' TCar = class');
- Add(' end;');
- Add(' TCars = class of TCar;');
- Add('var');
- Add(' Obj: tobject;');
- Add(' C: tclass;');
- Add(' Cars: tcars;');
- Add('begin');
- Add(' if c is tcar then ;');
- Add(' if c is tcars then ;');
- ConvertProgram;
- CheckSource('TestClassOf_Is',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'rtl.createClass(this, "TCar", this.TObject, function () {',
- '});',
- 'this.Obj = null;',
- 'this.C = null;',
- 'this.Cars = null;'
- ]),
- LinesToStr([ // this.$main
- 'if(rtl.is(this.C,this.TCar));',
- 'if(rtl.is(this.C,this.TCar));',
- '']));
- end;
- procedure TTestModule.TestClassOf_Compare;
- begin
- StartProgram(false);
- Add('type');
- Add(' TClass = class of TObject;');
- Add(' TObject = class');
- Add(' ClassType: TClass; ');
- Add(' end;');
- Add('var');
- Add(' b: boolean;');
- Add(' Obj: tobject;');
- Add(' C: tclass;');
- Add('begin');
- Add(' b:=c=nil;');
- Add(' b:=nil=c;');
- Add(' b:=c=obj.classtype;');
- Add(' b:=obj.classtype=c;');
- Add(' b:=c=TObject;');
- Add(' b:=TObject=c;');
- Add(' b:=c<>nil;');
- Add(' b:=nil<>c;');
- Add(' b:=c<>obj.classtype;');
- Add(' b:=obj.classtype<>c;');
- Add(' b:=c<>TObject;');
- Add(' b:=TObject<>c;');
- ConvertProgram;
- CheckSource('TestClassOf_Compare',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.ClassType = null;',
- ' };',
- ' this.$final = function () {',
- ' this.ClassType = undefined;',
- ' };',
- '});',
- 'this.b = false;',
- 'this.Obj = null;',
- 'this.C = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.b = this.C == null;',
- 'this.b = null == this.C;',
- 'this.b = this.C == this.Obj.ClassType;',
- 'this.b = this.Obj.ClassType == this.C;',
- 'this.b = this.C == this.TObject;',
- 'this.b = this.TObject == this.C;',
- 'this.b = this.C != null;',
- 'this.b = null != this.C;',
- 'this.b = this.C != this.Obj.ClassType;',
- 'this.b = this.Obj.ClassType != this.C;',
- 'this.b = this.C != this.TObject;',
- 'this.b = this.TObject != this.C;',
- '']));
- end;
- procedure TTestModule.TestClassOf_ClassVar;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' class var id: longint;');
- Add(' end;');
- Add(' TClass = class of TObject;');
- Add('var');
- Add(' C: tclass;');
- Add('begin');
- Add(' C.id:=C.id;');
- ConvertProgram;
- CheckSource('TestClassOf_ClassVar',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.id = 0;',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'this.C = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.C.id = this.C.id;',
- '']));
- end;
- procedure TTestModule.TestClassOf_ClassMethod;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' class function DoIt(i: longint = 0): longint;');
- Add(' end;');
- Add(' TClass = class of TObject;');
- Add('class function tobject.doit(i: longint = 0): longint; begin end;');
- Add('var');
- Add(' i: longint;');
- Add(' C: tclass;');
- Add('begin');
- Add(' C.DoIt;');
- Add(' C.DoIt();');
- Add(' i:=C.DoIt;');
- Add(' i:=C.DoIt();');
- ConvertProgram;
- CheckSource('TestClassOf_ClassMethod',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.DoIt = function (i) {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- '});',
- 'this.i = 0;',
- 'this.C = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.C.DoIt(0);',
- 'this.C.DoIt(0);',
- 'this.i = this.C.DoIt(0);',
- 'this.i = this.C.DoIt(0);',
- '']));
- end;
- procedure TTestModule.TestClassOf_ClassProperty;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' class var FA: longint;');
- Add(' class function GetA: longint;');
- Add(' class procedure SetA(Value: longint): longint;');
- Add(' class property pA: longint read fa write fa;');
- Add(' class property pB: longint read geta write seta;');
- Add(' end;');
- Add(' TObjectClass = class of tobject;');
- Add('class function tobject.geta: longint; begin end;');
- Add('class procedure tobject.seta(value: longint): longint; begin end;');
- Add('var');
- Add(' b: boolean;');
- Add(' Obj: tobject;');
- Add(' Cla: tobjectclass;');
- Add('begin');
- Add(' obj.pa:=obj.pa;');
- Add(' obj.pb:=obj.pb;');
- Add(' b:=obj.pa=4;');
- Add(' b:=obj.pb=obj.pb;');
- Add(' b:=5=obj.pa;');
- Add(' cla.pa:=6;');
- Add(' cla.pa:=cla.pa;');
- Add(' cla.pb:=cla.pb;');
- Add(' b:=cla.pa=7;');
- Add(' b:=cla.pb=cla.pb;');
- Add(' b:=8=cla.pa;');
- Add(' tobject.pa:=9;');
- Add(' tobject.pb:=tobject.pb;');
- Add(' b:=tobject.pa=10;');
- Add(' b:=11=tobject.pa;');
- ConvertProgram;
- CheckSource('TestClassOf_ClassProperty',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.FA = 0;',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.GetA = function () {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- ' this.SetA = function (Value) {',
- ' };',
- '});',
- 'this.b = false;',
- 'this.Obj = null;',
- 'this.Cla = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.Obj.$class.FA = this.Obj.FA;',
- 'this.Obj.$class.SetA(this.Obj.$class.GetA());',
- 'this.b = this.Obj.FA == 4;',
- 'this.b = this.Obj.$class.GetA() == this.Obj.$class.GetA();',
- 'this.b = 5 == this.Obj.FA;',
- 'this.Cla.FA = 6;',
- 'this.Cla.FA = this.Cla.FA;',
- 'this.Cla.SetA(this.Cla.GetA());',
- 'this.b = this.Cla.FA == 7;',
- 'this.b = this.Cla.GetA() == this.Cla.GetA();',
- 'this.b = 8 == this.Cla.FA;',
- 'this.TObject.FA = 9;',
- 'this.TObject.SetA(this.TObject.GetA());',
- 'this.b = this.TObject.FA == 10;',
- 'this.b = 11 == this.TObject.FA;',
- '']));
- end;
- procedure TTestModule.TestClassOf_ClassMethodSelf;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' class var GlobalId: longint;');
- Add(' class procedure ProcA;');
- Add(' end;');
- Add('class procedure tobject.proca;');
- Add('var b: boolean;');
- Add('begin');
- Add(' b:=self=nil;');
- Add(' b:=self.globalid=3;');
- Add(' b:=4=self.globalid;');
- Add(' self.globalid:=5;');
- Add(' self.proca;');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestClassOf_ClassMethodSelf',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.GlobalId = 0;',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.ProcA = function () {',
- ' var b = false;',
- ' b = this == null;',
- ' b = this.GlobalId == 3;',
- ' b = 4 == this.GlobalId;',
- ' this.GlobalId = 5;',
- ' this.ProcA();',
- ' };',
- '});'
- ]),
- LinesToStr([ // this.$main
- '']));
- end;
- procedure TTestModule.TestClassOf_TypeCast;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' class procedure {#TObject_DoIt}DoIt;');
- Add(' end;');
- Add(' TClass = class of TObject;');
- Add(' TMobile = class');
- Add(' class procedure {#TMobile_DoIt}DoIt;');
- Add(' end;');
- Add(' TMobileClass = class of TMobile;');
- Add(' TCar = class(TMobile)');
- Add(' class procedure {#TCar_DoIt}DoIt;');
- Add(' end;');
- Add(' TCarClass = class of TCar;');
- Add('class procedure TObject.DoIt;');
- Add('begin');
- Add(' TClass(Self).{@TObject_DoIt}DoIt;');
- Add(' TMobileClass(Self).{@TMobile_DoIt}DoIt;');
- Add('end;');
- Add('class procedure TMobile.DoIt;');
- Add('begin');
- Add(' TClass(Self).{@TObject_DoIt}DoIt;');
- Add(' TMobileClass(Self).{@TMobile_DoIt}DoIt;');
- Add(' TCarClass(Self).{@TCar_DoIt}DoIt;');
- Add('end;');
- Add('class procedure TCar.DoIt; begin end;');
- Add('var');
- Add(' ObjC: TClass;');
- Add(' MobileC: TMobileClass;');
- Add(' CarC: TCarClass;');
- Add('begin');
- Add(' ObjC.{@TObject_DoIt}DoIt;');
- Add(' MobileC.{@TMobile_DoIt}DoIt;');
- Add(' CarC.{@TCar_DoIt}DoIt;');
- Add(' TClass(ObjC).{@TObject_DoIt}DoIt;');
- Add(' TMobileClass(ObjC).{@TMobile_DoIt}DoIt;');
- Add(' TCarClass(ObjC).{@TCar_DoIt}DoIt;');
- Add(' TClass(MobileC).{@TObject_DoIt}DoIt;');
- Add(' TMobileClass(MobileC).{@TMobile_DoIt}DoIt;');
- Add(' TCarClass(MobileC).{@TCar_DoIt}DoIt;');
- Add(' TClass(CarC).{@TObject_DoIt}DoIt;');
- Add(' TMobileClass(CarC).{@TMobile_DoIt}DoIt;');
- Add(' TCarClass(CarC).{@TCar_DoIt}DoIt;');
- ConvertProgram;
- CheckSource('TestClassOf_TypeCast',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.DoIt = function () {',
- ' this.DoIt();',
- ' this.DoIt$1();',
- ' };',
- '});',
- 'rtl.createClass(this, "TMobile", this.TObject, function () {',
- ' this.DoIt$1 = function () {',
- ' this.DoIt();',
- ' this.DoIt$1();',
- ' this.DoIt$2();',
- ' };',
- '});',
- 'rtl.createClass(this, "TCar", this.TMobile, function () {',
- ' this.DoIt$2 = function () {',
- ' };',
- '});',
- 'this.ObjC = null;',
- 'this.MobileC = null;',
- 'this.CarC = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.ObjC.DoIt();',
- 'this.MobileC.DoIt$1();',
- 'this.CarC.DoIt$2();',
- 'this.ObjC.DoIt();',
- 'this.ObjC.DoIt$1();',
- 'this.ObjC.DoIt$2();',
- 'this.MobileC.DoIt();',
- 'this.MobileC.DoIt$1();',
- 'this.MobileC.DoIt$2();',
- 'this.CarC.DoIt();',
- 'this.CarC.DoIt$1();',
- 'this.CarC.DoIt$2();',
- '']));
- end;
- procedure TTestModule.TestClassOf_ImplicitFunctionCall;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' function CurNow: longint; ');
- Add(' class function Now: longint; ');
- Add(' end;');
- Add('function TObject.CurNow: longint; begin end;');
- Add('class function TObject.Now: longint; begin end;');
- Add('var');
- Add(' Obj: tobject;');
- Add(' vI: longint;');
- Add('begin');
- Add(' obj.curnow;');
- Add(' vi:=obj.curnow;');
- Add(' tobject.now;');
- Add(' vi:=tobject.now;');
- ConvertProgram;
- CheckSource('TestClassOf_ImplicitFunctionCall',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.CurNow = function () {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- ' this.Now = function () {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.vI = 0;',
- '']),
- LinesToStr([ // this.$main
- 'this.Obj.CurNow();',
- 'this.vI = this.Obj.CurNow();',
- 'this.TObject.Now();',
- 'this.vI = this.TObject.Now();',
- '']));
- end;
- procedure TTestModule.TestExternalClass_Var;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtObj''');
- Add(' Id: longint external name ''$Id'';');
- Add(' B: longint;');
- Add(' end;');
- Add('var Obj: TExtA;');
- Add('begin');
- Add(' obj.id:=obj.id+1;');
- Add(' obj.B:=obj.B+1;');
- ConvertProgram;
- CheckSource('TestExternalClass_Var',
- LinesToStr([ // statements
- 'this.Obj = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.Obj.$Id = this.Obj.$Id + 1;',
- 'this.Obj.B = this.Obj.B + 1;',
- '']));
- end;
- procedure TTestModule.TestExternalClass_DuplicateVarFail;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' Id: longint external name ''$Id'';');
- Add(' end;');
- Add(' TExtB = class external ''lib'' name ''ExtB''(TExtA)');
- Add(' Id: longint;');
- Add(' end;');
- Add('begin');
- SetExpectedPasResolverError('Duplicate identifier "Id" at test1.pp(6,6)',nDuplicateIdentifier);
- ConvertProgram;
- end;
- procedure TTestModule.TestExternalClass_Method;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtObj''');
- Add(' procedure DoIt(Id: longint = 1); external name ''$Execute'';');
- Add(' procedure DoSome(Id: longint = 1);');
- Add(' end;');
- Add('var Obj: texta;');
- Add('begin');
- Add(' obj.doit;');
- Add(' obj.doit();');
- Add(' obj.doit(2);');
- Add(' with obj do begin');
- Add(' doit;');
- Add(' doit();');
- Add(' doit(3);');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestExternalClass_Method',
- LinesToStr([ // statements
- 'this.Obj = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.Obj.$Execute(1);',
- 'this.Obj.$Execute(1);',
- 'this.Obj.$Execute(2);',
- 'var $with1 = this.Obj;',
- '$with1.$Execute(1);',
- '$with1.$Execute(1);',
- '$with1.$Execute(3);',
- '']));
- end;
- procedure TTestModule.TestExternalClass_NonExternalOverride;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtObjA''');
- Add(' procedure ProcA; virtual;');
- Add(' procedure ProcB; virtual;');
- Add(' end;');
- Add(' TExtB = class external name ''ExtObjB'' (TExtA)');
- Add(' end;');
- Add(' TExtC = class (TExtB)');
- Add(' procedure ProcA; override;');
- Add(' end;');
- Add('procedure TExtC.ProcA;');
- Add('begin');
- Add(' ProcA;');
- Add(' Self.ProcA;');
- Add(' ProcB;');
- Add(' Self.ProcB;');
- Add('end;');
- Add('var');
- Add(' A: texta;');
- Add(' B: textb;');
- Add(' C: textc;');
- Add('begin');
- Add(' a.proca;');
- Add(' b.proca;');
- Add(' c.proca;');
- ConvertProgram;
- CheckSource('TestExternalClass_NonExternalOverride',
- LinesToStr([ // statements
- 'rtl.createClassExt(this, "TExtC", ExtObjB, "", function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.ProcA = function () {',
- ' this.ProcA();',
- ' this.ProcA();',
- ' this.ProcB();',
- ' this.ProcB();',
- ' };',
- '});',
- 'this.A = null;',
- 'this.B = null;',
- 'this.C = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.A.ProcA();',
- 'this.B.ProcA();',
- 'this.C.ProcA();',
- '']));
- end;
- procedure TTestModule.TestExternalClass_Property;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' function getYear: longint;');
- Add(' procedure setYear(Value: longint);');
- Add(' property Year: longint read getyear write setyear;');
- Add(' end;');
- Add(' TExtB = class (TExtA)');
- Add(' procedure OtherSetYear(Value: longint);');
- Add(' property year write othersetyear;');
- Add(' end;');
- Add('procedure textb.othersetyear(value: longint);');
- Add('begin');
- Add(' setYear(Value+4);');
- Add('end;');
- Add('var');
- Add(' A: texta;');
- Add(' B: textb;');
- Add('begin');
- Add(' a.year:=a.year+1;');
- Add(' b.year:=b.year+2;');
- ConvertProgram;
- CheckSource('TestExternalClass_NonExternalOverride',
- LinesToStr([ // statements
- 'rtl.createClassExt(this, "TExtB", ExtA, "", function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.OtherSetYear = function (Value) {',
- ' this.setYear(Value+4);',
- ' };',
- '});',
- 'this.A = null;',
- 'this.B = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.A.setYear(this.A.getYear()+1);',
- 'this.B.OtherSetYear(this.B.getYear()+2);',
- '']));
- end;
- procedure TTestModule.TestExternalClass_ClassProperty;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' class function getYear: longint;');
- Add(' class procedure setYear(Value: longint);');
- Add(' class property Year: longint read getyear write setyear;');
- Add(' end;');
- Add(' TExtB = class (TExtA)');
- Add(' class function GetCentury: longint;');
- Add(' class procedure SetCentury(Value: longint);');
- Add(' class property Century: longint read getcentury write setcentury;');
- Add(' end;');
- Add('class function textb.getcentury: longint;');
- Add('begin');
- Add('end;');
- Add('class procedure textb.setcentury(value: longint);');
- Add('begin');
- Add(' setyear(value+11);');
- Add(' texta.year:=texta.year+12;');
- Add(' year:=year+13;');
- Add(' textb.century:=textb.century+14;');
- Add(' century:=century+15;');
- Add('end;');
- Add('var');
- Add(' A: texta;');
- Add(' B: textb;');
- Add('begin');
- Add(' texta.year:=texta.year+1;');
- Add(' textb.year:=textb.year+2;');
- Add(' a.year:=a.year+3;');
- Add(' b.year:=b.year+4;');
- Add(' textb.century:=textb.century+5;');
- Add(' b.century:=b.century+6;');
- ConvertProgram;
- CheckSource('TestExternalClass_ClassProperty',
- LinesToStr([ // statements
- 'rtl.createClassExt(this, "TExtB", ExtA, "", function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.GetCentury = function () {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- ' this.SetCentury = function (Value) {',
- ' this.setYear(Value + 11);',
- ' ExtA.setYear(ExtA.getYear() + 12);',
- ' this.setYear(this.getYear() + 13);',
- ' pas.program.TExtB.SetCentury(pas.program.TExtB.GetCentury() + 14);',
- ' this.SetCentury(this.GetCentury() + 15);',
- ' };',
- '});',
- 'this.A = null;',
- 'this.B = null;',
- '']),
- LinesToStr([ // this.$main
- 'ExtA.setYear(ExtA.getYear() + 1);',
- 'this.TExtB.setYear(this.TExtB.getYear() + 2);',
- 'this.A.setYear(this.A.getYear() + 3);',
- 'this.B.setYear(this.B.getYear() + 4);',
- 'this.TExtB.SetCentury(this.TExtB.GetCentury() + 5);',
- 'this.B.$class.SetCentury(this.B.$class.GetCentury() + 6);',
- '']));
- end;
- procedure TTestModule.TestExternalClass_ClassOf;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' procedure ProcA; virtual;');
- Add(' procedure ProcB; virtual;');
- Add(' end;');
- Add(' TExtAClass = class of TExtA;');
- Add(' TExtB = class external name ''ExtB'' (TExtA)');
- Add(' end;');
- Add(' TExtBClass = class of TExtB;');
- Add(' TExtC = class (TExtB)');
- Add(' procedure ProcA; override;');
- Add(' end;');
- Add(' TExtCClass = class of TExtC;');
- Add('procedure TExtC.ProcA; begin end;');
- Add('var');
- Add(' A: texta; ClA: TExtAClass;');
- Add(' B: textb; ClB: TExtBClass;');
- Add(' C: textc; ClC: TExtCClass;');
- Add('begin');
- Add(' ClA:=texta;');
- Add(' ClA:=textb;');
- Add(' ClA:=textc;');
- Add(' ClB:=textb;');
- Add(' ClB:=textc;');
- Add(' ClC:=textc;');
- ConvertProgram;
- CheckSource('TestExternalClass_ClassOf',
- LinesToStr([ // statements
- 'rtl.createClassExt(this, "TExtC", ExtB, "", function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.ProcA = function () {',
- ' };',
- '});',
- 'this.A = null;',
- 'this.ClA = null;',
- 'this.B = null;',
- 'this.ClB = null;',
- 'this.C = null;',
- 'this.ClC = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.ClA = ExtA;',
- 'this.ClA = ExtB;',
- 'this.ClA = this.TExtC;',
- 'this.ClB = ExtB;',
- 'this.ClB = this.TExtC;',
- 'this.ClC = this.TExtC;',
- '']));
- end;
- procedure TTestModule.TestExternalClass_ClassOtherUnit;
- begin
- AddModuleWithIntfImplSrc('unit2.pas',
- LinesToStr([
- '{$modeswitch externalclass}',
- 'type',
- ' TExtA = class external name ''ExtA''',
- ' class var Id: longint;',
- ' end;',
- '']),
- '');
- StartUnit(true);
- Add('interface');
- Add('uses unit2;');
- Add('implementation');
- Add('begin');
- Add(' unit2.texta.id:=unit2.texta.id+1;');
- ConvertUnit;
- CheckSource('TestExternalClass_ClassOtherUnit',
- LinesToStr([
- 'var $impl = {',
- '};',
- 'this.$impl = $impl;',
- '']),
- LinesToStr([
- 'ExtA.Id = ExtA.Id + 1;',
- '']));
- end;
- procedure TTestModule.TestExternalClass_Is;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' end;');
- Add(' TExtAClass = class of TExtA;');
- Add(' TExtB = class external name ''ExtB'' (TExtA)');
- Add(' end;');
- Add(' TExtBClass = class of TExtB;');
- Add(' TExtC = class (TExtB)');
- Add(' end;');
- Add(' TExtCClass = class of TExtC;');
- Add('var');
- Add(' A: texta; ClA: TExtAClass;');
- Add(' B: textb; ClB: TExtBClass;');
- Add(' C: textc; ClC: TExtCClass;');
- Add('begin');
- Add(' if a is textb then ;');
- Add(' if a is textc then ;');
- Add(' if b is textc then ;');
- Add(' if cla is textb then ;');
- Add(' if cla is textc then ;');
- Add(' if clb is textc then ;');
- ConvertProgram;
- CheckSource('TestExternalClass_Is',
- LinesToStr([ // statements
- 'rtl.createClassExt(this, "TExtC", ExtB, "", function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'this.A = null;',
- 'this.ClA = null;',
- 'this.B = null;',
- 'this.ClB = null;',
- 'this.C = null;',
- 'this.ClC = null;',
- '']),
- LinesToStr([ // this.$main
- 'if (rtl.isExt(this.A, ExtB)) ;',
- 'if (this.TExtC.isPrototypeOf(this.A)) ;',
- 'if (this.TExtC.isPrototypeOf(this.B)) ;',
- 'if (rtl.isExt(this.ClA, ExtB)) ;',
- 'if (rtl.is(this.ClA, this.TExtC)) ;',
- 'if (rtl.is(this.ClB, this.TExtC)) ;',
- '']));
- end;
- procedure TTestModule.TestExternalClass_As;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' end;');
- Add(' TExtB = class external name ''ExtB'' (TExtA)');
- Add(' end;');
- Add(' TExtC = class (TExtB)');
- Add(' end;');
- Add('var');
- Add(' A: texta;');
- Add(' B: textb;');
- Add(' C: textc;');
- Add('begin');
- Add(' b:=a as textb;');
- Add(' c:=a as textc;');
- Add(' c:=b as textc;');
- ConvertProgram;
- CheckSource('TestExternalClass_Is',
- LinesToStr([ // statements
- 'rtl.createClassExt(this, "TExtC", ExtB, "", function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'this.A = null;',
- 'this.B = null;',
- 'this.C = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.B = rtl.asExt(this.A, ExtB);',
- 'this.C = rtl.as(this.A, this.TExtC);',
- 'this.C = rtl.as(this.B, this.TExtC);',
- '']));
- end;
- procedure TTestModule.TestExternalClass_DestructorFail;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' destructor Free;');
- Add(' end;');
- SetExpectedPasResolverError('Pascal element not supported: destructor',
- nPasElementNotSupported);
- ConvertProgram;
- end;
- procedure TTestModule.TestExternalClass_New;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' constructor New;');
- Add(' constructor New(i: longint; j: longint = 2);');
- Add(' end;');
- Add('var');
- Add(' A: texta;');
- Add('begin');
- Add(' a:=texta.new;');
- Add(' a:=texta.new();');
- Add(' a:=texta.new(1);');
- Add(' with texta do begin');
- Add(' a:=new;');
- Add(' a:=new();');
- Add(' a:=new(2);');
- Add(' end;');
- Add(' a:=test1.texta.new;');
- Add(' a:=test1.texta.new();');
- Add(' a:=test1.texta.new(3);');
- ConvertProgram;
- CheckSource('TestExternalClass_ObjectCreate',
- LinesToStr([ // statements
- 'this.A = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.A = new ExtA();',
- 'this.A = new ExtA();',
- 'this.A = new ExtA(1,2);',
- 'var $with1 = ExtA;',
- 'this.A = new $with1();',
- 'this.A = new $with1();',
- 'this.A = new $with1(2,2);',
- 'this.A = new ExtA();',
- 'this.A = new ExtA();',
- 'this.A = new ExtA(3,2);',
- '']));
- end;
- procedure TTestModule.TestExternalClass_ClassOf_New;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtAClass = class of TExtA;');
- Add(' TExtA = class external name ''ExtA''');
- Add(' constructor New;');
- Add(' end;');
- Add('var');
- Add(' A: texta;');
- Add(' C: textaclass;');
- Add('begin');
- Add(' a:=c.new;');
- Add(' a:=c.new();');
- Add(' with C do begin');
- Add(' a:=new;');
- Add(' a:=new();');
- Add(' end;');
- Add(' a:=test1.c.new;');
- Add(' a:=test1.c.new();');
- ConvertProgram;
- CheckSource('TestExternalClass_ClassOf_New',
- LinesToStr([ // statements
- 'this.A = null;',
- 'this.C = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.A = new this.C();',
- 'this.A = new this.C();',
- 'var $with1 = this.C;',
- 'this.A = new $with1();',
- 'this.A = new $with1();',
- 'this.A = new this.C();',
- 'this.A = new this.C();',
- '']));
- end;
- procedure TTestModule.TestExternalClass_FuncClassOf_New;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtAClass = class of TExtA;');
- Add(' TExtA = class external name ''ExtA''');
- Add(' constructor New;');
- Add(' end;');
- Add('function GetCreator: TExtAClass;');
- Add('begin');
- Add(' Result:=TExtA;');
- Add('end;');
- Add('var');
- Add(' A: texta;');
- Add('begin');
- Add(' a:=getcreator.new;');
- Add(' a:=getcreator().new;');
- Add(' a:=getcreator().new();');
- Add(' a:=getcreator.new();');
- Add(' with getcreator do begin');
- Add(' a:=new;');
- Add(' a:=new();');
- Add(' end;');
- ConvertProgram;
- CheckSource('TestExternalClass_FuncClassOf_New',
- LinesToStr([ // statements
- 'this.GetCreator = function () {',
- ' var Result = null;',
- ' Result = ExtA;',
- ' return Result;',
- '};',
- 'this.A = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.A = new (this.GetCreator())();',
- 'this.A = new (this.GetCreator())();',
- 'this.A = new (this.GetCreator())();',
- 'this.A = new (this.GetCreator())();',
- 'var $with1 = this.GetCreator();',
- 'this.A = new $with1();',
- 'this.A = new $with1();',
- '']));
- end;
- procedure TTestModule.TestExternalClass_LocalConstSameName;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' constructor New;');
- Add(' end;');
- Add('function DoIt: longint;');
- Add('const ExtA = 3;');
- Add('begin');
- Add(' Result:=ExtA;');
- Add('end;');
- Add('var');
- Add(' A: texta;');
- Add('begin');
- Add(' a:=texta.new;');
- ConvertProgram;
- CheckSource('TestExternalClass_LocalConstSameName',
- LinesToStr([ // statements
- 'var ExtA$1 = 3;',
- 'this.DoIt = function () {',
- ' var Result = 0;',
- ' Result = ExtA$1;',
- ' return Result;',
- '};',
- 'this.A = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.A = new ExtA();',
- '']));
- end;
- procedure TTestModule.TestExternalClass_ReintroduceOverload;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' procedure DoIt;');
- Add(' end;');
- Add(' TMyA = class(TExtA)');
- Add(' procedure DoIt;');
- Add(' end;');
- Add('procedure TMyA.DoIt; begin end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestExternalClass_ReintroduceOverload',
- LinesToStr([ // statements
- 'rtl.createClassExt(this, "TMyA", ExtA, "", function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.DoIt$1 = function () {',
- ' };',
- '});',
- '']),
- LinesToStr([ // this.$main
- '']));
- end;
- procedure TTestModule.TestExternalClass_Inherited;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' procedure DoIt(i: longint = 1); virtual;');
- Add(' procedure DoSome(j: longint = 2);');
- Add(' end;');
- Add(' TExtB = class external name ''ExtB''(TExtA)');
- Add(' end;');
- Add(' TMyC = class(TExtB)');
- Add(' procedure DoIt(i: longint = 1); override;');
- Add(' procedure DoSome(j: longint = 2); reintroduce;');
- Add(' end;');
- Add('procedure TMyC.DoIt(i: longint);');
- Add('begin');
- Add(' inherited;');
- Add(' inherited DoIt;');
- Add(' inherited DoIt();');
- Add(' inherited DoIt(3);');
- Add(' inherited DoSome;');
- Add(' inherited DoSome();');
- Add(' inherited DoSome(4);');
- Add('end;');
- Add('procedure TMyC.DoSome(j: longint);');
- Add('begin');
- Add(' inherited;');
- Add('end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestExternalClass_ReintroduceOverload',
- LinesToStr([ // statements
- 'rtl.createClassExt(this, "TMyC", ExtB, "", function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.DoIt = function (i) {',
- ' ExtB.DoIt.apply(this, arguments);',
- ' ExtB.DoIt.call(this, 1);',
- ' ExtB.DoIt.call(this, 1);',
- ' ExtB.DoIt.call(this, 3);',
- ' ExtB.DoSome.call(this, 2);',
- ' ExtB.DoSome.call(this, 2);',
- ' ExtB.DoSome.call(this, 4);',
- ' };',
- ' this.DoSome$1 = function (j) {',
- ' ExtB.DoSome.apply(this, arguments);',
- ' };',
- '});',
- '']),
- LinesToStr([ // this.$main
- '']));
- end;
- procedure TTestModule.TestExternalClass_NewInstance;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' end;');
- Add(' TMyB = class(TExtA)');
- Add(' protected');
- Add(' class function NewInstance(fnname: string; const paramarray): TMyB; virtual;');
- Add(' end;');
- Add('class function TMyB.NewInstance(fnname: string; const paramarray): TMyB;');
- Add('begin end;');
- Add('begin');
- ConvertProgram;
- CheckSource('TestExternalClass_NewInstance',
- LinesToStr([ // statements
- 'rtl.createClassExt(this, "TMyB", ExtA, "NewInstance", function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.NewInstance = function (fnname, paramarray) {',
- ' var Result = null;',
- ' return Result;',
- ' };',
- '});',
- '']),
- LinesToStr([ // this.$main
- '']));
- end;
- procedure TTestModule.TestExternalClass_NewInstance_NonVirtualFail;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' end;');
- Add(' TMyB = class(TExtA)');
- Add(' protected');
- Add(' class function NewInstance(fnname: string; const paramarray): TMyB;');
- Add(' end;');
- Add('class function TMyB.NewInstance(fnname: string; const paramarray): TMyB;');
- Add('begin end;');
- Add('begin');
- SetExpectedPasResolverError(sNewInstanceFunctionMustBeVirtual,nNewInstanceFunctionMustBeVirtual);
- ConvertProgram;
- end;
- procedure TTestModule.TestExternalClass_NewInstance_FirstParamNotString_Fail;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' end;');
- Add(' TMyB = class(TExtA)');
- Add(' protected');
- Add(' class function NewInstance(fnname: longint; const paramarray): TMyB; virtual;');
- Add(' end;');
- Add('class function TMyB.NewInstance(fnname: longint; const paramarray): TMyB;');
- Add('begin end;');
- Add('begin');
- SetExpectedPasResolverError('Incompatible type arg no. 1: Got "Longint", expected "String"',
- nIncompatibleTypeArgNo);
- ConvertProgram;
- end;
- procedure TTestModule.TestExternalClass_NewInstance_SecondParamTyped_Fail;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TExtA = class external name ''ExtA''');
- Add(' end;');
- Add(' TMyB = class(TExtA)');
- Add(' protected');
- Add(' class function NewInstance(fnname: string; const paramarray: string): TMyB; virtual;');
- Add(' end;');
- Add('class function TMyB.NewInstance(fnname: string; const paramarray: string): TMyB;');
- Add('begin end;');
- Add('begin');
- SetExpectedPasResolverError('Incompatible type arg no. 2: Got "type", expected "untyped"',
- nIncompatibleTypeArgNo);
- ConvertProgram;
- end;
- procedure TTestModule.TestExternalClass_TypeCastToRootClass;
- begin
- StartProgram(false);
- Add('{$modeswitch externalclass}');
- Add('type');
- Add(' TObject = class');
- Add(' end;');
- Add(' TChild = class');
- Add(' end;');
- Add(' TExtRootA = class external name ''ExtRootA''');
- Add(' end;');
- Add(' TExtChildA = class external name ''ExtChildA''(TExtRootA)');
- Add(' end;');
- Add(' TExtRootB = class external name ''ExtRootB''');
- Add(' end;');
- Add(' TExtChildB = class external name ''ExtChildB''(TExtRootB)');
- Add(' end;');
- Add('var');
- Add(' Obj: TObject;');
- Add(' Child: TChild;');
- Add(' RootA: TExtRootA;');
- Add(' ChildA: TExtChildA;');
- Add(' RootB: TExtRootB;');
- Add(' ChildB: TExtChildB;');
- Add('begin');
- Add(' obj:=tobject(roota);');
- Add(' obj:=tobject(childa);');
- Add(' child:=tchild(tobject(roota));');
- Add(' roota:=textroota(obj);');
- Add(' roota:=textroota(child);');
- Add(' roota:=textroota(rootb);');
- Add(' roota:=textroota(childb);');
- Add(' childa:=textchilda(textroota(obj));');
- ConvertProgram;
- CheckSource('TestExternalClass_TypeCastToRootClass',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'rtl.createClass(this, "TChild", this.TObject, function () {',
- '});',
- 'this.Obj = null;',
- 'this.Child = null;',
- 'this.RootA = null;',
- 'this.ChildA = null;',
- 'this.RootB = null;',
- 'this.ChildB = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.Obj = this.RootA;',
- 'this.Obj = this.ChildA;',
- 'this.Child = this.RootA;',
- 'this.RootA = this.Obj;',
- 'this.RootA = this.Child;',
- 'this.RootA = this.RootB;',
- 'this.RootA = this.ChildB;',
- 'this.ChildA = this.Obj;',
- '']));
- end;
- procedure TTestModule.TestProcType;
- begin
- StartProgram(false);
- Add('type');
- Add(' TProcInt = procedure(vI: longint = 1);');
- Add('procedure DoIt(vJ: longint);');
- Add('begin end;');
- Add('var');
- Add(' b: boolean;');
- Add(' vP, vQ: tprocint;');
- Add('begin');
- Add(' vp:=nil;');
- Add(' vp:=vp;');
- Add(' vp:=@doit;');
- Add(' vp;');
- Add(' vp();');
- Add(' vp(2);');
- Add(' b:=vp=nil;');
- Add(' b:=nil=vp;');
- Add(' b:=vp=vq;');
- Add(' b:=vp=@doit;');
- Add(' b:=@doit=vp;');
- Add(' b:=vp<>nil;');
- Add(' b:=nil<>vp;');
- Add(' b:=vp<>vq;');
- Add(' b:=vp<>@doit;');
- Add(' b:=@doit<>vp;');
- Add(' b:=Assigned(vp);');
- ConvertProgram;
- CheckSource('TestProcType',
- LinesToStr([ // statements
- 'this.DoIt = function(vJ) {',
- '};',
- 'this.b = false;',
- 'this.vP = null;',
- 'this.vQ = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.vP = null;',
- 'this.vP = this.vP;',
- 'this.vP = rtl.createCallback(this,"DoIt");',
- 'this.vP(1);',
- 'this.vP(1);',
- 'this.vP(2);',
- 'this.b = this.vP == null;',
- 'this.b = null == this.vP;',
- 'this.b = rtl.eqCallback(this.vP,this.vQ);',
- 'this.b = rtl.eqCallback(this.vP, rtl.createCallback(this, "DoIt"));',
- 'this.b = rtl.eqCallback(rtl.createCallback(this, "DoIt"), this.vP);',
- 'this.b = this.vP != null;',
- 'this.b = null != this.vP;',
- 'this.b = !rtl.eqCallback(this.vP,this.vQ);',
- 'this.b = !rtl.eqCallback(this.vP, rtl.createCallback(this, "DoIt"));',
- 'this.b = !rtl.eqCallback(rtl.createCallback(this, "DoIt"), this.vP);',
- 'this.b = this.vP != null;',
- '']));
- end;
- procedure TTestModule.TestProcType_FunctionFPC;
- begin
- StartProgram(false);
- Add('type');
- Add(' TFuncInt = function(vA: longint = 1): longint;');
- Add('function DoIt(vI: longint): longint;');
- Add('begin end;');
- Add('var');
- Add(' b: boolean;');
- Add(' vP, vQ: tfuncint;');
- Add('begin');
- Add(' vp:=nil;');
- Add(' vp:=vp;');
- Add(' vp:=@doit;'); // ok in fpc and delphi
- //Add(' vp:=doit;'); // illegal in fpc, ok in delphi
- Add(' vp;'); // ok in fpc and delphi
- Add(' vp();');
- Add(' vp(2);');
- Add(' b:=vp=nil;'); // ok in fpc, illegal in delphi
- Add(' b:=nil=vp;'); // ok in fpc, illegal in delphi
- Add(' b:=vp=vq;'); // in fpc compare proctypes, in delphi compare results
- Add(' b:=vp=@doit;'); // ok in fpc, illegal in delphi
- Add(' b:=@doit=vp;'); // ok in fpc, illegal in delphi
- //Add(' b:=vp=3;'); // illegal in fpc, ok in delphi
- Add(' b:=4=vp;'); // illegal in fpc, ok in delphi
- Add(' b:=vp<>nil;'); // ok in fpc, illegal in delphi
- Add(' b:=nil<>vp;'); // ok in fpc, illegal in delphi
- Add(' b:=vp<>vq;'); // in fpc compare proctypes, in delphi compare results
- Add(' b:=vp<>@doit;'); // ok in fpc, illegal in delphi
- Add(' b:=@doit<>vp;'); // ok in fpc, illegal in delphi
- //Add(' b:=vp<>5;'); // illegal in fpc, ok in delphi
- Add(' b:=6<>vp;'); // illegal in fpc, ok in delphi
- Add(' b:=Assigned(vp);');
- //Add(' doit(vp);'); // illegal in fpc, ok in delphi
- Add(' doit(vp());'); // ok in fpc and delphi
- Add(' doit(vp(2));'); // ok in fpc and delphi
- ConvertProgram;
- CheckSource('TestProcType_FunctionFPC',
- LinesToStr([ // statements
- 'this.DoIt = function(vI) {',
- ' var Result = 0;',
- ' return Result;',
- '};',
- 'this.b = false;',
- 'this.vP = null;',
- 'this.vQ = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.vP = null;',
- 'this.vP = this.vP;',
- 'this.vP = rtl.createCallback(this,"DoIt");',
- 'this.vP(1);',
- 'this.vP(1);',
- 'this.vP(2);',
- 'this.b = this.vP == null;',
- 'this.b = null == this.vP;',
- 'this.b = rtl.eqCallback(this.vP,this.vQ);',
- 'this.b = rtl.eqCallback(this.vP, rtl.createCallback(this, "DoIt"));',
- 'this.b = rtl.eqCallback(rtl.createCallback(this, "DoIt"), this.vP);',
- 'this.b = 4 == this.vP(1);',
- 'this.b = this.vP != null;',
- 'this.b = null != this.vP;',
- 'this.b = !rtl.eqCallback(this.vP,this.vQ);',
- 'this.b = !rtl.eqCallback(this.vP, rtl.createCallback(this, "DoIt"));',
- 'this.b = !rtl.eqCallback(rtl.createCallback(this, "DoIt"), this.vP);',
- 'this.b = 6 != this.vP(1);',
- 'this.b = this.vP != null;',
- 'this.DoIt(this.vP(1));',
- 'this.DoIt(this.vP(2));',
- '']));
- end;
- procedure TTestModule.TestProcType_FunctionDelphi;
- begin
- StartProgram(false);
- Add('{$mode Delphi}');
- Add('type');
- Add(' TFuncInt = function(vA: longint = 1): longint;');
- Add('function DoIt(vI: longint): longint;');
- Add('begin end;');
- Add('var');
- Add(' b: boolean;');
- Add(' vP, vQ: tfuncint;');
- Add('begin');
- Add(' vp:=nil;');
- Add(' vp:=vp;');
- Add(' vp:=@doit;'); // ok in fpc and delphi
- Add(' vp:=doit;'); // illegal in fpc, ok in delphi
- Add(' vp;'); // ok in fpc and delphi
- Add(' vp();');
- Add(' vp(2);');
- //Add(' b:=vp=nil;'); // ok in fpc, illegal in delphi
- //Add(' b:=nil=vp;'); // ok in fpc, illegal in delphi
- Add(' b:=vp=vq;'); // in fpc compare proctypes, in delphi compare results
- //Add(' b:=vp=@doit;'); // ok in fpc, illegal in delphi
- //Add(' b:=@doit=vp;'); // ok in fpc, illegal in delphi
- Add(' b:=vp=3;'); // illegal in fpc, ok in delphi
- Add(' b:=4=vp;'); // illegal in fpc, ok in delphi
- //Add(' b:=vp<>nil;'); // ok in fpc, illegal in delphi
- //Add(' b:=nil<>vp;'); // ok in fpc, illegal in delphi
- Add(' b:=vp<>vq;'); // in fpc compare proctypes, in delphi compare results
- //Add(' b:=vp<>@doit;'); // ok in fpc, illegal in delphi
- //Add(' b:=@doit<>vp;'); // ok in fpc, illegal in delphi
- Add(' b:=vp<>5;'); // illegal in fpc, ok in delphi
- Add(' b:=6<>vp;'); // illegal in fpc, ok in delphi
- Add(' b:=Assigned(vp);');
- Add(' doit(vp);'); // illegal in fpc, ok in delphi
- Add(' doit(vp());'); // ok in fpc and delphi
- Add(' doit(vp(2));'); // ok in fpc and delphi *)
- ConvertProgram;
- CheckSource('TestProcType_FunctionDelphi',
- LinesToStr([ // statements
- 'this.DoIt = function(vI) {',
- ' var Result = 0;',
- ' return Result;',
- '};',
- 'this.b = false;',
- 'this.vP = null;',
- 'this.vQ = null;'
- ]),
- LinesToStr([ // this.$main
- 'this.vP = null;',
- 'this.vP = this.vP;',
- 'this.vP = rtl.createCallback(this,"DoIt");',
- 'this.vP = rtl.createCallback(this,"DoIt");',
- 'this.vP(1);',
- 'this.vP(1);',
- 'this.vP(2);',
- 'this.b = this.vP(1) == this.vQ(1);',
- 'this.b = this.vP(1) == 3;',
- 'this.b = 4 == this.vP(1);',
- 'this.b = this.vP(1) != this.vQ(1);',
- 'this.b = this.vP(1) != 5;',
- 'this.b = 6 != this.vP(1);',
- 'this.b = this.vP != null;',
- 'this.DoIt(this.vP(1));',
- 'this.DoIt(this.vP(1));',
- 'this.DoIt(this.vP(2));',
- '']));
- end;
- procedure TTestModule.TestProcType_AsParam;
- begin
- StartProgram(false);
- Add('type');
- Add(' TFuncInt = function(vA: longint = 1): longint;');
- Add('procedure DoIt(vG: tfuncint; const vH: tfuncint; var vI: tfuncint);');
- Add('var vJ: tfuncint;');
- Add('begin');
- Add(' vg:=vg;');
- Add(' vj:=vh;');
- Add(' vi:=vi;');
- Add(' doit(vg,vg,vg);');
- Add(' doit(vh,vh,vj);');
- Add(' doit(vi,vi,vi);');
- Add(' doit(vj,vj,vj);');
- Add('end;');
- Add('var i: tfuncint;');
- Add('begin');
- Add(' doit(i,i,i);');
- ConvertProgram;
- CheckSource('TestProcType_AsParam',
- LinesToStr([ // statements
- 'this.DoIt = function (vG,vH,vI) {',
- ' var vJ = null;',
- ' vG = vG;',
- ' vJ = vH;',
- ' vI.set(vI.get());',
- ' this.DoIt(vG, vG, {',
- ' get: function () {',
- ' return vG;',
- ' },',
- ' set: function (v) {',
- ' vG = v;',
- ' }',
- ' });',
- ' this.DoIt(vH, vH, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- ' this.DoIt(vI.get(), vI.get(), vI);',
- ' this.DoIt(vJ, vJ, {',
- ' get: function () {',
- ' return vJ;',
- ' },',
- ' set: function (v) {',
- ' vJ = v;',
- ' }',
- ' });',
- '};',
- 'this.i = null;'
- ]),
- LinesToStr([
- 'this.DoIt(this.i,this.i,{',
- ' p: this,',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});'
- ]));
- end;
- procedure TTestModule.TestProcType_MethodFPC;
- begin
- StartProgram(false);
- Add('type');
- Add(' TFuncInt = function(vA: longint = 1): longint of object;');
- Add(' TObject = class');
- Add(' function DoIt(vA: longint = 1): longint;');
- Add(' end;');
- Add('function TObject.DoIt(vA: longint = 1): longint;');
- Add('begin');
- Add('end;');
- Add('var');
- Add(' Obj: TObject;');
- Add(' vP: tfuncint;');
- Add(' b: boolean;');
- Add('begin');
- Add(' vp:[email protected];'); // ok in fpc and delphi
- //Add(' vp:=obj.doit;'); // illegal in fpc, ok in delphi
- Add(' vp;'); // ok in fpc and delphi
- Add(' vp();');
- Add(' vp(2);');
- Add(' b:[email protected];'); // ok in fpc, illegal in delphi
- Add(' b:[email protected]=vp;'); // ok in fpc, illegal in delphi
- Add(' b:=vp<>@obj.doit;'); // ok in fpc, illegal in delphi
- Add(' b:[email protected]<>vp;'); // ok in fpc, illegal in delphi
- ConvertProgram;
- CheckSource('TestProcType_MethodFPC',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.DoIt = function (vA) {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.vP = null;',
- 'this.b = false;'
- ]),
- LinesToStr([
- 'this.vP = rtl.createCallback(this.Obj, "DoIt");',
- 'this.vP(1);',
- 'this.vP(1);',
- 'this.vP(2);',
- 'this.b = rtl.eqCallback(this.vP, rtl.createCallback(this.Obj, "DoIt"));',
- 'this.b = rtl.eqCallback(rtl.createCallback(this.Obj, "DoIt"), this.vP);',
- 'this.b = !rtl.eqCallback(this.vP, rtl.createCallback(this.Obj, "DoIt"));',
- 'this.b = !rtl.eqCallback(rtl.createCallback(this.Obj, "DoIt"), this.vP);',
- '']));
- end;
- procedure TTestModule.TestProcType_MethodDelphi;
- begin
- StartProgram(false);
- Add('{$mode delphi}');
- Add('type');
- Add(' TFuncInt = function(vA: longint = 1): longint of object;');
- Add(' TObject = class');
- Add(' function DoIt(vA: longint = 1): longint;');
- Add(' end;');
- Add('function TObject.DoIt(vA: longint = 1): longint;');
- Add('begin');
- Add('end;');
- Add('var');
- Add(' Obj: TObject;');
- Add(' vP: tfuncint;');
- Add(' b: boolean;');
- Add('begin');
- Add(' vp:[email protected];'); // ok in fpc and delphi
- Add(' vp:=obj.doit;'); // illegal in fpc, ok in delphi
- Add(' vp;'); // ok in fpc and delphi
- Add(' vp();');
- Add(' vp(2);');
- //Add(' b:[email protected];'); // ok in fpc, illegal in delphi
- //Add(' b:[email protected]=vp;'); // ok in fpc, illegal in delphi
- //Add(' b:=vp<>@obj.doit;'); // ok in fpc, illegal in delphi
- //Add(' b:[email protected]<>vp;'); // ok in fpc, illegal in delphi
- ConvertProgram;
- CheckSource('TestProcType_MethodDelphi',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- ' this.DoIt = function (vA) {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.vP = null;',
- 'this.b = false;'
- ]),
- LinesToStr([
- 'this.vP = rtl.createCallback(this.Obj, "DoIt");',
- 'this.vP = rtl.createCallback(this.Obj, "DoIt");',
- 'this.vP(1);',
- 'this.vP(1);',
- 'this.vP(2);',
- '']));
- end;
- procedure TTestModule.TestProcType_PropertyFPC;
- begin
- StartProgram(false);
- Add('type');
- Add(' TFuncInt = function(vA: longint = 1): longint of object;');
- Add(' TObject = class');
- Add(' FOnFoo: TFuncInt;');
- Add(' function DoIt(vA: longint = 1): longint;');
- Add(' function GetFoo: TFuncInt;');
- Add(' procedure SetFoo(const Value: TFuncInt);');
- Add(' function GetEvents(Index: longint): TFuncInt;');
- Add(' procedure SetEvents(Index: longint; const Value: TFuncInt);');
- Add(' property OnFoo: TFuncInt read FOnFoo write FOnFoo;');
- Add(' property OnBar: TFuncInt read GetFoo write SetFoo;');
- Add(' property Events[Index: longint]: TFuncInt read GetEvents write SetEvents; default;');
- Add(' end;');
- Add('function tobject.doit(va: longint = 1): longint; begin end;');
- Add('function tobject.getfoo: tfuncint; begin end;');
- Add('procedure tobject.setfoo(const value: tfuncint); begin end;');
- Add('function tobject.getevents(index: longint): tfuncint; begin end;');
- Add('procedure tobject.setevents(index: longint; const value: tfuncint); begin end;');
- Add('var');
- Add(' Obj: TObject;');
- Add(' vP: tfuncint;');
- Add(' b: boolean;');
- Add('begin');
- Add(' obj.onfoo:=nil;');
- Add(' obj.onbar:=nil;');
- Add(' obj.events[1]:=nil;');
- Add(' obj.onfoo:=obj.onfoo;');
- Add(' obj.onbar:=obj.onbar;');
- Add(' obj.events[2]:=obj.events[3];');
- Add(' obj.onfoo:[email protected];');
- Add(' obj.onbar:[email protected];');
- Add(' obj.events[4]:[email protected];');
- //Add(' obj.onfoo:=obj.doit;'); // delphi
- //Add(' obj.onbar:=obj.doit;'); // delphi
- //Add(' obj.events[4]:=obj.doit;'); // delphi
- Add(' obj.onfoo;');
- Add(' obj.onbar;');
- //Add(' obj.events[5];'); ToDo in pasresolver
- Add(' obj.onfoo();');
- Add(' obj.onbar();');
- Add(' obj.events[6]();');
- Add(' b:=obj.onfoo=nil;');
- Add(' b:=obj.onbar=nil;');
- Add(' b:=obj.events[7]=nil;');
- Add(' b:=obj.onfoo<>nil;');
- Add(' b:=obj.onbar<>nil;');
- Add(' b:=obj.events[8]<>nil;');
- Add(' b:=obj.onfoo=vp;');
- Add(' b:=obj.onbar=vp;');
- Add(' b:=obj.events[9]=vp;');
- Add(' b:=obj.onfoo=obj.onfoo;');
- Add(' b:=obj.onbar=obj.onfoo;');
- Add(' b:=obj.events[10]=obj.onfoo;');
- Add(' b:=obj.onfoo<>obj.onfoo;');
- Add(' b:=obj.onbar<>obj.onfoo;');
- Add(' b:=obj.events[11]<>obj.onfoo;');
- Add(' b:[email protected];');
- Add(' b:[email protected];');
- Add(' b:=obj.events[12][email protected];');
- Add(' b:=obj.onfoo<>@obj.doit;');
- Add(' b:=obj.onbar<>@obj.doit;');
- Add(' b:=obj.events[12]<>@obj.doit;');
- Add(' b:=Assigned(obj.onfoo);');
- Add(' b:=Assigned(obj.onbar);');
- Add(' b:=Assigned(obj.events[13]);');
- ConvertProgram;
- CheckSource('TestProcType_PropertyFPC',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.FOnFoo = null;',
- ' };',
- ' this.$final = function () {',
- ' this.FOnFoo = undefined;',
- ' };',
- ' this.DoIt = function (vA) {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- 'this.GetFoo = function () {',
- ' var Result = null;',
- ' return Result;',
- '};',
- 'this.SetFoo = function (Value) {',
- '};',
- 'this.GetEvents = function (Index) {',
- ' var Result = null;',
- ' return Result;',
- '};',
- 'this.SetEvents = function (Index, Value) {',
- '};',
- '});',
- 'this.Obj = null;',
- 'this.vP = null;',
- 'this.b = false;'
- ]),
- LinesToStr([
- 'this.Obj.FOnFoo = null;',
- 'this.Obj.SetFoo(null);',
- 'this.Obj.SetEvents(1, null);',
- 'this.Obj.FOnFoo = this.Obj.FOnFoo;',
- 'this.Obj.SetFoo(this.Obj.GetFoo());',
- 'this.Obj.SetEvents(2, this.Obj.GetEvents(3));',
- 'this.Obj.FOnFoo = rtl.createCallback(this.Obj, "DoIt");',
- 'this.Obj.SetFoo(rtl.createCallback(this.Obj, "DoIt"));',
- 'this.Obj.SetEvents(4, rtl.createCallback(this.Obj, "DoIt"));',
- 'this.Obj.FOnFoo(1);',
- 'this.Obj.GetFoo();',
- 'this.Obj.FOnFoo(1);',
- 'this.Obj.GetFoo()(1);',
- 'this.Obj.GetEvents(6)(1);',
- 'this.b = this.Obj.FOnFoo == null;',
- 'this.b = this.Obj.GetFoo() == null;',
- 'this.b = this.Obj.GetEvents(7) == null;',
- 'this.b = this.Obj.FOnFoo != null;',
- 'this.b = this.Obj.GetFoo() != null;',
- 'this.b = this.Obj.GetEvents(8) != null;',
- 'this.b = rtl.eqCallback(this.Obj.FOnFoo, this.vP);',
- 'this.b = rtl.eqCallback(this.Obj.GetFoo(), this.vP);',
- 'this.b = rtl.eqCallback(this.Obj.GetEvents(9), this.vP);',
- 'this.b = rtl.eqCallback(this.Obj.FOnFoo, this.Obj.FOnFoo);',
- 'this.b = rtl.eqCallback(this.Obj.GetFoo(), this.Obj.FOnFoo);',
- 'this.b = rtl.eqCallback(this.Obj.GetEvents(10), this.Obj.FOnFoo);',
- 'this.b = !rtl.eqCallback(this.Obj.FOnFoo, this.Obj.FOnFoo);',
- 'this.b = !rtl.eqCallback(this.Obj.GetFoo(), this.Obj.FOnFoo);',
- 'this.b = !rtl.eqCallback(this.Obj.GetEvents(11), this.Obj.FOnFoo);',
- 'this.b = rtl.eqCallback(this.Obj.FOnFoo, rtl.createCallback(this.Obj, "DoIt"));',
- 'this.b = rtl.eqCallback(this.Obj.GetFoo(), rtl.createCallback(this.Obj, "DoIt"));',
- 'this.b = rtl.eqCallback(this.Obj.GetEvents(12), rtl.createCallback(this.Obj, "DoIt"));',
- 'this.b = !rtl.eqCallback(this.Obj.FOnFoo, rtl.createCallback(this.Obj, "DoIt"));',
- 'this.b = !rtl.eqCallback(this.Obj.GetFoo(), rtl.createCallback(this.Obj, "DoIt"));',
- 'this.b = !rtl.eqCallback(this.Obj.GetEvents(12), rtl.createCallback(this.Obj, "DoIt"));',
- 'this.b = this.Obj.FOnFoo != null;',
- 'this.b = this.Obj.GetFoo() != null;',
- 'this.b = this.Obj.GetEvents(13) != null;',
- '']));
- end;
- procedure TTestModule.TestProcType_PropertyDelphi;
- begin
- StartProgram(false);
- Add('{$mode delphi}');
- Add('type');
- Add(' TFuncInt = function(vA: longint = 1): longint of object;');
- Add(' TObject = class');
- Add(' FOnFoo: TFuncInt;');
- Add(' function DoIt(vA: longint = 1): longint;');
- Add(' function GetFoo: TFuncInt;');
- Add(' procedure SetFoo(const Value: TFuncInt);');
- Add(' function GetEvents(Index: longint): TFuncInt;');
- Add(' procedure SetEvents(Index: longint; const Value: TFuncInt);');
- Add(' property OnFoo: TFuncInt read FOnFoo write FOnFoo;');
- Add(' property OnBar: TFuncInt read GetFoo write SetFoo;');
- Add(' property Events[Index: longint]: TFuncInt read GetEvents write SetEvents; default;');
- Add(' end;');
- Add('function tobject.doit(va: longint = 1): longint; begin end;');
- Add('function tobject.getfoo: tfuncint; begin end;');
- Add('procedure tobject.setfoo(const value: tfuncint); begin end;');
- Add('function tobject.getevents(index: longint): tfuncint; begin end;');
- Add('procedure tobject.setevents(index: longint; const value: tfuncint); begin end;');
- Add('var');
- Add(' Obj: TObject;');
- Add(' vP: tfuncint;');
- Add(' b: boolean;');
- Add('begin');
- Add(' obj.onfoo:=nil;');
- Add(' obj.onbar:=nil;');
- Add(' obj.events[1]:=nil;');
- Add(' obj.onfoo:=obj.onfoo;');
- Add(' obj.onbar:=obj.onbar;');
- Add(' obj.events[2]:=obj.events[3];');
- Add(' obj.onfoo:[email protected];');
- Add(' obj.onbar:[email protected];');
- Add(' obj.events[4]:[email protected];');
- Add(' obj.onfoo:=obj.doit;'); // delphi
- Add(' obj.onbar:=obj.doit;'); // delphi
- Add(' obj.events[4]:=obj.doit;'); // delphi
- Add(' obj.onfoo;');
- Add(' obj.onbar;');
- //Add(' obj.events[5];'); ToDo in pasresolver
- Add(' obj.onfoo();');
- Add(' obj.onbar();');
- Add(' obj.events[6]();');
- //Add(' b:=obj.onfoo=nil;'); // fpc
- //Add(' b:=obj.onbar=nil;'); // fpc
- //Add(' b:=obj.events[7]=nil;'); // fpc
- //Add(' b:=obj.onfoo<>nil;'); // fpc
- //Add(' b:=obj.onbar<>nil;'); // fpc
- //Add(' b:=obj.events[8]<>nil;'); // fpc
- Add(' b:=obj.onfoo=vp;');
- Add(' b:=obj.onbar=vp;');
- //Add(' b:=obj.events[9]=vp;'); ToDo in pasresolver
- Add(' b:=obj.onfoo=obj.onfoo;');
- Add(' b:=obj.onbar=obj.onfoo;');
- //Add(' b:=obj.events[10]=obj.onfoo;'); // ToDo in pasresolver
- Add(' b:=obj.onfoo<>obj.onfoo;');
- Add(' b:=obj.onbar<>obj.onfoo;');
- //Add(' b:=obj.events[11]<>obj.onfoo;'); // ToDo in pasresolver
- //Add(' b:[email protected];'); // fpc
- //Add(' b:[email protected];'); // fpc
- //Add(' b:=obj.events[12][email protected];'); // fpc
- //Add(' b:=obj.onfoo<>@obj.doit;'); // fpc
- //Add(' b:=obj.onbar<>@obj.doit;'); // fpc
- //Add(' b:=obj.events[12]<>@obj.doit;'); // fpc
- Add(' b:=Assigned(obj.onfoo);');
- Add(' b:=Assigned(obj.onbar);');
- Add(' b:=Assigned(obj.events[13]);');
- ConvertProgram;
- CheckSource('TestProcType_PropertyDelphi',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.FOnFoo = null;',
- ' };',
- ' this.$final = function () {',
- ' this.FOnFoo = undefined;',
- ' };',
- ' this.DoIt = function (vA) {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- 'this.GetFoo = function () {',
- ' var Result = null;',
- ' return Result;',
- '};',
- 'this.SetFoo = function (Value) {',
- '};',
- 'this.GetEvents = function (Index) {',
- ' var Result = null;',
- ' return Result;',
- '};',
- 'this.SetEvents = function (Index, Value) {',
- '};',
- '});',
- 'this.Obj = null;',
- 'this.vP = null;',
- 'this.b = false;'
- ]),
- LinesToStr([
- 'this.Obj.FOnFoo = null;',
- 'this.Obj.SetFoo(null);',
- 'this.Obj.SetEvents(1, null);',
- 'this.Obj.FOnFoo = this.Obj.FOnFoo;',
- 'this.Obj.SetFoo(this.Obj.GetFoo());',
- 'this.Obj.SetEvents(2, this.Obj.GetEvents(3));',
- 'this.Obj.FOnFoo = rtl.createCallback(this.Obj, "DoIt");',
- 'this.Obj.SetFoo(rtl.createCallback(this.Obj, "DoIt"));',
- 'this.Obj.SetEvents(4, rtl.createCallback(this.Obj, "DoIt"));',
- 'this.Obj.FOnFoo = rtl.createCallback(this.Obj, "DoIt");',
- 'this.Obj.SetFoo(rtl.createCallback(this.Obj, "DoIt"));',
- 'this.Obj.SetEvents(4, rtl.createCallback(this.Obj, "DoIt"));',
- 'this.Obj.FOnFoo(1);',
- 'this.Obj.GetFoo();',
- 'this.Obj.FOnFoo(1);',
- 'this.Obj.GetFoo()(1);',
- 'this.Obj.GetEvents(6)(1);',
- 'this.b = this.Obj.FOnFoo(1) == this.vP(1);',
- 'this.b = this.Obj.GetFoo() == this.vP(1);',
- 'this.b = this.Obj.FOnFoo(1) == this.Obj.FOnFoo(1);',
- 'this.b = this.Obj.GetFoo() == this.Obj.FOnFoo(1);',
- 'this.b = this.Obj.FOnFoo(1) != this.Obj.FOnFoo(1);',
- 'this.b = this.Obj.GetFoo() != this.Obj.FOnFoo(1);',
- 'this.b = this.Obj.FOnFoo != null;',
- 'this.b = this.Obj.GetFoo() != null;',
- 'this.b = this.Obj.GetEvents(13) != null;',
- '']));
- end;
- procedure TTestModule.TestProcType_WithClassInstDoPropertyFPC;
- begin
- StartProgram(false);
- Add('type');
- Add(' TFuncInt = function(vA: longint = 1): longint of object;');
- Add(' TObject = class');
- Add(' FOnFoo: TFuncInt;');
- Add(' function DoIt(vA: longint = 1): longint;');
- Add(' function GetFoo: TFuncInt;');
- Add(' procedure SetFoo(const Value: TFuncInt);');
- Add(' property OnFoo: TFuncInt read FOnFoo write FOnFoo;');
- Add(' property OnBar: TFuncInt read GetFoo write SetFoo;');
- Add(' end;');
- Add('function tobject.doit(va: longint = 1): longint; begin end;');
- Add('function tobject.getfoo: tfuncint; begin end;');
- Add('procedure tobject.setfoo(const value: tfuncint); begin end;');
- Add('var');
- Add(' Obj: TObject;');
- Add(' vP: tfuncint;');
- Add(' b: boolean;');
- Add('begin');
- Add('with obj do begin');
- Add(' fonfoo:=nil;');
- Add(' onfoo:=nil;');
- Add(' onbar:=nil;');
- Add(' fonfoo:=fonfoo;');
- Add(' onfoo:=onfoo;');
- Add(' onbar:=onbar;');
- Add(' fonfoo:=@doit;');
- Add(' onfoo:=@doit;');
- Add(' onbar:=@doit;');
- //Add(' fonfoo:=doit;'); // delphi
- //Add(' onfoo:=doit;'); // delphi
- //Add(' onbar:=doit;'); // delphi
- Add(' fonfoo;');
- Add(' onfoo;');
- Add(' onbar;');
- Add(' fonfoo();');
- Add(' onfoo();');
- Add(' onbar();');
- Add(' b:=fonfoo=nil;');
- Add(' b:=onfoo=nil;');
- Add(' b:=onbar=nil;');
- Add(' b:=fonfoo<>nil;');
- Add(' b:=onfoo<>nil;');
- Add(' b:=onbar<>nil;');
- Add(' b:=fonfoo=vp;');
- Add(' b:=onfoo=vp;');
- Add(' b:=onbar=vp;');
- Add(' b:=fonfoo=fonfoo;');
- Add(' b:=onfoo=onfoo;');
- Add(' b:=onbar=onfoo;');
- Add(' b:=fonfoo<>fonfoo;');
- Add(' b:=onfoo<>onfoo;');
- Add(' b:=onbar<>onfoo;');
- Add(' b:=fonfoo=@doit;');
- Add(' b:=onfoo=@doit;');
- Add(' b:=onbar=@doit;');
- Add(' b:=fonfoo<>@doit;');
- Add(' b:=onfoo<>@doit;');
- Add(' b:=onbar<>@doit;');
- Add(' b:=Assigned(fonfoo);');
- Add(' b:=Assigned(onfoo);');
- Add(' b:=Assigned(onbar);');
- Add('end;');
- ConvertProgram;
- CheckSource('TestProcType_WithClassInstDoPropertyFPC',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' this.FOnFoo = null;',
- ' };',
- ' this.$final = function () {',
- ' this.FOnFoo = undefined;',
- ' };',
- ' this.DoIt = function (vA) {',
- ' var Result = 0;',
- ' return Result;',
- ' };',
- ' this.GetFoo = function () {',
- ' var Result = null;',
- ' return Result;',
- ' };',
- ' this.SetFoo = function (Value) {',
- ' };',
- '});',
- 'this.Obj = null;',
- 'this.vP = null;',
- 'this.b = false;'
- ]),
- LinesToStr([
- 'var $with1 = this.Obj;',
- '$with1.FOnFoo = null;',
- '$with1.FOnFoo = null;',
- '$with1.SetFoo(null);',
- '$with1.FOnFoo = $with1.FOnFoo;',
- '$with1.FOnFoo = $with1.FOnFoo;',
- '$with1.SetFoo($with1.GetFoo());',
- '$with1.FOnFoo = rtl.createCallback($with1, "DoIt");',
- '$with1.FOnFoo = rtl.createCallback($with1, "DoIt");',
- '$with1.SetFoo(rtl.createCallback($with1, "DoIt"));',
- '$with1.FOnFoo(1);',
- '$with1.FOnFoo(1);',
- '$with1.GetFoo();',
- '$with1.FOnFoo(1);',
- '$with1.FOnFoo(1);',
- '$with1.GetFoo()(1);',
- 'this.b = $with1.FOnFoo == null;',
- 'this.b = $with1.FOnFoo == null;',
- 'this.b = $with1.GetFoo() == null;',
- 'this.b = $with1.FOnFoo != null;',
- 'this.b = $with1.FOnFoo != null;',
- 'this.b = $with1.GetFoo() != null;',
- 'this.b = rtl.eqCallback($with1.FOnFoo, this.vP);',
- 'this.b = rtl.eqCallback($with1.FOnFoo, this.vP);',
- 'this.b = rtl.eqCallback($with1.GetFoo(), this.vP);',
- 'this.b = rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);',
- 'this.b = rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);',
- 'this.b = rtl.eqCallback($with1.GetFoo(), $with1.FOnFoo);',
- 'this.b = !rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);',
- 'this.b = !rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);',
- 'this.b = !rtl.eqCallback($with1.GetFoo(), $with1.FOnFoo);',
- 'this.b = rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));',
- 'this.b = rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));',
- 'this.b = rtl.eqCallback($with1.GetFoo(), rtl.createCallback($with1, "DoIt"));',
- 'this.b = !rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));',
- 'this.b = !rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));',
- 'this.b = !rtl.eqCallback($with1.GetFoo(), rtl.createCallback($with1, "DoIt"));',
- 'this.b = $with1.FOnFoo != null;',
- 'this.b = $with1.FOnFoo != null;',
- 'this.b = $with1.GetFoo() != null;',
- '']));
- end;
- procedure TTestModule.TestJSValue_AssignToJSValue;
- begin
- StartProgram(false);
- Add('var');
- Add(' v: jsvalue;');
- Add(' i: longint;');
- Add(' s: string;');
- Add(' b: boolean;');
- Add(' d: double;');
- Add('begin');
- Add(' v:=v;');
- Add(' v:=1;');
- Add(' v:=i;');
- Add(' v:='''';');
- Add(' v:=''c'';');
- Add(' v:=''foo'';');
- Add(' v:=s;');
- Add(' v:=false;');
- Add(' v:=true;');
- Add(' v:=b;');
- Add(' v:=0.1;');
- Add(' v:=d;');
- Add(' v:=nil;');
- ConvertProgram;
- CheckSource('TestJSValue_AssignToJSValue',
- LinesToStr([ // statements
- 'this.v = undefined;',
- 'this.i = 0;',
- 'this.s = "";',
- 'this.b = false;',
- 'this.d = 0.0;',
- '']),
- LinesToStr([ // this.$main
- 'this.v = this.v;',
- 'this.v = 1;',
- 'this.v = this.i;',
- 'this.v = "";',
- 'this.v = "c";',
- 'this.v = "foo";',
- 'this.v = this.s;',
- 'this.v = false;',
- 'this.v = true;',
- 'this.v = this.b;',
- 'this.v = 0.1;',
- 'this.v = this.d;',
- 'this.v = null;',
- '']));
- end;
- procedure TTestModule.TestJSValue_TypeCastToBaseType;
- begin
- StartProgram(false);
- Add('type');
- Add(' integer = longint;');
- Add(' TYesNo = boolean;');
- Add(' TFloat = double;');
- Add(' TCaption = string;');
- Add(' TChar = char;');
- Add('var');
- Add(' v: jsvalue;');
- Add(' i: integer;');
- Add(' s: TCaption;');
- Add(' b: TYesNo;');
- Add(' d: TFloat;');
- Add(' c: char;');
- Add('begin');
- Add(' i:=longint(v);');
- Add(' i:=integer(v);');
- Add(' s:=string(v);');
- Add(' s:=TCaption(v);');
- Add(' b:=boolean(v);');
- Add(' b:=TYesNo(v);');
- Add(' d:=double(v);');
- Add(' d:=TFloat(v);');
- Add(' c:=char(v);');
- Add(' c:=TChar(v);');
- ConvertProgram;
- CheckSource('TestJSValue_TypeCastToBaseType',
- LinesToStr([ // statements
- 'this.v = undefined;',
- 'this.i = 0;',
- 'this.s = "";',
- 'this.b = false;',
- 'this.d = 0.0;',
- 'this.c = "";',
- '']),
- LinesToStr([ // this.$main
- 'this.i = Math.floor(this.v);',
- 'this.i = Math.floor(this.v);',
- 'this.s = "" + this.v;',
- 'this.s = "" + this.v;',
- 'this.b = !(this.v == false);',
- 'this.b = !(this.v == false);',
- 'this.d = rtl.getNumber(this.v);',
- 'this.d = rtl.getNumber(this.v);',
- 'this.c = rtl.getChar(this.v);',
- 'this.c = rtl.getChar(this.v);',
- '']));
- end;
- procedure TTestModule.TestJSValue_Enum;
- begin
- StartProgram(false);
- Add('type');
- Add(' TColor = (red, blue);');
- Add(' TRedBlue = TColor;');
- Add('var');
- Add(' v: jsvalue;');
- Add(' e: TColor;');
- Add('begin');
- Add(' v:=e;');
- Add(' v:=TColor(e);');
- Add(' v:=TRedBlue(e);');
- Add(' e:=TColor(v);');
- Add(' e:=TRedBlue(v);');
- ConvertProgram;
- CheckSource('TestJSValue_Enum',
- LinesToStr([ // statements
- 'this.TColor = {',
- ' "0": "red",',
- ' red: 0,',
- ' "1": "blue",',
- ' blue: 1',
- '};',
- 'this.v = undefined;',
- 'this.e = 0;',
- '']),
- LinesToStr([ // this.$main
- 'this.v = this.e;',
- 'this.v = this.e;',
- 'this.v = this.e;',
- 'this.e = this.v;',
- 'this.e = this.v;',
- '']));
- end;
- procedure TTestModule.TestJSValue_ClassInstance;
- begin
- StartProgram(false);
- Add('type');
- Add(' TObject = class');
- Add(' end;');
- Add(' TBirdObject = TObject;');
- Add('var');
- Add(' v: jsvalue;');
- Add(' o: TObject;');
- Add('begin');
- Add(' v:=o;');
- Add(' v:=TObject(o);');
- Add(' v:=TBirdObject(o);');
- Add(' o:=TObject(v);');
- Add(' o:=TBirdObject(v);');
- ConvertProgram;
- CheckSource('TestJSValue_ClassInstance',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'this.v = undefined;',
- 'this.o = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.v = this.o;',
- 'this.v = this.o;',
- 'this.v = this.o;',
- 'this.o = rtl.getObject(this.v);',
- 'this.o = rtl.getObject(this.v);',
- '']));
- end;
- procedure TTestModule.TestJSValue_ClassOf;
- begin
- StartProgram(false);
- Add('type');
- Add(' TClass = class of TObject;');
- Add(' TObject = class');
- Add(' end;');
- Add(' TBirds = class of TBird;');
- Add(' TBird = class(TObject) end;');
- Add('var');
- Add(' v: jsvalue;');
- Add(' c: TClass;');
- Add('begin');
- Add(' v:=c;');
- Add(' v:=TClass(c);');
- Add(' v:=TBirds(c);');
- Add(' c:=TClass(v);');
- Add(' c:=TBirds(v);');
- ConvertProgram;
- CheckSource('TestJSValue_ClassOf',
- LinesToStr([ // statements
- 'rtl.createClass(this, "TObject", null, function () {',
- ' this.$init = function () {',
- ' };',
- ' this.$final = function () {',
- ' };',
- '});',
- 'rtl.createClass(this, "TBird", this.TObject, function () {',
- '});',
- 'this.v = undefined;',
- 'this.c = null;',
- '']),
- LinesToStr([ // this.$main
- 'this.v = this.c;',
- 'this.v = this.c;',
- 'this.v = this.c;',
- 'this.c = rtl.getObject(this.v);',
- 'this.c = rtl.getObject(this.v);',
- '']));
- end;
- procedure TTestModule.TestJSValue_ArrayOfJSValue;
- begin
- StartProgram(false);
- Add('type');
- Add(' integer = longint;');
- Add(' TArray = array of JSValue;');
- Add(' TArrgh = tarray;');
- Add('var');
- Add(' v: jsvalue;');
- Add(' TheArray: TArray;');
- Add(' Arr: TArrgh;');
- Add(' i: integer;');
- Add('begin');
- Add(' Arr:=TheArray;');
- Add(' TheArray:=Arr;');
- Add(' SetLength(Arr,2);');
- Add(' SetLength(TheArray,3);');
- Add(' Arr[4]:=v;');
- Add(' Arr[5]:=i;');
- Add(' Arr[6]:=nil;');
- Add(' Arr[7]:=TheArray[8];');
- ConvertProgram;
- CheckSource('TestJSValue_ArrayOfJSValue',
- LinesToStr([ // statements
- 'this.v = undefined;',
- 'this.TheArray = [];',
- 'this.Arr = [];',
- 'this.i = 0;',
- '']),
- LinesToStr([ // this.$main
- 'this.Arr = this.TheArray;',
- 'this.TheArray = this.Arr;',
- 'this.Arr.length = 2;',
- 'this.TheArray.length = 3;',
- 'this.Arr[4] = this.v;',
- 'this.Arr[5] = this.i;',
- 'this.Arr[6] = null;',
- 'this.Arr[7] = this.TheArray[8];',
- '']));
- end;
- procedure TTestModule.TestJSValue_Params;
- begin
- StartProgram(false);
- Add('type');
- Add(' integer = longint;');
- Add(' TYesNo = boolean;');
- Add(' TFloat = double;');
- Add(' TCaption = string;');
- Add(' TChar = char;');
- Add('function DoIt(a: jsvalue; const b: jsvalue; var c: jsvalue; out d: jsvalue): jsvalue;');
- Add('var');
- Add(' l: jsvalue;');
- Add('begin');
- Add(' a:=a;');
- Add(' l:=b;');
- Add(' c:=c;');
- Add(' d:=d;');
- Add(' Result:=l;');
- Add('end;');
- Add('function DoSome(a: jsvalue; const b: jsvalue): jsvalue; begin end;');
- Add('var');
- Add(' v: jsvalue;');
- Add(' i: integer;');
- Add(' b: TYesNo;');
- Add(' d: TFloat;');
- Add(' s: TCaption;');
- Add(' c: TChar;');
- Add('begin');
- Add(' v:=doit(v,v,v,v);');
- Add(' i:=integer(dosome(i,i));');
- Add(' b:=TYesNo(dosome(b,b));');
- Add(' d:=TFloat(dosome(d,d));');
- Add(' s:=TCaption(dosome(s,s));');
- Add(' c:=TChar(dosome(c,c));');
- ConvertProgram;
- CheckSource('TestJSValue_Params',
- LinesToStr([ // statements
- 'this.DoIt = function (a, b, c, d) {',
- ' var Result = undefined;',
- ' var l = undefined;',
- ' a = a;',
- ' l = b;',
- ' c.set(c.get());',
- ' d.set(d.get());',
- ' Result = l;',
- ' return Result;',
- '};',
- 'this.DoSome = function (a, b) {',
- ' var Result = undefined;',
- ' return Result;',
- '};',
- 'this.v = undefined;',
- 'this.i = 0;',
- 'this.b = false;',
- 'this.d = 0.0;',
- 'this.s = "";',
- 'this.c = "";',
- '']),
- LinesToStr([ // this.$main
- 'this.v = this.DoIt(this.v, this.v, {',
- ' p: this,',
- ' get: function () {',
- ' return this.p.v;',
- ' },',
- ' set: function (v) {',
- ' this.p.v = v;',
- ' }',
- '}, {',
- ' p: this,',
- ' get: function () {',
- ' return this.p.v;',
- ' },',
- ' set: function (v) {',
- ' this.p.v = v;',
- ' }',
- '});',
- 'this.i = Math.floor(this.DoSome(this.i, this.i));',
- 'this.b = !(this.DoSome(this.b, this.b) == false);',
- 'this.d = rtl.getNumber(this.DoSome(this.d, this.d));',
- 'this.s = "" + this.DoSome(this.s, this.s);',
- 'this.c = rtl.getChar(this.DoSome(this.c, this.c));',
- '']));
- end;
- procedure TTestModule.TestJSValue_UntypedParam;
- begin
- StartProgram(false);
- Add('function DoIt(const a; var b; out c): jsvalue;');
- Add('begin');
- Add(' Result:=a;');
- Add(' Result:=b;');
- Add(' Result:=c;');
- Add(' b:=Result;');
- Add(' c:=Result;');
- Add('end;');
- Add('var i: longint;');
- Add('begin');
- Add(' doit(i,i,i);');
- ConvertProgram;
- CheckSource('TestJSValue_UntypedParam',
- LinesToStr([ // statements
- 'this.DoIt = function (a, b, c) {',
- ' var Result = undefined;',
- ' Result = a;',
- ' Result = b.get();',
- ' Result = c.get();',
- ' b.set(Result);',
- ' c.set(Result);',
- ' return Result;',
- '};',
- 'this.i = 0;',
- '']),
- LinesToStr([ // this.$main
- 'this.DoIt(this.i, {',
- ' p: this,',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '}, {',
- ' p: this,',
- ' get: function () {',
- ' return this.p.i;',
- ' },',
- ' set: function (v) {',
- ' this.p.i = v;',
- ' }',
- '});',
- '']));
- end;
- procedure TTestModule.TestJSValue_FuncType;
- begin
- StartProgram(false);
- Add('type');
- Add(' integer = longint;');
- Add(' TJSValueArray = array of JSValue;');
- Add(' TListSortCompare = function(Item1, Item2: JSValue): Integer;');
- Add('procedure Sort(P: JSValue; aList: TJSValueArray; const Compare: TListSortCompare);');
- Add('begin');
- Add(' while Compare(P,aList[0])>0 do ;');
- Add('end;');
- Add('var');
- Add(' Compare: TListSortCompare;');
- Add(' V: JSValue;');
- Add(' i: integer;');
- Add('begin');
- Add(' if Compare(V,V)>0 then ;');
- Add(' if Compare(i,i)>1 then ;');
- Add(' if Compare(nil,false)>2 then ;');
- Add(' if Compare(1,true)>3 then ;');
- ConvertProgram;
- CheckSource('TestJSValue_UntypedParam',
- LinesToStr([ // statements
- 'this.Sort = function (P, aList, Compare) {',
- ' while (Compare(P, aList[0]) > 0) {',
- ' };',
- '};',
- 'this.Compare = null;',
- 'this.V = undefined;',
- 'this.i = 0;',
- '']),
- LinesToStr([ // this.$main
- 'if (this.Compare(this.V, this.V) > 0) ;',
- 'if (this.Compare(this.i, this.i) > 1) ;',
- 'if (this.Compare(null, false) > 2) ;',
- 'if (this.Compare(1, true) > 3) ;',
- '']));
- end;
- Initialization
- RegisterTests([TTestModule]);
- end.
|