test_cindent.vim 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453
  1. " Test for cinoptions and cindent
  2. "
  3. func Test_cino_hash()
  4. " Test that curbuf->b_ind_hash_comment is correctly reset
  5. new
  6. setlocal cindent cinoptions=#1
  7. setlocal cinoptions=
  8. call setline(1, ["#include <iostream>"])
  9. call cursor(1, 1)
  10. norm! o#include
  11. "call feedkeys("o#include\<esc>", 't')
  12. call assert_equal(["#include <iostream>", "#include"], getline(1,2))
  13. bwipe!
  14. endfunc
  15. func Test_cino_extern_c()
  16. " Test for cino-E
  17. let without_ind =<< trim [CODE]
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. int func_a(void);
  22. #ifdef __cplusplus
  23. }
  24. #endif
  25. [CODE]
  26. let with_ind =<< trim [CODE]
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. int func_a(void);
  31. #ifdef __cplusplus
  32. }
  33. #endif
  34. [CODE]
  35. new
  36. setlocal cindent cinoptions=E0
  37. call setline(1, without_ind)
  38. call feedkeys("gg=G", 'tx')
  39. call assert_equal(with_ind, getline(1, '$'))
  40. setlocal cinoptions=E-s
  41. call setline(1, with_ind)
  42. call feedkeys("gg=G", 'tx')
  43. call assert_equal(without_ind, getline(1, '$'))
  44. setlocal cinoptions=Es
  45. let tests = [
  46. \ ['recognized', ['extern "C" {'], "\t\t;"],
  47. \ ['recognized', ['extern "C++" {'], "\t\t;"],
  48. \ ['recognized', ['extern /* com */ "C"{'], "\t\t;"],
  49. \ ['recognized', ['extern"C"{'], "\t\t;"],
  50. \ ['recognized', ['extern "C"', '{'], "\t\t;"],
  51. \ ['not recognized', ['extern {'], "\t;"],
  52. \ ['not recognized', ['extern /*"C"*/{'], "\t;"],
  53. \ ['not recognized', ['extern "C" //{'], ";"],
  54. \ ['not recognized', ['extern "C" /*{*/'], ";"],
  55. \ ]
  56. for pair in tests
  57. let lines = pair[1]
  58. call setline(1, lines)
  59. call feedkeys(len(lines) . "Go;", 'tx')
  60. call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"')
  61. endfor
  62. bwipe!
  63. endfunc
  64. func Test_cindent_rawstring()
  65. new
  66. setl cindent
  67. call feedkeys("i" .
  68. \ "int main() {\<CR>" .
  69. \ "R\"(\<CR>" .
  70. \ ")\";\<CR>" .
  71. \ "statement;\<Esc>", "x")
  72. call assert_equal("\tstatement;", getline(line('.')))
  73. bw!
  74. endfunc
  75. func Test_cindent_expr()
  76. new
  77. func! MyIndentFunction()
  78. return v:lnum == 1 ? shiftwidth() : 0
  79. endfunc
  80. setl expandtab sw=8 indentkeys+=; indentexpr=MyIndentFunction()
  81. let testinput =<< trim [CODE]
  82. var_a = something()
  83. b = something()
  84. [CODE]
  85. call setline(1, testinput)
  86. call cursor(1, 1)
  87. call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
  88. let expected =<< [CODE]
  89. var_a = something();
  90. b = something();
  91. [CODE]
  92. call assert_equal(expected, getline(1, '$'))
  93. %d
  94. let testinput =<< [CODE]
  95. var_a = something()
  96. b = something()
  97. [CODE]
  98. call setline(1, testinput)
  99. call cursor(1, 1)
  100. call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
  101. let expected =<< [CODE]
  102. var_a = something();
  103. b = something()
  104. [CODE]
  105. call assert_equal(expected, getline(1, '$'))
  106. bw!
  107. endfunc
  108. func Test_cindent_func()
  109. new
  110. setlocal cindent
  111. call setline(1, ['int main(void)', '{', 'return 0;', '}'])
  112. call assert_equal(-1, cindent(0))
  113. call assert_equal(&sw, 3->cindent())
  114. call assert_equal(-1, cindent(line('$')+1))
  115. bwipe!
  116. endfunc
  117. func Test_cindent_1()
  118. new
  119. setl cindent ts=4 sw=4
  120. setl cino& sts&
  121. let code =<< trim [CODE]
  122. /* start of AUTO matically checked vim: set ts=4 : */
  123. {
  124. if (test)
  125. cmd1;
  126. cmd2;
  127. }
  128. {
  129. if (test)
  130. cmd1;
  131. else
  132. cmd2;
  133. }
  134. {
  135. if (test)
  136. {
  137. cmd1;
  138. cmd2;
  139. }
  140. }
  141. {
  142. if (test)
  143. {
  144. cmd1;
  145. else
  146. }
  147. }
  148. {
  149. while (this)
  150. if (test)
  151. cmd1;
  152. cmd2;
  153. }
  154. {
  155. while (this)
  156. if (test)
  157. cmd1;
  158. else
  159. cmd2;
  160. }
  161. {
  162. if (test)
  163. {
  164. cmd;
  165. }
  166. if (test)
  167. cmd;
  168. }
  169. {
  170. if (test) {
  171. cmd;
  172. }
  173. if (test) cmd;
  174. }
  175. {
  176. cmd1;
  177. for (blah)
  178. while (this)
  179. if (test)
  180. cmd2;
  181. cmd3;
  182. }
  183. {
  184. cmd1;
  185. for (blah)
  186. while (this)
  187. if (test)
  188. cmd2;
  189. cmd3;
  190. if (test)
  191. {
  192. cmd1;
  193. cmd2;
  194. cmd3;
  195. }
  196. }
  197. /* Test for 'cindent' do/while mixed with if/else: */
  198. {
  199. do
  200. if (asdf)
  201. asdfasd;
  202. while (cond);
  203. do
  204. if (asdf)
  205. while (asdf)
  206. asdf;
  207. while (asdf);
  208. }
  209. /* Test for 'cindent' with two ) on a continuation line */
  210. {
  211. if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d
  212. aal;sdkjf ( ;asldfkja;sldfk
  213. al;sdjfka ;slkdf ) sa;ldkjfsa dlk;)
  214. line up here;
  215. }
  216. /* C++ tests: */
  217. // foo() these three lines should remain in column 0
  218. // {
  219. // }
  220. /* Test for continuation and unterminated lines: */
  221. {
  222. i = 99 + 14325 +
  223. 21345 +
  224. 21345 +
  225. 21345 + ( 21345 +
  226. 21345) +
  227. 2345 +
  228. 1234;
  229. c = 1;
  230. }
  231. /*
  232. testje for indent with empty line
  233. here */
  234. {
  235. if (testing &&
  236. not a joke ||
  237. line up here)
  238. hay;
  239. if (testing &&
  240. (not a joke || testing
  241. )line up here)
  242. hay;
  243. if (testing &&
  244. (not a joke || testing
  245. line up here))
  246. hay;
  247. }
  248. {
  249. switch (c)
  250. {
  251. case xx:
  252. do
  253. if (asdf)
  254. do
  255. asdfasdf;
  256. while (asdf);
  257. else
  258. asdfasdf;
  259. while (cond);
  260. case yy:
  261. case xx:
  262. case zz:
  263. testing;
  264. }
  265. }
  266. {
  267. if (cond) {
  268. foo;
  269. }
  270. else
  271. {
  272. bar;
  273. }
  274. }
  275. {
  276. if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf
  277. alsdkfj (asldk;fj
  278. awith cino=(0 ;lf this one goes to below the paren with ==
  279. ;laksjfd ;lsakdjf ;alskdf asd)
  280. asdfasdf;)))
  281. asdfasdf;
  282. }
  283. int
  284. func(a, b)
  285. int a;
  286. int c;
  287. {
  288. if (c1 && (c2 ||
  289. c3))
  290. foo;
  291. if (c1 &&
  292. (c2 || c3)
  293. )
  294. }
  295. {
  296. while (asd)
  297. {
  298. if (asdf)
  299. if (test)
  300. if (that)
  301. {
  302. if (asdf)
  303. do
  304. cdasd;
  305. while (as
  306. df);
  307. }
  308. else
  309. if (asdf)
  310. asdf;
  311. else
  312. asdf;
  313. asdf;
  314. }
  315. }
  316. {
  317. s = "/*"; b = ';'
  318. s = "/*"; b = ';';
  319. a = b;
  320. }
  321. {
  322. switch (a)
  323. {
  324. case a:
  325. switch (t)
  326. {
  327. case 1:
  328. cmd;
  329. break;
  330. case 2:
  331. cmd;
  332. break;
  333. }
  334. cmd;
  335. break;
  336. case b:
  337. {
  338. int i;
  339. cmd;
  340. }
  341. break;
  342. case c: {
  343. int i;
  344. cmd;
  345. }
  346. case d: if (cond &&
  347. test) { /* this line doesn't work right */
  348. int i;
  349. cmd;
  350. }
  351. break;
  352. }
  353. }
  354. {
  355. if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) &&
  356. (bp_to->b_p_initialized ||
  357. (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
  358. return;
  359. label :
  360. asdf = asdf ?
  361. asdf : asdf;
  362. asdf = asdf ?
  363. asdf: asdf;
  364. }
  365. /* Special Comments : This function has the added complexity (compared */
  366. /* : to addtolist) of having to check for a detail */
  367. /* : texture and add that to the list first. */
  368. char *(array[100]) = {
  369. "testje",
  370. "foo",
  371. "bar",
  372. }
  373. enum soppie
  374. {
  375. yes = 0,
  376. no,
  377. maybe
  378. };
  379. typedef enum soppie
  380. {
  381. yes = 0,
  382. no,
  383. maybe
  384. };
  385. static enum
  386. {
  387. yes = 0,
  388. no,
  389. maybe
  390. } soppie;
  391. public static enum
  392. {
  393. yes = 0,
  394. no,
  395. maybe
  396. } soppie;
  397. static private enum
  398. {
  399. yes = 0,
  400. no,
  401. maybe
  402. } soppie;
  403. {
  404. int a,
  405. b;
  406. }
  407. {
  408. struct Type
  409. {
  410. int i;
  411. char *str;
  412. } var[] =
  413. {
  414. 0, "zero",
  415. 1, "one",
  416. 2, "two",
  417. 3, "three"
  418. };
  419. float matrix[3][3] =
  420. {
  421. {
  422. 0,
  423. 1,
  424. 2
  425. },
  426. {
  427. 3,
  428. 4,
  429. 5
  430. },
  431. {
  432. 6,
  433. 7,
  434. 8
  435. }
  436. };
  437. }
  438. {
  439. /* blah ( blah */
  440. /* where does this go? */
  441. /* blah ( blah */
  442. cmd;
  443. func(arg1,
  444. /* comment */
  445. arg2);
  446. a;
  447. {
  448. b;
  449. {
  450. c; /* Hey, NOW it indents?! */
  451. }
  452. }
  453. {
  454. func(arg1,
  455. arg2,
  456. arg3);
  457. /* Hey, what am I doing here? Is this coz of the ","? */
  458. }
  459. }
  460. main ()
  461. {
  462. if (cond)
  463. {
  464. a = b;
  465. }
  466. if (cond) {
  467. a = c;
  468. }
  469. if (cond)
  470. a = d;
  471. return;
  472. }
  473. {
  474. case 2: if (asdf &&
  475. asdfasdf)
  476. aasdf;
  477. a = 9;
  478. case 3: if (asdf)
  479. aasdf;
  480. a = 9;
  481. case 4: x = 1;
  482. y = 2;
  483. label: if (asdf)
  484. here;
  485. label: if (asdf &&
  486. asdfasdf)
  487. {
  488. }
  489. label: if (asdf &&
  490. asdfasdf) {
  491. there;
  492. }
  493. label: if (asdf &&
  494. asdfasdf)
  495. there;
  496. }
  497. {
  498. /*
  499. hello with ":set comments= cino=c5"
  500. */
  501. /*
  502. hello with ":set comments= cino="
  503. */
  504. }
  505. {
  506. if (a < b) {
  507. a = a + 1;
  508. } else
  509. a = a + 2;
  510. if (a)
  511. do {
  512. testing;
  513. } while (asdfasdf);
  514. a = b + 1;
  515. asdfasdf
  516. }
  517. {
  518. for ( int i = 0;
  519. i < 10; i++ )
  520. {
  521. }
  522. i = 0;
  523. }
  524. class bob
  525. {
  526. int foo() {return 1;}
  527. int bar;
  528. }
  529. main()
  530. {
  531. while(1)
  532. if (foo)
  533. {
  534. bar;
  535. }
  536. else {
  537. asdf;
  538. }
  539. misplacedline;
  540. }
  541. {
  542. if (clipboard.state == SELECT_DONE
  543. && ((row == clipboard.start.lnum
  544. && col >= clipboard.start.col)
  545. || row > clipboard.start.lnum))
  546. }
  547. {
  548. if (1) {i += 4;}
  549. where_am_i;
  550. return 0;
  551. }
  552. {
  553. {
  554. } // sdf(asdf
  555. if (asdf)
  556. asd;
  557. }
  558. {
  559. label1:
  560. label2:
  561. }
  562. {
  563. int fooRet = foo(pBar1, false /*fKB*/,
  564. true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
  565. f() {
  566. for ( i = 0;
  567. i < m;
  568. /* c */ i++ ) {
  569. a = b;
  570. }
  571. }
  572. }
  573. {
  574. f1(/*comment*/);
  575. f2();
  576. }
  577. {
  578. do {
  579. if (foo) {
  580. } else
  581. ;
  582. } while (foo);
  583. foo(); // was wrong
  584. }
  585. int x; // no extra indent because of the ;
  586. void func()
  587. {
  588. }
  589. char *tab[] = {"aaa",
  590. "};", /* }; */ NULL}
  591. int indented;
  592. {}
  593. char *a[] = {"aaa", "bbb",
  594. "ccc", NULL};
  595. // here
  596. char *tab[] = {"aaa",
  597. "xx", /* xx */}; /* asdf */
  598. int not_indented;
  599. {
  600. do {
  601. switch (bla)
  602. {
  603. case 1: if (foo)
  604. bar;
  605. }
  606. } while (boo);
  607. wrong;
  608. }
  609. int foo,
  610. bar;
  611. int foo;
  612. #if defined(foo) \
  613. && defined(bar)
  614. char * xx = "asdf\
  615. foo\
  616. bor";
  617. int x;
  618. char *foo = "asdf\
  619. asdf\
  620. asdf",
  621. *bar;
  622. void f()
  623. {
  624. #if defined(foo) \
  625. && defined(bar)
  626. char *foo = "asdf\
  627. asdf\
  628. asdf",
  629. *bar;
  630. {
  631. int i;
  632. char *foo = "asdf\
  633. asdf\
  634. asdf",
  635. *bar;
  636. }
  637. #endif
  638. }
  639. #endif
  640. int y; // comment
  641. // comment
  642. // comment
  643. {
  644. Constructor(int a,
  645. int b ) : BaseClass(a)
  646. {
  647. }
  648. }
  649. void foo()
  650. {
  651. char one,
  652. two;
  653. struct bla piet,
  654. jan;
  655. enum foo kees,
  656. jannie;
  657. static unsigned sdf,
  658. krap;
  659. unsigned int piet,
  660. jan;
  661. int
  662. kees,
  663. jan;
  664. }
  665. {
  666. t(int f,
  667. int d); // )
  668. d();
  669. }
  670. Constructor::Constructor(int a,
  671. int b
  672. ) :
  673. BaseClass(a,
  674. b,
  675. c),
  676. mMember(b),
  677. {
  678. }
  679. Constructor::Constructor(int a,
  680. int b ) :
  681. BaseClass(a)
  682. {
  683. }
  684. Constructor::Constructor(int a,
  685. int b ) /*x*/ : /*x*/ BaseClass(a),
  686. member(b)
  687. {
  688. }
  689. A::A(int a, int b)
  690. : aa(a),
  691. bb(b),
  692. cc(c)
  693. {
  694. }
  695. class CAbc :
  696. public BaseClass1,
  697. protected BaseClass2
  698. {
  699. int Test() { return FALSE; }
  700. int Test1() { return TRUE; }
  701. CAbc(int a, int b ) :
  702. BaseClass(a)
  703. {
  704. switch(xxx)
  705. {
  706. case abc:
  707. asdf();
  708. break;
  709. case 999:
  710. baer();
  711. break;
  712. }
  713. }
  714. public: // <-- this was incorrectly indented before!!
  715. void testfall();
  716. protected:
  717. void testfall();
  718. };
  719. class CAbc : public BaseClass1,
  720. protected BaseClass2
  721. {
  722. };
  723. static struct
  724. {
  725. int a;
  726. int b;
  727. } variable[COUNT] =
  728. {
  729. {
  730. 123,
  731. 456
  732. },
  733. {
  734. 123,
  735. 456
  736. }
  737. };
  738. static struct
  739. {
  740. int a;
  741. int b;
  742. } variable[COUNT] =
  743. {
  744. { 123, 456 },
  745. { 123, 456 }
  746. };
  747. void asdf() /* ind_maxparen may cause trouble here */
  748. {
  749. if ((0
  750. && 1
  751. && 1
  752. && 1
  753. && 1
  754. && 1
  755. && 1
  756. && 1
  757. && 1
  758. && 1
  759. && 1
  760. && 1
  761. && 1
  762. && 1
  763. && 1
  764. && 1
  765. && 1
  766. && 1
  767. && 1
  768. && 1
  769. && 1
  770. && 1
  771. && 1
  772. && 1
  773. && 1
  774. && 1)) break;
  775. }
  776. foo()
  777. {
  778. a = cond ? foo() : asdf
  779. + asdf;
  780. a = cond ?
  781. foo() : asdf
  782. + asdf;
  783. }
  784. int main(void)
  785. {
  786. if (a)
  787. if (b)
  788. 2;
  789. else 3;
  790. next_line_of_code();
  791. }
  792. barry()
  793. {
  794. Foo::Foo (int one,
  795. int two)
  796. : something(4)
  797. {}
  798. }
  799. barry()
  800. {
  801. Foo::Foo (int one, int two)
  802. : something(4)
  803. {}
  804. }
  805. Constructor::Constructor(int a,
  806. int b
  807. ) :
  808. BaseClass(a,
  809. b,
  810. c),
  811. mMember(b)
  812. {
  813. }
  814. int main ()
  815. {
  816. if (lala)
  817. do
  818. ++(*lolo);
  819. while (lili
  820. && lele);
  821. lulu;
  822. }
  823. int main ()
  824. {
  825. switch (c)
  826. {
  827. case 'c': if (cond)
  828. {
  829. }
  830. }
  831. }
  832. main()
  833. {
  834. (void) MyFancyFuasdfadsfnction(
  835. argument);
  836. }
  837. main()
  838. {
  839. char foo[] = "/*";
  840. /* as
  841. df */
  842. hello
  843. }
  844. /* valid namespaces with normal indent */
  845. namespace
  846. {
  847. {
  848. 111111111111;
  849. }
  850. }
  851. namespace /* test */
  852. {
  853. 11111111111111111;
  854. }
  855. namespace // test
  856. {
  857. 111111111111111111;
  858. }
  859. namespace
  860. {
  861. 111111111111111111;
  862. }
  863. namespace test
  864. {
  865. 111111111111111111;
  866. }
  867. namespace{
  868. 111111111111111111;
  869. }
  870. namespace test{
  871. 111111111111111111;
  872. }
  873. namespace {
  874. 111111111111111111;
  875. }
  876. namespace test {
  877. 111111111111111111;
  878. namespace test2 {
  879. 22222222222222222;
  880. }
  881. }
  882. inline namespace {
  883. 111111111111111111;
  884. }
  885. inline /* test */ namespace {
  886. 111111111111111111;
  887. }
  888. inline/* test */namespace {
  889. 111111111111111111;
  890. }
  891. /* invalid namespaces use block indent */
  892. namespace test test2 {
  893. 111111111111111111111;
  894. }
  895. namespace11111111111 {
  896. 111111111111;
  897. }
  898. namespace() {
  899. 1111111111111;
  900. }
  901. namespace()
  902. {
  903. 111111111111111111;
  904. }
  905. namespace test test2
  906. {
  907. 1111111111111111111;
  908. }
  909. namespace111111111
  910. {
  911. 111111111111111111;
  912. }
  913. inlinenamespace {
  914. 111111111111111111;
  915. }
  916. void getstring() {
  917. /* Raw strings */
  918. const char* s = R"(
  919. test {
  920. # comment
  921. field: 123
  922. }
  923. )";
  924. }
  925. void getstring() {
  926. const char* s = R"foo(
  927. test {
  928. # comment
  929. field: 123
  930. }
  931. )foo";
  932. }
  933. {
  934. int a[4] = {
  935. [0] = 0,
  936. [1] = 1,
  937. [2] = 2,
  938. [3] = 3,
  939. };
  940. }
  941. {
  942. a = b[2]
  943. + 3;
  944. }
  945. {
  946. if (1)
  947. /* aaaaa
  948. * bbbbb
  949. */
  950. a = 1;
  951. }
  952. void func()
  953. {
  954. switch (foo)
  955. {
  956. case (bar):
  957. if (baz())
  958. quux();
  959. break;
  960. case (shmoo):
  961. if (!bar)
  962. {
  963. }
  964. case (foo1):
  965. switch (bar)
  966. {
  967. case baz:
  968. baz_f();
  969. break;
  970. }
  971. break;
  972. default:
  973. baz();
  974. baz();
  975. break;
  976. }
  977. }
  978. /* end of AUTO */
  979. [CODE]
  980. call append(0, code)
  981. normal gg
  982. call search('start of AUTO')
  983. exe "normal =/end of AUTO\<CR>"
  984. let expected =<< trim [CODE]
  985. /* start of AUTO matically checked vim: set ts=4 : */
  986. {
  987. if (test)
  988. cmd1;
  989. cmd2;
  990. }
  991. {
  992. if (test)
  993. cmd1;
  994. else
  995. cmd2;
  996. }
  997. {
  998. if (test)
  999. {
  1000. cmd1;
  1001. cmd2;
  1002. }
  1003. }
  1004. {
  1005. if (test)
  1006. {
  1007. cmd1;
  1008. else
  1009. }
  1010. }
  1011. {
  1012. while (this)
  1013. if (test)
  1014. cmd1;
  1015. cmd2;
  1016. }
  1017. {
  1018. while (this)
  1019. if (test)
  1020. cmd1;
  1021. else
  1022. cmd2;
  1023. }
  1024. {
  1025. if (test)
  1026. {
  1027. cmd;
  1028. }
  1029. if (test)
  1030. cmd;
  1031. }
  1032. {
  1033. if (test) {
  1034. cmd;
  1035. }
  1036. if (test) cmd;
  1037. }
  1038. {
  1039. cmd1;
  1040. for (blah)
  1041. while (this)
  1042. if (test)
  1043. cmd2;
  1044. cmd3;
  1045. }
  1046. {
  1047. cmd1;
  1048. for (blah)
  1049. while (this)
  1050. if (test)
  1051. cmd2;
  1052. cmd3;
  1053. if (test)
  1054. {
  1055. cmd1;
  1056. cmd2;
  1057. cmd3;
  1058. }
  1059. }
  1060. /* Test for 'cindent' do/while mixed with if/else: */
  1061. {
  1062. do
  1063. if (asdf)
  1064. asdfasd;
  1065. while (cond);
  1066. do
  1067. if (asdf)
  1068. while (asdf)
  1069. asdf;
  1070. while (asdf);
  1071. }
  1072. /* Test for 'cindent' with two ) on a continuation line */
  1073. {
  1074. if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d
  1075. aal;sdkjf ( ;asldfkja;sldfk
  1076. al;sdjfka ;slkdf ) sa;ldkjfsa dlk;)
  1077. line up here;
  1078. }
  1079. /* C++ tests: */
  1080. // foo() these three lines should remain in column 0
  1081. // {
  1082. // }
  1083. /* Test for continuation and unterminated lines: */
  1084. {
  1085. i = 99 + 14325 +
  1086. 21345 +
  1087. 21345 +
  1088. 21345 + ( 21345 +
  1089. 21345) +
  1090. 2345 +
  1091. 1234;
  1092. c = 1;
  1093. }
  1094. /*
  1095. testje for indent with empty line
  1096. here */
  1097. {
  1098. if (testing &&
  1099. not a joke ||
  1100. line up here)
  1101. hay;
  1102. if (testing &&
  1103. (not a joke || testing
  1104. )line up here)
  1105. hay;
  1106. if (testing &&
  1107. (not a joke || testing
  1108. line up here))
  1109. hay;
  1110. }
  1111. {
  1112. switch (c)
  1113. {
  1114. case xx:
  1115. do
  1116. if (asdf)
  1117. do
  1118. asdfasdf;
  1119. while (asdf);
  1120. else
  1121. asdfasdf;
  1122. while (cond);
  1123. case yy:
  1124. case xx:
  1125. case zz:
  1126. testing;
  1127. }
  1128. }
  1129. {
  1130. if (cond) {
  1131. foo;
  1132. }
  1133. else
  1134. {
  1135. bar;
  1136. }
  1137. }
  1138. {
  1139. if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf
  1140. alsdkfj (asldk;fj
  1141. awith cino=(0 ;lf this one goes to below the paren with ==
  1142. ;laksjfd ;lsakdjf ;alskdf asd)
  1143. asdfasdf;)))
  1144. asdfasdf;
  1145. }
  1146. int
  1147. func(a, b)
  1148. int a;
  1149. int c;
  1150. {
  1151. if (c1 && (c2 ||
  1152. c3))
  1153. foo;
  1154. if (c1 &&
  1155. (c2 || c3)
  1156. )
  1157. }
  1158. {
  1159. while (asd)
  1160. {
  1161. if (asdf)
  1162. if (test)
  1163. if (that)
  1164. {
  1165. if (asdf)
  1166. do
  1167. cdasd;
  1168. while (as
  1169. df);
  1170. }
  1171. else
  1172. if (asdf)
  1173. asdf;
  1174. else
  1175. asdf;
  1176. asdf;
  1177. }
  1178. }
  1179. {
  1180. s = "/*"; b = ';'
  1181. s = "/*"; b = ';';
  1182. a = b;
  1183. }
  1184. {
  1185. switch (a)
  1186. {
  1187. case a:
  1188. switch (t)
  1189. {
  1190. case 1:
  1191. cmd;
  1192. break;
  1193. case 2:
  1194. cmd;
  1195. break;
  1196. }
  1197. cmd;
  1198. break;
  1199. case b:
  1200. {
  1201. int i;
  1202. cmd;
  1203. }
  1204. break;
  1205. case c: {
  1206. int i;
  1207. cmd;
  1208. }
  1209. case d: if (cond &&
  1210. test) { /* this line doesn't work right */
  1211. int i;
  1212. cmd;
  1213. }
  1214. break;
  1215. }
  1216. }
  1217. {
  1218. if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) &&
  1219. (bp_to->b_p_initialized ||
  1220. (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
  1221. return;
  1222. label :
  1223. asdf = asdf ?
  1224. asdf : asdf;
  1225. asdf = asdf ?
  1226. asdf: asdf;
  1227. }
  1228. /* Special Comments : This function has the added complexity (compared */
  1229. /* : to addtolist) of having to check for a detail */
  1230. /* : texture and add that to the list first. */
  1231. char *(array[100]) = {
  1232. "testje",
  1233. "foo",
  1234. "bar",
  1235. }
  1236. enum soppie
  1237. {
  1238. yes = 0,
  1239. no,
  1240. maybe
  1241. };
  1242. typedef enum soppie
  1243. {
  1244. yes = 0,
  1245. no,
  1246. maybe
  1247. };
  1248. static enum
  1249. {
  1250. yes = 0,
  1251. no,
  1252. maybe
  1253. } soppie;
  1254. public static enum
  1255. {
  1256. yes = 0,
  1257. no,
  1258. maybe
  1259. } soppie;
  1260. static private enum
  1261. {
  1262. yes = 0,
  1263. no,
  1264. maybe
  1265. } soppie;
  1266. {
  1267. int a,
  1268. b;
  1269. }
  1270. {
  1271. struct Type
  1272. {
  1273. int i;
  1274. char *str;
  1275. } var[] =
  1276. {
  1277. 0, "zero",
  1278. 1, "one",
  1279. 2, "two",
  1280. 3, "three"
  1281. };
  1282. float matrix[3][3] =
  1283. {
  1284. {
  1285. 0,
  1286. 1,
  1287. 2
  1288. },
  1289. {
  1290. 3,
  1291. 4,
  1292. 5
  1293. },
  1294. {
  1295. 6,
  1296. 7,
  1297. 8
  1298. }
  1299. };
  1300. }
  1301. {
  1302. /* blah ( blah */
  1303. /* where does this go? */
  1304. /* blah ( blah */
  1305. cmd;
  1306. func(arg1,
  1307. /* comment */
  1308. arg2);
  1309. a;
  1310. {
  1311. b;
  1312. {
  1313. c; /* Hey, NOW it indents?! */
  1314. }
  1315. }
  1316. {
  1317. func(arg1,
  1318. arg2,
  1319. arg3);
  1320. /* Hey, what am I doing here? Is this coz of the ","? */
  1321. }
  1322. }
  1323. main ()
  1324. {
  1325. if (cond)
  1326. {
  1327. a = b;
  1328. }
  1329. if (cond) {
  1330. a = c;
  1331. }
  1332. if (cond)
  1333. a = d;
  1334. return;
  1335. }
  1336. {
  1337. case 2: if (asdf &&
  1338. asdfasdf)
  1339. aasdf;
  1340. a = 9;
  1341. case 3: if (asdf)
  1342. aasdf;
  1343. a = 9;
  1344. case 4: x = 1;
  1345. y = 2;
  1346. label: if (asdf)
  1347. here;
  1348. label: if (asdf &&
  1349. asdfasdf)
  1350. {
  1351. }
  1352. label: if (asdf &&
  1353. asdfasdf) {
  1354. there;
  1355. }
  1356. label: if (asdf &&
  1357. asdfasdf)
  1358. there;
  1359. }
  1360. {
  1361. /*
  1362. hello with ":set comments= cino=c5"
  1363. */
  1364. /*
  1365. hello with ":set comments= cino="
  1366. */
  1367. }
  1368. {
  1369. if (a < b) {
  1370. a = a + 1;
  1371. } else
  1372. a = a + 2;
  1373. if (a)
  1374. do {
  1375. testing;
  1376. } while (asdfasdf);
  1377. a = b + 1;
  1378. asdfasdf
  1379. }
  1380. {
  1381. for ( int i = 0;
  1382. i < 10; i++ )
  1383. {
  1384. }
  1385. i = 0;
  1386. }
  1387. class bob
  1388. {
  1389. int foo() {return 1;}
  1390. int bar;
  1391. }
  1392. main()
  1393. {
  1394. while(1)
  1395. if (foo)
  1396. {
  1397. bar;
  1398. }
  1399. else {
  1400. asdf;
  1401. }
  1402. misplacedline;
  1403. }
  1404. {
  1405. if (clipboard.state == SELECT_DONE
  1406. && ((row == clipboard.start.lnum
  1407. && col >= clipboard.start.col)
  1408. || row > clipboard.start.lnum))
  1409. }
  1410. {
  1411. if (1) {i += 4;}
  1412. where_am_i;
  1413. return 0;
  1414. }
  1415. {
  1416. {
  1417. } // sdf(asdf
  1418. if (asdf)
  1419. asd;
  1420. }
  1421. {
  1422. label1:
  1423. label2:
  1424. }
  1425. {
  1426. int fooRet = foo(pBar1, false /*fKB*/,
  1427. true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
  1428. f() {
  1429. for ( i = 0;
  1430. i < m;
  1431. /* c */ i++ ) {
  1432. a = b;
  1433. }
  1434. }
  1435. }
  1436. {
  1437. f1(/*comment*/);
  1438. f2();
  1439. }
  1440. {
  1441. do {
  1442. if (foo) {
  1443. } else
  1444. ;
  1445. } while (foo);
  1446. foo(); // was wrong
  1447. }
  1448. int x; // no extra indent because of the ;
  1449. void func()
  1450. {
  1451. }
  1452. char *tab[] = {"aaa",
  1453. "};", /* }; */ NULL}
  1454. int indented;
  1455. {}
  1456. char *a[] = {"aaa", "bbb",
  1457. "ccc", NULL};
  1458. // here
  1459. char *tab[] = {"aaa",
  1460. "xx", /* xx */}; /* asdf */
  1461. int not_indented;
  1462. {
  1463. do {
  1464. switch (bla)
  1465. {
  1466. case 1: if (foo)
  1467. bar;
  1468. }
  1469. } while (boo);
  1470. wrong;
  1471. }
  1472. int foo,
  1473. bar;
  1474. int foo;
  1475. #if defined(foo) \
  1476. && defined(bar)
  1477. char * xx = "asdf\
  1478. foo\
  1479. bor";
  1480. int x;
  1481. char *foo = "asdf\
  1482. asdf\
  1483. asdf",
  1484. *bar;
  1485. void f()
  1486. {
  1487. #if defined(foo) \
  1488. && defined(bar)
  1489. char *foo = "asdf\
  1490. asdf\
  1491. asdf",
  1492. *bar;
  1493. {
  1494. int i;
  1495. char *foo = "asdf\
  1496. asdf\
  1497. asdf",
  1498. *bar;
  1499. }
  1500. #endif
  1501. }
  1502. #endif
  1503. int y; // comment
  1504. // comment
  1505. // comment
  1506. {
  1507. Constructor(int a,
  1508. int b ) : BaseClass(a)
  1509. {
  1510. }
  1511. }
  1512. void foo()
  1513. {
  1514. char one,
  1515. two;
  1516. struct bla piet,
  1517. jan;
  1518. enum foo kees,
  1519. jannie;
  1520. static unsigned sdf,
  1521. krap;
  1522. unsigned int piet,
  1523. jan;
  1524. int
  1525. kees,
  1526. jan;
  1527. }
  1528. {
  1529. t(int f,
  1530. int d); // )
  1531. d();
  1532. }
  1533. Constructor::Constructor(int a,
  1534. int b
  1535. ) :
  1536. BaseClass(a,
  1537. b,
  1538. c),
  1539. mMember(b),
  1540. {
  1541. }
  1542. Constructor::Constructor(int a,
  1543. int b ) :
  1544. BaseClass(a)
  1545. {
  1546. }
  1547. Constructor::Constructor(int a,
  1548. int b ) /*x*/ : /*x*/ BaseClass(a),
  1549. member(b)
  1550. {
  1551. }
  1552. A::A(int a, int b)
  1553. : aa(a),
  1554. bb(b),
  1555. cc(c)
  1556. {
  1557. }
  1558. class CAbc :
  1559. public BaseClass1,
  1560. protected BaseClass2
  1561. {
  1562. int Test() { return FALSE; }
  1563. int Test1() { return TRUE; }
  1564. CAbc(int a, int b ) :
  1565. BaseClass(a)
  1566. {
  1567. switch(xxx)
  1568. {
  1569. case abc:
  1570. asdf();
  1571. break;
  1572. case 999:
  1573. baer();
  1574. break;
  1575. }
  1576. }
  1577. public: // <-- this was incorrectly indented before!!
  1578. void testfall();
  1579. protected:
  1580. void testfall();
  1581. };
  1582. class CAbc : public BaseClass1,
  1583. protected BaseClass2
  1584. {
  1585. };
  1586. static struct
  1587. {
  1588. int a;
  1589. int b;
  1590. } variable[COUNT] =
  1591. {
  1592. {
  1593. 123,
  1594. 456
  1595. },
  1596. {
  1597. 123,
  1598. 456
  1599. }
  1600. };
  1601. static struct
  1602. {
  1603. int a;
  1604. int b;
  1605. } variable[COUNT] =
  1606. {
  1607. { 123, 456 },
  1608. { 123, 456 }
  1609. };
  1610. void asdf() /* ind_maxparen may cause trouble here */
  1611. {
  1612. if ((0
  1613. && 1
  1614. && 1
  1615. && 1
  1616. && 1
  1617. && 1
  1618. && 1
  1619. && 1
  1620. && 1
  1621. && 1
  1622. && 1
  1623. && 1
  1624. && 1
  1625. && 1
  1626. && 1
  1627. && 1
  1628. && 1
  1629. && 1
  1630. && 1
  1631. && 1
  1632. && 1
  1633. && 1
  1634. && 1
  1635. && 1
  1636. && 1
  1637. && 1)) break;
  1638. }
  1639. foo()
  1640. {
  1641. a = cond ? foo() : asdf
  1642. + asdf;
  1643. a = cond ?
  1644. foo() : asdf
  1645. + asdf;
  1646. }
  1647. int main(void)
  1648. {
  1649. if (a)
  1650. if (b)
  1651. 2;
  1652. else 3;
  1653. next_line_of_code();
  1654. }
  1655. barry()
  1656. {
  1657. Foo::Foo (int one,
  1658. int two)
  1659. : something(4)
  1660. {}
  1661. }
  1662. barry()
  1663. {
  1664. Foo::Foo (int one, int two)
  1665. : something(4)
  1666. {}
  1667. }
  1668. Constructor::Constructor(int a,
  1669. int b
  1670. ) :
  1671. BaseClass(a,
  1672. b,
  1673. c),
  1674. mMember(b)
  1675. {
  1676. }
  1677. int main ()
  1678. {
  1679. if (lala)
  1680. do
  1681. ++(*lolo);
  1682. while (lili
  1683. && lele);
  1684. lulu;
  1685. }
  1686. int main ()
  1687. {
  1688. switch (c)
  1689. {
  1690. case 'c': if (cond)
  1691. {
  1692. }
  1693. }
  1694. }
  1695. main()
  1696. {
  1697. (void) MyFancyFuasdfadsfnction(
  1698. argument);
  1699. }
  1700. main()
  1701. {
  1702. char foo[] = "/*";
  1703. /* as
  1704. df */
  1705. hello
  1706. }
  1707. /* valid namespaces with normal indent */
  1708. namespace
  1709. {
  1710. {
  1711. 111111111111;
  1712. }
  1713. }
  1714. namespace /* test */
  1715. {
  1716. 11111111111111111;
  1717. }
  1718. namespace // test
  1719. {
  1720. 111111111111111111;
  1721. }
  1722. namespace
  1723. {
  1724. 111111111111111111;
  1725. }
  1726. namespace test
  1727. {
  1728. 111111111111111111;
  1729. }
  1730. namespace{
  1731. 111111111111111111;
  1732. }
  1733. namespace test{
  1734. 111111111111111111;
  1735. }
  1736. namespace {
  1737. 111111111111111111;
  1738. }
  1739. namespace test {
  1740. 111111111111111111;
  1741. namespace test2 {
  1742. 22222222222222222;
  1743. }
  1744. }
  1745. inline namespace {
  1746. 111111111111111111;
  1747. }
  1748. inline /* test */ namespace {
  1749. 111111111111111111;
  1750. }
  1751. inline/* test */namespace {
  1752. 111111111111111111;
  1753. }
  1754. /* invalid namespaces use block indent */
  1755. namespace test test2 {
  1756. 111111111111111111111;
  1757. }
  1758. namespace11111111111 {
  1759. 111111111111;
  1760. }
  1761. namespace() {
  1762. 1111111111111;
  1763. }
  1764. namespace()
  1765. {
  1766. 111111111111111111;
  1767. }
  1768. namespace test test2
  1769. {
  1770. 1111111111111111111;
  1771. }
  1772. namespace111111111
  1773. {
  1774. 111111111111111111;
  1775. }
  1776. inlinenamespace {
  1777. 111111111111111111;
  1778. }
  1779. void getstring() {
  1780. /* Raw strings */
  1781. const char* s = R"(
  1782. test {
  1783. # comment
  1784. field: 123
  1785. }
  1786. )";
  1787. }
  1788. void getstring() {
  1789. const char* s = R"foo(
  1790. test {
  1791. # comment
  1792. field: 123
  1793. }
  1794. )foo";
  1795. }
  1796. {
  1797. int a[4] = {
  1798. [0] = 0,
  1799. [1] = 1,
  1800. [2] = 2,
  1801. [3] = 3,
  1802. };
  1803. }
  1804. {
  1805. a = b[2]
  1806. + 3;
  1807. }
  1808. {
  1809. if (1)
  1810. /* aaaaa
  1811. * bbbbb
  1812. */
  1813. a = 1;
  1814. }
  1815. void func()
  1816. {
  1817. switch (foo)
  1818. {
  1819. case (bar):
  1820. if (baz())
  1821. quux();
  1822. break;
  1823. case (shmoo):
  1824. if (!bar)
  1825. {
  1826. }
  1827. case (foo1):
  1828. switch (bar)
  1829. {
  1830. case baz:
  1831. baz_f();
  1832. break;
  1833. }
  1834. break;
  1835. default:
  1836. baz();
  1837. baz();
  1838. break;
  1839. }
  1840. }
  1841. /* end of AUTO */
  1842. [CODE]
  1843. call assert_equal(expected, getline(1, '$'))
  1844. enew! | close
  1845. endfunc
  1846. func Test_cindent_2()
  1847. new
  1848. setl cindent ts=4 sw=4
  1849. setl tw=0 noai fo=croq
  1850. let &wm = &columns - 20
  1851. let code =<< trim [CODE]
  1852. {
  1853. /* this is
  1854. * a real serious important big
  1855. * comment
  1856. */
  1857. /* insert " about life, the universe, and the rest" after "serious" */
  1858. }
  1859. [CODE]
  1860. call append(0, code)
  1861. normal gg
  1862. call search('serious', 'e')
  1863. normal a about life, the universe, and the rest
  1864. let expected =<< trim [CODE]
  1865. {
  1866. /* this is
  1867. * a real serious
  1868. * about life, the
  1869. * universe, and the
  1870. * rest important big
  1871. * comment
  1872. */
  1873. /* insert " about life, the universe, and the rest" after "serious" */
  1874. }
  1875. [CODE]
  1876. call assert_equal(expected, getline(1, '$'))
  1877. set wm&
  1878. enew! | close
  1879. endfunc
  1880. func Test_cindent_3()
  1881. new
  1882. setl nocindent ts=4 sw=4
  1883. let code =<< trim [CODE]
  1884. {
  1885. /*
  1886. * Testing for comments, without 'cin' set
  1887. */
  1888. /*
  1889. * what happens here?
  1890. */
  1891. /*
  1892. the end of the comment, try inserting a line below */
  1893. /* how about
  1894. this one */
  1895. }
  1896. [CODE]
  1897. call append(0, code)
  1898. normal gg
  1899. call search('comments')
  1900. normal joabout life
  1901. call search('happens')
  1902. normal jothere
  1903. call search('below')
  1904. normal oline
  1905. call search('this')
  1906. normal Ohello
  1907. let expected =<< trim [CODE]
  1908. {
  1909. /*
  1910. * Testing for comments, without 'cin' set
  1911. */
  1912. about life
  1913. /*
  1914. * what happens here?
  1915. */
  1916. there
  1917. /*
  1918. the end of the comment, try inserting a line below */
  1919. line
  1920. /* how about
  1921. hello
  1922. this one */
  1923. }
  1924. [CODE]
  1925. call assert_equal(expected, getline(1, '$'))
  1926. enew! | close
  1927. endfunc
  1928. func Test_cindent_4()
  1929. new
  1930. setl cindent ts=4 sw=4
  1931. let code =<< trim [CODE]
  1932. {
  1933. var = this + that + vec[0] * vec[0]
  1934. + vec[1] * vec[1]
  1935. + vec2[2] * vec[2];
  1936. }
  1937. [CODE]
  1938. call append(0, code)
  1939. normal gg
  1940. call search('vec2')
  1941. normal ==
  1942. let expected =<< trim [CODE]
  1943. {
  1944. var = this + that + vec[0] * vec[0]
  1945. + vec[1] * vec[1]
  1946. + vec2[2] * vec[2];
  1947. }
  1948. [CODE]
  1949. call assert_equal(expected, getline(1, '$'))
  1950. enew! | close
  1951. endfunc
  1952. func Test_cindent_5()
  1953. new
  1954. setl cindent ts=4 sw=4
  1955. setl cino=}4
  1956. let code =<< trim [CODE]
  1957. {
  1958. asdf asdflkajds f;
  1959. if (tes & ting) {
  1960. asdf asdf asdf ;
  1961. asdfa sdf asdf;
  1962. }
  1963. testing1;
  1964. if (tes & ting)
  1965. {
  1966. asdf asdf asdf ;
  1967. asdfa sdf asdf;
  1968. }
  1969. testing2;
  1970. }
  1971. [CODE]
  1972. call append(0, code)
  1973. normal gg
  1974. call search('testing1')
  1975. exe "normal k2==/testing2\<CR>"
  1976. normal k2==
  1977. let expected =<< trim [CODE]
  1978. {
  1979. asdf asdflkajds f;
  1980. if (tes & ting) {
  1981. asdf asdf asdf ;
  1982. asdfa sdf asdf;
  1983. }
  1984. testing1;
  1985. if (tes & ting)
  1986. {
  1987. asdf asdf asdf ;
  1988. asdfa sdf asdf;
  1989. }
  1990. testing2;
  1991. }
  1992. [CODE]
  1993. call assert_equal(expected, getline(1, '$'))
  1994. enew! | close
  1995. endfunc
  1996. func Test_cindent_6()
  1997. new
  1998. setl cindent ts=4 sw=4
  1999. setl cino=(0,)20
  2000. let code =<< trim [CODE]
  2001. main ( int first_par, /*
  2002. * Comment for
  2003. * first par
  2004. */
  2005. int second_par /*
  2006. * Comment for
  2007. * second par
  2008. */
  2009. )
  2010. {
  2011. func( first_par, /*
  2012. * Comment for
  2013. * first par
  2014. */
  2015. second_par /*
  2016. * Comment for
  2017. * second par
  2018. */
  2019. );
  2020. }
  2021. [CODE]
  2022. call append(0, code)
  2023. normal gg
  2024. call search('main')
  2025. normal =][
  2026. let expected =<< trim [CODE]
  2027. main ( int first_par, /*
  2028. * Comment for
  2029. * first par
  2030. */
  2031. int second_par /*
  2032. * Comment for
  2033. * second par
  2034. */
  2035. )
  2036. {
  2037. func( first_par, /*
  2038. * Comment for
  2039. * first par
  2040. */
  2041. second_par /*
  2042. * Comment for
  2043. * second par
  2044. */
  2045. );
  2046. }
  2047. [CODE]
  2048. call assert_equal(expected, getline(1, '$'))
  2049. enew! | close
  2050. endfunc
  2051. func Test_cindent_7()
  2052. new
  2053. setl cindent ts=4 sw=4
  2054. setl cino=es,n0s
  2055. let code =<< trim [CODE]
  2056. main(void)
  2057. {
  2058. /* Make sure that cino=X0s is not parsed like cino=Xs. */
  2059. if (cond)
  2060. foo();
  2061. else
  2062. {
  2063. bar();
  2064. }
  2065. }
  2066. [CODE]
  2067. call append(0, code)
  2068. normal gg
  2069. call search('main')
  2070. normal =][
  2071. let expected =<< trim [CODE]
  2072. main(void)
  2073. {
  2074. /* Make sure that cino=X0s is not parsed like cino=Xs. */
  2075. if (cond)
  2076. foo();
  2077. else
  2078. {
  2079. bar();
  2080. }
  2081. }
  2082. [CODE]
  2083. call assert_equal(expected, getline(1, '$'))
  2084. enew! | close
  2085. endfunc
  2086. func Test_cindent_8()
  2087. new
  2088. setl cindent ts=4 sw=4
  2089. setl cino=
  2090. let code =<< trim [CODE]
  2091. {
  2092. do
  2093. {
  2094. if ()
  2095. {
  2096. if ()
  2097. asdf;
  2098. else
  2099. asdf;
  2100. }
  2101. } while ();
  2102. cmd; /* this should go under the } */
  2103. }
  2104. [CODE]
  2105. call append(0, code)
  2106. normal gg
  2107. normal ]]=][
  2108. let expected =<< trim [CODE]
  2109. {
  2110. do
  2111. {
  2112. if ()
  2113. {
  2114. if ()
  2115. asdf;
  2116. else
  2117. asdf;
  2118. }
  2119. } while ();
  2120. cmd; /* this should go under the } */
  2121. }
  2122. [CODE]
  2123. call assert_equal(expected, getline(1, '$'))
  2124. enew! | close
  2125. endfunc
  2126. func Test_cindent_9()
  2127. new
  2128. setl cindent ts=4 sw=4
  2129. let code =<< trim [CODE]
  2130. void f()
  2131. {
  2132. if ( k() ) {
  2133. l();
  2134. } else { /* Start (two words) end */
  2135. m();
  2136. }
  2137. n();
  2138. }
  2139. [CODE]
  2140. call append(0, code)
  2141. normal gg
  2142. normal ]]=][
  2143. let expected =<< trim [CODE]
  2144. void f()
  2145. {
  2146. if ( k() ) {
  2147. l();
  2148. } else { /* Start (two words) end */
  2149. m();
  2150. }
  2151. n();
  2152. }
  2153. [CODE]
  2154. call assert_equal(expected, getline(1, '$'))
  2155. enew! | close
  2156. endfunc
  2157. func Test_cindent_10()
  2158. new
  2159. setl cindent ts=4 sw=4
  2160. setl cino={s,e-s
  2161. let code =<< trim [CODE]
  2162. void f()
  2163. {
  2164. if ( k() )
  2165. {
  2166. l();
  2167. } else { /* Start (two words) end */
  2168. m();
  2169. }
  2170. n(); /* should be under the if () */
  2171. }
  2172. [CODE]
  2173. call append(0, code)
  2174. normal gg
  2175. normal ]]=][
  2176. let expected =<< trim [CODE]
  2177. void f()
  2178. {
  2179. if ( k() )
  2180. {
  2181. l();
  2182. } else { /* Start (two words) end */
  2183. m();
  2184. }
  2185. n(); /* should be under the if () */
  2186. }
  2187. [CODE]
  2188. call assert_equal(expected, getline(1, '$'))
  2189. enew! | close
  2190. endfunc
  2191. func Test_cindent_11()
  2192. new
  2193. setl cindent ts=4 sw=4
  2194. setl cino={s,fs
  2195. let code =<< trim [CODE]
  2196. void bar(void)
  2197. {
  2198. static array[2][2] =
  2199. {
  2200. { 1, 2 },
  2201. { 3, 4 },
  2202. }
  2203. while (a)
  2204. {
  2205. foo(&a);
  2206. }
  2207. {
  2208. int a;
  2209. {
  2210. a = a + 1;
  2211. }
  2212. }
  2213. b = a;
  2214. }
  2215. void func(void)
  2216. {
  2217. a = 1;
  2218. {
  2219. b = 2;
  2220. }
  2221. c = 3;
  2222. d = 4;
  2223. }
  2224. /* foo */
  2225. [CODE]
  2226. call append(0, code)
  2227. normal gg
  2228. exe "normal ]]=/ foo\<CR>"
  2229. let expected =<< trim [CODE]
  2230. void bar(void)
  2231. {
  2232. static array[2][2] =
  2233. {
  2234. { 1, 2 },
  2235. { 3, 4 },
  2236. }
  2237. while (a)
  2238. {
  2239. foo(&a);
  2240. }
  2241. {
  2242. int a;
  2243. {
  2244. a = a + 1;
  2245. }
  2246. }
  2247. b = a;
  2248. }
  2249. void func(void)
  2250. {
  2251. a = 1;
  2252. {
  2253. b = 2;
  2254. }
  2255. c = 3;
  2256. d = 4;
  2257. }
  2258. /* foo */
  2259. [CODE]
  2260. call assert_equal(expected, getline(1, '$'))
  2261. enew! | close
  2262. endfunc
  2263. func Test_cindent_12()
  2264. new
  2265. setl cindent ts=4 sw=4
  2266. setl cino=
  2267. let code =<< trim [CODE]
  2268. a()
  2269. {
  2270. do {
  2271. a = a +
  2272. a;
  2273. } while ( a ); /* add text under this line */
  2274. if ( a )
  2275. a;
  2276. }
  2277. [CODE]
  2278. call append(0, code)
  2279. normal gg
  2280. call search('while')
  2281. normal ohere
  2282. let expected =<< trim [CODE]
  2283. a()
  2284. {
  2285. do {
  2286. a = a +
  2287. a;
  2288. } while ( a ); /* add text under this line */
  2289. here
  2290. if ( a )
  2291. a;
  2292. }
  2293. [CODE]
  2294. call assert_equal(expected, getline(1, '$'))
  2295. enew! | close
  2296. endfunc
  2297. func Test_cindent_13()
  2298. new
  2299. setl cindent ts=4 sw=4
  2300. setl cino= com=
  2301. let code =<< trim [CODE]
  2302. a()
  2303. {
  2304. label1:
  2305. /* hmm */
  2306. // comment
  2307. }
  2308. [CODE]
  2309. call append(0, code)
  2310. normal gg
  2311. call search('comment')
  2312. exe "normal olabel2: b();\rlabel3 /* post */:\r/* pre */ label4:\r" .
  2313. \ "f(/*com*/);\rif (/*com*/)\rcmd();"
  2314. let expected =<< trim [CODE]
  2315. a()
  2316. {
  2317. label1:
  2318. /* hmm */
  2319. // comment
  2320. label2: b();
  2321. label3 /* post */:
  2322. /* pre */ label4:
  2323. f(/*com*/);
  2324. if (/*com*/)
  2325. cmd();
  2326. }
  2327. [CODE]
  2328. call assert_equal(expected, getline(1, '$'))
  2329. enew! | close
  2330. endfunc
  2331. func Test_cindent_14()
  2332. new
  2333. setl cindent ts=4 sw=4
  2334. setl comments& comments^=s:/*,m:**,ex:*/
  2335. let code =<< trim [CODE]
  2336. /*
  2337. * A simple comment
  2338. */
  2339. /*
  2340. ** A different comment
  2341. */
  2342. [CODE]
  2343. call append(0, code)
  2344. normal gg
  2345. call search('simple')
  2346. normal =5j
  2347. let expected =<< trim [CODE]
  2348. /*
  2349. * A simple comment
  2350. */
  2351. /*
  2352. ** A different comment
  2353. */
  2354. [CODE]
  2355. call assert_equal(expected, getline(1, '$'))
  2356. enew! | close
  2357. endfunc
  2358. func Test_cindent_15()
  2359. new
  2360. setl cindent ts=4 sw=4
  2361. setl cino=c0
  2362. setl comments& comments-=s1:/* comments^=s0:/*
  2363. let code =<< trim [CODE]
  2364. void f()
  2365. {
  2366. /*********
  2367. A comment.
  2368. *********/
  2369. }
  2370. [CODE]
  2371. call append(0, code)
  2372. normal gg
  2373. normal ]]=][
  2374. let expected =<< trim [CODE]
  2375. void f()
  2376. {
  2377. /*********
  2378. A comment.
  2379. *********/
  2380. }
  2381. [CODE]
  2382. call assert_equal(expected, getline(1, '$'))
  2383. enew! | close
  2384. endfunc
  2385. func Test_cindent_16()
  2386. new
  2387. setl cindent ts=4 sw=4
  2388. setl cino=c0,C1
  2389. setl comments& comments-=s1:/* comments^=s0:/*
  2390. let code =<< trim [CODE]
  2391. void f()
  2392. {
  2393. /*********
  2394. A comment.
  2395. *********/
  2396. }
  2397. [CODE]
  2398. call append(0, code)
  2399. normal gg
  2400. normal ]]=][
  2401. let expected =<< trim [CODE]
  2402. void f()
  2403. {
  2404. /*********
  2405. A comment.
  2406. *********/
  2407. }
  2408. [CODE]
  2409. call assert_equal(expected, getline(1, '$'))
  2410. enew! | close
  2411. endfunc
  2412. func Test_cindent_17()
  2413. new
  2414. setl cindent ts=4 sw=4
  2415. setl cino=
  2416. let code =<< trim [CODE]
  2417. void f()
  2418. {
  2419. c = c1 &&
  2420. (
  2421. c2 ||
  2422. c3
  2423. ) && c4;
  2424. }
  2425. [CODE]
  2426. call append(0, code)
  2427. normal gg
  2428. normal ]]=][
  2429. let expected =<< trim [CODE]
  2430. void f()
  2431. {
  2432. c = c1 &&
  2433. (
  2434. c2 ||
  2435. c3
  2436. ) && c4;
  2437. }
  2438. [CODE]
  2439. call assert_equal(expected, getline(1, '$'))
  2440. enew! | close
  2441. endfunc
  2442. func Test_cindent_18()
  2443. new
  2444. setl cindent ts=4 sw=4
  2445. setl cino=(s
  2446. let code =<< trim [CODE]
  2447. void f()
  2448. {
  2449. c = c1 &&
  2450. (
  2451. c2 ||
  2452. c3
  2453. ) && c4;
  2454. }
  2455. [CODE]
  2456. call append(0, code)
  2457. normal gg
  2458. normal ]]=][
  2459. let expected =<< trim [CODE]
  2460. void f()
  2461. {
  2462. c = c1 &&
  2463. (
  2464. c2 ||
  2465. c3
  2466. ) && c4;
  2467. }
  2468. [CODE]
  2469. call assert_equal(expected, getline(1, '$'))
  2470. enew! | close
  2471. endfunc
  2472. func Test_cindent_19()
  2473. new
  2474. setl cindent ts=4 sw=4
  2475. set cino=(s,U1
  2476. let code =<< trim [CODE]
  2477. void f()
  2478. {
  2479. c = c1 &&
  2480. (
  2481. c2 ||
  2482. c3
  2483. ) && c4;
  2484. }
  2485. [CODE]
  2486. call append(0, code)
  2487. normal gg
  2488. normal ]]=][
  2489. let expected =<< trim [CODE]
  2490. void f()
  2491. {
  2492. c = c1 &&
  2493. (
  2494. c2 ||
  2495. c3
  2496. ) && c4;
  2497. }
  2498. [CODE]
  2499. call assert_equal(expected, getline(1, '$'))
  2500. enew! | close
  2501. endfunc
  2502. func Test_cindent_20()
  2503. new
  2504. setl cindent ts=4 sw=4
  2505. setl cino=(0
  2506. let code =<< trim [CODE]
  2507. void f()
  2508. {
  2509. if ( c1
  2510. && ( c2
  2511. || c3))
  2512. foo;
  2513. }
  2514. [CODE]
  2515. call append(0, code)
  2516. normal gg
  2517. normal ]]=][
  2518. let expected =<< trim [CODE]
  2519. void f()
  2520. {
  2521. if ( c1
  2522. && ( c2
  2523. || c3))
  2524. foo;
  2525. }
  2526. [CODE]
  2527. call assert_equal(expected, getline(1, '$'))
  2528. enew! | close
  2529. endfunc
  2530. func Test_cindent_21()
  2531. new
  2532. setl cindent ts=4 sw=4
  2533. setl cino=(0,w1
  2534. let code =<< trim [CODE]
  2535. void f()
  2536. {
  2537. if ( c1
  2538. && ( c2
  2539. || c3))
  2540. foo;
  2541. }
  2542. [CODE]
  2543. call append(0, code)
  2544. normal gg
  2545. normal ]]=][
  2546. let expected =<< trim [CODE]
  2547. void f()
  2548. {
  2549. if ( c1
  2550. && ( c2
  2551. || c3))
  2552. foo;
  2553. }
  2554. [CODE]
  2555. call assert_equal(expected, getline(1, '$'))
  2556. enew! | close
  2557. endfunc
  2558. func Test_cindent_22()
  2559. new
  2560. setl cindent ts=4 sw=4
  2561. setl cino=(s
  2562. let code =<< trim [CODE]
  2563. void f()
  2564. {
  2565. c = c1 && (
  2566. c2 ||
  2567. c3
  2568. ) && c4;
  2569. if (
  2570. c1 && c2
  2571. )
  2572. foo;
  2573. }
  2574. [CODE]
  2575. call append(0, code)
  2576. normal gg
  2577. normal ]]=][
  2578. let expected =<< trim [CODE]
  2579. void f()
  2580. {
  2581. c = c1 && (
  2582. c2 ||
  2583. c3
  2584. ) && c4;
  2585. if (
  2586. c1 && c2
  2587. )
  2588. foo;
  2589. }
  2590. [CODE]
  2591. call assert_equal(expected, getline(1, '$'))
  2592. enew! | close
  2593. endfunc
  2594. func Test_cindent_23()
  2595. new
  2596. setl cindent ts=4 sw=4
  2597. setl cino=(s,m1
  2598. let code =<< trim [CODE]
  2599. void f()
  2600. {
  2601. c = c1 && (
  2602. c2 ||
  2603. c3
  2604. ) && c4;
  2605. if (
  2606. c1 && c2
  2607. )
  2608. foo;
  2609. }
  2610. [CODE]
  2611. call append(0, code)
  2612. normal gg
  2613. normal ]]=][
  2614. let expected =<< trim [CODE]
  2615. void f()
  2616. {
  2617. c = c1 && (
  2618. c2 ||
  2619. c3
  2620. ) && c4;
  2621. if (
  2622. c1 && c2
  2623. )
  2624. foo;
  2625. }
  2626. [CODE]
  2627. call assert_equal(expected, getline(1, '$'))
  2628. enew! | close
  2629. endfunc
  2630. func Test_cindent_24()
  2631. new
  2632. setl cindent ts=4 sw=4
  2633. setl cino=b1
  2634. let code =<< trim [CODE]
  2635. void f()
  2636. {
  2637. switch (x)
  2638. {
  2639. case 1:
  2640. a = b;
  2641. break;
  2642. default:
  2643. a = 0;
  2644. break;
  2645. }
  2646. }
  2647. [CODE]
  2648. call append(0, code)
  2649. normal gg
  2650. normal ]]=][
  2651. let expected =<< trim [CODE]
  2652. void f()
  2653. {
  2654. switch (x)
  2655. {
  2656. case 1:
  2657. a = b;
  2658. break;
  2659. default:
  2660. a = 0;
  2661. break;
  2662. }
  2663. }
  2664. [CODE]
  2665. call assert_equal(expected, getline(1, '$'))
  2666. enew! | close
  2667. endfunc
  2668. func Test_cindent_25()
  2669. new
  2670. setl cindent ts=4 sw=4
  2671. setl cino=(0,W5
  2672. let code =<< trim [CODE]
  2673. void f()
  2674. {
  2675. invokeme(
  2676. argu,
  2677. ment);
  2678. invokeme(
  2679. argu,
  2680. ment
  2681. );
  2682. invokeme(argu,
  2683. ment
  2684. );
  2685. }
  2686. [CODE]
  2687. call append(0, code)
  2688. normal gg
  2689. normal ]]=][
  2690. let expected =<< trim [CODE]
  2691. void f()
  2692. {
  2693. invokeme(
  2694. argu,
  2695. ment);
  2696. invokeme(
  2697. argu,
  2698. ment
  2699. );
  2700. invokeme(argu,
  2701. ment
  2702. );
  2703. }
  2704. [CODE]
  2705. call assert_equal(expected, getline(1, '$'))
  2706. enew! | close
  2707. endfunc
  2708. func Test_cindent_26()
  2709. new
  2710. setl cindent ts=4 sw=4
  2711. setl cino=/6
  2712. let code =<< trim [CODE]
  2713. void f()
  2714. {
  2715. statement;
  2716. // comment 1
  2717. // comment 2
  2718. }
  2719. [CODE]
  2720. call append(0, code)
  2721. normal gg
  2722. normal ]]=][
  2723. let expected =<< trim [CODE]
  2724. void f()
  2725. {
  2726. statement;
  2727. // comment 1
  2728. // comment 2
  2729. }
  2730. [CODE]
  2731. call assert_equal(expected, getline(1, '$'))
  2732. enew! | close
  2733. endfunc
  2734. func Test_cindent_27()
  2735. new
  2736. setl cindent ts=4 sw=4
  2737. setl cino=
  2738. let code =<< trim [CODE]
  2739. void f()
  2740. {
  2741. statement;
  2742. // comment 1
  2743. // comment 2
  2744. }
  2745. [CODE]
  2746. call append(0, code)
  2747. normal gg
  2748. exe "normal ]]/comment 1/+1\<CR>=="
  2749. let expected =<< trim [CODE]
  2750. void f()
  2751. {
  2752. statement;
  2753. // comment 1
  2754. // comment 2
  2755. }
  2756. [CODE]
  2757. call assert_equal(expected, getline(1, '$'))
  2758. enew! | close
  2759. endfunc
  2760. func Test_cindent_28()
  2761. new
  2762. setl cindent ts=4 sw=4
  2763. setl cino=g0
  2764. let code =<< trim [CODE]
  2765. class CAbc
  2766. {
  2767. int Test() { return FALSE; }
  2768. public: // comment
  2769. void testfall();
  2770. protected:
  2771. void testfall();
  2772. };
  2773. [CODE]
  2774. call append(0, code)
  2775. normal gg
  2776. normal ]]=][
  2777. let expected =<< trim [CODE]
  2778. class CAbc
  2779. {
  2780. int Test() { return FALSE; }
  2781. public: // comment
  2782. void testfall();
  2783. protected:
  2784. void testfall();
  2785. };
  2786. [CODE]
  2787. call assert_equal(expected, getline(1, '$'))
  2788. enew! | close
  2789. endfunc
  2790. func Test_cindent_29()
  2791. new
  2792. setl cindent ts=4 sw=4
  2793. setl cino=(0,gs,hs
  2794. let code =<< trim [CODE]
  2795. class Foo : public Bar
  2796. {
  2797. public:
  2798. virtual void method1(void) = 0;
  2799. virtual void method2(int arg1,
  2800. int arg2,
  2801. int arg3) = 0;
  2802. };
  2803. [CODE]
  2804. call append(0, code)
  2805. normal gg
  2806. normal ]]=][
  2807. let expected =<< trim [CODE]
  2808. class Foo : public Bar
  2809. {
  2810. public:
  2811. virtual void method1(void) = 0;
  2812. virtual void method2(int arg1,
  2813. int arg2,
  2814. int arg3) = 0;
  2815. };
  2816. [CODE]
  2817. call assert_equal(expected, getline(1, '$'))
  2818. enew! | close
  2819. endfunc
  2820. func Test_cindent_30()
  2821. new
  2822. setl cindent ts=4 sw=4
  2823. setl cino=+20
  2824. let code =<< [CODE]
  2825. void
  2826. foo()
  2827. {
  2828. if (a)
  2829. {
  2830. } else
  2831. asdf;
  2832. }
  2833. [CODE]
  2834. call append(0, code)
  2835. normal gg
  2836. normal ]]=][
  2837. let expected =<< [CODE]
  2838. void
  2839. foo()
  2840. {
  2841. if (a)
  2842. {
  2843. } else
  2844. asdf;
  2845. }
  2846. [CODE]
  2847. call assert_equal(expected, getline(1, '$'))
  2848. enew! | close
  2849. endfunc
  2850. func Test_cindent_31()
  2851. new
  2852. setl cindent ts=4 sw=4
  2853. setl cino=(0,W2s
  2854. let code =<< trim [CODE]
  2855. {
  2856. averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
  2857. asdasdf,
  2858. func(asdf,
  2859. asdfadsf),
  2860. asdfasdf
  2861. );
  2862. /* those are ugly, but consequent */
  2863. func()->asd(asdasdf,
  2864. averylongfunctionname(
  2865. abc,
  2866. dec)->averylongfunctionname(
  2867. asdfadsf,
  2868. asdfasdf,
  2869. asdfasdf,
  2870. ),
  2871. func(asdfadf,
  2872. asdfasdf
  2873. ),
  2874. asdasdf
  2875. );
  2876. averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
  2877. abc,
  2878. dec)->asdfasdfasdf(
  2879. asdfadsf,
  2880. asdfasdf,
  2881. asdfasdf,
  2882. ),
  2883. func(asdfadf,
  2884. asdfasdf),
  2885. asdasdf
  2886. );
  2887. }
  2888. [CODE]
  2889. call append(0, code)
  2890. normal gg
  2891. normal ]]=][
  2892. let expected =<< trim [CODE]
  2893. {
  2894. averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
  2895. asdasdf,
  2896. func(asdf,
  2897. asdfadsf),
  2898. asdfasdf
  2899. );
  2900. /* those are ugly, but consequent */
  2901. func()->asd(asdasdf,
  2902. averylongfunctionname(
  2903. abc,
  2904. dec)->averylongfunctionname(
  2905. asdfadsf,
  2906. asdfasdf,
  2907. asdfasdf,
  2908. ),
  2909. func(asdfadf,
  2910. asdfasdf
  2911. ),
  2912. asdasdf
  2913. );
  2914. averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
  2915. abc,
  2916. dec)->asdfasdfasdf(
  2917. asdfadsf,
  2918. asdfasdf,
  2919. asdfasdf,
  2920. ),
  2921. func(asdfadf,
  2922. asdfasdf),
  2923. asdasdf
  2924. );
  2925. }
  2926. [CODE]
  2927. call assert_equal(expected, getline(1, '$'))
  2928. enew! | close
  2929. endfunc
  2930. func Test_cindent_32()
  2931. new
  2932. setl cindent ts=4 sw=4
  2933. setl cino=M1
  2934. let code =<< trim [CODE]
  2935. int main ()
  2936. {
  2937. if (cond1 &&
  2938. cond2
  2939. )
  2940. foo;
  2941. }
  2942. [CODE]
  2943. call append(0, code)
  2944. normal gg
  2945. normal ]]=][
  2946. let expected =<< trim [CODE]
  2947. int main ()
  2948. {
  2949. if (cond1 &&
  2950. cond2
  2951. )
  2952. foo;
  2953. }
  2954. [CODE]
  2955. call assert_equal(expected, getline(1, '$'))
  2956. enew! | close
  2957. endfunc
  2958. func Test_cindent_33()
  2959. new
  2960. setl cindent ts=4 sw=4
  2961. setl cino=(0,ts
  2962. let code =<< trim [CODE]
  2963. void func(int a
  2964. #if defined(FOO)
  2965. , int b
  2966. , int c
  2967. #endif
  2968. )
  2969. {
  2970. }
  2971. [CODE]
  2972. call append(0, code)
  2973. normal gg
  2974. normal 2j=][
  2975. let expected =<< trim [CODE]
  2976. void func(int a
  2977. #if defined(FOO)
  2978. , int b
  2979. , int c
  2980. #endif
  2981. )
  2982. {
  2983. }
  2984. [CODE]
  2985. call assert_equal(expected, getline(1, '$'))
  2986. enew! | close
  2987. endfunc
  2988. func Test_cindent_34()
  2989. new
  2990. setl cindent ts=4 sw=4
  2991. setl cino=(0
  2992. let code =<< trim [CODE]
  2993. void
  2994. func(int a
  2995. #if defined(FOO)
  2996. , int b
  2997. , int c
  2998. #endif
  2999. )
  3000. {
  3001. }
  3002. [CODE]
  3003. call append(0, code)
  3004. normal gg
  3005. normal =][
  3006. let expected =<< trim [CODE]
  3007. void
  3008. func(int a
  3009. #if defined(FOO)
  3010. , int b
  3011. , int c
  3012. #endif
  3013. )
  3014. {
  3015. }
  3016. [CODE]
  3017. call assert_equal(expected, getline(1, '$'))
  3018. enew! | close
  3019. endfunc
  3020. func Test_cindent_35()
  3021. new
  3022. setl cindent ts=4 sw=4
  3023. setl cino&
  3024. let code =<< trim [CODE]
  3025. void func(void)
  3026. {
  3027. if(x==y)
  3028. if(y==z)
  3029. foo=1;
  3030. else { bar=1;
  3031. baz=2;
  3032. }
  3033. printf("Foo!\n");
  3034. }
  3035. void func1(void)
  3036. {
  3037. char* tab[] = {"foo", "bar",
  3038. "baz", "quux",
  3039. "this line used", "to be indented incorrectly"};
  3040. foo();
  3041. }
  3042. void func2(void)
  3043. {
  3044. int tab[] =
  3045. {1, 2,
  3046. 3, 4,
  3047. 5, 6};
  3048. printf("This line used to be indented incorrectly.\n");
  3049. }
  3050. int foo[]
  3051. #ifdef BAR
  3052. = { 1, 2, 3,
  3053. 4, 5, 6 }
  3054. #endif
  3055. ;
  3056. int baz;
  3057. void func3(void)
  3058. {
  3059. int tab[] = {
  3060. 1, 2,
  3061. 3, 4,
  3062. 5, 6};
  3063. printf("Don't you dare indent this line incorrectly!\n");
  3064. }
  3065. void
  3066. func4(a, b,
  3067. c)
  3068. int a;
  3069. int b;
  3070. int c;
  3071. {
  3072. }
  3073. void
  3074. func5(
  3075. int a,
  3076. int b)
  3077. {
  3078. }
  3079. void
  3080. func6(
  3081. int a)
  3082. {
  3083. }
  3084. [CODE]
  3085. call append(0, code)
  3086. normal gg
  3087. normal ]]=7][
  3088. let expected =<< trim [CODE]
  3089. void func(void)
  3090. {
  3091. if(x==y)
  3092. if(y==z)
  3093. foo=1;
  3094. else { bar=1;
  3095. baz=2;
  3096. }
  3097. printf("Foo!\n");
  3098. }
  3099. void func1(void)
  3100. {
  3101. char* tab[] = {"foo", "bar",
  3102. "baz", "quux",
  3103. "this line used", "to be indented incorrectly"};
  3104. foo();
  3105. }
  3106. void func2(void)
  3107. {
  3108. int tab[] =
  3109. {1, 2,
  3110. 3, 4,
  3111. 5, 6};
  3112. printf("This line used to be indented incorrectly.\n");
  3113. }
  3114. int foo[]
  3115. #ifdef BAR
  3116. = { 1, 2, 3,
  3117. 4, 5, 6 }
  3118. #endif
  3119. ;
  3120. int baz;
  3121. void func3(void)
  3122. {
  3123. int tab[] = {
  3124. 1, 2,
  3125. 3, 4,
  3126. 5, 6};
  3127. printf("Don't you dare indent this line incorrectly!\n");
  3128. }
  3129. void
  3130. func4(a, b,
  3131. c)
  3132. int a;
  3133. int b;
  3134. int c;
  3135. {
  3136. }
  3137. void
  3138. func5(
  3139. int a,
  3140. int b)
  3141. {
  3142. }
  3143. void
  3144. func6(
  3145. int a)
  3146. {
  3147. }
  3148. [CODE]
  3149. call assert_equal(expected, getline(1, '$'))
  3150. enew! | close
  3151. endfunc
  3152. func Test_cindent_36()
  3153. new
  3154. setl cindent ts=4 sw=4
  3155. setl cino&
  3156. setl cino+=l1
  3157. let code =<< trim [CODE]
  3158. void func(void)
  3159. {
  3160. int tab[] =
  3161. {
  3162. 1, 2, 3,
  3163. 4, 5, 6};
  3164. printf("Indent this line correctly!\n");
  3165. switch (foo)
  3166. {
  3167. case bar:
  3168. printf("bar");
  3169. break;
  3170. case baz: {
  3171. printf("baz");
  3172. break;
  3173. }
  3174. case quux:
  3175. printf("But don't break the indentation of this instruction\n");
  3176. break;
  3177. }
  3178. }
  3179. [CODE]
  3180. call append(0, code)
  3181. normal gg
  3182. normal ]]=][
  3183. let expected =<< trim [CODE]
  3184. void func(void)
  3185. {
  3186. int tab[] =
  3187. {
  3188. 1, 2, 3,
  3189. 4, 5, 6};
  3190. printf("Indent this line correctly!\n");
  3191. switch (foo)
  3192. {
  3193. case bar:
  3194. printf("bar");
  3195. break;
  3196. case baz: {
  3197. printf("baz");
  3198. break;
  3199. }
  3200. case quux:
  3201. printf("But don't break the indentation of this instruction\n");
  3202. break;
  3203. }
  3204. }
  3205. [CODE]
  3206. call assert_equal(expected, getline(1, '$'))
  3207. enew! | close
  3208. endfunc
  3209. func Test_cindent_37()
  3210. new
  3211. setl cindent ts=4 sw=4
  3212. setl cino&
  3213. let code =<< trim [CODE]
  3214. void func(void)
  3215. {
  3216. cout << "a"
  3217. << "b"
  3218. << ") :"
  3219. << "c";
  3220. }
  3221. [CODE]
  3222. call append(0, code)
  3223. normal gg
  3224. normal ]]=][
  3225. let expected =<< trim [CODE]
  3226. void func(void)
  3227. {
  3228. cout << "a"
  3229. << "b"
  3230. << ") :"
  3231. << "c";
  3232. }
  3233. [CODE]
  3234. call assert_equal(expected, getline(1, '$'))
  3235. enew! | close
  3236. endfunc
  3237. func Test_cindent_38()
  3238. new
  3239. setl cindent ts=4 sw=4
  3240. setl com=s1:/*,m:*,ex:*/
  3241. let code =<< trim [CODE]
  3242. void func(void)
  3243. {
  3244. /*
  3245. * This is a comment.
  3246. */
  3247. }
  3248. [CODE]
  3249. call append(0, code)
  3250. normal gg
  3251. normal ]]3jofoo();
  3252. let expected =<< trim [CODE]
  3253. void func(void)
  3254. {
  3255. /*
  3256. * This is a comment.
  3257. */
  3258. foo();
  3259. }
  3260. [CODE]
  3261. call assert_equal(expected, getline(1, '$'))
  3262. enew! | close
  3263. endfunc
  3264. func Test_cindent_39()
  3265. new
  3266. setl cindent ts=4 sw=4
  3267. setl cino&
  3268. let code =<< trim [CODE]
  3269. void func(void)
  3270. {
  3271. for (int i = 0; i < 10; ++i)
  3272. if (i & 1) {
  3273. foo(1);
  3274. } else
  3275. foo(0);
  3276. baz();
  3277. }
  3278. [CODE]
  3279. call append(0, code)
  3280. normal gg
  3281. normal ]]=][
  3282. let expected =<< trim [CODE]
  3283. void func(void)
  3284. {
  3285. for (int i = 0; i < 10; ++i)
  3286. if (i & 1) {
  3287. foo(1);
  3288. } else
  3289. foo(0);
  3290. baz();
  3291. }
  3292. [CODE]
  3293. call assert_equal(expected, getline(1, '$'))
  3294. enew! | close
  3295. endfunc
  3296. func Test_cindent_40()
  3297. new
  3298. setl cindent ts=4 sw=4
  3299. setl cino=k2s,(0
  3300. let code =<< trim [CODE]
  3301. void func(void)
  3302. {
  3303. if (condition1
  3304. && condition2)
  3305. action();
  3306. function(argument1
  3307. && argument2);
  3308. if (c1 && (c2 ||
  3309. c3))
  3310. foo;
  3311. if (c1 &&
  3312. (c2 || c3))
  3313. {
  3314. }
  3315. if ( c1
  3316. && ( c2
  3317. || c3))
  3318. foo;
  3319. func( c1
  3320. && ( c2
  3321. || c3))
  3322. foo;
  3323. }
  3324. [CODE]
  3325. call append(0, code)
  3326. normal gg
  3327. normal ]]=][
  3328. let expected =<< trim [CODE]
  3329. void func(void)
  3330. {
  3331. if (condition1
  3332. && condition2)
  3333. action();
  3334. function(argument1
  3335. && argument2);
  3336. if (c1 && (c2 ||
  3337. c3))
  3338. foo;
  3339. if (c1 &&
  3340. (c2 || c3))
  3341. {
  3342. }
  3343. if ( c1
  3344. && ( c2
  3345. || c3))
  3346. foo;
  3347. func( c1
  3348. && ( c2
  3349. || c3))
  3350. foo;
  3351. }
  3352. [CODE]
  3353. call assert_equal(expected, getline(1, '$'))
  3354. enew! | close
  3355. endfunc
  3356. func Test_cindent_41()
  3357. new
  3358. setl cindent ts=4 sw=4
  3359. setl cino=k2s,(s
  3360. let code =<< trim [CODE]
  3361. void func(void)
  3362. {
  3363. if (condition1
  3364. && condition2)
  3365. action();
  3366. function(argument1
  3367. && argument2);
  3368. if (c1 && (c2 ||
  3369. c3))
  3370. foo;
  3371. if (c1 &&
  3372. (c2 || c3))
  3373. {
  3374. }
  3375. if ( c1
  3376. && ( c2
  3377. || c3))
  3378. foo;
  3379. func( c1
  3380. && ( c2
  3381. || c3))
  3382. foo;
  3383. }
  3384. [CODE]
  3385. call append(0, code)
  3386. normal gg
  3387. normal ]]=][
  3388. let expected =<< trim [CODE]
  3389. void func(void)
  3390. {
  3391. if (condition1
  3392. && condition2)
  3393. action();
  3394. function(argument1
  3395. && argument2);
  3396. if (c1 && (c2 ||
  3397. c3))
  3398. foo;
  3399. if (c1 &&
  3400. (c2 || c3))
  3401. {
  3402. }
  3403. if ( c1
  3404. && ( c2
  3405. || c3))
  3406. foo;
  3407. func( c1
  3408. && ( c2
  3409. || c3))
  3410. foo;
  3411. }
  3412. [CODE]
  3413. call assert_equal(expected, getline(1, '$'))
  3414. enew! | close
  3415. endfunc
  3416. func Test_cindent_42()
  3417. new
  3418. setl cindent ts=4 sw=4
  3419. setl cino=k2s,(s,U1
  3420. let code =<< trim [CODE]
  3421. void func(void)
  3422. {
  3423. if (condition1
  3424. && condition2)
  3425. action();
  3426. function(argument1
  3427. && argument2);
  3428. if (c1 && (c2 ||
  3429. c3))
  3430. foo;
  3431. if (c1 &&
  3432. (c2 || c3))
  3433. {
  3434. }
  3435. if (c123456789
  3436. && (c22345
  3437. || c3))
  3438. printf("foo\n");
  3439. c = c1 &&
  3440. (
  3441. c2 ||
  3442. c3
  3443. ) && c4;
  3444. }
  3445. [CODE]
  3446. call append(0, code)
  3447. normal gg
  3448. normal ]]=][
  3449. let expected =<< trim [CODE]
  3450. void func(void)
  3451. {
  3452. if (condition1
  3453. && condition2)
  3454. action();
  3455. function(argument1
  3456. && argument2);
  3457. if (c1 && (c2 ||
  3458. c3))
  3459. foo;
  3460. if (c1 &&
  3461. (c2 || c3))
  3462. {
  3463. }
  3464. if (c123456789
  3465. && (c22345
  3466. || c3))
  3467. printf("foo\n");
  3468. c = c1 &&
  3469. (
  3470. c2 ||
  3471. c3
  3472. ) && c4;
  3473. }
  3474. [CODE]
  3475. call assert_equal(expected, getline(1, '$'))
  3476. enew! | close
  3477. endfunc
  3478. func Test_cindent_43()
  3479. new
  3480. setl cindent ts=4 sw=4
  3481. setl cino=k2s,(0,W4
  3482. let code =<< trim [CODE]
  3483. void func(void)
  3484. {
  3485. if (condition1
  3486. && condition2)
  3487. action();
  3488. function(argument1
  3489. && argument2);
  3490. if (c1 && (c2 ||
  3491. c3))
  3492. foo;
  3493. if (c1 &&
  3494. (c2 || c3))
  3495. {
  3496. }
  3497. if (c123456789
  3498. && (c22345
  3499. || c3))
  3500. printf("foo\n");
  3501. if ( c1
  3502. && ( c2
  3503. || c3))
  3504. foo;
  3505. a_long_line(
  3506. argument,
  3507. argument);
  3508. a_short_line(argument,
  3509. argument);
  3510. }
  3511. [CODE]
  3512. call append(0, code)
  3513. normal gg
  3514. normal ]]=][
  3515. let expected =<< trim [CODE]
  3516. void func(void)
  3517. {
  3518. if (condition1
  3519. && condition2)
  3520. action();
  3521. function(argument1
  3522. && argument2);
  3523. if (c1 && (c2 ||
  3524. c3))
  3525. foo;
  3526. if (c1 &&
  3527. (c2 || c3))
  3528. {
  3529. }
  3530. if (c123456789
  3531. && (c22345
  3532. || c3))
  3533. printf("foo\n");
  3534. if ( c1
  3535. && ( c2
  3536. || c3))
  3537. foo;
  3538. a_long_line(
  3539. argument,
  3540. argument);
  3541. a_short_line(argument,
  3542. argument);
  3543. }
  3544. [CODE]
  3545. call assert_equal(expected, getline(1, '$'))
  3546. enew! | close
  3547. endfunc
  3548. func Test_cindent_44()
  3549. new
  3550. setl cindent ts=4 sw=4
  3551. setl cino=k2s,u2
  3552. let code =<< trim [CODE]
  3553. void func(void)
  3554. {
  3555. if (condition1
  3556. && condition2)
  3557. action();
  3558. function(argument1
  3559. && argument2);
  3560. if (c1 && (c2 ||
  3561. c3))
  3562. foo;
  3563. if (c1 &&
  3564. (c2 || c3))
  3565. {
  3566. }
  3567. if (c123456789
  3568. && (c22345
  3569. || c3))
  3570. printf("foo\n");
  3571. }
  3572. [CODE]
  3573. call append(0, code)
  3574. normal gg
  3575. normal ]]=][
  3576. let expected =<< trim [CODE]
  3577. void func(void)
  3578. {
  3579. if (condition1
  3580. && condition2)
  3581. action();
  3582. function(argument1
  3583. && argument2);
  3584. if (c1 && (c2 ||
  3585. c3))
  3586. foo;
  3587. if (c1 &&
  3588. (c2 || c3))
  3589. {
  3590. }
  3591. if (c123456789
  3592. && (c22345
  3593. || c3))
  3594. printf("foo\n");
  3595. }
  3596. [CODE]
  3597. call assert_equal(expected, getline(1, '$'))
  3598. enew! | close
  3599. endfunc
  3600. func Test_cindent_45()
  3601. new
  3602. setl cindent ts=4 sw=4
  3603. setl cino=k2s,(0,w1
  3604. let code =<< trim [CODE]
  3605. void func(void)
  3606. {
  3607. if (condition1
  3608. && condition2)
  3609. action();
  3610. function(argument1
  3611. && argument2);
  3612. if (c1 && (c2 ||
  3613. c3))
  3614. foo;
  3615. if (c1 &&
  3616. (c2 || c3))
  3617. {
  3618. }
  3619. if (c123456789
  3620. && (c22345
  3621. || c3))
  3622. printf("foo\n");
  3623. if ( c1
  3624. && ( c2
  3625. || c3))
  3626. foo;
  3627. func( c1
  3628. && ( c2
  3629. || c3))
  3630. foo;
  3631. }
  3632. [CODE]
  3633. call append(0, code)
  3634. normal gg
  3635. normal ]]=][
  3636. let expected =<< trim [CODE]
  3637. void func(void)
  3638. {
  3639. if (condition1
  3640. && condition2)
  3641. action();
  3642. function(argument1
  3643. && argument2);
  3644. if (c1 && (c2 ||
  3645. c3))
  3646. foo;
  3647. if (c1 &&
  3648. (c2 || c3))
  3649. {
  3650. }
  3651. if (c123456789
  3652. && (c22345
  3653. || c3))
  3654. printf("foo\n");
  3655. if ( c1
  3656. && ( c2
  3657. || c3))
  3658. foo;
  3659. func( c1
  3660. && ( c2
  3661. || c3))
  3662. foo;
  3663. }
  3664. [CODE]
  3665. call assert_equal(expected, getline(1, '$'))
  3666. enew! | close
  3667. endfunc
  3668. func Test_cindent_46()
  3669. new
  3670. setl cindent ts=4 sw=4
  3671. setl cino=k2,(s
  3672. let code =<< trim [CODE]
  3673. void func(void)
  3674. {
  3675. if (condition1
  3676. && condition2)
  3677. action();
  3678. function(argument1
  3679. && argument2);
  3680. if (c1 && (c2 ||
  3681. c3))
  3682. foo;
  3683. if (c1 &&
  3684. (c2 || c3))
  3685. {
  3686. }
  3687. }
  3688. [CODE]
  3689. call append(0, code)
  3690. normal gg
  3691. normal ]]=][
  3692. let expected =<< trim [CODE]
  3693. void func(void)
  3694. {
  3695. if (condition1
  3696. && condition2)
  3697. action();
  3698. function(argument1
  3699. && argument2);
  3700. if (c1 && (c2 ||
  3701. c3))
  3702. foo;
  3703. if (c1 &&
  3704. (c2 || c3))
  3705. {
  3706. }
  3707. }
  3708. [CODE]
  3709. call assert_equal(expected, getline(1, '$'))
  3710. enew! | close
  3711. endfunc
  3712. func Test_cindent_47()
  3713. new
  3714. setl cindent ts=4 sw=4
  3715. setl cino=N-s
  3716. let code =<< trim [CODE]
  3717. NAMESPACESTART
  3718. /* valid namespaces with normal indent */
  3719. namespace
  3720. {
  3721. {
  3722. 111111111111;
  3723. }
  3724. }
  3725. namespace /* test */
  3726. {
  3727. 11111111111111111;
  3728. }
  3729. namespace // test
  3730. {
  3731. 111111111111111111;
  3732. }
  3733. namespace
  3734. {
  3735. 111111111111111111;
  3736. }
  3737. namespace test
  3738. {
  3739. 111111111111111111;
  3740. }
  3741. namespace test::cpp17
  3742. {
  3743. 111111111111111111;
  3744. }
  3745. namespace ::incorrectcpp17
  3746. {
  3747. 111111111111111111;
  3748. }
  3749. namespace test::incorrectcpp17::
  3750. {
  3751. 111111111111111111;
  3752. }
  3753. namespace test:incorrectcpp17
  3754. {
  3755. 111111111111111111;
  3756. }
  3757. namespace test:::incorrectcpp17
  3758. {
  3759. 111111111111111111;
  3760. }
  3761. namespace{
  3762. 111111111111111111;
  3763. }
  3764. namespace test{
  3765. 111111111111111111;
  3766. }
  3767. namespace {
  3768. 111111111111111111;
  3769. }
  3770. namespace test {
  3771. 111111111111111111;
  3772. namespace test2 {
  3773. 22222222222222222;
  3774. }
  3775. }
  3776. inline namespace {
  3777. 111111111111111111;
  3778. }
  3779. inline /* test */ namespace {
  3780. 111111111111111111;
  3781. }
  3782. inline/* test */namespace {
  3783. 111111111111111111;
  3784. }
  3785. export namespace {
  3786. 111111111111111111;
  3787. }
  3788. export inline namespace {
  3789. 111111111111111111;
  3790. }
  3791. export/* test */inline namespace {
  3792. 111111111111111111;
  3793. }
  3794. inline export namespace {
  3795. 111111111111111111;
  3796. }
  3797. /* invalid namespaces use block indent */
  3798. namespace test test2 {
  3799. 111111111111111111111;
  3800. }
  3801. namespace11111111111 {
  3802. 111111111111;
  3803. }
  3804. namespace() {
  3805. 1111111111111;
  3806. }
  3807. namespace()
  3808. {
  3809. 111111111111111111;
  3810. }
  3811. namespace test test2
  3812. {
  3813. 1111111111111111111;
  3814. }
  3815. namespace111111111
  3816. {
  3817. 111111111111111111;
  3818. }
  3819. inlinenamespace {
  3820. 111111111111111111;
  3821. }
  3822. NAMESPACEEND
  3823. [CODE]
  3824. call append(0, code)
  3825. normal gg
  3826. call search('^NAMESPACESTART')
  3827. exe "normal =/^NAMESPACEEND\n"
  3828. let expected =<< trim [CODE]
  3829. NAMESPACESTART
  3830. /* valid namespaces with normal indent */
  3831. namespace
  3832. {
  3833. {
  3834. 111111111111;
  3835. }
  3836. }
  3837. namespace /* test */
  3838. {
  3839. 11111111111111111;
  3840. }
  3841. namespace // test
  3842. {
  3843. 111111111111111111;
  3844. }
  3845. namespace
  3846. {
  3847. 111111111111111111;
  3848. }
  3849. namespace test
  3850. {
  3851. 111111111111111111;
  3852. }
  3853. namespace test::cpp17
  3854. {
  3855. 111111111111111111;
  3856. }
  3857. namespace ::incorrectcpp17
  3858. {
  3859. 111111111111111111;
  3860. }
  3861. namespace test::incorrectcpp17::
  3862. {
  3863. 111111111111111111;
  3864. }
  3865. namespace test:incorrectcpp17
  3866. {
  3867. 111111111111111111;
  3868. }
  3869. namespace test:::incorrectcpp17
  3870. {
  3871. 111111111111111111;
  3872. }
  3873. namespace{
  3874. 111111111111111111;
  3875. }
  3876. namespace test{
  3877. 111111111111111111;
  3878. }
  3879. namespace {
  3880. 111111111111111111;
  3881. }
  3882. namespace test {
  3883. 111111111111111111;
  3884. namespace test2 {
  3885. 22222222222222222;
  3886. }
  3887. }
  3888. inline namespace {
  3889. 111111111111111111;
  3890. }
  3891. inline /* test */ namespace {
  3892. 111111111111111111;
  3893. }
  3894. inline/* test */namespace {
  3895. 111111111111111111;
  3896. }
  3897. export namespace {
  3898. 111111111111111111;
  3899. }
  3900. export inline namespace {
  3901. 111111111111111111;
  3902. }
  3903. export/* test */inline namespace {
  3904. 111111111111111111;
  3905. }
  3906. inline export namespace {
  3907. 111111111111111111;
  3908. }
  3909. /* invalid namespaces use block indent */
  3910. namespace test test2 {
  3911. 111111111111111111111;
  3912. }
  3913. namespace11111111111 {
  3914. 111111111111;
  3915. }
  3916. namespace() {
  3917. 1111111111111;
  3918. }
  3919. namespace()
  3920. {
  3921. 111111111111111111;
  3922. }
  3923. namespace test test2
  3924. {
  3925. 1111111111111111111;
  3926. }
  3927. namespace111111111
  3928. {
  3929. 111111111111111111;
  3930. }
  3931. inlinenamespace {
  3932. 111111111111111111;
  3933. }
  3934. NAMESPACEEND
  3935. [CODE]
  3936. call assert_equal(expected, getline(1, '$'))
  3937. enew! | close
  3938. endfunc
  3939. func Test_cindent_48()
  3940. new
  3941. setl cindent ts=4 sw=4
  3942. setl cino=j1,J1
  3943. let code =<< trim [CODE]
  3944. JSSTART
  3945. var bar = {
  3946. foo: {
  3947. that: this,
  3948. some: ok,
  3949. },
  3950. "bar":{
  3951. a : 2,
  3952. b: "123abc",
  3953. x: 4,
  3954. "y": 5
  3955. }
  3956. }
  3957. JSEND
  3958. [CODE]
  3959. call append(0, code)
  3960. normal gg
  3961. call search('^JSSTART')
  3962. exe "normal =/^JSEND\n"
  3963. let expected =<< trim [CODE]
  3964. JSSTART
  3965. var bar = {
  3966. foo: {
  3967. that: this,
  3968. some: ok,
  3969. },
  3970. "bar":{
  3971. a : 2,
  3972. b: "123abc",
  3973. x: 4,
  3974. "y": 5
  3975. }
  3976. }
  3977. JSEND
  3978. [CODE]
  3979. call assert_equal(expected, getline(1, '$'))
  3980. enew! | close
  3981. endfunc
  3982. func Test_cindent_49()
  3983. new
  3984. setl cindent ts=4 sw=4
  3985. setl cino=j1,J1
  3986. let code =<< trim [CODE]
  3987. JSSTART
  3988. var foo = [
  3989. 1,
  3990. 2,
  3991. 3
  3992. ];
  3993. JSEND
  3994. [CODE]
  3995. call append(0, code)
  3996. normal gg
  3997. call search('^JSSTART')
  3998. exe "normal =/^JSEND\n"
  3999. let expected =<< trim [CODE]
  4000. JSSTART
  4001. var foo = [
  4002. 1,
  4003. 2,
  4004. 3
  4005. ];
  4006. JSEND
  4007. [CODE]
  4008. call assert_equal(expected, getline(1, '$'))
  4009. enew! | close
  4010. endfunc
  4011. func Test_cindent_50()
  4012. new
  4013. setl cindent ts=4 sw=4
  4014. setl cino=j1,J1
  4015. let code =<< trim [CODE]
  4016. JSSTART
  4017. function bar() {
  4018. var foo = [
  4019. 1,
  4020. 2,
  4021. 3
  4022. ];
  4023. }
  4024. JSEND
  4025. [CODE]
  4026. call append(0, code)
  4027. normal gg
  4028. call search('^JSSTART')
  4029. exe "normal =/^JSEND\n"
  4030. let expected =<< trim [CODE]
  4031. JSSTART
  4032. function bar() {
  4033. var foo = [
  4034. 1,
  4035. 2,
  4036. 3
  4037. ];
  4038. }
  4039. JSEND
  4040. [CODE]
  4041. call assert_equal(expected, getline(1, '$'))
  4042. enew! | close
  4043. endfunc
  4044. func Test_cindent_51()
  4045. new
  4046. setl cindent ts=4 sw=4
  4047. setl cino=j1,J1
  4048. let code =<< trim [CODE]
  4049. JSSTART
  4050. (function($){
  4051. if (cond &&
  4052. cond) {
  4053. stmt;
  4054. }
  4055. window.something.left =
  4056. (width - 50 + offset) + "px";
  4057. var class_name='myclass';
  4058. function private_method() {
  4059. }
  4060. var public_method={
  4061. method: function(options,args){
  4062. private_method();
  4063. }
  4064. }
  4065. function init(options) {
  4066. $(this).data(class_name+'_public',$.extend({},{
  4067. foo: 'bar',
  4068. bar: 2,
  4069. foobar: [
  4070. 1,
  4071. 2,
  4072. 3
  4073. ],
  4074. callback: function(){
  4075. return true;
  4076. }
  4077. }, options||{}));
  4078. }
  4079. $.fn[class_name]=function() {
  4080. var _arguments=arguments;
  4081. return this.each(function(){
  4082. var options=$(this).data(class_name+'_public');
  4083. if (!options) {
  4084. init.apply(this,_arguments);
  4085. } else {
  4086. var method=public_method[_arguments[0]];
  4087. if (typeof(method)!='function') {
  4088. console.log(class_name+' has no method "'+_arguments[0]+'"');
  4089. return false;
  4090. }
  4091. _arguments[0]=options;
  4092. method.apply(this,_arguments);
  4093. }
  4094. });
  4095. }
  4096. })(jQuery);
  4097. JSEND
  4098. [CODE]
  4099. call append(0, code)
  4100. normal gg
  4101. call search('^JSSTART')
  4102. exe "normal =/^JSEND\n"
  4103. let expected =<< trim [CODE]
  4104. JSSTART
  4105. (function($){
  4106. if (cond &&
  4107. cond) {
  4108. stmt;
  4109. }
  4110. window.something.left =
  4111. (width - 50 + offset) + "px";
  4112. var class_name='myclass';
  4113. function private_method() {
  4114. }
  4115. var public_method={
  4116. method: function(options,args){
  4117. private_method();
  4118. }
  4119. }
  4120. function init(options) {
  4121. $(this).data(class_name+'_public',$.extend({},{
  4122. foo: 'bar',
  4123. bar: 2,
  4124. foobar: [
  4125. 1,
  4126. 2,
  4127. 3
  4128. ],
  4129. callback: function(){
  4130. return true;
  4131. }
  4132. }, options||{}));
  4133. }
  4134. $.fn[class_name]=function() {
  4135. var _arguments=arguments;
  4136. return this.each(function(){
  4137. var options=$(this).data(class_name+'_public');
  4138. if (!options) {
  4139. init.apply(this,_arguments);
  4140. } else {
  4141. var method=public_method[_arguments[0]];
  4142. if (typeof(method)!='function') {
  4143. console.log(class_name+' has no method "'+_arguments[0]+'"');
  4144. return false;
  4145. }
  4146. _arguments[0]=options;
  4147. method.apply(this,_arguments);
  4148. }
  4149. });
  4150. }
  4151. })(jQuery);
  4152. JSEND
  4153. [CODE]
  4154. call assert_equal(expected, getline(1, '$'))
  4155. enew! | close
  4156. endfunc
  4157. func Test_cindent_52()
  4158. new
  4159. setl cindent ts=4 sw=4
  4160. setl cino=j1,J1
  4161. let code =<< trim [CODE]
  4162. JSSTART
  4163. function init(options) {
  4164. $(this).data(class_name+'_public',$.extend({},{
  4165. foo: 'bar',
  4166. bar: 2,
  4167. foobar: [
  4168. 1,
  4169. 2,
  4170. 3
  4171. ],
  4172. callback: function(){
  4173. return true;
  4174. }
  4175. }, options||{}));
  4176. }
  4177. JSEND
  4178. [CODE]
  4179. call append(0, code)
  4180. normal gg
  4181. call search('^JSSTART')
  4182. exe "normal =/^JSEND\n"
  4183. let expected =<< trim [CODE]
  4184. JSSTART
  4185. function init(options) {
  4186. $(this).data(class_name+'_public',$.extend({},{
  4187. foo: 'bar',
  4188. bar: 2,
  4189. foobar: [
  4190. 1,
  4191. 2,
  4192. 3
  4193. ],
  4194. callback: function(){
  4195. return true;
  4196. }
  4197. }, options||{}));
  4198. }
  4199. JSEND
  4200. [CODE]
  4201. call assert_equal(expected, getline(1, '$'))
  4202. enew! | close
  4203. endfunc
  4204. func Test_cindent_53()
  4205. new
  4206. setl cindent ts=4 sw=4
  4207. setl cino=j1,J1
  4208. let code =<< trim [CODE]
  4209. JSSTART
  4210. (function($){
  4211. function init(options) {
  4212. $(this).data(class_name+'_public',$.extend({},{
  4213. foo: 'bar',
  4214. bar: 2,
  4215. foobar: [
  4216. 1,
  4217. 2,
  4218. 3
  4219. ],
  4220. callback: function(){
  4221. return true;
  4222. }
  4223. }, options||{}));
  4224. }
  4225. })(jQuery);
  4226. JSEND
  4227. [CODE]
  4228. call append(0, code)
  4229. normal gg
  4230. call search('^JSSTART')
  4231. exe "normal =/^JSEND\n"
  4232. let expected =<< trim [CODE]
  4233. JSSTART
  4234. (function($){
  4235. function init(options) {
  4236. $(this).data(class_name+'_public',$.extend({},{
  4237. foo: 'bar',
  4238. bar: 2,
  4239. foobar: [
  4240. 1,
  4241. 2,
  4242. 3
  4243. ],
  4244. callback: function(){
  4245. return true;
  4246. }
  4247. }, options||{}));
  4248. }
  4249. })(jQuery);
  4250. JSEND
  4251. [CODE]
  4252. call assert_equal(expected, getline(1, '$'))
  4253. enew! | close
  4254. endfunc
  4255. func Test_cindent_54()
  4256. new
  4257. setl cindent ts=4 sw=4
  4258. setl cino=j1,J1,+2
  4259. let code =<< trim [CODE]
  4260. JSSTART
  4261. // Results of JavaScript indent
  4262. // 1
  4263. (function(){
  4264. var a = [
  4265. 'a',
  4266. 'b',
  4267. 'c',
  4268. 'd',
  4269. 'e',
  4270. 'f',
  4271. 'g',
  4272. 'h',
  4273. 'i'
  4274. ];
  4275. }())
  4276. // 2
  4277. (function(){
  4278. var a = [
  4279. 0 +
  4280. 5 *
  4281. 9 *
  4282. 'a',
  4283. 'b',
  4284. 0 +
  4285. 5 *
  4286. 9 *
  4287. 'c',
  4288. 'd',
  4289. 'e',
  4290. 'f',
  4291. 'g',
  4292. 'h',
  4293. 'i'
  4294. ];
  4295. }())
  4296. // 3
  4297. (function(){
  4298. var a = [
  4299. 0 +
  4300. // comment 1
  4301. 5 *
  4302. /* comment 2 */
  4303. 9 *
  4304. 'a',
  4305. 'b',
  4306. 0 +
  4307. 5 *
  4308. 9 *
  4309. 'c',
  4310. 'd',
  4311. 'e',
  4312. 'f',
  4313. 'g',
  4314. 'h',
  4315. 'i'
  4316. ];
  4317. }())
  4318. // 4
  4319. {
  4320. var a = [
  4321. 0,
  4322. 1
  4323. ];
  4324. var b;
  4325. var c;
  4326. }
  4327. // 5
  4328. {
  4329. var a = [
  4330. [
  4331. 0
  4332. ],
  4333. 2,
  4334. 3
  4335. ];
  4336. }
  4337. // 6
  4338. {
  4339. var a = [
  4340. [
  4341. 0,
  4342. 1
  4343. ],
  4344. 2,
  4345. 3
  4346. ];
  4347. }
  4348. // 7
  4349. {
  4350. var a = [
  4351. // [
  4352. 0,
  4353. // 1
  4354. // ],
  4355. 2,
  4356. 3
  4357. ];
  4358. }
  4359. // 8
  4360. var x = [
  4361. (function(){
  4362. var a,
  4363. b,
  4364. c,
  4365. d,
  4366. e,
  4367. f,
  4368. g,
  4369. h,
  4370. i;
  4371. })
  4372. ];
  4373. // 9
  4374. var a = [
  4375. 0 +
  4376. 5 *
  4377. 9 *
  4378. 'a',
  4379. 'b',
  4380. 0 +
  4381. 5 *
  4382. 9 *
  4383. 'c',
  4384. 'd',
  4385. 'e',
  4386. 'f',
  4387. 'g',
  4388. 'h',
  4389. 'i'
  4390. ];
  4391. // 10
  4392. var a,
  4393. b,
  4394. c,
  4395. d,
  4396. e,
  4397. f,
  4398. g,
  4399. h,
  4400. i;
  4401. JSEND
  4402. [CODE]
  4403. call append(0, code)
  4404. normal gg
  4405. call search('^JSSTART')
  4406. exe "normal =/^JSEND\n"
  4407. let expected =<< trim [CODE]
  4408. JSSTART
  4409. // Results of JavaScript indent
  4410. // 1
  4411. (function(){
  4412. var a = [
  4413. 'a',
  4414. 'b',
  4415. 'c',
  4416. 'd',
  4417. 'e',
  4418. 'f',
  4419. 'g',
  4420. 'h',
  4421. 'i'
  4422. ];
  4423. }())
  4424. // 2
  4425. (function(){
  4426. var a = [
  4427. 0 +
  4428. 5 *
  4429. 9 *
  4430. 'a',
  4431. 'b',
  4432. 0 +
  4433. 5 *
  4434. 9 *
  4435. 'c',
  4436. 'd',
  4437. 'e',
  4438. 'f',
  4439. 'g',
  4440. 'h',
  4441. 'i'
  4442. ];
  4443. }())
  4444. // 3
  4445. (function(){
  4446. var a = [
  4447. 0 +
  4448. // comment 1
  4449. 5 *
  4450. /* comment 2 */
  4451. 9 *
  4452. 'a',
  4453. 'b',
  4454. 0 +
  4455. 5 *
  4456. 9 *
  4457. 'c',
  4458. 'd',
  4459. 'e',
  4460. 'f',
  4461. 'g',
  4462. 'h',
  4463. 'i'
  4464. ];
  4465. }())
  4466. // 4
  4467. {
  4468. var a = [
  4469. 0,
  4470. 1
  4471. ];
  4472. var b;
  4473. var c;
  4474. }
  4475. // 5
  4476. {
  4477. var a = [
  4478. [
  4479. 0
  4480. ],
  4481. 2,
  4482. 3
  4483. ];
  4484. }
  4485. // 6
  4486. {
  4487. var a = [
  4488. [
  4489. 0,
  4490. 1
  4491. ],
  4492. 2,
  4493. 3
  4494. ];
  4495. }
  4496. // 7
  4497. {
  4498. var a = [
  4499. // [
  4500. 0,
  4501. // 1
  4502. // ],
  4503. 2,
  4504. 3
  4505. ];
  4506. }
  4507. // 8
  4508. var x = [
  4509. (function(){
  4510. var a,
  4511. b,
  4512. c,
  4513. d,
  4514. e,
  4515. f,
  4516. g,
  4517. h,
  4518. i;
  4519. })
  4520. ];
  4521. // 9
  4522. var a = [
  4523. 0 +
  4524. 5 *
  4525. 9 *
  4526. 'a',
  4527. 'b',
  4528. 0 +
  4529. 5 *
  4530. 9 *
  4531. 'c',
  4532. 'd',
  4533. 'e',
  4534. 'f',
  4535. 'g',
  4536. 'h',
  4537. 'i'
  4538. ];
  4539. // 10
  4540. var a,
  4541. b,
  4542. c,
  4543. d,
  4544. e,
  4545. f,
  4546. g,
  4547. h,
  4548. i;
  4549. JSEND
  4550. [CODE]
  4551. call assert_equal(expected, getline(1, '$'))
  4552. enew! | close
  4553. endfunc
  4554. func Test_cindent_55()
  4555. new
  4556. setl cindent ts=4 sw=4
  4557. setl cino&
  4558. let code =<< trim [CODE]
  4559. /* start of define */
  4560. {
  4561. }
  4562. #define AAA \
  4563. BBB\
  4564. CCC
  4565. #define CNT \
  4566. 1 + \
  4567. 2 + \
  4568. 4
  4569. /* end of define */
  4570. [CODE]
  4571. call append(0, code)
  4572. normal gg
  4573. call search('start of define')
  4574. exe "normal =/end of define\n"
  4575. let expected =<< trim [CODE]
  4576. /* start of define */
  4577. {
  4578. }
  4579. #define AAA \
  4580. BBB\
  4581. CCC
  4582. #define CNT \
  4583. 1 + \
  4584. 2 + \
  4585. 4
  4586. /* end of define */
  4587. [CODE]
  4588. call assert_equal(expected, getline(1, '$'))
  4589. enew! | close
  4590. endfunc
  4591. func Test_cindent_56()
  4592. new
  4593. setl cindent ts=4 sw=4
  4594. setl cino&
  4595. let code =<< trim [CODE]
  4596. {
  4597. a = second/*bug*/*line;
  4598. }
  4599. [CODE]
  4600. call append(0, code)
  4601. normal gg
  4602. call search('a = second')
  4603. normal ox
  4604. let expected =<< trim [CODE]
  4605. {
  4606. a = second/*bug*/*line;
  4607. x
  4608. }
  4609. [CODE]
  4610. call assert_equal(expected, getline(1, '$'))
  4611. enew! | close
  4612. endfunc
  4613. " this was going beyond the end of the line.
  4614. func Test_cindent_case()
  4615. new
  4616. call setline(1, 'case x: // x')
  4617. set cindent
  4618. norm! f:a:
  4619. call assert_equal('case x:: // x', getline(1))
  4620. set cindent&
  4621. bwipe!
  4622. endfunc
  4623. " Test for changing multiple lines (using c) with cindent
  4624. func Test_cindent_change_multline()
  4625. new
  4626. setlocal cindent
  4627. call setline(1, ['if (a)', '{', ' i = 1;', '}'])
  4628. normal! jc3jm = 2;
  4629. call assert_equal("\tm = 2;", getline(2))
  4630. close!
  4631. endfunc
  4632. " This was reading past the end of the line
  4633. func Test_cindent_check_funcdecl()
  4634. new
  4635. sil norm o0('\0=L
  4636. bwipe!
  4637. endfunc
  4638. func Test_cindent_scopedecls()
  4639. new
  4640. setl cindent ts=4 sw=4
  4641. setl cino=g0
  4642. setl cinsd+=public\ slots,signals
  4643. let code =<< trim [CODE]
  4644. class Foo
  4645. {
  4646. public:
  4647. virtual void foo() = 0;
  4648. public slots:
  4649. void onBar();
  4650. signals:
  4651. void baz();
  4652. private:
  4653. int x;
  4654. };
  4655. [CODE]
  4656. call append(0, code)
  4657. normal gg
  4658. normal ]]=][
  4659. let expected =<< trim [CODE]
  4660. class Foo
  4661. {
  4662. public:
  4663. virtual void foo() = 0;
  4664. public slots:
  4665. void onBar();
  4666. signals:
  4667. void baz();
  4668. private:
  4669. int x;
  4670. };
  4671. [CODE]
  4672. call assert_equal(expected, getline(1, '$'))
  4673. enew! | close
  4674. endfunc
  4675. func Test_cindent_pragma()
  4676. new
  4677. setl cindent ts=4 sw=4
  4678. setl cino=Ps
  4679. let code =<< trim [CODE]
  4680. {
  4681. #pragma omp parallel
  4682. {
  4683. #pragma omp task
  4684. foo();
  4685. # pragma omp taskwait
  4686. }
  4687. }
  4688. [CODE]
  4689. call append(0, code)
  4690. normal gg
  4691. normal =G
  4692. let expected =<< trim [CODE]
  4693. {
  4694. #pragma omp parallel
  4695. {
  4696. #pragma omp task
  4697. foo();
  4698. # pragma omp taskwait
  4699. }
  4700. }
  4701. [CODE]
  4702. call assert_equal(expected, getline(1, '$'))
  4703. enew! | close
  4704. endfunc
  4705. func Test_backslash_at_end_of_line()
  4706. new
  4707. exe "norm v>O'\\\<C-m>-"
  4708. exe "norm \<C-q>="
  4709. bwipe!
  4710. endfunc
  4711. func Test_find_brace_backwards()
  4712. " this was looking beyond the end of the line
  4713. new
  4714. norm R/*
  4715. norm o0{
  4716. norm o//
  4717. norm V{=
  4718. call assert_equal(['/*', ' 0{', '//'], getline(1, 3))
  4719. bwipe!
  4720. endfunc
  4721. " vim: shiftwidth=2 sts=2 expandtab