Skip to content

Commit

Permalink
Merge pull request #290 from talex5/astring
Browse files Browse the repository at this point in the history
Use String.starts_with instead of Astring
  • Loading branch information
talex5 authored Nov 18, 2024
2 parents c120635 + 9a1af2d commit 05a56f9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion test-bin/calc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ let () =
Logs.set_reporter reporter;
Logs.set_level ~all:true (Some Logs.Info);
Logs.Src.list () |> List.iter (fun src ->
if Astring.String.is_prefix ~affix:"capnp" (Logs.Src.name src) then
if String.starts_with ~prefix:"capnp" (Logs.Src.name src) then
Logs.Src.set_level src (Some Logs.Debug);
);
let doc = "a calculator example" in
Expand Down
6 changes: 2 additions & 4 deletions test/proto/test.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Astring

module Core_types = Testbed.Capnp_direct.Core_types
module Request = Testbed.Capnp_direct.String_content.Request
module Response = Testbed.Capnp_direct.String_content.Response
Expand Down Expand Up @@ -954,12 +952,12 @@ let test_shorten_field () =
let ensure_is_cycle_error (x:#Core_types.struct_ref) : unit =
match x#response with
| Some (Error (`Exception ex))
when (String.is_prefix ~affix:"Attempt to create a cycle detected:" ex.Exception.reason) -> ()
when (String.starts_with ~prefix:"Attempt to create a cycle detected:" ex.Exception.reason) -> ()
| _ -> Alcotest.fail (Fmt.str "Not a cycle error: %t" x#pp)

let ensure_is_cycle_error_cap cap =
match cap#problem with
| Some ex when (String.is_prefix ~affix:"<cycle: " ex.Exception.reason) -> ()
| Some ex when (String.starts_with ~prefix:"<cycle: " ex.Exception.reason) -> ()
| _ -> Alcotest.fail (Fmt.str "Not a cycle error: %t" cap#pp)

let test_cycle () =
Expand Down
3 changes: 1 addition & 2 deletions test/test.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
open Eio.Std
open Astring
open Testlib
open Capnp_rpc.Std
open Capnp_rpc_net
Expand Down Expand Up @@ -147,7 +146,7 @@ let test_bad_crypto ~net =
| Ok _ -> Alcotest.fail "Wrong TLS key should have been rejected"
| Error e ->
let msg = Fmt.to_to_string Capnp_rpc.Exception.pp e in
assert (String.is_prefix ~affix:"Failed: TLS connection failed: TLS failure: authentication failure" msg);
assert (String.starts_with ~prefix:"Failed: TLS connection failed: TLS failure: authentication failure" msg);
Logs.info (fun f -> f "Wait for server to log warning...");
while Logs.warn_count () = old_warnings do
Fiber.yield ()
Expand Down
3 changes: 1 addition & 2 deletions unix/capnp_rpc_unix.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
open Eio.Std
open Astring

module Log = Capnp_rpc.Debug.Log

Expand Down Expand Up @@ -61,7 +60,7 @@ end

let sturdy_uri =
let of_string s =
if String.is_prefix s ~affix:"capnp://" then parse_uri s
if String.starts_with s ~prefix:"capnp://" then parse_uri s
else if Sys.file_exists s then Cap_file.load_uri s
else error "Expected a URI starting with \"capnp://\" \
or the path to a file containing such a URI, but got %S." s
Expand Down

0 comments on commit 05a56f9

Please sign in to comment.