forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManglingNameOfProvidedTypes.fs
71 lines (59 loc) · 2.82 KB
/
ManglingNameOfProvidedTypes.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace FSharp.Compiler.UnitTests
open System
open System.Text
open Xunit
open FSharp.Test
open FSharp.Test.Utilities
open FSharp.Compiler.Syntax
type ManglingNamesOfProvidedTypesWithSingleParameter() =
[<Fact>]
member this.MangleWithNonDefaultValue() =
let mangled =
PrettyNaming.ComputeMangledNameWithoutDefaultArgValues("MyNamespace.Test", [| "xyz" |], [| "Foo", Some "abc" |])
Assert.shouldBe "MyNamespace.Test,Foo=\"xyz\"" mangled
[<Fact>]
member this.MangleWithDefaultValue() =
let mangled =
PrettyNaming.ComputeMangledNameWithoutDefaultArgValues("MyNamespace.Test", [| "xyz" |], [| "Foo", Some "xyz" |])
Assert.shouldBe "MyNamespace.Test" mangled
[<Fact>]
member this.DemangleNonDefaultValue() =
let name, parameters = PrettyNaming.DemangleProvidedTypeName "MyNamespace.Test,Foo=\"xyz\""
Assert.shouldBe "MyNamespace.Test" name
Assert.shouldBeEquivalentTo [| "Foo", "xyz" |] parameters
[<Fact>]
member this.DemangleDefaultValue() =
let name, parameters = PrettyNaming.DemangleProvidedTypeName "MyNamespace.Test,"
Assert.shouldBe "MyNamespace.Test" name
Assert.shouldBeEquivalentTo [||] parameters
[<Fact>]
member this.DemangleNewDefaultValue() =
let name, parameters = PrettyNaming.DemangleProvidedTypeName "MyNamespace.Test"
Assert.shouldBe "MyNamespace.Test" name
Assert.shouldBeEquivalentTo [||] parameters
type ManglingNamesOfProvidedTypesWithMultipleParameter() =
[<Fact>]
member this.MangleWithNonDefaultValue() =
let mangled =
PrettyNaming.ComputeMangledNameWithoutDefaultArgValues
("MyNamespace.Test", [| "xyz"; "abc" |],
[| "Foo", Some "foo"
"Foo2", Some "foo2" |])
Assert.shouldBe "MyNamespace.Test,Foo=\"xyz\",Foo2=\"abc\"" mangled
[<Fact>]
member this.MangleWithDefaultValue() =
let mangled =
PrettyNaming.ComputeMangledNameWithoutDefaultArgValues
("MyNamespace.Test", [| "xyz"; "abc" |],
[| "Foo", Some "xyz"
"Foo2", Some "abc" |])
Assert.shouldBe "MyNamespace.Test" mangled
[<Fact>]
member this.DemangleMultiParameter() =
let smashtogether arr = arr |> Seq.fold(fun acc (f,s) -> acc + $"-{f}-{s}") ""
let name, parameters = PrettyNaming.DemangleProvidedTypeName "TestType,Foo=\"xyz\",Foo2=\"abc\""
Assert.shouldBe "TestType" name
let parameters = smashtogether parameters
let expected = smashtogether [| "Foo", "xyz"; "Foo2", "abc" |]
Assert.shouldBe expected parameters