Skip to content

Commit c6f4e47

Browse files
committed
Expand test cases for overloaded CE members
1 parent 7f7b4f7 commit c6f4e47

File tree

2 files changed

+118
-15
lines changed

2 files changed

+118
-15
lines changed

tests/fsharp/Compiler/Conformance/DataExpressions/ComputationExpressions.fs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,3 +710,105 @@ let ceResult =
710710
check "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+
"""

tests/fsharp/typecheck/sigs/neg60.fs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,39 +95,40 @@ module QuerySyntaxWithValidOverloading =
9595
type ContentBuilder() =
9696
member this.Run(c: Content) =
9797
let crlf = "\r\n"B
98-
[|for part in c do
99-
yield! part.Array.[part.Offset..part.Count]
98+
[|for part in List.rev c do
99+
yield! part.Array.[part.Offset..(part.Count+part.Offset-1)]
100100
yield! crlf |]
101101

102102
member this.Yield(_) = []
103-
103+
104104
[<CustomOperation("body")>]
105-
member this.Body(c, segment) =
105+
member this.Body(c: Content, segment: ArraySegment<byte>) =
106106
segment::c
107107

108108
[<CustomOperation("body")>]
109-
member this.Body(c, bytes, offset, count) =
110-
this.Body(c, ArraySegment(bytes, offset, count))
109+
member this.Body(c: Content, bytes: byte[], offset, count) =
110+
ArraySegment<byte>(bytes, offset, count)::c
111111

112112
[<CustomOperation("body")>]
113-
member this.Body(c, bytes: byte[]) =
114-
this.Body(c, bytes, 0, bytes.Length)
113+
member this.Body(c: Content, [<ParamArray>] contents: string[]) =
114+
let rec loop acc (contents: string list) =
115+
match contents with
116+
| [] -> acc
117+
| content::rest ->
118+
let bytes = Text.Encoding.ASCII.GetBytes(content)
119+
loop (this.Body(c, bytes, 0, bytes.Length)) rest
120+
loop c (List.ofArray contents)
115121

116-
[<CustomOperation("body")>]
117-
member this.Body(c, text:string) =
118-
let bytes = Text.Encoding.ASCII.GetBytes(text)
119-
this.Body(c, bytes)
120-
121122
let content = ContentBuilder()
122123

123124
//---------------------------------------------------------------
124125

125126
let values =
126127
content {
127128
body "Name"
128-
body "Email"B
129+
body (ArraySegment<_>("Email"B, 0, 5))
129130
body "Password"B 2 4
130-
body (ArraySegment("Description"B, 0, 4))
131+
body "Description" "of" "content"
131132
}
132133

133134
module QuerySyntaxWithOptionalParamAndParamsArray =

0 commit comments

Comments
 (0)