mirror of
				https://github.com/sharkdp/bat.git
				synced 2025-10-31 07:04:04 +00:00 
			
		
		
		
	Add an OCaml file for syntax tests.
This commit is contained in:
		
				
					committed by
					
						 David Peter
						David Peter
					
				
			
			
				
	
			
			
			
						parent
						
							14092fbadb
						
					
				
				
					commit
					203d0bd8ae
				
			
							
								
								
									
										83
									
								
								tests/syntax-tests/highlighted/OCaml/syntax-test.ml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								tests/syntax-tests/highlighted/OCaml/syntax-test.ml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,83 @@ | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;255;255;255ms[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mhello world[0m[38;2;230;219;116m"[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46mn[0m[38;2;248;248;242m [0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mint [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m87[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46mid[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mx[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m x[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46madd[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mx[0m[38;2;248;248;242m [0m[3;38;2;253;151;31my[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m x [0m[38;2;249;38;114m+[0m[38;2;248;248;242m y[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46madd'[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mx[0m[38;2;248;248;242m [0m[3;38;2;253;151;31my[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;255;255;255mleft[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m x [0m[38;2;249;38;114min[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;255;255;255mright[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m y [0m[38;2;249;38;114min[0m | ||||
| [38;2;248;248;242m  x [0m[38;2;249;38;114m+[0m[38;2;248;248;242m y[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46madd''[0m[38;2;248;248;242m [0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mint -> int -> int [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114mfun[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mx[0m[38;2;248;248;242m [0m[38;2;248;248;242m->[0m[38;2;248;248;242m [0m[38;2;249;38;114mfun[0m[38;2;248;248;242m [0m[3;38;2;253;151;31my[0m[38;2;248;248;242m [0m[38;2;248;248;242m->[0m[38;2;248;248;242m x [0m[38;2;249;38;114m+[0m[38;2;248;248;242m y[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46munwrap_option[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mdefault[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mopt[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mmatch[0m[38;2;248;248;242m opt [0m[38;2;249;38;114mwith[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;166;226;46mNone[0m[38;2;248;248;242m [0m[38;2;248;248;242m->[0m[38;2;248;248;242m default[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;166;226;46mSome[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mv[0m[38;2;248;248;242m [0m[38;2;248;248;242m->[0m[38;2;248;248;242m v[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46mstring_of_bool[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114mfunction[0m[38;2;248;248;242m [0m[38;2;190;132;255mtrue[0m[38;2;248;248;242m [0m[38;2;248;248;242m->[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mtrue[0m[38;2;230;219;116m"[0m[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255mfalse[0m[38;2;248;248;242m [0m[38;2;248;248;242m->[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mfalse[0m[38;2;230;219;116m"[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46mis_a[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mc[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mif[0m[38;2;248;248;242m c [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m'a'[0m[38;2;248;248;242m [0m[38;2;249;38;114mthen[0m[38;2;248;248;242m [0m[38;2;190;132;255mtrue[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114melse[0m[38;2;248;248;242m [0m[38;2;190;132;255mfalse[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m _ [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;248;248;242mPrintf.[0m[38;2;248;248;242mprintf [0m[38;2;230;219;116m"[0m[38;2;230;219;116m%s[0m[38;2;230;219;116m"[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mhello[0m[38;2;230;219;116m"[0m | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;190;132;255m([0m[38;2;190;132;255m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;248;248;242mPrintf.[0m[38;2;248;248;242mprintf [0m[38;2;230;219;116m"[0m[38;2;230;219;116m%s[0m[38;2;190;132;255m\n[0m[38;2;230;219;116m"[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mworld[0m[38;2;230;219;116m"[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;255;255;255mx[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114mref[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m _ [0m[38;2;249;38;114m=[0m[38;2;248;248;242m x [0m[38;2;249;38;114m:=[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m | ||||
|  | ||||
| [38;2;249;38;114mtype[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mmy_bool [0m[38;2;248;248;242m=[0m[38;2;248;248;242m [0m[38;2;166;226;46mTrue[0m[38;2;248;248;242m [0m[38;2;248;248;242m|[0m[38;2;248;248;242m [0m[38;2;166;226;46mFalse[0m | ||||
|  | ||||
| [38;2;249;38;114mtype[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mshape [0m[38;2;248;248;242m=[0m[38;2;248;248;242m [0m[38;2;166;226;46mCircle[0m[38;2;248;248;242m [0m[38;2;249;38;114mof[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mfloat[0m[38;2;248;248;242m [0m[38;2;248;248;242m|[0m[38;2;248;248;242m [0m[38;2;166;226;46mSquare[0m[38;2;248;248;242m [0m[38;2;249;38;114mof[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mfloat[0m[38;2;248;248;242m [0m[38;2;248;248;242m|[0m[38;2;248;248;242m [0m[38;2;166;226;46mRectangle[0m[38;2;248;248;242m [0m[38;2;249;38;114mof[0m[38;2;248;248;242m [0m[38;2;248;248;242m([0m[3;38;2;102;217;239mfloat[0m[38;2;248;248;242m [0m[38;2;249;38;114m*[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mfloat[0m[38;2;248;248;242m)[0m | ||||
|  | ||||
| [38;2;249;38;114mtype[0m[38;2;248;248;242m [0m[3;38;2;102;217;239muser [0m[38;2;248;248;242m=[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m | ||||
| [38;2;248;248;242m  [0m[38;2;248;248;242mlogin[0m[38;2;248;248;242m [0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mstring[0m[38;2;249;38;114m;[0m | ||||
| [38;2;248;248;242m  [0m[38;2;248;248;242mpassword[0m[38;2;248;248;242m [0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mstring[0m[38;2;249;38;114m;[0m | ||||
| [38;2;248;248;242m}[0m | ||||
|  | ||||
| [38;2;249;38;114mtype[0m[38;2;248;248;242m [0m[3;38;2;102;217;239m'a my_ref [0m[38;2;248;248;242m=[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m[38;2;248;248;242m [0m[38;2;249;38;114mmutable [0m[38;2;248;248;242mref_value[0m[38;2;248;248;242m [0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239m'a[0m[38;2;248;248;242m [0m[38;2;248;248;242m}[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46m(:=)[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mr[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mv[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m r.ref_value [0m[38;2;249;38;114m<[0m[38;2;249;38;114m-[0m[38;2;248;248;242m v[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46m(+)[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m5[0m | ||||
|  | ||||
| [38;2;249;38;114mexception[0m[38;2;248;248;242m [0m[38;2;166;226;46mBad_value[0m[38;2;248;248;242m of [0m[3;38;2;102;217;239mstring[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46mbad_value_error[0m[38;2;248;248;242m [0m[3;38;2;253;151;31m()[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m raise [0m[38;2;248;248;242m([0m[38;2;166;226;46mBad_value[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116myour value is bad and you should feel bad[0m[38;2;230;219;116m"[0m[38;2;248;248;242m)[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;190;132;255m([0m[38;2;190;132;255m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mtry[0m[38;2;248;248;242m bad_value_error [0m[38;2;190;132;255m([0m[38;2;190;132;255m)[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mwith[0m[38;2;248;248;242m [0m[38;2;166;226;46mBad_value[0m[38;2;248;248;242m [0m[38;2;190;132;255m_[0m[38;2;248;248;242m [0m[38;2;248;248;242m->[0m[38;2;248;248;242m [0m[38;2;190;132;255m([0m[38;2;190;132;255m)[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;190;132;255m([0m[38;2;190;132;255m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mtry[0m[38;2;248;248;242m bad_value_error [0m[38;2;190;132;255m([0m[38;2;190;132;255m)[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mwith[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;166;226;46mBad_value[0m[38;2;248;248;242m [0m[38;2;190;132;255m_[0m[38;2;248;248;242m [0m[38;2;248;248;242m->[0m[38;2;248;248;242m [0m[38;2;190;132;255m([0m[38;2;190;132;255m)[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;166;226;46mNot_found[0m[38;2;248;248;242m [0m[38;2;248;248;242m->[0m[38;2;248;248;242m [0m[38;2;190;132;255m([0m[38;2;190;132;255m)[0m | ||||
|  | ||||
| [38;2;249;38;114mmodule type [0m[38;2;166;226;46mFOO[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114msig[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mval[0m[38;2;248;248;242m [0m[38;2;166;226;46mfoo[0m[38;2;248;248;242m [0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;102;217;239m'a[0m[38;2;248;248;242m [0m[38;2;248;248;242m->[0m[38;2;248;248;242m [0m[3;38;2;102;217;239m'a[0m | ||||
| [38;2;249;38;114mend[0m | ||||
|  | ||||
| [38;2;249;38;114mmodule[0m[38;2;248;248;242m [0m[38;2;166;226;46mFoo[0m[38;2;248;248;242m [0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;166;226;46mFOO[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114mstruct[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;166;226;46mfoo[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mx[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m x[0m | ||||
| [38;2;249;38;114mend[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;255;255;255mgreeter[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114mobject[0m | ||||
| [38;2;248;248;242m  val greeting [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mHello[0m[38;2;230;219;116m"[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mmethod[0m[38;2;248;248;242m [0m[38;2;166;226;46mgreet[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mname[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;248;248;242mPrintf.[0m[38;2;248;248;242msprintf [0m[38;2;230;219;116m"[0m[38;2;230;219;116m%s, %s![0m[38;2;230;219;116m"[0m[38;2;248;248;242m greeting name [0m | ||||
| [38;2;249;38;114mend[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;255;255;255mgreeting[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m greeter[0m[38;2;248;248;242m#[0m[38;2;248;248;242mgreet[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mworld[0m[38;2;230;219;116m"[0m | ||||
|  | ||||
| [38;2;249;38;114mclass[0m[38;2;248;248;242m [0m[38;2;166;226;46mgreeter_factory[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mgreeting_text[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114mobject[0m[38;2;248;248;242m [0m[38;2;248;248;242m([0m[38;2;166;226;46mself[0m[38;2;248;248;242m)[0m | ||||
| [38;2;248;248;242m  val greeting [0m[38;2;249;38;114m=[0m[38;2;248;248;242m greeting_text[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114mmethod[0m[38;2;248;248;242m [0m[38;2;166;226;46mgreet[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mname[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;248;248;242mPrintf.[0m[38;2;248;248;242msprintf [0m[38;2;230;219;116m"[0m[38;2;230;219;116m%s, %s![0m[38;2;230;219;116m"[0m[38;2;248;248;242m greeting name[0m | ||||
| [38;2;248;248;242m  [0m[38;2;249;38;114minitializer[0m[38;2;248;248;242m [0m[38;2;248;248;242mPrintf.[0m[38;2;248;248;242mprintf [0m[38;2;230;219;116m"[0m[38;2;230;219;116mObjects will greet the user with [0m[38;2;190;132;255m\"[0m[38;2;230;219;116m%s[0m[38;2;190;132;255m\"[0m[38;2;190;132;255m\n[0m[38;2;230;219;116m"[0m[38;2;248;248;242m greeting[0m | ||||
| [38;2;249;38;114mend[0m | ||||
|  | ||||
| [38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;255;255;255mg[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114mnew[0m[38;2;248;248;242m greeter_factory [0m[38;2;230;219;116m"[0m[38;2;230;219;116mHi[0m[38;2;230;219;116m"[0m | ||||
							
								
								
									
										83
									
								
								tests/syntax-tests/source/OCaml/syntax-test.ml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								tests/syntax-tests/source/OCaml/syntax-test.ml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,83 @@ | ||||
| let s = "hello world" | ||||
|  | ||||
| let n : int = 87 | ||||
|  | ||||
| let id x = x | ||||
|  | ||||
| let add x y = x + y | ||||
|  | ||||
| let add' x y = | ||||
|   let left = x in | ||||
|   let right = y in | ||||
|   x + y | ||||
|  | ||||
| let add'' : int -> int -> int = fun x -> fun y -> x + y | ||||
|  | ||||
| let unwrap_option default opt = | ||||
|   match opt with | ||||
|   | None -> default | ||||
|   | Some v -> v | ||||
|  | ||||
| let string_of_bool = function true -> "true" | false -> "false" | ||||
|  | ||||
| let is_a c = | ||||
|   if c = 'a' then true | ||||
|   else false | ||||
|  | ||||
| let _ = Printf.printf "%s" "hello" | ||||
| let () = Printf.printf "%s\n" "world" | ||||
|  | ||||
| let x = ref 0 | ||||
| let _ = x := 1 | ||||
|  | ||||
| type my_bool = True | False | ||||
|  | ||||
| type shape = Circle of float | Square of float | Rectangle of (float * float) | ||||
|  | ||||
| type user = { | ||||
|   login : string; | ||||
|   password : string; | ||||
| } | ||||
|  | ||||
| type 'a my_ref = { mutable ref_value : 'a } | ||||
|  | ||||
| let (:=) r v = r.ref_value <- v | ||||
|  | ||||
| let (+) 2 2 = 5 | ||||
|  | ||||
| exception Bad_value of string | ||||
|  | ||||
| let bad_value_error () = raise (Bad_value "your value is bad and you should feel bad") | ||||
|  | ||||
| let () = | ||||
|   try bad_value_error () | ||||
|   with Bad_value _ -> () | ||||
|  | ||||
| let () = | ||||
|   try bad_value_error () | ||||
|   with | ||||
|   | Bad_value _ -> () | ||||
|   | Not_found -> () | ||||
|  | ||||
| module type FOO = sig | ||||
|   val foo : 'a -> 'a | ||||
| end | ||||
|  | ||||
| module Foo : FOO = struct | ||||
|   let foo x = x | ||||
| end | ||||
|  | ||||
| let greeter = object | ||||
|   val greeting = "Hello" | ||||
|   method greet name = Printf.sprintf "%s, %s!" greeting name  | ||||
| end | ||||
|  | ||||
| let greeting = greeter#greet "world" | ||||
|  | ||||
| class greeter_factory greeting_text = object (self) | ||||
|   val greeting = greeting_text | ||||
|   method greet name = Printf.sprintf "%s, %s!" greeting name | ||||
|   initializer Printf.printf "Objects will greet the user with \"%s\"\n" greeting | ||||
| end | ||||
|  | ||||
| let g = new greeter_factory "Hi" | ||||
		Reference in New Issue
	
	Block a user