Add type printing for App (#33)
Some checks are pending
.NET / check-dotnet-format (push) Waiting to run
.NET / check-nix-format (push) Waiting to run
.NET / Check links (push) Waiting to run
.NET / Check flake (push) Waiting to run
.NET / nuget-pack (push) Waiting to run
.NET / build (Debug) (push) Waiting to run
.NET / build (Release) (push) Waiting to run
.NET / analyzers (push) Waiting to run
.NET / expected-pack (push) Blocked by required conditions
.NET / check-accurate-generations (push) Waiting to run
.NET / all-required-checks-complete (push) Blocked by required conditions
.NET / nuget-publish (push) Blocked by required conditions
.NET / nuget-publish-core (push) Blocked by required conditions
.NET / nuget-publish-fantomas (push) Blocked by required conditions
.NET / nuget-publish-json-plugin (push) Blocked by required conditions
.NET / nuget-publish-json-attrs (push) Blocked by required conditions
.NET / nuget-publish-argparser-plugin (push) Blocked by required conditions
.NET / nuget-publish-argparser-attrs (push) Blocked by required conditions
.NET / nuget-publish-httpclient-plugin (push) Blocked by required conditions
.NET / nuget-publish-httpclient-attrs (push) Blocked by required conditions
.NET / nuget-publish-interfacemock-plugin (push) Blocked by required conditions
.NET / nuget-publish-interfacemock-attrs (push) Blocked by required conditions
.NET / nuget-publish-swagger-plugin (push) Blocked by required conditions

This commit is contained in:
Patrick Stevens
2025-04-21 17:56:07 +01:00
committed by GitHub
parent 5849ddcbdd
commit 2e83aa30bf
3 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
namespace WoofWare.Whippet.Fantomas.Test
open Fantomas.FCS.Syntax
open Fantomas.FCS.Text
open NUnit.Framework
open FsUnitTyped
open WoofWare.Whippet.Fantomas
open Fantomas.FCS
[<TestFixture>]
module TestSynType =
let typeToStringCases =
[ "string", "string" ; "ResizeArray<int>", "ResizeArray<int32>" ]
|> List.map TestCaseData
[<TestCaseSource(nameof typeToStringCases)>]
let ``Snapshot tests for SynType.toHumanReadableString`` (fsharpTypeString : string, expected : string) =
let parsed, diags =
Parse.parseFile false (SourceText.ofString $"let x : %s{fsharpTypeString} = failwith \"\"") []
diags |> shouldBeEmpty
let (SynModuleOrNamespace (decls = parsed)) =
match parsed with
| ParsedInput.ImplFile parsedImplFileInput -> parsedImplFileInput.Contents.[0]
| ParsedInput.SigFile _ -> failwith "logic error"
let (SynBinding (expr = parsed)) =
match List.exactlyOne parsed with
| SynModuleDecl.Let (bindings = bindings) -> bindings.[0]
| _ -> failwith "logic error"
let ty =
match parsed with
| SynExpr.Typed (targetType = targetType) -> targetType
| _ -> failwith $"logic error: %O{parsed}"
SynType.toHumanReadableString ty |> shouldEqual expected

View File

@@ -9,10 +9,12 @@
<ItemGroup> <ItemGroup>
<Compile Include="TestSurface.fs" /> <Compile Include="TestSurface.fs" />
<Compile Include="TestSynType.fs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ApiSurface" Version="4.1.5" /> <PackageReference Include="ApiSurface" Version="4.1.5" />
<PackageReference Include="FsUnit" Version="7.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="NUnit" Version="4.2.2"/> <PackageReference Include="NUnit" Version="4.2.2"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0"/> <PackageReference Include="NUnit3TestAdapter" Version="4.6.0"/>

View File

@@ -508,6 +508,9 @@ module SynType =
| DateOnly -> "DateOnly" | DateOnly -> "DateOnly"
| TimeSpan -> "TimeSpan" | TimeSpan -> "TimeSpan"
| SynType.LongIdent (SynLongIdent.SynLongIdent (ident, _, _)) -> ident |> List.map _.idText |> String.concat "." | SynType.LongIdent (SynLongIdent.SynLongIdent (ident, _, _)) -> ident |> List.map _.idText |> String.concat "."
| SynType.App (ty, _, args, _, _, _, _) ->
let args = args |> Seq.map toHumanReadableString |> String.concat ", "
$"%s{toHumanReadableString ty}<%s{args}>"
| ty -> failwithf "could not compute human-readable string for type: %O" ty | ty -> failwithf "could not compute human-readable string for type: %O" ty
/// Guess whether the types are equal. We err on the side of saying "no, they're different". /// Guess whether the types are equal. We err on the side of saying "no, they're different".