From 5267e59dc1cb470a1b2ed169a5853273bce4af93 Mon Sep 17 00:00:00 2001 From: Clombrong Date: Wed, 2 Jul 2025 01:14:04 +0200 Subject: test(jid): add all RFC7622 examples --- lib/jid.ml | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'lib') diff --git a/lib/jid.ml b/lib/jid.ml index 6bbdd93..d2c7361 100644 --- a/lib/jid.ml +++ b/lib/jid.ml @@ -60,6 +60,9 @@ let show ({ localpart; domainpart; resourcepart } : t) = resourcepart = %s }|} (show_opt localpart) domainpart (show_opt resourcepart) + +(* RFC7622 3.5 examples *) + let%expect_test {|A "bare JID"|} = "juliet@example.com" |> of_string |> show |> print_string; [%expect {| @@ -74,6 +77,46 @@ let%expect_test {|A "full JID"|} = domainpart = "example.com"; resourcepart = Some "foo" } |}] +let%expect_test {|Single space in resourcepart|} = + "juliet@example.com/foo bar" |> of_string |> show |> print_string + +let%expect_test {|"At" sign in resourcepart|} = + "juliet@example.com/foo@bar" |> of_string |> show |> print_string + +let%expect_test {|Single space in localpart, as optionally escaped using the XMPP JID Escaping extension|} = + "foo\\20bar@example.com" |> of_string |> show |> print_string + +let%expect_test {|Another bare JID|} = + "fussball@example.com" |> of_string |> show |> print_string + +let%expect_test {|The third character is LATIN SMALL LETTER SHARP S (U+00DF)|} = + "fußball@example.com" |> of_string |> show |> print_string + +let%expect_test {|A localpart of GREEK SMALL LETTER PI (U+03C0)|} = + "π@example.com" |> of_string |> show |> print_string + +let%expect_test {|A localpart of GREEK CAPITAL LETTER SIGMA (U+03A3)|} = + "Σ@example.com/foo" |> of_string |> show |> print_string + +let%expect_test {|A localpart of GREEK SMALL LETTER SIGMA (U+03C3)|} = + "σ@example.com/foo" |> of_string |> show |> print_string + +let%expect_test {|A localpart of GREEK SMALL LETTER FINAL SIGMA (U+03C2)|} = + "ς@example.com/foo" |> of_string |> show |> print_string + +let%expect_test {|A resourcepart of the Unicode character BLACK CHESS KING (U+265A)|} = + "king@example.com/♚" |> of_string |> show |> print_string + +let%expect_test {|A domainpart|} = + "example.com" |> of_string |> show |> print_string + +let%expect_test {|A domainpart and resourcepart|} = + "example.com/foobar" |> of_string |> show |> print_string + +let%expect_test {|A domainpart followed by a resourcepart that contains an "at" sign|} = + "a.example.com/b@example.net" |> of_string |> show |> print_string + + let to_string ({ localpart; domainpart; resourcepart } : t) = let local = Option.fold ~none:"" ~some:(fun l -> l ^ "@") localpart and resource = Option.fold ~none:"" ~some:(fun r -> "/" ^ r) resourcepart -- cgit v1.2.3