diff --git a/Simulation.sln b/Simulation.sln index bfe0e7c6315..0abbff54fdc 100644 --- a/Simulation.sln +++ b/Simulation.sln @@ -47,6 +47,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library1", "src\Simulation\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library2", "src\Simulation\Simulators.Tests\TestProjects\Library2\Library2.csproj", "{A85277B3-4E07-4E15-8F0C-07CC855A3BCB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library with Spaces", "src\Simulation\Simulators.Tests\TestProjects\Library with Spaces\Library with Spaces.csproj", "{418E79F7-9FCF-4128-AA35-1334A685377D}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "src\Simulation\Simulators.Tests\TestProjects\UnitTests\UnitTests.csproj", "{46278108-D247-4EFC-AC34-23D4A676F62F}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Azure", "Azure", "{37CDC768-16D4-4574-8553-07D99D0A72F7}" @@ -355,6 +357,22 @@ Global {46278108-D247-4EFC-AC34-23D4A676F62F}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU {46278108-D247-4EFC-AC34-23D4A676F62F}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU {46278108-D247-4EFC-AC34-23D4A676F62F}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.Debug|x64.ActiveCfg = Debug|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.Debug|x64.Build.0 = Debug|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.Release|Any CPU.Build.0 = Release|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.Release|x64.ActiveCfg = Release|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.Release|x64.Build.0 = Release|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {418E79F7-9FCF-4128-AA35-1334A685377D}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU {7F05FD87-A2FB-4915-A988-4EF92AB82179}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7F05FD87-A2FB-4915-A988-4EF92AB82179}.Debug|Any CPU.Build.0 = Debug|Any CPU {7F05FD87-A2FB-4915-A988-4EF92AB82179}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -411,6 +429,7 @@ Global {7256B986-6705-42FC-9F57-485D72D9DE51} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820} {A85277B3-4E07-4E15-8F0C-07CC855A3BCB} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820} {46278108-D247-4EFC-AC34-23D4A676F62F} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820} + {418E79F7-9FCF-4128-AA35-1334A685377D} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820} {7F05FD87-A2FB-4915-A988-4EF92AB82179} = {37CDC768-16D4-4574-8553-07D99D0A72F7} {4858E5E3-23FA-4928-B99A-54065875A2B9} = {37CDC768-16D4-4574-8553-07D99D0A72F7} EndGlobalSection diff --git a/src/Simulation/CsharpGeneration.Tests/SimulationCodeTests.fs b/src/Simulation/CsharpGeneration.Tests/SimulationCodeTests.fs index 31fb2e62e04..90416d37e9e 100644 --- a/src/Simulation/CsharpGeneration.Tests/SimulationCodeTests.fs +++ b/src/Simulation/CsharpGeneration.Tests/SimulationCodeTests.fs @@ -7,6 +7,7 @@ open System open System.Collections.Immutable open System.IO open System.Globalization +open System.Web open Microsoft.CodeAnalysis open Microsoft.CodeAnalysis.CSharp @@ -218,9 +219,13 @@ namespace N1 let testOneFile fileName (expected:string) = - let expected = expected.Replace("%%%", (Uri(Path.GetFullPath fileName)).AbsolutePath) - let expected = expected.Replace("%%", (Path.GetFullPath fileName).Replace("\\", "\\\\")) - let tree = parse [(Path.Combine("Circuits","Intrinsic.qs")); fileName] + let fullPath = Path.GetFullPath fileName + let escapeCSharpString (s : string) = SymbolDisplay.FormatLiteral (s, false) + let expected = + expected + |> (fun s -> s.Replace("%%%", fullPath |> HttpUtility.JavaScriptStringEncode |> escapeCSharpString)) + |> (fun s -> s.Replace("%%", fullPath |> escapeCSharpString)) + let tree = parse [Path.Combine ("Circuits", "Intrinsic.qs"); fileName] let actual = CodegenContext.Create (tree, ImmutableDictionary.Empty) |> generate (Path.GetFullPath fileName |> NonNullable.New) @@ -2307,7 +2312,7 @@ namespace N1 false |> testOne randomOperation let testOneClass (_,op : QsCallable) executionTarget (expected : string) = - let expected = expected.Replace("%%%", op.SourceFile.Value) + let expected = expected.Replace("%%%", HttpUtility.JavaScriptStringEncode op.SourceFile.Value) let assemblyConstants = new System.Collections.Generic.KeyValuePair<_,_> (AssemblyConstants.ExecutionTarget, executionTarget) |> Seq.singleton @@ -3397,7 +3402,7 @@ using Microsoft.Quantum.Simulation.Core; #line hidden namespace Microsoft.Quantum.Tests.Inline { - [SourceLocation("%%%", OperationFunctor.Body, 7, -1)] + [SourceLocation("%%", OperationFunctor.Body, 7, -1)] public partial class HelloWorld : Operation, ICallable { public HelloWorld(IOperationFactory m) : base(m) @@ -3454,7 +3459,7 @@ using Microsoft.Quantum.Simulation.Core; #line hidden namespace Microsoft.Quantum.Tests.LineNumbers { - [SourceLocation("%%%", OperationFunctor.Body, 9, -1)] + [SourceLocation("%%", OperationFunctor.Body, 9, -1)] public partial class TestLineInBlocks : Operation, ICallable { public TestLineInBlocks(IOperationFactory m) : base(m) @@ -3628,7 +3633,7 @@ namespace Microsoft.Quantum.Diagnostics #line hidden namespace Microsoft.Quantum.Tests.UnitTests { - [SourceLocation("%%%", OperationFunctor.Body, 22, 26)] + [SourceLocation("%%", OperationFunctor.Body, 22, 26)] public partial class UnitTest1 : Operation, ICallable { public UnitTest1(IOperationFactory m) : base(m) @@ -3651,7 +3656,7 @@ namespace Microsoft.Quantum.Tests.UnitTests [Xunit.Trait("Target", "QuantumSimulator")] [Xunit.Trait("Name", "UnitTest1")] public void UnitTest1() -#line 22 "%%%" +#line 22 "%%" { var sim = new Microsoft.Quantum.Simulation.Simulators.QuantumSimulator(); if (sim is Microsoft.Quantum.Simulation.Common.SimulatorBase baseSim && this.Output != null) @@ -3683,7 +3688,7 @@ namespace Microsoft.Quantum.Tests.UnitTests [Xunit.Trait("Target", "ToffoliSimulator")] [Xunit.Trait("Name", "UnitTest1")] public void UnitTest1() -#line 22 "%%%" +#line 22 "%%" { var sim = new Microsoft.Quantum.Simulation.Simulators.ToffoliSimulator(); if (sim is Microsoft.Quantum.Simulation.Common.SimulatorBase baseSim && this.Output != null) @@ -3721,7 +3726,7 @@ namespace Microsoft.Quantum.Tests.UnitTests } } - [SourceLocation("%%%", OperationFunctor.Body, 26, -1)] + [SourceLocation("%%", OperationFunctor.Body, 26, -1)] public partial class UnitTest2 : Operation, ICallable { public UnitTest2(IOperationFactory m) : base(m) @@ -3744,7 +3749,7 @@ namespace Microsoft.Quantum.Tests.UnitTests [Xunit.Trait("Target", "CustomSimulator")] [Xunit.Trait("Name", "UnitTest2")] public void UnitTest2() -#line 26 "%%%" +#line 26 "%%" { var sim = new SomeNamespace.CustomSimulator(); if (sim is Microsoft.Quantum.Simulation.Common.SimulatorBase baseSim && this.Output != null) diff --git a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj index 1bc1a267e83..03679c61a32 100644 --- a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj +++ b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj @@ -21,7 +21,7 @@ - + diff --git a/src/Simulation/CsharpGeneration/SimulationCode.fs b/src/Simulation/CsharpGeneration/SimulationCode.fs index e0c6b0c0810..30e83926c90 100644 --- a/src/Simulation/CsharpGeneration/SimulationCode.fs +++ b/src/Simulation/CsharpGeneration/SimulationCode.fs @@ -1573,13 +1573,10 @@ module SimulationCode = generator.Apply elements // Returns only those namespaces and their elements that are defined for the given file. - let findLocalElements selector fileName syntaxTree = - let path = - match CompilationBuilder.CompilationUnitManager.TryGetUri fileName with - | true, uri -> uri.AbsolutePath |> NonNullable.New - | false, _ -> NonNullable.New "" + let findLocalElements selector (fileName : NonNullable) syntaxTree = syntaxTree - |> Seq.map (fun ns -> (ns.Name, (FilterBySourceFile.Apply (ns, path)).Elements |> Seq.choose selector |> Seq.toList)) + |> Seq.map (fun ns -> + (ns.Name, (FilterBySourceFile.Apply (ns, fileName)).Elements |> Seq.choose selector |> Seq.toList)) |> Seq.sortBy fst |> Seq.filter (fun (_,elements) -> not elements.IsEmpty) |> Seq.toList diff --git a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj index 93d81f193bb..ce03e2cb766 100644 --- a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj +++ b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj index 03556c866bd..d5553a8964a 100644 --- a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj +++ b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj new file mode 100644 index 00000000000..abfb0b57f2f --- /dev/null +++ b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj @@ -0,0 +1,25 @@ + + + netstandard2.1 + false + false + + + true + + + + + + + + + + + + + diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library.qs b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library.qs new file mode 100644 index 00000000000..eebe352cb30 --- /dev/null +++ b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library.qs @@ -0,0 +1,5 @@ +namespace LibraryWithSpaces { + function HelloQ() : String { + return "Hello quantum world!"; + } +} diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj index 8e69c0a388d..b195d6d4eb0 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj index 8e69c0a388d..b195d6d4eb0 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj index 9326805e5a9..15a9579387e 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/Facts.qs b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/Facts.qs new file mode 100644 index 00000000000..880bdf81a85 --- /dev/null +++ b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/Facts.qs @@ -0,0 +1,37 @@ +namespace Microsoft.Quantum.Testing { + internal function FactI(expected : Int, got : Int) : Unit { + if (expected != got) { + fail $"Expected: {expected}, got: {got}"; + } + } + + internal function FactS(expected : String, got : String) : Unit { + if (expected != got) { + fail $"Expected: {expected}, got: {got}"; + } + } + + internal function FactMyInt1(expected : Int, got : Library1.MyInt) : Unit { + if (expected != got::Value1) { + fail $"Expected: {expected}, got: {got::Value1}"; + } + } + + internal function FactMyInt2(expected : Int, got : Library2.MyInt) : Unit { + if (expected != got::Value2) { + fail $"Expected: {expected}, got: {got::Value2}"; + } + } + + internal function FactMyString1(expected : String, got : Microsoft.Quantum.Library.MyString) : Unit { + if (expected != got::Text) { + fail $"Expected: {expected}, got: {got::Text}"; + } + } + + internal function FactMyString2(expected : String, got : Library2.MyString) : Unit { + if (expected != got::Text) { + fail $"Expected: {expected}, got: {got::Text}"; + } + } +} diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/SpaceTests.qs b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/SpaceTests.qs new file mode 100644 index 00000000000..2faa5616e2b --- /dev/null +++ b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/SpaceTests.qs @@ -0,0 +1,9 @@ +namespace Microsoft.Quantum.Testing.SpacesInFileName { + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Testing; + + @Test("QuantumSimulator") + function LibraryWithSpacesTest() : Unit { + FactS("Hello quantum world!", LibraryWithSpaces.HelloQ()); + } +} diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/Tests.qs b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/TestNameTests.qs similarity index 52% rename from src/Simulation/Simulators.Tests/TestProjects/UnitTests/Tests.qs rename to src/Simulation/Simulators.Tests/TestProjects/UnitTests/TestNameTests.qs index 008f2c9f646..68a3ee38845 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/Tests.qs +++ b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/TestNameTests.qs @@ -2,43 +2,7 @@ open Microsoft.Quantum.Diagnostics; open Microsoft.Quantum.Intrinsic; - - internal function FactI(expected : Int, got : Int) : Unit { - if (expected != got) { - fail $"Expected: {expected}, got: {got}"; - } - } - - internal function FactS(expected : String, got : String) : Unit { - if (expected != got) { - fail $"Expected: {expected}, got: {got}"; - } - } - - internal function FactMyInt1(expected : Int, got : Library1.MyInt) : Unit { - if (expected != got::Value1) { - fail $"Expected: {expected}, got: {got::Value1}"; - } - } - - internal function FactMyInt2(expected : Int, got : Library2.MyInt) : Unit { - if (expected != got::Value2) { - fail $"Expected: {expected}, got: {got::Value2}"; - } - } - - internal function FactMyString1(expected : String, got : Microsoft.Quantum.Library.MyString) : Unit { - if (expected != got::Text) { - fail $"Expected: {expected}, got: {got::Text}"; - } - } - - internal function FactMyString2(expected : String, got : Library2.MyString) : Unit { - if (expected != got::Text) { - fail $"Expected: {expected}, got: {got::Text}"; - } - } - + open Microsoft.Quantum.Testing; @Test("QuantumSimulator") operation BothCallables () : Unit { diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj index 73c103678c0..8ac7acf29f7 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 @@ -15,6 +15,7 @@ + diff --git a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj index cc6001ef292..88591686fa8 100644 --- a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj index 167a6619277..3ae4043c9c0 100644 --- a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,4 @@ - +