123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178openPpx_yojson_conv_lib.Yojson_conv.Primitivesopen!Awso.ImportmoduleStdlib=StdlibmoduleAttribute=structtyperaw_attribute={name:string;value:stringoption}[@@derivingyojson]typet=[`Unknownofraw_attribute|`Customofraw_attribute|`Genderofstring|`Family_nameofstring|`Localeofstring|`Middle_nameofstringoption|`Nicknameofstring|`Profileofstringoption|`Websiteofstringoption|`Pictureofstring|`Emailofstring|`Nameofstring|`Updated_atofstring|`Preferred_user_nameofstringoption|`Given_nameofstring][@@derivingyojson]endtypeattribute=Attribute.t[@@derivingyojson]typet={username:string;attributes:attributelist;access_token:string}[@@derivingyojson]typemsg=stringletrequired_attributet~name~f=matchList.find_mapt.attributes~fwith|Somex->Okx|None->Error(sprintf"%s attribute required but not present"name);;letrequired_attribute_exnt~name~f=Result.ok_or_failwith(required_attributet~name~f);;let%expect_test"required_attribute"=letcall~attributes=letuser={username="";attributes;access_token=""}inletname="name"inletf=function|`Namen->Somen|_->Noneinrequired_attributeuser~name~finlettest~attributes=matchcall~attributeswith|Oks->printf"Ok %s"s|Errors->printf"Error %s"sintest~attributes:[`Name"foo"];[%expect{|Ok foo|}];test~attributes:[`Email"foo"];[%expect{|Error name attribute required but not present|}];;letoptional_attributet~f=List.find_mapt.attributes~flet%expect_test"optional_attribute"=lettest~attributes=letuser={username="";attributes;access_token=""}inletf=function|`Namen->Somen|_->Noneinmatchoptional_attributeuser~fwith|Somes->printf"Some %s"s|None->printf"None"intest~attributes:[`Name"foo"];[%expect{|Some foo|}];test~attributes:[`Email"foo"];[%expect{|None|}];;letemailt=required_attributet~name:"email"~f:(function|`Emaile->Somee|_->None);;letemail_exnt=Result.ok_or_failwith(emailt)let%expect_test"email"=letcall~attributes=email{username="";attributes;access_token=""}inlettest~attributes=matchcall~attributeswith|Oks->printf"Ok %s"s|Errors->printf"Error %s"sintest~attributes:[`Email"foo"];[%expect{|Ok foo|}];test~attributes:[`Name"foo"];[%expect{|Error email attribute required but not present|}];;letpreferred_namet=optional_attributet~f:(function|`Preferred_user_namee->Somee|_->None);;let%expect_test"preferred_name"=lettest~attributes=matchpreferred_name{username="";attributes;access_token=""}with|Some(Somes)->printf"Some (Some %s)"s|SomeNone->printf"Some None"|None->printf"None"intest~attributes:[`Preferred_user_name(Some"foo")];[%expect{|Some (Some foo)|}];test~attributes:[`Preferred_user_nameNone];[%expect{|Some None|}];test~attributes:[`Email"foo"];[%expect{|None|}];;letfamily_namet=required_attributet~name:"family_name"~f:(function|`Family_namee->Somee|_->None);;letfamily_name_exnt=Result.ok_or_failwith(family_namet)let%expect_test"family_name"=letcall~attributes=family_name{username="";attributes;access_token=""}inlettest~attributes=matchcall~attributeswith|Oks->printf"Ok %s"s|Errors->printf"Error %s"sintest~attributes:[`Family_name"foo"];[%expect{|Ok foo|}];test~attributes:[`Name"foo"];[%expect{|Error family_name attribute required but not present|}];;letnamet=optional_attributet~f:(function|`Namee->Somee|_->None);;let%expect_test"name"=lettest~attributes=matchname{username="";attributes;access_token=""}with|Somes->printf"Some %s"s|None->printf"None"intest~attributes:[`Name"foo"];[%expect{|Some foo|}];test~attributes:[`Email"foo"];[%expect{|None|}];;moduleExn=structletrequired_attribute=required_attribute_exnletemail=email_exnletfamily_name=family_name_exnend