Skip to content

Commit

Permalink
Add applicative test for accessor function shorthand
Browse files Browse the repository at this point in the history
  • Loading branch information
MangelMaxime committed Oct 27, 2023
1 parent 4f1b4cd commit ae236c6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/quicktest/Quicktest.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RollForward>Major</RollForward>
<!-- <LangVersion>Preview</LangVersion> -->
<LangVersion>Preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="QuickTest.fs" />
Expand All @@ -12,4 +12,4 @@
<ItemGroup>
<ProjectReference Include="..\Fable.Core\Fable.Core.fsproj" />
</ItemGroup>
</Project>
</Project>
30 changes: 30 additions & 0 deletions tests/Js/Main/ApplicativeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,35 @@ module MultipleInlines =
NonEmptyList("a", ["b"; "c"]) |> mapMyList |> equal (NonEmptyList("a_", ["b_"; "c_"]))
]

module AccessorFunctionShorthand =

type User =
{
Name : string
}

let tests =
[
testCase "Accessor function shorthand works for records" <| fun () ->
let people =
[
{ Name = "John" }
{ Name = "Jane" }
]

let names = people |> List.map _.Name

Check failure on line 1751 in tests/Js/Main/ApplicativeTests.fs

View workflow job for this annotation

GitHub Actions / build-javascript

Unexpected symbol '_' in binding. Expected incomplete structured construct at or before this point or other token.
equal names ["John"; "Jane"]

testCase "Accessor function shorthand works for anonymous records" <| fun () ->
let people =
[
{| Name = "John" |}
{| Name = "Jane" |}
]

let names = people |> List.map _.Name

Check failure on line 1761 in tests/Js/Main/ApplicativeTests.fs

View workflow job for this annotation

GitHub Actions / build-javascript

Unexpected symbol '_' in binding. Expected incomplete structured construct at or before this point or other token.
equal names ["John"; "Jane"]
]
let tests =
testList "Applicative" (
tests1
Expand All @@ -1745,4 +1774,5 @@ let tests =
@ Curry.tests
@ Uncurry.tests
@ MultipleInlines.tests
@ AccessorFunctionShorthand.tests
)
29 changes: 29 additions & 0 deletions tests/Python/TestApplicative.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1684,3 +1684,32 @@ let ``test Trait call works with multiple inlined functions II`` () = // See #28
[<Fact>]
let ``test Identifiers from witnesses don't get duplicated when resolving inline expressions`` () = // See #2855
NonEmptyList("a", ["b"; "c"]) |> mapMyList |> equal (NonEmptyList("a_", ["b_"; "c_"]))

module AccessorFunctionShorthand =

type User =
{
Name : string
}

[<Fact>]
let ``test Accessor function shorthand works for records`` () =
let people : AccessorFunctionShorthand.User list =
[
{ Name = "John" }
{ Name = "Jane" }
]

let names = people |> List.map _.Name

Check failure on line 1703 in tests/Python/TestApplicative.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.10)

Unexpected symbol '_' in binding. Expected incomplete structured construct at or before this point or other token.
equal names ["John"; "Jane"]

[<Fact>]
let ``test Accessor function shorthand works for anonymous records`` () =
let people =
[
{| Name = "John" |}
{| Name = "Jane" |}
]

let names = people |> List.map _.Name

Check failure on line 1714 in tests/Python/TestApplicative.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.10)

Unexpected symbol '_' in binding. Expected incomplete structured construct at or before this point or other token.
equal names ["John"; "Jane"]
29 changes: 29 additions & 0 deletions tests/Rust/tests/src/ApplicativeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1761,3 +1761,32 @@ let ``Trait call works with multiple inlined functions II`` () = // See #2809
[<Fact>]
let ``Identifiers from witnesses don't get duplicated when resolving inline expressions`` () = // See #2855
NonEmptyList("a", ["b"; "c"]) |> mapMyList |> equal (NonEmptyList("a_", ["b_"; "c_"]))

module AccessorFunctionShorthand =

type User =
{
Name : string
}

[<Fact>]
let ``test Accessor function shorthand works for records`` () =
let people : AccessorFunctionShorthand.User list =
[
{ Name = "John" }
{ Name = "Jane" }
]

let names = people |> List.map _.Name

Check failure on line 1780 in tests/Rust/tests/src/ApplicativeTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (default)

Unexpected symbol '_' in binding. Expected incomplete structured construct at or before this point or other token.

Check failure on line 1780 in tests/Rust/tests/src/ApplicativeTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (no_std)

Unexpected symbol '_' in binding. Expected incomplete structured construct at or before this point or other token.
equal names ["John"; "Jane"]

[<Fact>]
let ``test Accessor function shorthand works for anonymous records`` () =
let people =
[
{| Name = "John" |}
{| Name = "Jane" |}
]

let names = people |> List.map _.Name

Check failure on line 1791 in tests/Rust/tests/src/ApplicativeTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (default)

Unexpected symbol '_' in binding. Expected incomplete structured construct at or before this point or other token.

Check failure on line 1791 in tests/Rust/tests/src/ApplicativeTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (no_std)

Unexpected symbol '_' in binding. Expected incomplete structured construct at or before this point or other token.
equal names ["John"; "Jane"]

0 comments on commit ae236c6

Please sign in to comment.