Skip to content

Commit

Permalink
Add test for equality of entities from assemblies with the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
auduchinok committed Apr 2, 2018
1 parent 0c7c3bc commit 8cf0d21
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/service/CSharpProjectAnalysis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,47 @@ let _ = CSharpClass(0)
Seq.exists (fun (mfv : FSharpMemberOrFunctionOrValue) -> mfv.IsEffectivelySameAs ctor) members |> should be True
| None -> failwith "Expected Some for DeclaringEntity"

let getEntitiesUses source =
let csharpAssembly = PathRelativeToTestAssembly "CSharp_Analysis.dll"
let results, _ = getProjectReferences(source, [csharpAssembly], None, None)
results.GetAllUsesOfAllSymbols()
|> Async.RunSynchronously
|> Seq.choose (fun su ->
match su.Symbol with
| :? FSharpEntity as entity -> Some entity
| _ -> None)
|> List.ofSeq

[<Test>]
let ``Different types with the same short name equality check`` () =
let source = """
module CtorTest
let (s1: System.String) = null
let (s2: FSharp.Compiler.Service.Tests.String) = null
"""

let stringSymbols =
getEntitiesUses source
|> List.filter (fun entity -> entity.LogicalName = "String")

match stringSymbols with
| e1 :: e2 :: [] -> e1.IsEffectivelySameAs(e2) |> should be False
| _ -> sprintf "Expecting two symbols, got %A" stringSymbols |> failwith

[<Test>]
let ``Different namespaces with the same short name equality check`` () =
let source = """
module CtorTest
open System.Linq
open FSharp.Compiler.Service.Tests.Linq
"""

let stringSymbols =
getEntitiesUses source
|> List.filter (fun entity -> entity.LogicalName = "Linq")

match stringSymbols with
| e1 :: e2 :: [] -> e1.IsEffectivelySameAs(e2) |> should be False
| _ -> sprintf "Expecting two symbols, got %A" stringSymbols |> failwith
10 changes: 10 additions & 0 deletions tests/service/data/CSharp_Analysis/CSharpClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,14 @@ public static int StaticMember()
}
}

public class String
{
}

namespace Linq
{
public class DummyClass
{
}
}
}

0 comments on commit 8cf0d21

Please sign in to comment.