@@ -710,3 +710,105 @@ let ceResult =
710710check "grwerjkrwejgk42" ceResult.Value 2
711711 """
712712
713+ let overloadLib includeInternalExtensions includeExternalExtensions =
714+ """
715+ open System
716+
717+ type Content = ArraySegment<byte> list
718+
719+ type ContentBuilder() =
720+ member this.Run(c: Content) =
721+ let crlf = "\r\n"B
722+ [|for part in List.rev c do
723+ yield! part.Array.[part.Offset..(part.Count+part.Offset-1)]
724+ yield! crlf |]
725+
726+ member this.Yield(_) = []
727+
728+ [<CustomOperation("body")>]
729+ member this.Body(c: Content, segment) =
730+ segment::c
731+ """ + ( if includeInternalExtensions then """
732+
733+ type ContentBuilder with
734+ [<CustomOperation("body")>]
735+ member this.Body(c: Content, bytes: byte[], offset, count) =
736+ ArraySegment<byte>(bytes, offset, count)::c
737+ """ else """
738+
739+ [<CustomOperation("body")>]
740+ member this.Body(c: Content, bytes: byte[], offset, count) =
741+ ArraySegment<byte>(bytes, offset, count)::c
742+ """ ) + ( if includeExternalExtensions then """
743+
744+ module Extensions =
745+ type ContentBuilder with
746+ [<CustomOperation("body")>]
747+ member this.Body(c: Content, [<ParamArray>] contents: string[]) =
748+ let rec loop acc (contents: string list) =
749+ match contents with
750+ | [] -> acc
751+ | content::rest ->
752+ let bytes = Text.Encoding.ASCII.GetBytes(content)
753+ loop (this.Body(c, bytes, 0, bytes.Length)) rest
754+ loop c (List.ofArray contents)
755+ """ else """
756+
757+ [<CustomOperation("body")>]
758+ member this.Body(c: Content, [<ParamArray>] contents: string[]) =
759+ let rec loop acc (contents: string list) =
760+ match contents with
761+ | [] -> acc
762+ | content::rest ->
763+ let bytes = Text.Encoding.ASCII.GetBytes(content)
764+ loop (this.Body(c, bytes, 0, bytes.Length)) rest
765+ loop c (List.ofArray contents)
766+ """ ) + """
767+
768+ let check msg actual expected = if actual <> expected then failwithf "FAILED %s , expected %A , got %A " msg expected actual
769+ """
770+
771+ let OverloadLibTest inclInternalExt inclExternalExt source =
772+ CompilerAssert.CompileExeAndRunWithOptions [| " /langversion:preview" |] ( overloadLib inclInternalExt inclExternalExt + source)
773+
774+ [<Test>]
775+ let ``OverloadLib accepts overloaded methods`` () =
776+ OverloadLibTest false false """
777+ let content = ContentBuilder()
778+ let ceResult =
779+ content {
780+ body "Name"
781+ body (ArraySegment<_>("Email"B, 0, 5))
782+ body "Password"B 2 4
783+ body "Description" "of" "content"
784+ }
785+ check "TmFtZVxyXG5FbWF1" ceResult "Name\r\nEmail\r\nsswo\r\nDescription\r\nof\r\ncontent\r\n"B
786+ """
787+
788+ [<Test>]
789+ let ``OverloadLib accepts overloaded internal extension methods`` () =
790+ OverloadLibTest true false """
791+ let content = ContentBuilder()
792+ let ceResult =
793+ content {
794+ body "Name"
795+ body (ArraySegment<_>("Email"B, 0, 5))
796+ body "Password"B 2 4
797+ body "Description" "of" "content"
798+ }
799+ check "TmFtZVxyXG5FbWF2" ceResult "Name\r\nEmail\r\nsswo\r\nDescription\r\nof\r\ncontent\r\n"B
800+ """
801+
802+ [<Test>]
803+ let ``OverloadLib accepts overloaded internal and external extensions`` () =
804+ OverloadLibTest true true """
805+ let content = ContentBuilder()
806+ let ceResult =
807+ content {
808+ body "Name"
809+ body (ArraySegment<_>("Email"B, 0, 5))
810+ body "Password"B 2 4
811+ body "Description" "of" "content"
812+ }
813+ check "TmFtZVxyXG5FbWF3" ceResult "Name\r\nEmail\r\nsswo\r\nDescription\r\nof\r\ncontent\r\n"B
814+ """
0 commit comments