Punycode (RFC3492) in OCaml

fix(lint): use failf instead of fail (Fmt.str ...) (E616)

+19 -22
+17 -20
test/test_punycode.ml
··· 30 30 let result = Punycode.encode input in 31 31 check string "encode" expected result 32 32 with Punycode.Error e -> 33 - fail (Fmt.str "encode failed: %a" Punycode.pp_error_reason e) 33 + failf "encode failed: %a" Punycode.pp_error_reason e 34 34 35 35 let check_decode_ok expected input = 36 36 try ··· 44 44 (Uchar.to_int u)) 45 45 result 46 46 with Punycode.Error e -> 47 - fail (Fmt.str "decode failed: %a" Punycode.pp_error_reason e) 47 + failf "decode failed: %a" Punycode.pp_error_reason e 48 48 49 49 let check_utf8_roundtrip s = 50 50 try ··· 52 52 let decoded = Punycode.decode_utf8 encoded in 53 53 check string "roundtrip" s decoded 54 54 with Punycode.Error e -> 55 - fail (Fmt.str "roundtrip failed: %a" Punycode.pp_error_reason e) 55 + failf "roundtrip failed: %a" Punycode.pp_error_reason e 56 56 57 57 (* RFC 3492 Section 7.1 Test Vectors *) 58 58 ··· 608 608 let result = Punycode.encode_label "example" in 609 609 check string "ascii passthrough" "example" result 610 610 with Punycode.Error e -> 611 - fail (Fmt.str "encode_label failed: %a" Punycode.pp_error_reason e) 611 + failf "encode_label failed: %a" Punycode.pp_error_reason e 612 612 613 613 let test_label_encode_german () = 614 614 try 615 615 let result = Punycode.encode_label "münchen" in 616 616 check string "german label" "xn--mnchen-3ya" result 617 617 with Punycode.Error e -> 618 - fail (Fmt.str "encode_label failed: %a" Punycode.pp_error_reason e) 618 + failf "encode_label failed: %a" Punycode.pp_error_reason e 619 619 620 620 let test_label_decode_german () = 621 621 try 622 622 let result = Punycode.decode_label "xn--mnchen-3ya" in 623 623 check string "german decode" "münchen" result 624 624 with Punycode.Error e -> 625 - fail (Fmt.str "decode_label failed: %a" Punycode.pp_error_reason e) 625 + failf "decode_label failed: %a" Punycode.pp_error_reason e 626 626 627 627 (* IDNA tests *) 628 628 let test_idna_to_ascii_simple () = ··· 630 630 let result = Punycode_idna.to_ascii "münchen.example.com" in 631 631 check string "idna to_ascii" "xn--mnchen-3ya.example.com" result 632 632 with Punycode_idna.Error e -> 633 - fail (Fmt.str "to_ascii failed: %a" Punycode_idna.pp_error_reason e) 633 + failf "to_ascii failed: %a" Punycode_idna.pp_error_reason e 634 634 635 635 let test_idna_to_unicode_simple () = 636 636 try 637 637 let result = Punycode_idna.to_unicode "xn--mnchen-3ya.example.com" in 638 638 check string "idna to_unicode" "münchen.example.com" result 639 639 with Punycode_idna.Error e -> 640 - fail (Fmt.str "to_unicode failed: %a" Punycode_idna.pp_error_reason e) 640 + failf "to_unicode failed: %a" Punycode_idna.pp_error_reason e 641 641 642 642 let test_idna_roundtrip () = 643 643 let original = "münchen.example.com" in ··· 646 646 let unicode = Punycode_idna.to_unicode ascii in 647 647 check string "idna roundtrip" original unicode 648 648 with Punycode_idna.Error e -> 649 - fail (Fmt.str "roundtrip failed: %a" Punycode_idna.pp_error_reason e) 649 + failf "roundtrip failed: %a" Punycode_idna.pp_error_reason e 650 650 651 651 let test_idna_all_ascii () = 652 652 try 653 653 let result = Punycode_idna.to_ascii "www.example.com" in 654 654 check string "all ascii passthrough" "www.example.com" result 655 655 with Punycode_idna.Error e -> 656 - fail (Fmt.str "to_ascii failed: %a" Punycode_idna.pp_error_reason e) 656 + failf "to_ascii failed: %a" Punycode_idna.pp_error_reason e 657 657 658 658 let test_idna_mixed_labels () = 659 659 try ··· 664 664 (String.length result > 12 665 665 && String.sub result (String.length result - 12) 12 = ".example.com") 666 666 with Punycode_idna.Error e -> 667 - fail (Fmt.str "to_ascii failed: %a" Punycode_idna.pp_error_reason e) 667 + failf "to_ascii failed: %a" Punycode_idna.pp_error_reason e 668 668 669 669 (* Case annotation tests *) 670 670 let test_case_annotation_decode () = ··· 683 683 (* a should be lowercase *) 684 684 check bool "a lowercase" true (case_flags.(1) = Punycode.Lowercase) 685 685 with Punycode.Error e -> 686 - fail (Fmt.str "decode_with_case failed: %a" Punycode.pp_error_reason e) 686 + failf "decode_with_case failed: %a" Punycode.pp_error_reason e 687 687 688 688 let test_case_annotation_encode () = 689 689 let codepoints = codepoints_of_hex_list [ 0x0061; 0x0062; 0x0063 ] in ··· 696 696 (* Should encode as "AbC-" (basic code points with case annotation) *) 697 697 check string "case encoded" "AbC-" result 698 698 with Punycode.Error e -> 699 - fail (Fmt.str "encode_with_case failed: %a" Punycode.pp_error_reason e) 699 + failf "encode_with_case failed: %a" Punycode.pp_error_reason e 700 700 701 701 (* Edge case tests *) 702 702 let test_empty_input () = ··· 717 717 let result = Punycode.encode input in 718 718 check string "pure ascii" "hello-" result 719 719 with Punycode.Error e -> 720 - fail (Fmt.str "encode failed: %a" Punycode.pp_error_reason e) 720 + failf "encode failed: %a" Punycode.pp_error_reason e 721 721 722 722 let test_invalid_digit () = 723 723 try ··· 725 725 fail "should fail on invalid digit" 726 726 with 727 727 | Punycode.Error (Punycode.Invalid_digit _) -> () 728 - | Punycode.Error e -> 729 - fail (Fmt.str "wrong error type: %a" Punycode.pp_error_reason e) 728 + | Punycode.Error e -> failf "wrong error type: %a" Punycode.pp_error_reason e 730 729 731 730 let test_label_too_long () = 732 731 let long_label = String.make 100 'a' in ··· 735 734 fail "should fail on long label" 736 735 with 737 736 | Punycode.Error (Punycode.Label_too_long _) -> () 738 - | Punycode.Error e -> 739 - fail (Fmt.str "wrong error type: %a" Punycode.pp_error_reason e) 737 + | Punycode.Error e -> failf "wrong error type: %a" Punycode.pp_error_reason e 740 738 741 739 let test_empty_label () = 742 740 try ··· 744 742 fail "should fail on empty label" 745 743 with 746 744 | Punycode.Error Punycode.Empty_label -> () 747 - | Punycode.Error e -> 748 - fail (Fmt.str "wrong error type: %a" Punycode.pp_error_reason e) 745 + | Punycode.Error e -> failf "wrong error type: %a" Punycode.pp_error_reason e 749 746 750 747 (* Validation tests *) 751 748 let test_is_basic () =
+2 -2
test/test_punycode_idna.ml
··· 14 14 let result = Punycode_idna.to_ascii input in 15 15 check string msg expected result 16 16 with Punycode_idna.Error e -> 17 - fail (Fmt.str "%s: to_ascii failed: %a" msg Punycode_idna.pp_error_reason e) 17 + failf "%s: to_ascii failed: %a" msg Punycode_idna.pp_error_reason e 18 18 19 19 let check_to_unicode ~msg expected input = 20 20 try ··· 54 54 let check_raises_error ~msg f = 55 55 try 56 56 ignore (f ()); 57 - fail (Fmt.str "%s: expected Error but succeeded" msg) 57 + failf "%s: expected Error but succeeded" msg 58 58 with Punycode_idna.Error _ -> () 59 59 60 60 (* {1 to_ascii Test Vectors} *)