Skip to content

Commit 475746a

Browse files
authored
Migrate byref tests (#15760)
* Migrate byref tests from legacy test suite
1 parent 1f55b85 commit 475746a

File tree

110 files changed

+2542
-1991
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+2542
-1991
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
open Prelude
2+
3+
module ByRefParam =
4+
type C() =
5+
static member M(x: byref<int>) = x <- 5
6+
let mutable res = 9
7+
let v = C.M(&res)
8+
check "cwvereweoiwekl4" res 5
9+
10+
let minfo = typeof<C>.GetMethod("M")
11+
check "cwnoreeker1" (minfo.GetParameters().[0].IsIn) false
12+
check "cwnoreeker2" (minfo.GetParameters().[0].IsOut) false
13+
check "cwnoreeker3" (minfo.ReturnParameter.IsIn) false
14+
check "cwnoreeker4" (minfo.ReturnParameter.IsOut) false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
open Prelude
2+
3+
module ByRefParam_ExplicitInAttribute =
4+
type C() =
5+
static member M([<System.Runtime.InteropServices.In>] x: byref<int>) = x <- 5
6+
let mutable res = 9
7+
let v = C.M(&res)
8+
check "cwvereweoiwekl4" res 5
9+
10+
let minfo = typeof<C>.GetMethod("M")
11+
check "cwnoreeker9" (minfo.GetParameters().[0].IsIn) true
12+
check "cwnoreekerq" (minfo.GetParameters().[0].IsOut) false
13+
check "cwnoreeker6c" (minfo.GetParameters().[0].GetRequiredCustomModifiers().Length) 0
14+
check "cwnoreekers2" (minfo.ReturnParameter.GetRequiredCustomModifiers().Length) 0
15+
check "cwnoreekerw" (minfo.ReturnParameter.IsIn) false
16+
check "cwnoreekere" (minfo.ReturnParameter.IsOut) false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
open Prelude
2+
3+
module ByRefParam_ExplicitOutAttribute =
4+
type C() =
5+
static member M([<System.Runtime.InteropServices.Out>] x: byref<int>) = x <- 5
6+
let mutable res = 9
7+
let v = C.M(&res)
8+
check "cwvereweoiwekl4" res 5
9+
10+
let minfo = typeof<C>.GetMethod("M")
11+
check "cwnoreeker5" (minfo.GetParameters().[0].IsIn) false
12+
check "cwnoreeker6a" (minfo.GetParameters().[0].IsOut) true
13+
check "cwnoreeker6b" (minfo.GetParameters().[0].GetRequiredCustomModifiers().Length) 0
14+
check "cwnoreekers1" (minfo.ReturnParameter.GetRequiredCustomModifiers().Length) 0
15+
check "cwnoreeker7" (minfo.ReturnParameter.IsIn) false
16+
check "cwnoreeker8" (minfo.ReturnParameter.IsOut) false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
open Prelude
2+
3+
module ByRefParam_OverloadedTest_ExplicitOutAttribute =
4+
type C() =
5+
static member M(a: int, [<System.Runtime.InteropServices.Out>] x: byref<int>) = x <- 7
6+
static member M(a: string, [<System.Runtime.InteropServices.Out>] x: byref<int>) = x <- 8
7+
let mutable res = 9
8+
C.M("a", &res)
9+
check "cweweoiwek2cbe9" res 8
10+
C.M(3, &res)
11+
check "cweweoiwek28498" res 7
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
open Prelude
2+
3+
module ByRefReturn =
4+
type C() =
5+
static member M(x: byref<int>) = x <- x + 1; &x
6+
let mutable res = 9
7+
let v = C.M(&res)
8+
check "cwvereweoiwvw4" v 10
9+
10+
let minfo = typeof<C>.GetMethod("M")
11+
check "cwnoreeker6d" (minfo.GetParameters().[0].GetRequiredCustomModifiers().Length) 0
12+
check "cwnoreekerr" (minfo.ReturnParameter.IsIn) false
13+
check "cwnoreekert" (minfo.ReturnParameter.IsOut) false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
open Prelude
2+
3+
module TestArrayParam =
4+
5+
let f (x:int[]) = &x.[0]
6+
7+
let test() =
8+
let r = [| 1 |]
9+
let addr = &f r
10+
addr <- addr + 1
11+
check2 "cepojcwem14" 2 r.[0]
12+
13+
test()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
open Prelude
2+
3+
module TestBaseCall =
4+
type Incrementor(z) =
5+
abstract member Increment : int byref * int byref -> unit
6+
default this.Increment(i : int byref,j : int byref) =
7+
i <- i + z
8+
9+
type Decrementor(z) =
10+
inherit Incrementor(z)
11+
override this.Increment(i, j) =
12+
base.Increment(&i, &j)
13+
14+
i <- i - z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
open Prelude
2+
3+
module TestClassParamMutableField =
4+
5+
type C() = [<DefaultValue>] val mutable z : int
6+
7+
let f (x:C) = &x.z
8+
9+
let test() =
10+
let c = C()
11+
let addr = &f c
12+
addr <- addr + 1
13+
check2 "cepojcwem13b" 1 c.z
14+
15+
test()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
open Prelude
2+
3+
module TestConditionalReturn =
4+
let mutable x = 1
5+
let mutable y = 1
6+
7+
let f inp = if inp = 3 then &x else &y
8+
9+
let test() =
10+
let addr = &f 3
11+
addr <- addr + 1
12+
check2 "cepojcwem6" 2 x
13+
check2 "cepojcwem7" 1 y
14+
let addr = &f 4
15+
addr <- addr + 1
16+
check2 "cepojcwem8" 2 x
17+
check2 "cepojcwem9" 2 y
18+
19+
let test2() =
20+
let res = f 3
21+
let res2 = res + 1
22+
check2 "cepojcwem8b" 3 res2
23+
check2 "cepojcwem9b" 2 res
24+
25+
test()
26+
test2()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
open Prelude
2+
3+
module TestDelegateMethod =
4+
let mutable x = 1
5+
6+
type D = delegate of unit -> byref<int>
7+
8+
let d() = D(fun () -> &x)
9+
10+
let f (d:D) = &d.Invoke()
11+
12+
let test() =
13+
let addr = &f (d())
14+
check2 "cepojcwem18a" 1 x
15+
addr <- addr + 1
16+
check2 "cepojcwem18b" 2 x
17+
18+
test()

0 commit comments

Comments
 (0)