diff --git a/.gitignore b/.gitignore index 15918cfa29..f81a9f8ee0 100644 --- a/.gitignore +++ b/.gitignore @@ -216,7 +216,6 @@ release.sh localpackages/ paket-files *.orig -.paket/paket.exe docs/content/license.md docs/content/release-notes.md .fake diff --git a/.paket/paket.exe b/.paket/paket.exe new file mode 100644 index 0000000000..18b1ef3068 Binary files /dev/null and b/.paket/paket.exe differ diff --git a/.paket/paket.targets b/.paket/paket.targets new file mode 100644 index 0000000000..0fd370f901 --- /dev/null +++ b/.paket/paket.targets @@ -0,0 +1,41 @@ + + + + + true + + true + $(MSBuildThisFileDirectory) + $(MSBuildThisFileDirectory)..\ + /Library/Frameworks/Mono.framework/Commands/mono + mono + + + + $(PaketToolsPath)paket.exe + $(PaketToolsPath)paket.bootstrapper.exe + "$(PaketExePath)" + $(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)" + "$(PaketBootStrapperExePath)" $(PaketBootStrapperCommandArgs) + $(MonoPath) --runtime=v4.0.30319 $(PaketBootStrapperExePath) $(PaketBootStrapperCommandArgs) + + $(MSBuildProjectDirectory)\paket.references + $(MSBuildStartupDirectory)\paket.references + $(MSBuildProjectFullPath).paket.references + $(PaketCommand) restore --references-files "$(PaketReferences)" + $(PaketBootStrapperCommand) + + RestorePackages; $(BuildDependsOn); + + + + + + + + + + + + + diff --git a/build.cmd b/build.cmd index 40aff4563e..b4babe508c 100644 --- a/build.cmd +++ b/build.cmd @@ -1,11 +1,6 @@ @echo off cls -.paket\paket.bootstrapper.exe -if errorlevel 1 ( - exit /b %errorlevel% -) - .paket\paket.exe restore if errorlevel 1 ( exit /b %errorlevel% diff --git a/build.fsx b/build.fsx index 475b9e4151..ed97ab20d1 100644 --- a/build.fsx +++ b/build.fsx @@ -312,7 +312,7 @@ Target "FableCompilerNetcore" (fun _ -> Target "NUnitTest" (fun _ -> let testsBuildDir = "build/tests" - !! "src/tests/Fable.Tests.fsproj" + !! "src/tests/Main/Fable.Tests.fsproj" |> MSBuildRelease testsBuildDir "Build" |> ignore @@ -322,11 +322,10 @@ Target "NUnitTest" (fun _ -> let compileAndRunMochaTests es2015 = let testsBuildDir = "build/tests" - let testCompileArgs = if es2015 then ["--ecma es2015"] else [] + let testCompileArgs = + ["--verbose" + if es2015 then " --ecma es2015" else ""] - MSBuildDebug "src/tests/DllRef/bin" "Build" ["src/tests/DllRef/Fable.Tests.DllRef.fsproj"] |> ignore Node.run "." "build/fable" ["src/tests/DllRef"] - Node.run "." "build/fable" ["src/tests/Other"] Node.run "." "build/fable" ("src/tests/"::testCompileArgs) FileUtils.cp "src/tests/package.json" testsBuildDir Npm.install testsBuildDir [] diff --git a/build.sh b/build.sh index 8ffb08d49e..8c0c661cc3 100755 --- a/build.sh +++ b/build.sh @@ -7,11 +7,6 @@ else MONO="mono" fi -$MONO .paket/paket.bootstrapper.exe -exit_code=$? -if [ $exit_code -ne 0 ]; then -exit $exit_code -fi if [ -e "paket.lock" ]; then $MONO .paket/paket.exe restore else diff --git a/docs/source/docs/compiling.md b/docs/source/docs/compiling.md index 6d35f194dc..bf868f87b4 100644 --- a/docs/source/docs/compiling.md +++ b/docs/source/docs/compiling.md @@ -40,7 +40,6 @@ Option | Short | Description `--loose` | | Enable “loose” transformations for babel-preset-es2015 plugins (true by default). `--babelrc` | | Use a `.babelrc` file for Babel configuration (invalidates other Babel related options). `--refs` | | Specify dll or project references in `Reference=js/import/path` format (see below). -`--msbuild` | | Pass MSBuild arguments like `Configuration=Release`. `--clamp` | | Compile unsigned byte arrays as Uint8ClampedArray. `--copyExt` | | Copy external files into `fable_external` folder (true by default). `--coreLib` | | In some cases, you may need to pass a different route to the core library, like `--coreLib fable-core/es2015`. diff --git a/paket.dependencies b/paket.dependencies index ee7262cb9c..526e4f09b2 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -1,22 +1,17 @@ source https://www.nuget.org/api/v2 nuget FAKE -nuget FSharp.Compiler.Service -nuget FSharp.Compiler.Service.ProjectCracker +nuget FSharp.Compiler.Service 8.0.0 nuget FSharp.Core nuget Newtonsoft.Json nuget Fable.JsonConverter nuget NUnit nuget NUnit.Runners -github fsprojects/FSharp.TypeProviders.StarterPack src/ProvidedTypes.fs - -github fsprojects/Forge/1.0.1 src/Forge.ProjectSystem/Prelude.fs -github fsprojects/Forge/1.0.1 src/Forge.ProjectSystem/XLinq.fs -github fsprojects/Forge/1.0.1 src/Forge.ProjectSystem/ResizeArray.fs -github fsprojects/Forge/1.0.1 src/Forge.ProjectSystem/Constants.fs -github fsprojects/Forge/1.0.1 src/Forge.ProjectSystem/ProjectSystem.fs - nuget Suave +github fable-compiler/Forge +github fsprojects/FSharp.TypeProviders.StarterPack src/ProvidedTypes.fs +github fsharp/FSharp.Compiler.Service src/fsharp/ReferenceResolver.fs +github fsharp/FSharp.Compiler.Service src/fsharp/SimulatedMSBuildReferenceResolver.fs group Docs source https://www.nuget.org/api/v2 diff --git a/paket.lock b/paket.lock index 4ab2b9151c..f4775045d8 100644 --- a/paket.lock +++ b/paket.lock @@ -1,14 +1,26 @@ NUGET remote: https://www.nuget.org/api/v2 + Argu (3.2) Fable.JsonConverter (0.0.3) FSharp.Core Newtonsoft.Json - FAKE (4.41.6) + FAKE (4.42) + FParsec (1.0.2) FSharp.Compiler.Service (8.0) System.Collections.Immutable (>= 1.2) System.Reflection.Metadata (>= 1.4.1-beta-24227-04) - FSharp.Compiler.Service.ProjectCracker (8.0) FSharp.Core (4.0.0.1) + FSharp.Formatting (2.10) + FSharp.Compiler.Service (>= 0.0.87) + FSharpVSPowerTools.Core (1.8) + FSharpVSPowerTools.Core (1.8) + FSharp.Compiler.Service (>= 0.0.87) + FsUnit (2.3.2) + FSharp.Core (>= 3.1.2.5) + NUnit (3.5) + Microsoft.Bcl (1.1.10) - framework: net10, net11, net20, net30, net35, net40, net40-full + Microsoft.Bcl.Build (>= 1.0.14) + Microsoft.Bcl.Build (1.0.21) - import_targets: false, framework: net10, net11, net20, net30, net35, net40, net40-full Microsoft.CSharp (4.0.1) - framework: >= netstandard10 System.Collections (>= 4.0.11) - framework: dnxcore50, >= netstandard13 System.Diagnostics.Debug (>= 4.0.11) - framework: dnxcore50, >= netstandard13 @@ -26,8 +38,12 @@ NUGET System.Runtime.Extensions (>= 4.1) - framework: dnxcore50, >= netstandard13 System.Runtime.InteropServices (>= 4.1) - framework: dnxcore50, >= netstandard13 System.Threading (>= 4.0.11) - framework: dnxcore50, >= netstandard13 + Microsoft.Net.Http (2.2.29) - framework: net10, net11, net20, net30, net35, net40, net40-full + Microsoft.Bcl (>= 1.1.10) + Microsoft.Bcl.Build (>= 1.0.14) Microsoft.NETCore.Platforms (1.0.1) - framework: >= netstandard10 Microsoft.NETCore.Targets (1.0.1) - framework: >= netstandard10 + Mono.Posix (4.0) Newtonsoft.Json (9.0.1) Microsoft.CSharp (>= 4.0.1) - framework: >= netstandard10 System.Collections (>= 4.0.11) - framework: >= netstandard10 @@ -65,12 +81,16 @@ NUGET NUnit.Extension.NUnitV2ResultWriter (>= 3.5) NUnit.Extension.TeamCityEventListener (>= 1.0.2) NUnit.Extension.VSProjectLoader (>= 3.5) + Octokit (0.23) + Microsoft.Net.Http - framework: net10, net11, net20, net30, net35, net40, net40-full runtime.native.System (4.0) - framework: >= netstandard13 Microsoft.NETCore.Platforms (>= 1.0.1) Microsoft.NETCore.Targets (>= 1.0.1) runtime.native.System.IO.Compression (4.1) - framework: >= netstandard13 Microsoft.NETCore.Platforms (>= 1.0.1) Microsoft.NETCore.Targets (>= 1.0.1) + SharpZipLib (0.86) + SourceLink.Fake (1.1) Suave (1.1.3) FSharp.Core (>= 3.1.2.5) System.Collections (4.0.11) - framework: >= netstandard10 @@ -311,19 +331,32 @@ NUGET System.Threading (>= 4.0.11) - framework: dnxcore50, >= netstandard13 System.Xml.ReaderWriter (>= 4.0.11) - framework: dnxcore50, netstandard10, >= netstandard13 GITHUB + remote: fable-compiler/Forge + FULLPROJECT (7677a368304f0337047ed8ad925991aa7187a8bf) + Argu + FAKE + FParsec + FSharp.Core + FSharp.Formatting + FsUnit + Mono.Posix + NUnit + NUnit.Runners + SharpZipLib + SourceLink.Fake + remote: fsharp/FAKE + modules/Octokit/Octokit.fsx (f3f230ffde29fa370daf7d7be53e872e929dd487) + Octokit (>= 0.20) remote: fsprojects/FSharp.TypeProviders.StarterPack src/ProvidedTypes.fs (c50ace31d335b7bcb83b102d2cfd0ce2007ed681) - remote: fsprojects/Forge - src/Forge.ProjectSystem/Constants.fs (f75374896a2894e3187e3a2909e769fb920f3af4) - src/Forge.ProjectSystem/Prelude.fs (f75374896a2894e3187e3a2909e769fb920f3af4) - src/Forge.ProjectSystem/ProjectSystem.fs (f75374896a2894e3187e3a2909e769fb920f3af4) - src/Forge.ProjectSystem/ResizeArray.fs (f75374896a2894e3187e3a2909e769fb920f3af4) - src/Forge.ProjectSystem/XLinq.fs (f75374896a2894e3187e3a2909e769fb920f3af4) + remote: fsharp/FSharp.Compiler.Service + src/fsharp/ReferenceResolver.fs (174875dde3dcc5288616adca7b5b1468fda3bdb2) + src/fsharp/SimulatedMSBuildReferenceResolver.fs (174875dde3dcc5288616adca7b5b1468fda3bdb2) GROUP Docs NUGET remote: https://www.nuget.org/api/v2 DotLiquid (2.0.55) - FAKE (4.41.6) + FAKE (4.42) FSharp.Compiler.Service (2.0.0.6) FSharp.Core (4.0.0.1) FSharp.Formatting (2.14.2) diff --git a/src/fable/Fable.Client.Node/Fable.Client.Node.fsproj b/src/fable/Fable.Client.Node/Fable.Client.Node.fsproj index ef8da59aac..06c3bef844 100644 --- a/src/fable/Fable.Client.Node/Fable.Client.Node.fsproj +++ b/src/fable/Fable.Client.Node/Fable.Client.Node.fsproj @@ -45,14 +45,28 @@ + + + True + paket-files/ReferenceResolver.fs + + + True + paket-files/SimulatedMSBuildReferenceResolver.fs + + + Forge.ProjectSystem + {9029be0f-a72c-4281-9fd1-aa15f5722306} + True + Fable.Compiler {d341ff6b-f526-4370-8318-0f5a654ba70c} @@ -80,14 +94,7 @@ - - - - <__paket__FSharp_Compiler_Service_ProjectCracker_targets>net45\FSharp.Compiler.Service.ProjectCracker - - - - - - - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 11 - - - - - $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets - - - - - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets - - - - - - - - Fable.Tests.Clamp - {1e44403b-7834-4842-91b1-53a5fa731c58} - True - - - - - - - ..\..\packages\Fable.JsonConverter\lib\net45\Fable.JsonConverter.dll - True - True - - - - - - - - - ..\..\packages\Microsoft.CSharp\ref\netstandard1.0\Microsoft.CSharp.dll - False - True - - - - - - - - - ..\..\packages\Newtonsoft.Json\lib\net20\Newtonsoft.Json.dll - True - True - - - - - - - ..\..\packages\Newtonsoft.Json\lib\net35\Newtonsoft.Json.dll - True - True - - - - - - - ..\..\packages\Newtonsoft.Json\lib\net40\Newtonsoft.Json.dll - True - True - - - - - - - ..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll - True - True - - - - - - - ..\..\packages\Newtonsoft.Json\lib\netstandard1.0\Newtonsoft.Json.dll - True - True - - - - - - - ..\..\packages\Newtonsoft.Json\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll - True - True - - - - - - - ..\..\packages\Newtonsoft.Json\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll - True - True - - - - - - - - - ..\..\packages\NUnit\lib\net20\NUnit.System.Linq.dll - True - True - - - ..\..\packages\NUnit\lib\net20\nunit.framework.dll - True - True - - - - - - - ..\..\packages\NUnit\lib\net35\nunit.framework.dll - True - True - - - - - - - ..\..\packages\NUnit\lib\net40\nunit.framework.dll - True - True - - - - - - - ..\..\packages\NUnit\lib\net45\nunit.framework.dll - True - True - - - - - - - ..\..\packages\NUnit\lib\portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10\nunit.framework.dll - True - True - - - - - - - - - ..\..\packages\System.Collections\ref\netstandard1.0\System.Collections.dll - False - True - - - - - - - ..\..\packages\System.Collections\ref\netstandard1.3\System.Collections.dll - False - True - - - - - - - - - ..\..\packages\System.Diagnostics.Debug\ref\netstandard1.0\System.Diagnostics.Debug.dll - False - True - - - - - - - ..\..\packages\System.Diagnostics.Debug\ref\netstandard1.3\System.Diagnostics.Debug.dll - False - True - - - - - - - - - ..\..\packages\System.Diagnostics.Tools\ref\netstandard1.0\System.Diagnostics.Tools.dll - False - True - - - - - - - - - ..\..\packages\System.Dynamic.Runtime\ref\netstandard1.0\System.Dynamic.Runtime.dll - False - True - - - - - - - ..\..\packages\System.Dynamic.Runtime\ref\netstandard1.3\System.Dynamic.Runtime.dll - False - True - - - - - - - - - ..\..\packages\System.Globalization\ref\netstandard1.0\System.Globalization.dll - False - True - - - - - - - ..\..\packages\System.Globalization\ref\netstandard1.3\System.Globalization.dll - False - True - - - - - - - - - ..\..\packages\System.IO\ref\netstandard1.0\System.IO.dll - False - True - - - - - - - ..\..\packages\System.IO\ref\netstandard1.3\System.IO.dll - False - True - - - - - - - ..\..\packages\System.IO\ref\netstandard1.5\System.IO.dll - False - True - - - - - - - - - ..\..\packages\System.IO.FileSystem\ref\netstandard1.3\System.IO.FileSystem.dll - False - True - - - - - - - - - ..\..\packages\System.IO.FileSystem.Primitives\ref\netstandard1.3\System.IO.FileSystem.Primitives.dll - False - True - - - - - - - - - ..\..\packages\System.Linq\ref\netstandard1.0\System.Linq.dll - False - True - - - - - - - ..\..\packages\System.Linq\ref\netstandard1.6\System.Linq.dll - False - True - - - - - - - - - ..\..\packages\System.Linq.Expressions\ref\netstandard1.0\System.Linq.Expressions.dll - False - True - - - - - - - ..\..\packages\System.Linq.Expressions\ref\netstandard1.3\System.Linq.Expressions.dll - False - True - - - - - - - ..\..\packages\System.Linq.Expressions\ref\netstandard1.6\System.Linq.Expressions.dll - False - True - - - - - - - - - ..\..\packages\System.ObjectModel\ref\netstandard1.0\System.ObjectModel.dll - False - True - - - - - - - ..\..\packages\System.ObjectModel\ref\netstandard1.3\System.ObjectModel.dll - False - True - - - - - - - - - ..\..\packages\System.Reflection\ref\netstandard1.0\System.Reflection.dll - False - True - - - - - - - ..\..\packages\System.Reflection\ref\netstandard1.3\System.Reflection.dll - False - True - - - - - - - ..\..\packages\System.Reflection\ref\netstandard1.5\System.Reflection.dll - False - True - - - - - - - - - ..\..\packages\System.Reflection.Emit\ref\netstandard1.1\System.Reflection.Emit.dll - False - True - - - - - - - - - ..\..\packages\System.Reflection.Emit.ILGeneration\ref\netstandard1.0\System.Reflection.Emit.ILGeneration.dll - False - True - - - - - - - - - ..\..\packages\System.Reflection.Emit.Lightweight\ref\netstandard1.0\System.Reflection.Emit.Lightweight.dll - False - True - - - - - - - - - ..\..\packages\System.Reflection.Extensions\ref\netstandard1.0\System.Reflection.Extensions.dll - False - True - - - - - - - - - ..\..\packages\System.Reflection.Primitives\ref\netstandard1.0\System.Reflection.Primitives.dll - False - True - - - - - - - - - ..\..\packages\System.Reflection.TypeExtensions\ref\netstandard1.3\System.Reflection.TypeExtensions.dll - False - True - - - - - - - ..\..\packages\System.Reflection.TypeExtensions\ref\netstandard1.5\System.Reflection.TypeExtensions.dll - False - True - - - - - - - - - ..\..\packages\System.Resources.ResourceManager\ref\netstandard1.0\System.Resources.ResourceManager.dll - False - True - - - - - - - - - ..\..\packages\System.Runtime\ref\netstandard1.0\System.Runtime.dll - False - True - - - - - - - ..\..\packages\System.Runtime\ref\netstandard1.2\System.Runtime.dll - False - True - - - - - - - ..\..\packages\System.Runtime\ref\netstandard1.3\System.Runtime.dll - False - True - - - - - - - ..\..\packages\System.Runtime\ref\netstandard1.5\System.Runtime.dll - False - True - - - - - - - - - ..\..\packages\System.Runtime.Extensions\ref\netstandard1.0\System.Runtime.Extensions.dll - False - True - - - - - - - ..\..\packages\System.Runtime.Extensions\ref\netstandard1.3\System.Runtime.Extensions.dll - False - True - - - - - - - ..\..\packages\System.Runtime.Extensions\ref\netstandard1.5\System.Runtime.Extensions.dll - False - True - - - - - - - - - ..\..\packages\System.Runtime.Handles\ref\netstandard1.3\System.Runtime.Handles.dll - False - True - - - - - - - - - ..\..\packages\System.Runtime.InteropServices\ref\netstandard1.1\System.Runtime.InteropServices.dll - False - True - - - - - - - ..\..\packages\System.Runtime.InteropServices\ref\netstandard1.2\System.Runtime.InteropServices.dll - False - True - - - - - - - ..\..\packages\System.Runtime.InteropServices\ref\netstandard1.3\System.Runtime.InteropServices.dll - False - True - - - - - - - ..\..\packages\System.Runtime.InteropServices\ref\netstandard1.5\System.Runtime.InteropServices.dll - False - True - - - - - - - - - ..\..\packages\System.Runtime.Serialization.Primitives\ref\netstandard1.0\System.Runtime.Serialization.Primitives.dll - False - True - - - - - - - ..\..\packages\System.Runtime.Serialization.Primitives\ref\netstandard1.3\System.Runtime.Serialization.Primitives.dll - False - True - - - - - - - - - ..\..\packages\System.Text.Encoding\ref\netstandard1.0\System.Text.Encoding.dll - False - True - - - - - - - ..\..\packages\System.Text.Encoding\ref\netstandard1.3\System.Text.Encoding.dll - False - True - - - - - - - - - ..\..\packages\System.Text.Encoding.Extensions\ref\netstandard1.0\System.Text.Encoding.Extensions.dll - False - True - - - - - - - ..\..\packages\System.Text.Encoding.Extensions\ref\netstandard1.3\System.Text.Encoding.Extensions.dll - False - True - - - - - - - - - ..\..\packages\System.Text.RegularExpressions\ref\netstandard1.0\System.Text.RegularExpressions.dll - False - True - - - - - - - ..\..\packages\System.Text.RegularExpressions\ref\netstandard1.3\System.Text.RegularExpressions.dll - False - True - - - - - - - ..\..\packages\System.Text.RegularExpressions\ref\netstandard1.6\System.Text.RegularExpressions.dll - False - True - - - - - - - - - ..\..\packages\System.Threading\ref\netstandard1.0\System.Threading.dll - False - True - - - - - - - ..\..\packages\System.Threading\ref\netstandard1.3\System.Threading.dll - False - True - - - - - - - - - ..\..\packages\System.Threading.Tasks\ref\netstandard1.0\System.Threading.Tasks.dll - False - True - - - - - - - ..\..\packages\System.Threading.Tasks\ref\netstandard1.3\System.Threading.Tasks.dll - False - True - - - - - - - - - ..\..\packages\System.Threading.Tasks.Extensions\lib\netstandard1.0\System.Threading.Tasks.Extensions.dll - True - True - - - - - - - - - ..\..\packages\System.Xml.ReaderWriter\ref\netstandard1.0\System.Xml.ReaderWriter.dll - False - True - - - - - - - ..\..\packages\System.Xml.ReaderWriter\ref\netstandard1.3\System.Xml.ReaderWriter.dll - False - True - - - - - - - - - ..\..\packages\System.Xml.XDocument\ref\netstandard1.0\System.Xml.XDocument.dll - False - True - - - - - - - ..\..\packages\System.Xml.XDocument\ref\netstandard1.3\System.Xml.XDocument.dll - False - True - - - - - \ No newline at end of file diff --git a/src/tests/Fable.Tests.sln b/src/tests/Fable.Tests.sln deleted file mode 100644 index af08590a87..0000000000 --- a/src/tests/Fable.Tests.sln +++ /dev/null @@ -1,32 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{830F1EC7-4FC9-4250-B0A9-619F0A6AC2B7}" - ProjectSection(SolutionItems) = preProject - ..\..\paket.dependencies = ..\..\paket.dependencies - EndProjectSection -EndProject -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.Tests", "Fable.Tests.fsproj", "{6EF06954-FBDF-42C7-815C-B13BA2926C93}" -EndProject -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.Tests.Clamp", "Other\Fable.Tests.Clamp.fsproj", "{1E44403B-7834-4842-91B1-53A5FA731C58}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6EF06954-FBDF-42C7-815C-B13BA2926C93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6EF06954-FBDF-42C7-815C-B13BA2926C93}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6EF06954-FBDF-42C7-815C-B13BA2926C93}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6EF06954-FBDF-42C7-815C-B13BA2926C93}.Release|Any CPU.Build.0 = Release|Any CPU - {1E44403B-7834-4842-91B1-53A5FA731C58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1E44403B-7834-4842-91B1-53A5FA731C58}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1E44403B-7834-4842-91B1-53A5FA731C58}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1E44403B-7834-4842-91B1-53A5FA731C58}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/tests/ApplicativeTests.fs b/src/tests/Main/ApplicativeTests.fs similarity index 92% rename from src/tests/ApplicativeTests.fs rename to src/tests/Main/ApplicativeTests.fs index 472fb58921..bb25bdbc10 100644 --- a/src/tests/ApplicativeTests.fs +++ b/src/tests/Main/ApplicativeTests.fs @@ -1,7 +1,7 @@ -[] +[] module Fable.Tests.Applicative open System -open NUnit.Framework +open Util.Testing type Result<'s, 'f> = | Ok of 's diff --git a/src/tests/ArithmeticTests.fs b/src/tests/Main/ArithmeticTests.fs similarity index 67% rename from src/tests/ArithmeticTests.fs rename to src/tests/Main/ArithmeticTests.fs index 84218151b1..02a9dbadf9 100644 --- a/src/tests/ArithmeticTests.fs +++ b/src/tests/Main/ArithmeticTests.fs @@ -1,7 +1,7 @@ -[] +[] module Fable.Tests.Arithmetic open System -open NUnit.Framework +open Util.Testing [] let ``Infix add can be generated``() = @@ -56,74 +56,74 @@ let ``abs works``() = [] let ``round works``() = - Assert.AreEqual (round -12.5, -12) + Assert.AreEqual (round -12.5, -12.) [] let ``ceil works``() = - Assert.AreEqual (ceil 11.25, 12) + Assert.AreEqual (ceil 11.25, 12.) [] let ``floor works``() = - Assert.AreEqual (floor 11.75, 11) + Assert.AreEqual (floor 11.75, 11.) -let checkTo3dp expected actual = +let checkTo3dp (expected: float) actual = Assert.AreEqual (floor(actual * 1000.), expected) [] let ``pown works``() = - pown 2.2 3 |> checkTo3dp 10648 + pown 2.2 3 |> checkTo3dp 10648. [] let ``sqrt works``() = - sqrt 4.5 |> checkTo3dp 2121 - + sqrt 4.5 |> checkTo3dp 2121. + [] let ``acos works``() = - acos 0.25 |> checkTo3dp 1318 + acos 0.25 |> checkTo3dp 1318. [] let ``asin works``() = - asin 0.25 |> checkTo3dp 252 + asin 0.25 |> checkTo3dp 252. [] let ``atan works``() = - atan 0.25 |> checkTo3dp 244 + atan 0.25 |> checkTo3dp 244. [] let ``atan2 works``() = - atan2 90. 15. |> checkTo3dp 1405 + atan2 90. 15. |> checkTo3dp 1405. [] let ``cos works``() = - cos 0.25 |> checkTo3dp 968 + cos 0.25 |> checkTo3dp 968. [] let ``sin works``() = - sin 0.25 |> checkTo3dp 247 + sin 0.25 |> checkTo3dp 247. [] let ``tan works``() = - tan 0.25 |> checkTo3dp 255 + tan 0.25 |> checkTo3dp 255. [] let ``exp works``() = - exp 8.0 |> checkTo3dp 2980957 + exp 8.0 |> checkTo3dp 2980957. [] let ``log works``() = - log 232.12 |> checkTo3dp 5447 + log 232.12 |> checkTo3dp 5447. [] let ``log10 works``() = - log10 232.12 |> checkTo3dp 2365 + log10 232.12 |> checkTo3dp 2365. [] let ``PI works``() = - checkTo3dp 3141 Math.PI + checkTo3dp 3141. Math.PI [] let ``E works``() = - checkTo3dp 2718 Math.E + checkTo3dp 2718. Math.E [] let ``Math.abs works``() = @@ -131,76 +131,76 @@ let ``Math.abs works``() = [] let ``Math.pown works``() = - Math.Pow(2.2, 3.0) |> checkTo3dp 10648 + Math.Pow(2.2, 3.0) |> checkTo3dp 10648. [] let ``Math.sqrt works``() = - Math.Sqrt 4.5 |> checkTo3dp 2121 + Math.Sqrt 4.5 |> checkTo3dp 2121. [] let ``Math.round works``() = - Assert.AreEqual(Math.Round -12.5, -12) + Assert.AreEqual(Math.Round -12.5, -12.) [] let ``Math.ceil works``() = - Assert.AreEqual(Math.Ceiling 11.25, 12) + Assert.AreEqual(Math.Ceiling 11.25, 12.) [] let ``Math.floor works``() = - Assert.AreEqual(Math.Floor 11.75, 11) + Assert.AreEqual(Math.Floor 11.75, 11.) [] let ``Math.acos works``() = - Math.Acos 0.25 |> checkTo3dp 1318 + Math.Acos 0.25 |> checkTo3dp 1318. [] let ``Math.asin works``() = - Math.Asin 0.25 |> checkTo3dp 252 + Math.Asin 0.25 |> checkTo3dp 252. [] let ``Math.atan works``() = - Math.Atan 0.25 |> checkTo3dp 244 + Math.Atan 0.25 |> checkTo3dp 244. [] let ``Math.atan2 works``() = - Math.Atan2(90., 15.) |> checkTo3dp 1405 + Math.Atan2(90., 15.) |> checkTo3dp 1405. [] let ``Math.cos works``() = - Math.Cos(0.1 * Math.PI) |> checkTo3dp 951 + Math.Cos(0.1 * Math.PI) |> checkTo3dp 951. [] let ``Math.sin works``() = - Math.Sin(0.25 * Math.PI) |> checkTo3dp 707 + Math.Sin(0.25 * Math.PI) |> checkTo3dp 707. [] let ``Math.tan works``() = - Math.Tan(0.5) |> checkTo3dp 546 + Math.Tan(0.5) |> checkTo3dp 546. [] let ``Math.exp works``() = - Math.Exp 8.0 |> checkTo3dp 2980957 + Math.Exp 8.0 |> checkTo3dp 2980957. [] let ``Math.log works``() = - Math.Log 232.12 |> checkTo3dp 5447 + Math.Log 232.12 |> checkTo3dp 5447. [] let ``Math.log10 works``() = - Math.Log10 232.12 |> checkTo3dp 2365 + Math.Log10 232.12 |> checkTo3dp 2365. [] let ``incr works``() = let i = ref 5 incr i Assert.AreEqual(!i, 6) - + [] let ``decr works``() = let i = ref 5 decr i Assert.AreEqual(!i, 4) - + [] let ``System.Random works``() = let rnd = System.Random() diff --git a/src/tests/ArrayTests.fs b/src/tests/Main/ArrayTests.fs similarity index 83% rename from src/tests/ArrayTests.fs rename to src/tests/Main/ArrayTests.fs index b0df4d9c8e..8bfcab27ee 100644 --- a/src/tests/ArrayTests.fs +++ b/src/tests/Main/ArrayTests.fs @@ -1,8 +1,8 @@ -[] +[] module Fable.Tests.Arrays open System -open NUnit.Framework +open Util.Testing open Fable.Tests.Util open System.Collections.Generic @@ -21,25 +21,25 @@ type ParamArrayTest = let add (xs: int[]) = ParamArrayTest.Add(xs) [] -let ``ParamArrayAttribute works``() = +let ``ParamArrayAttribute works``() = ParamArrayTest.Add(1, 2) |> equal 3 [] -let ``Passing an array to ParamArrayAttribute works``() = +let ``Passing an array to ParamArrayAttribute works``() = ParamArrayTest.Add([|3; 2|]) |> equal 5 [] -let ``Passing an array to ParamArrayAttribute from another function works``() = +let ``Passing an array to ParamArrayAttribute from another function works``() = add [|5;-7|] |> equal -2 #if FABLE_COMPILER open Fable.Core [] -let jsConstructorIs (s: string) (ar: 'T[]) = true +let jsConstructorIs (s: string) (ar: 'T[]) = true [] -let ``Typed Arrays work``() = +let ``Typed Arrays work``() = let xs = [| 1; 2; 3; |] let ys = [| 1.; 2.; 3.; |] let zs = [| "This is a string" |] @@ -48,19 +48,19 @@ let ``Typed Arrays work``() = zs |> jsConstructorIs "Array" |> equal true [] -let ``Mapping from Typed Arrays work``() = +let ``Mapping from Typed Arrays work``() = [| 1; 2; 3; |] |> Array.map string |> jsConstructorIs "Int32Array" |> equal false [] -let ``Mapping to Typed Arrays work``() = +let ``Mapping to Typed Arrays work``() = [| "1"; "2"; "3"; |] |> Array.map int |> jsConstructorIs "Int32Array" |> equal true - + [| 1; 2; 3; |] |> Array.map float |> jsConstructorIs "Float64Array" @@ -70,7 +70,7 @@ let ``Mapping to Typed Arrays work``() = let f (x:obj) (y:obj) (z:obj) = (string x) + (string y) + (string z) [] -let ``Mapping from values to functions works``() = +let ``Mapping from values to functions works``() = let a = [| "a"; "b"; "c" |] let b = [| 1; 2; 3 |] let concaters1 = a |> Array.map (fun x y -> y + x) @@ -97,42 +97,42 @@ let ``Mapping from typed arrays to non-numeric arrays doesn't coerce values``() [] let ``Byte arrays are not clamped by default``() = - let ar = [|5uy|] + let ar = Util2.Helper2.CreateArray() ar.[0] <- ar.[0] + 255uy equal 4uy ar.[0] #if FABLE_COMPILER && !DOTNETCORE [] let ``Clamped byte arrays work``() = - let ar = Util2.Helper2.CreateClampedArray() + let ar = DllRef.Lib.createClampedArray() ar.[0] <- ar.[0] + 255uy equal 255uy ar.[0] #endif [] -let ``Array slice with upper index work``() = +let ``Array slice with upper index work``() = let xs = [| 1; 2; 3; 4; 5; 6 |] let ys = [| 8; 8; 8; 8; 8; 8; 8; 8; |] xs.[..2] |> Array.sum |> equal 6 xs.[..2] <- ys xs |> Array.sum |> equal 39 - + [] -let ``Array slice with lower index work``() = +let ``Array slice with lower index work``() = let xs = [| 1; 2; 3; 4; 5; 6 |] let ys = [| 8; 8; 8; 8; 8; 8; 8; 8; |] xs.[4..] |> Array.sum |> equal 11 xs.[4..] <- ys xs |> Array.sum |> equal 26 - + [] -let ``Array slice with both indices work``() = +let ``Array slice with both indices work``() = let xs = [| 1; 2; 3; 4; 5; 6 |] let ys = [| 8; 8; 8; 8; 8; 8; 8; 8; |] xs.[1..3] |> Array.sum |> equal 9 xs.[1..3] <- ys xs |> Array.sum |> equal 36 - + [] let ``Array slice with non-numeric arrays work``() = let xs = [|"A";"B";"C";"D"|] @@ -141,77 +141,77 @@ let ``Array slice with non-numeric arrays work``() = equal xs.[3] "D" [] -let ``Array literals work``() = +let ``Array literals work``() = let x = [| 1; 2; 3; 4; 5 |] equal 5 x.Length [] -let ``Array indexer getter works``() = +let ``Array indexer getter works``() = let x = [| 1.; 2.; 3.; 4.; 5. |] x.[2] |> equal 3. [] -let ``Array indexer setter works``() = +let ``Array indexer setter works``() = let x = [| 1.; 2.; 3.; 4.; 5. |] x.[3] <- 10. equal 10. x.[3] [] -let ``Array getter works``() = +let ``Array getter works``() = let x = [| 1.; 2.; 3.; 4.; 5. |] Array.get x 2 |> equal 3. [] -let ``Array setter works``() = +let ``Array setter works``() = let x = [| 1.; 2.; 3.; 4.; 5. |] Array.set x 3 10. equal 10. x.[3] [] -let ``Array.Length works``() = +let ``Array.Length works``() = let xs = [|1.; 2.; 3.; 4.|] xs.Length |> equal 4 [] -let ``Array.zeroCreate works``() = +let ``Array.zeroCreate works``() = let xs = Array.zeroCreate 2 equal 2 xs.Length equal 0 xs.[1] [] -let ``Array.create works``() = +let ``Array.create works``() = let xs = Array.create 2 5 equal 2 xs.Length Array.sum xs |> equal 10 [] -let ``Array.blit works``() = +let ``Array.blit works``() = let xs = [|1..10|] let ys = Array.zeroCreate 20 Array.blit xs 3 ys 5 4 // [|0; 0; 0; 0; 0; 4; 5; 6; 7; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0|] ys.[5] + ys.[6] + ys.[7] + ys.[8] |> equal 22 [] -let ``Array.copy works``() = +let ``Array.copy works``() = let xs = [|1; 2; 3; 4|] let ys = Array.copy xs xs.[0] <- 0 // Ensure a deep copy ys |> Array.sum |> equal 10 [] -let ``Array.sub works``() = +let ``Array.sub works``() = let xs = [|0..99|] let ys = Array.sub xs 5 10 // [|5; 6; 7; 8; 9; 10; 11; 12; 13; 14|] ys |> Array.sum |> equal 95 [] -let ``Array.fill works``() = +let ``Array.fill works``() = let xs = Array.zeroCreate 4 // [|0; 0; 0; 0|] Array.fill xs 1 2 3 // [|0; 3; 3; 0|] xs |> Array.sum |> equal 6 [] -let ``Array.empty works``() = +let ``Array.empty works``() = let xs = Array.empty xs.Length |> equal 0 @@ -225,72 +225,72 @@ let ``Array.append works``() = zs2.[1] + zs2.[3] |> equal "yb" [] -let ``Array.average works``() = +let ``Array.average works``() = let xs = [|1.; 2.; 3.; 4.|] Array.average xs |> equal 2.5 [] -let ``Array.averageBy works``() = +let ``Array.averageBy works``() = let xs = [|1.; 2.; 3.; 4.|] Array.averageBy ((*) 2.) xs |> equal 5. [] -let ``Array.choose works``() = +let ``Array.choose works``() = let xs = [|1L; 2L; 3L; 4L|] let result = xs |> Array.choose (fun x -> if x > 2L then Some x - else None) + else None) result.[0] + result.[1] |> equal 7L [] -let ``Array.collect works``() = +let ``Array.collect works``() = let xs = [|[|1|]; [|2|]; [|3|]; [|4|]|] let ys = xs |> Array.collect id ys.[0] + ys.[1] |> equal 3 - + let xs1 = [|[|1.; 2.|]; [|3.|]; [|4.; 5.; 6.;|]; [|7.|]|] let ys1 = xs1 |> Array.collect id ys1.[0] + ys1.[1] + ys1.[2] + ys1.[3] + ys1.[4] - |> equal 15. + |> equal 15. [] -let ``Array.concat works``() = +let ``Array.concat works``() = let xs = [|[|1.|]; [|2.|]; [|3.|]; [|4.|]|] let ys = xs |> Array.concat ys.[0] + ys.[1] |> equal 3. [] -let ``Array.exists works``() = +let ``Array.exists works``() = let xs = [|1u; 2u; 3u; 4u|] xs |> Array.exists (fun x -> x = 2u) |> equal true [] -let ``Array.exists2 works``() = +let ``Array.exists2 works``() = let xs = [|1UL; 2UL; 3UL; 4UL|] let ys = [|1UL; 2UL; 3UL; 4UL|] Array.exists2 (fun x y -> x * y = 16UL) xs ys |> equal true [] -let ``Array.filter works``() = +let ``Array.filter works``() = let xs = [|1s; 2s; 3s; 4s|] let ys = xs |> Array.filter (fun x -> x > 2s) ys.Length |> equal 2 [] -let ``Array.find works``() = +let ``Array.find works``() = let xs = [|1us; 2us; 3us; 4us|] xs |> Array.find ((=) 2us) |> equal 2us [] -let ``Array.findIndex works``() = +let ``Array.findIndex works``() = let xs = [|1.f; 2.f; 3.f; 4.f|] xs |> Array.findIndex ((=) 2.f) |> equal 1 @@ -322,39 +322,39 @@ let ``Array.tryFindIndexBack works``() = xs |> Array.tryFindIndexBack ((=) 5.) |> equal None [] -let ``Array.fold works``() = +let ``Array.fold works``() = let xs = [|1y; 2y; 3y; 4y|] let total = xs |> Array.fold (+) 0y total |> equal 10y [] -let ``Array.fold2 works``() = +let ``Array.fold2 works``() = let xs = [|1uy; 2uy; 3uy; 4uy|] let ys = [|1uy; 2uy; 3uy; 4uy|] let total = Array.fold2 (fun x y z -> x + y + z) 0uy xs ys total |> equal 20uy [] -let ``Array.foldBack works``() = +let ``Array.foldBack works``() = let xs = [|1.; 2.; 3.; 4.|] let total = Array.foldBack (fun x acc -> acc - x) xs 0. total |> equal -10. [] -let ``Array.foldBack2 works``() = +let ``Array.foldBack2 works``() = let xs = [|1; 2; 3; 4|] let ys = [|1; 2; 3; 4|] let total = Array.foldBack2 (fun x y acc -> x + y - acc) xs ys 0 total |> equal -4 [] -let ``Array.forall works``() = +let ``Array.forall works``() = let xs = [|1.; 2.; 3.; 4.|] Array.forall ((>) 5.) xs |> equal true [] -let ``Array.forall2 works``() = +let ``Array.forall2 works``() = let xs = [|1.; 2.; 3.; 4.|] let ys = [|1.; 2.; 3.; 5.|] Array.forall2 (=) xs ys @@ -363,7 +363,7 @@ let ``Array.forall2 works``() = |> equal true [] -let ``Array.init works``() = +let ``Array.init works``() = let xs = Array.init 4 (float >> sqrt) xs.[0] + xs.[1] |> equal 1. @@ -371,12 +371,12 @@ let ``Array.init works``() = |> equal true [] -let ``Array.isEmpty works``() = +let ``Array.isEmpty works``() = Array.isEmpty [|"a"|] |> equal false Array.isEmpty [||] |> equal true [] -let ``Array.iter works``() = +let ``Array.iter works``() = let xs = [|1.; 2.; 3.; 4.|] let total = ref 0. xs |> Array.iter (fun x -> @@ -385,7 +385,7 @@ let ``Array.iter works``() = !total |> equal 10. [] -let ``Array.iter2 works``() = +let ``Array.iter2 works``() = let xs = [|1; 2; 3; 4|] let mutable total = 0 Array.iter2 (fun x y -> @@ -394,7 +394,7 @@ let ``Array.iter2 works``() = total |> equal -20 [] -let ``Array.iteri works``() = +let ``Array.iteri works``() = let xs = [|1.; 2.; 3.; 4.|] let total = ref 0. xs |> Array.iteri (fun i x -> @@ -403,7 +403,7 @@ let ``Array.iteri works``() = !total |> equal 20. [] -let ``Array.iteri2 works``() = +let ``Array.iteri2 works``() = let xs = [|1.; 2.; 3.; 4.|] let total = ref 0. Array.iteri2 (fun i x y -> @@ -412,101 +412,101 @@ let ``Array.iteri2 works``() = !total |> equal 40. [] -let ``Array.length works``() = +let ``Array.length works``() = let xs = [|"a"; "a"; "a"; "a"|] Array.length xs |> equal 4 [] -let ``Array.map works``() = +let ``Array.map works``() = let xs = [|1.|] let ys = xs |> Array.map ((*) 2.) ys.[0] |> equal 2. [] -let ``Array.map2 works``() = +let ``Array.map2 works``() = let xs = [|1.|] let ys = [|2.|] let zs = Array.map2 (*) xs ys zs.[0] |> equal 2. [] -let ``Array.mapi works``() = +let ``Array.mapi works``() = let xs = [|1.; 2.|] let ys = xs |> Array.mapi (fun i x -> float i + x) ys.[1] |> equal 3. [] -let ``Array.mapi2 works``() = +let ``Array.mapi2 works``() = let xs = [|1.; 2.|] let ys = [|2.; 3.|] let zs = Array.mapi2 (fun i x y -> float i + x * y) xs ys zs.[1] |> equal 7. [] -let ``Array.mapFold works`` () = +let ``Array.mapFold works`` () = let xs = [|1y; 2y; 3y; 4y|] let result = xs |> Array.mapFold (fun acc x -> (x * 2y, acc + x)) 0y fst result |> Array.sum |> equal 20y snd result |> equal 10y [] -let ``Array.mapFoldBack works`` () = +let ``Array.mapFoldBack works`` () = let xs = [|1.; 2.; 3.; 4.|] let result = Array.mapFoldBack (fun x acc -> (x * -2., acc - x)) xs 0. fst result |> Array.sum |> equal -20. snd result |> equal -10. [] -let ``Array.max works``() = +let ``Array.max works``() = let xs = [|1.; 2.|] xs |> Array.max |> equal 2. [] -let ``Array.maxBy works``() = +let ``Array.maxBy works``() = let xs = [|1.; 2.|] xs |> Array.maxBy (fun x -> -x) |> equal 1. [] -let ``Array.min works``() = +let ``Array.min works``() = let xs = [|1.; 2.|] xs |> Array.min |> equal 1. [] -let ``Array.minBy works``() = +let ``Array.minBy works``() = let xs = [|1.; 2.|] xs |> Array.minBy (fun x -> -x) |> equal 2. [] -let ``Array.ofList works``() = +let ``Array.ofList works``() = let xs = [1.; 2.] let ys = Array.ofList xs ys.Length |> equal 2 [] -let ``Array.ofSeq works``() = +let ``Array.ofSeq works``() = let xs = seq { yield 1; yield 2 } let ys = Array.ofSeq xs ys.[0] |> equal 1 [] -let ``Array.partition works``() = +let ``Array.partition works``() = let xs = [|1.; 2.|] let ys, zs = xs |> Array.partition (fun x -> x <= 1.) ys.[0] - zs.[0] |> equal -1. [] -let ``Array.permute works``() = +let ``Array.permute works``() = let xs = [|1.; 2.|] let ys = xs |> Array.permute (fun i -> i + 1 - 2 * (i % 2)) ys.[0] |> equal 2. [] -let ``Array.pick works``() = +let ``Array.pick works``() = let xs = [|1.; 2.|] xs |> Array.pick (fun x -> match x with @@ -524,32 +524,32 @@ let ``Array.range works``() = |> equal 20 [] -let ``Array.reduce works``() = +let ``Array.reduce works``() = let xs = [|1.; 2.; 3.; 4.|] xs |> Array.reduce (-) |> equal -8. [] -let ``Array.reduceBack works``() = +let ``Array.reduceBack works``() = let xs = [|1.; 2.; 3.; 4.|] xs |> Array.reduceBack (-) |> equal -2. [] -let ``Array.rev works``() = +let ``Array.rev works``() = let xs = [|1.; 2.|] let ys = xs |> Array.rev ys.[0] |> equal 2. [] -let ``Array.scan works``() = +let ``Array.scan works``() = let xs = [|1.; 2.; 3.; 4.|] let ys = xs |> Array.scan (+) 0. ys.[2] + ys.[3] |> equal 9. [] -let ``Array.scanBack works``() = +let ``Array.scanBack works``() = let xs = [|1.; 2.; 3.; 4.|] let ys = Array.scanBack (-) xs 0. ys.[2] + ys.[3] @@ -560,7 +560,7 @@ let ``Array.sort works``() = let xs = [|3; 4; 1; -3; 2; 10|] let ys = [|"a"; "c"; "B"; "d"|] xs |> Array.sort |> Array.take 3 |> Array.sum |> equal 0 - ys |> Array.sort |> Array.item 1 |> equal "a" + ys |> Array.sort |> Array.item 1 |> equal "a" [] let ``Array.truncate works``() = @@ -568,7 +568,7 @@ let ``Array.truncate works``() = xs |> Array.truncate 2 |> Array.last |> equal 2. - // Array.truncate shouldn't throw an exception if there're not enough elements + // Array.truncate shouldn't throw an exception if there're not enough elements try xs |> Array.truncate 20 |> Array.length with _ -> -1 |> equal 5 @@ -577,71 +577,71 @@ let ``Array.sortDescending works``() = let xs = [|3; 4; 1; -3; 2; 10|] let ys = [|"a"; "c"; "B"; "d"|] xs |> Array.sortDescending |> Array.take 3 |> Array.sum |> equal 17 - ys |> Array.sortDescending |> Array.item 1 |> equal "c" + ys |> Array.sortDescending |> Array.item 1 |> equal "c" [] -let ``Array.sortBy works``() = +let ``Array.sortBy works``() = let xs = [|3.; 4.; 1.; 2.|] let ys = xs |> Array.sortBy (fun x -> -x) ys.[0] + ys.[1] |> equal 7. [] -let ``Array.sortWith works``() = +let ``Array.sortWith works``() = let xs = [|3.; 4.; 1.; 2.|] let ys = xs |> Array.sortWith (fun x y -> int(x - y)) ys.[0] + ys.[1] |> equal 3. [] -let ``Array.sortInPlace works``() = +let ``Array.sortInPlace works``() = let xs = [|3.; 4.; 1.; 2.; 10.|] Array.sortInPlace xs xs.[0] + xs.[1] |> equal 3. [] -let ``Array.sortInPlaceBy works``() = +let ``Array.sortInPlaceBy works``() = let xs = [|3.; 4.; 1.; 2.; 10.|] Array.sortInPlaceBy (fun x -> -x) xs xs.[0] + xs.[1] |> equal 14. [] -let ``Array.sortInPlaceWith works``() = +let ``Array.sortInPlaceWith works``() = let xs = [|3.; 4.; 1.; 2.; 10.|] Array.sortInPlaceWith (fun x y -> int(x - y)) xs xs.[0] + xs.[1] |> equal 3. [] -let ``Array.sum works``() = +let ``Array.sum works``() = let xs = [|1.; 2.|] xs |> Array.sum |> equal 3. [] -let ``Array.sumBy works``() = +let ``Array.sumBy works``() = let xs = [|1.; 2.|] xs |> Array.sumBy ((*) 2.) |> equal 6. [] -let ``Array.toList works``() = +let ``Array.toList works``() = let xs = [|1.; 2.|] let ys = xs |> Array.toList ys.[0] + ys.[1] |> equal 3. [] -let ``Array.toSeq works``() = +let ``Array.toSeq works``() = let xs = [|1.; 2.|] let ys = xs |> Array.toSeq ys |> Seq.head |> equal 1. [] -let ``Array.tryFind works``() = +let ``Array.tryFind works``() = let xs = [|1.; 2.|] xs |> Array.tryFind ((=) 1.) |> Option.isSome |> equal true @@ -649,7 +649,7 @@ let ``Array.tryFind works``() = |> Option.isSome |> equal false [] -let ``Array.tryFindIndex works``() = +let ``Array.tryFindIndex works``() = let xs = [|1.; 2.|] xs |> Array.tryFindIndex ((=) 2.) |> equal (Some 1) @@ -657,7 +657,7 @@ let ``Array.tryFindIndex works``() = |> equal None [] -let ``Array.tryPick works``() = +let ``Array.tryPick works``() = let xs = [|1.; 2.|] let r = xs |> Array.tryPick (fun x -> match x with @@ -669,21 +669,21 @@ let ``Array.tryPick works``() = |> equal 2. [] -let ``Array.unzip works``() = +let ``Array.unzip works``() = let xs = [|1., 2.|] let ys, zs = xs |> Array.unzip ys.[0] + zs.[0] |> equal 3. [] -let ``Array.unzip3 works``() = +let ``Array.unzip3 works``() = let xs = [|1., 2., 3.|] let ys, zs, ks = xs |> Array.unzip3 ys.[0] + zs.[0] + ks.[0] |> equal 6. [] -let ``Array.zip works``() = +let ``Array.zip works``() = let xs = [|1.; 2.; 3.|] let ys = [|1.; 2.; 3.|] let zs = Array.zip xs ys @@ -691,7 +691,7 @@ let ``Array.zip works``() = x + y |> equal 2. [] -let ``Array.zip3 works``() = +let ``Array.zip3 works``() = let xs = [|1.; 2.; 3.|] let ys = [|1.; 2.; 3.|] let zs = [|1.; 2.; 3.|] @@ -764,7 +764,7 @@ let ``Array.last works``() = let xs = [|1.; 2.; 3.; 4.|] xs |> Array.last |> equal 4. - + [] let ``Array.tryLast works``() = let xs = [|1.; 2.; 3.; 4.|] diff --git a/src/tests/AsyncTests.fs b/src/tests/Main/AsyncTests.fs similarity index 95% rename from src/tests/AsyncTests.fs rename to src/tests/Main/AsyncTests.fs index e7dfbf100f..cb9c68d7f2 100644 --- a/src/tests/AsyncTests.fs +++ b/src/tests/Main/AsyncTests.fs @@ -1,7 +1,7 @@ -[] +[] module Fable.Tests.Async open System -open NUnit.Framework +open Util.Testing open Fable.Tests.Util [] @@ -12,7 +12,7 @@ let ``Simple async translates without exception``() = [] let ``Async while binding works correctly``() = let mutable result = 0 - async { + async { while result < 10 do result <- result + 1 } |> Async.StartImmediate @@ -22,7 +22,7 @@ let ``Async while binding works correctly``() = let ``Async for binding works correctly``() = let inputs = [|1; 2; 3|] let result = ref 0 - async { + async { for inp in inputs do result := !result + inp } |> Async.StartImmediate @@ -32,7 +32,7 @@ let ``Async for binding works correctly``() = let ``Async exceptions are handled correctly``() = let result = ref 0 let f shouldThrow = - async { + async { try if shouldThrow then failwith "boom!" else result := 12 @@ -45,13 +45,13 @@ let ``Async exceptions are handled correctly``() = let ``Simple async is executed correctly``() = let result = ref false let x = async { return 99 } - async { + async { let! x = x let y = 99 result := x = y } //TODO: RunSynchronously would make more sense here but in JS I think this will be ok. - |> Async.StartImmediate + |> Async.StartImmediate equal !result true type DisposableAction(f) = @@ -66,12 +66,12 @@ let ``async use statements should dispose of resources when they go out of scope let resource = async { return new DisposableAction(fun () -> isDisposed := true) } - async { + async { use! r = resource step1ok := not !isDisposed } //TODO: RunSynchronously would make more sense here but in JS I think this will be ok. - |> Async.StartImmediate + |> Async.StartImmediate step2ok := !isDisposed (!step1ok && !step2ok) |> equal true @@ -80,7 +80,7 @@ let ``Try ... with ... expressions inside async expressions work the same``() = let result = ref "" let throw() : unit = raise(exn "Boo!") - let append(x) = + let append(x) = result := !result + x let innerAsync() = async { @@ -91,7 +91,7 @@ let ``Try ... with ... expressions inside async expressions work the same``() = with _ -> append "d" append "e" } - async { + async { append "a" try do! innerAsync() with _ -> append "2" @@ -209,7 +209,7 @@ let ``Interaction between Async and Promise works``() = } |> Async.RunSynchronously [] -let ``Promises can be cancelled``() = +let ``Promises can be cancelled``() = async { let res = ref 0 let tcs = new System.Threading.CancellationTokenSource(50) @@ -262,7 +262,7 @@ let ``MailboxProcessor.postAndAsyncReply works``() = async { let formatString = "Msg: {0} - {1}" let agent = MailboxProcessor.Start(fun inbox -> - let rec loop n = async { + let rec loop n = async { let! (message, replyChannel) = inbox.Receive() do! Async.Sleep(100) // Delay a bit replyChannel.Reply(String.Format(formatString, n, message)) @@ -277,8 +277,8 @@ let ``MailboxProcessor.postAndAsyncReply works``() = [] let ``Async try .. with returns correctly from 'with' branch``() = - let work = async { - try + let work = async { + try failwith "testing" return -1 with e -> @@ -305,29 +305,29 @@ let ``Deep recursion with async doesn't cause stack overflow``() = let ``Nested failure propagates in async expressions``() = async { let data = ref "" - let f1 x = + let f1 x = async { try failwith "1" return x with - | e -> return! failwith ("2 " + e.Message.Trim('"')) + | e -> return! failwith ("2 " + e.Message.Trim('"')) } - let f2 x = + let f2 x = async { try return! f1 x with - | e -> return! failwith ("3 " + e.Message.Trim('"')) + | e -> return! failwith ("3 " + e.Message.Trim('"')) } let f() = - async { + async { try let! y = f2 4 return () with | e -> data := e.Message.Trim('"') - } + } |> Async.StartImmediate f() do! Async.Sleep 100 @@ -360,13 +360,13 @@ let ``Final statement inside async expressions can throw``() = try data := !data + "1 " finally failwith "boom!" } - async { + async { try do! f() return () with | e -> data := !data + e.Message.Trim('"') - } + } |> Async.StartImmediate do! Async.Sleep 100 equal "1 boom!" !data diff --git a/src/tests/ComparisonTests.fs b/src/tests/Main/ComparisonTests.fs similarity index 90% rename from src/tests/ComparisonTests.fs rename to src/tests/Main/ComparisonTests.fs index e922c6dfe9..bab5f10ab7 100644 --- a/src/tests/ComparisonTests.fs +++ b/src/tests/Main/ComparisonTests.fs @@ -1,12 +1,12 @@ -[] +[] module Fable.Tests.Comparison open System -open NUnit.Framework +open Util.Testing open Fable.Tests.Util open System.Collections.Generic [] -let ``Typed array equality works``() = +let ``Typed array equality works``() = let xs1 = [| 1; 2; 3 |] let xs2 = [| 1; 2; 3 |] let xs3 = [| 1; 2; 4 |] @@ -18,7 +18,7 @@ let ``Typed array equality works``() = equal true (xs1 <> xs4) [] -let ``Array equality works``() = +let ``Array equality works``() = let xs1 = [| "1"; "2"; "3" |] let xs2 = [| "1"; "2"; "3" |] let xs3 = [| "1"; "2"; "4" |] @@ -30,7 +30,7 @@ let ``Array equality works``() = equal true (xs1 <> xs4) [] -let ``Tuple equality works``() = +let ``Tuple equality works``() = let xs1 = ( 1, 2, 3 ) let xs2 = ( 1, 2, 3 ) let xs3 = ( 1, 2, 4 ) @@ -40,7 +40,7 @@ let ``Tuple equality works``() = equal false (xs1 <> xs2) [] -let ``List equality works``() = +let ``List equality works``() = let xs1 = [ 1; 2; 3 ] let xs2 = [ 1; 2; 3 ] let xs3 = [ 1; 2; 4 ] @@ -50,7 +50,7 @@ let ``List equality works``() = equal false (xs1 <> xs2) [] -let ``Set equality works``() = +let ``Set equality works``() = let xs1 = Set [ 1; 2; 3 ] let xs2 = Set [ 1; 2; 3 ] let xs3 = Set [ 1; 2; 4 ] @@ -62,9 +62,9 @@ let ``Set equality works``() = equal false (xs1 <> xs2) equal true (xs1 = xs4) equal false (xs1 <> xs5) - + [] -let ``Map equality works``() = +let ``Map equality works``() = let xs1 = Map [ ("a", 1); ("b", 2); ("c", 3) ] let xs2 = Map [ ("a", 1); ("b", 2); ("c", 3) ] let xs3 = Map [ ("a", 1); ("b", 2); ("c", 4) ] @@ -74,11 +74,11 @@ let ``Map equality works``() = equal true (xs1 <> xs3) equal false (xs1 <> xs2) equal true (xs1 = xs4) - + type UTest = A of int | B of int [] -let ``Union equality works``() = +let ``Union equality works``() = let u1 = A 2 let u2 = A 2 let u3 = A 4 @@ -120,7 +120,7 @@ type UTest2 = #endif [] -let ``Union custom equality works``() = +let ``Union custom equality works``() = let u1 = String "A" let u2 = String "A" let u3 = String "AA" @@ -130,7 +130,7 @@ let ``Union custom equality works``() = type RTest = { a: int; b: int } [] -let ``Record equality works``() = +let ``Record equality works``() = let r1 = { a = 1; b = 2 } let r2 = { a = 1; b = 2 } let r3 = { a = 1; b = 4 } @@ -145,7 +145,7 @@ let ``Record equality works``() = type RTest2 = { a2: int; b2: int } [] -let ``Record reference equality works``() = +let ``Record reference equality works``() = let r1 = { a2 = 1; b2 = 2 } let r2 = { a2 = 1; b2 = 2 } equal false (r1 = r2) @@ -156,7 +156,7 @@ type Test(i: int) = override x.Equals(yobj) = match yobj with | :? Test as y -> y.Value + 1 = x.Value - | _ -> false + | _ -> false interface System.IComparable with member x.CompareTo(yobj) = match yobj with @@ -170,9 +170,9 @@ type Test(i: int) = interface System.IEquatable with member x.Equals(y) = y.Value + 1 = x.Value - + [] -let ``Equality with objects implementing IEquatable works``() = +let ``Equality with objects implementing IEquatable works``() = let c1 = Test(5) let c2 = Test(4) let c3 = Test(5) @@ -184,7 +184,7 @@ let ``Equality with objects implementing IEquatable works``() = Object.ReferenceEquals(c1, c2) |> equal false [] -let ``Typed array comparison works``() = +let ``Typed array comparison works``() = let xs1 = [| 1; 2; 3 |] let xs2 = [| 1; 2; 3 |] let xs3 = [| 1; 2; 4 |] @@ -202,7 +202,7 @@ let ``Typed array comparison works``() = equal false (xs1 > xs6) [] -let ``Array comparison works``() = +let ``Array comparison works``() = let xs1 = [| "1"; "2"; "3" |] let xs2 = [| "1"; "2"; "3" |] let xs3 = [| "1"; "2"; "4" |] @@ -220,7 +220,7 @@ let ``Array comparison works``() = equal false (xs1 > xs6) [] -let ``Tuple comparison works``() = +let ``Tuple comparison works``() = let xs1 = ( 1, 2, 3 ) let xs2 = ( 1, 2, 3 ) let xs3 = ( 1, 2, 4 ) @@ -232,7 +232,7 @@ let ``Tuple comparison works``() = equal false (xs1 < xs4) [] -let ``List comparison works``() = +let ``List comparison works``() = let xs1 = [ 1; 2; 3 ] let xs2 = [ 1; 2; 3 ] let xs3 = [ 1; 2; 4 ] @@ -250,7 +250,7 @@ let ``List comparison works``() = equal false (xs1 > xs6) [] -let ``Set comparison works``() = +let ``Set comparison works``() = let xs1 = Set [ 1; 2; 3 ] let xs2 = Set [ 1; 2; 3 ] let xs3 = Set [ 1; 2; 4 ] @@ -265,9 +265,9 @@ let ``Set comparison works``() = equal 1 (compare xs1 xs5) equal true (xs1 > xs5) equal 0 (compare xs1 xs6) - + [] -let ``Map comparison works``() = +let ``Map comparison works``() = let xs1 = Map [ ("a", 1); ("b", 2); ("c", 3) ] let xs2 = Map [ ("a", 1); ("b", 2); ("c", 3) ] let xs3 = Map [ ("a", 1); ("b", 2); ("c", 4) ] @@ -285,7 +285,7 @@ let ``Map comparison works``() = equal false (xs1 > xs6) [] -let ``Union comparison works``() = +let ``Union comparison works``() = let u1 = A 2 let u2 = A 2 let u3 = A 4 @@ -299,36 +299,36 @@ let ``Union comparison works``() = (compare u1 u5) = 0 |> equal false [] -let ``Union custom comparison works``() = +let ``Union custom comparison works``() = let u1 = String "A" let u2 = String "A" let u3 = String "AA" equal 0 (compare u1 u3) equal true (compare u1 u2 > 0) - + [] -let ``Record comparison works``() = +let ``Record comparison works``() = let r1 = { a = 1; b = 2 } let r2 = { a = 1; b = 2 } let r3 = { a = 1; b = 4 } equal 0 (compare r1 r2) (compare r1 r3) = 0 |> equal false - + [] -let ``Comparison with objects implementing IComparable works``() = +let ``Comparison with objects implementing IComparable works``() = let c1 = Test(5) let c2 = Test(4) let c3 = Test(5) equal 0 (compare c1 c2) equal 1 (compare c1 c3) - equal true (c1 > c3) + equal true (c1 > c3) [] -let ``max works with primitives``() = +let ``max works with primitives``() = max 1 2 |> equal 2 Math.Max(1, 2) |> equal 2 max "a" "b" |> equal "b" - + [] let ``max works with records``() = let r1 = {a=1; b=1} @@ -336,31 +336,31 @@ let ``max works with records``() = max r1 r2 |> equal r2 [] -let ``max with objects implementing IComparable works``() = +let ``max with objects implementing IComparable works``() = let c1 = Test(5) let c2 = Test(5) max c1 c2 |> equal c1 - + [] -let ``min works with primitives``() = +let ``min works with primitives``() = min 1 2 |> equal 1 Math.Min(1, 2) |> equal 1 min "a" "b" |> equal "a" - + [] let ``min works with records``() = let r1 = {a=1; b=1} let r2 = {a=1; b=2} min r1 r2 |> equal r1 - + [] -let ``min with objects implementing IComparable works``() = +let ``min with objects implementing IComparable works``() = let c1 = Test(5) let c2 = Test(5) min c1 c2 |> equal c2 [] -let ``isNull works with primitives``() = +let ``isNull works with primitives``() = isNull null |> equal true isNull "" |> equal false isNull "0" |> equal false diff --git a/src/tests/ConvertTests.fs b/src/tests/Main/ConvertTests.fs similarity index 99% rename from src/tests/ConvertTests.fs rename to src/tests/Main/ConvertTests.fs index 03b2cd080e..c0d2dc11be 100644 --- a/src/tests/ConvertTests.fs +++ b/src/tests/Main/ConvertTests.fs @@ -1,7 +1,7 @@ -[] +[] module Fable.Tests.Convert open System -open NUnit.Framework +open Util.Testing open Fable.Tests.Util [] diff --git a/src/tests/DateTimeTests.fs b/src/tests/Main/DateTimeTests.fs similarity index 99% rename from src/tests/DateTimeTests.fs rename to src/tests/Main/DateTimeTests.fs index 40af95c4c7..fa0c202096 100644 --- a/src/tests/DateTimeTests.fs +++ b/src/tests/Main/DateTimeTests.fs @@ -1,7 +1,7 @@ -[] +[] module Fable.Tests.DateTime open System -open NUnit.Framework +open Util.Testing open Fable.Tests.Util #if DOTNETCORE @@ -40,8 +40,8 @@ let ``DateTime.ToString with format works``() = let ``DateTime can be JSON serialized forth and back``() = let utc = DateTime(2016, 8, 4, 17, 30, 0, DateTimeKind.Utc) #if FABLE_COMPILER - let json = Fable.Core.Serialize.toJson utc - let utc = Fable.Core.Serialize.ofJson json + let json = Fable.Core.JsInterop.toJson utc + let utc = Fable.Core.JsInterop.ofJson json #else let json = Newtonsoft.Json.JsonConvert.SerializeObject utc let utc = Newtonsoft.Json.JsonConvert.DeserializeObject json diff --git a/src/tests/DictionaryTests.fs b/src/tests/Main/DictionaryTests.fs similarity index 92% rename from src/tests/DictionaryTests.fs rename to src/tests/Main/DictionaryTests.fs index 0ee8ce67cb..acbf5ed0bf 100644 --- a/src/tests/DictionaryTests.fs +++ b/src/tests/Main/DictionaryTests.fs @@ -1,8 +1,8 @@ -[] +[] module Fable.Tests.Dictionaries open System open System.Collections.Generic -open NUnit.Framework +open Util.Testing open Fable.Tests.Util [] @@ -21,7 +21,7 @@ let ``Dictionary creation from IDictionary works``() = let dic = Dictionary<_,_>(idic) dic.Add("100", 100) equal 10 idic.Count - equal 11 dic.Count + equal 11 dic.Count [] let ``Interface IDictionary iteration works``() = @@ -93,7 +93,7 @@ let ``Dictionary.Keys works``() = dic.Add("B", 2) dic.Keys |> Seq.fold (fun acc k -> acc + dic.[k]) 0 |> equal 3 - + [] let ``Dictionary.Keys.Count works``() = let dic = Dictionary<_,_>() @@ -101,7 +101,7 @@ let ``Dictionary.Keys.Count works``() = dic.Add("B", 2) dic.Keys.Count |> equal 2 - + [] let ``Dictionary.Values works``() = let dic = Dictionary<_,_>() @@ -197,14 +197,14 @@ type R = { i: int; s: string } let ``Dictionaries can be JSON serialized forth and back``() = let x = Dictionary<_,_>() x.Add("a", { i=1; s="1" }) - x.Add("b", { i=2; s="2" }) + x.Add("b", { i=2; s="2" }) #if FABLE_COMPILER - let json = Fable.Core.Serialize.toJson x - let x2 = Fable.Core.Serialize.ofJson> json + let json = Fable.Core.JsInterop.toJson x + let x2 = Fable.Core.JsInterop.ofJson> json (0, x2) ||> Seq.fold (fun acc kv -> acc + kv.Value.i) - |> equal 3 - let json = Fable.Core.Serialize.toJsonWithTypeInfo x - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo> json + |> equal 3 + let json = Fable.Core.JsInterop.toJsonWithTypeInfo x + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo> json #else let json = Newtonsoft.Json.JsonConvert.SerializeObject x let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject> json @@ -216,11 +216,11 @@ let ``Dictionaries can be JSON serialized forth and back``() = let ``Dictionaries serialized with Json.NET can be deserialized``() = // let x = Dictionary<_,_>() // x.Add("a", { i=1; s="1" }) - // x.Add("b", { i=2; s="2" }) + // x.Add("b", { i=2; s="2" }) // let json = JsonConvert.SerializeObject(x, JsonSerializerSettings(TypeNameHandling=TypeNameHandling.All)) let json = """{"$type":"System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[Fable.Tests.Maps+R, Fable.Tests]], FSharp.Core","a":{"$type":"Fable.Tests.Maps+R, Fable.Tests","i":1,"s":"1"},"b":{"$type":"Fable.Tests.Maps+R, Fable.Tests","i":2,"s":"2"}}""" #if FABLE_COMPILER - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo> json + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo> json #else let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject> json #endif diff --git a/src/tests/EnumTests.fs b/src/tests/Main/EnumTests.fs similarity index 98% rename from src/tests/EnumTests.fs rename to src/tests/Main/EnumTests.fs index 875ecf1309..19dce3ab20 100644 --- a/src/tests/EnumTests.fs +++ b/src/tests/Main/EnumTests.fs @@ -1,9 +1,9 @@ -[] +[] module Fable.Tests.Enum open System open FSharp.Core.LanguagePrimitives -open NUnit.Framework +open Util.Testing open Fable.Tests.Util type Fruits = diff --git a/src/tests/EnumerableTests.fs b/src/tests/Main/EnumerableTests.fs similarity index 82% rename from src/tests/EnumerableTests.fs rename to src/tests/Main/EnumerableTests.fs index df06ef9ad8..e3b87f8cbc 100644 --- a/src/tests/EnumerableTests.fs +++ b/src/tests/Main/EnumerableTests.fs @@ -1,15 +1,15 @@ -[] +[] module Fable.Tests.Enumerable open System open System.Collections open System.Collections.Generic -open NUnit.Framework +open Util.Testing open Fable.Tests.Util type Enumerator<'T>(gen) = - interface IEnumerable<'T> with + interface IEnumerable<'T> with member x.GetEnumerator() = gen() - interface IEnumerable with + interface IEnumerable with member x.GetEnumerator() = (gen() :> IEnumerator) type Fibonacci() = @@ -20,7 +20,7 @@ type Fibonacci() = member x.Current = box (fst state) member x.MoveNext() = state <- (snd state, fst state + snd state); (fst state) < 1000 member x.Reset() = state <- (1,1) - interface System.IDisposable with + interface System.IDisposable with member x.Dispose() = () let fibGen() = @@ -31,13 +31,13 @@ let fibGen() = member x.Current = box (fst state) member x.MoveNext() = state <- (snd state, fst state + snd state); (fst state) < 1000 member x.Reset() = state <- (1,1) - interface System.IDisposable with + interface System.IDisposable with member x.Dispose() = () } -let toSeq gen = - { new IEnumerable<'T> with - member x.GetEnumerator() = gen() - interface IEnumerable with +let toSeq gen = + { new IEnumerable<'T> with + member x.GetEnumerator() = gen() + interface IEnumerable with member x.GetEnumerator() = (gen() :> IEnumerator) } let fib() = Seq.unfold (fun state -> diff --git a/src/tests/EventTests.fs b/src/tests/Main/EventTests.fs similarity index 88% rename from src/tests/EventTests.fs rename to src/tests/Main/EventTests.fs index 4f48571a66..bdd97635b6 100644 --- a/src/tests/EventTests.fs +++ b/src/tests/Main/EventTests.fs @@ -1,7 +1,7 @@ -[] +[] module Fable.Tests.Event open System -open NUnit.Framework +open Util.Testing open Fable.Tests.Util [] @@ -22,16 +22,16 @@ let ``Event.choose works``() = |> Event.add (fun n -> result <- n) source.Trigger (Choice1Of2 2) source.Trigger (Choice2Of2 3) - + equal 3 result [] let ``Event.filter works``() = - let mutable result = 0 - + let mutable result = 0 + let source = Event<_>() source.Publish - |> Event.filter ((>) 5) + |> Event.filter ((>) 5) |> Event.add (fun n -> result <- n ) source.Trigger 3 equal 3 result @@ -40,14 +40,14 @@ let ``Event.filter works``() = [] let ``Event.map works``() = - let mutable result = 0 + let mutable result = 0 let source = Event<_>() - source.Publish + source.Publish |> Event.map ((+) 3) |> Event.add (fun n -> result <- n) source.Trigger 10 - + equal 13 result [] @@ -77,10 +77,10 @@ let ``Event.pairwise works``() = result2 <- y) source.Trigger 1 source.Trigger 2 - + equal 1 result1 equal 2 result2 - + [] let ``Event.partition works``() = @@ -94,7 +94,7 @@ let ``Event.partition works``() = Event.add (fun n -> result2 <- n) source2 source.Trigger 8 source.Trigger 3 - + equal 3 result1 equal 8 result2 @@ -109,7 +109,7 @@ let ``Event.scan works``() = ) source.Trigger 1 source.Trigger 1 - + equal state 7 [] @@ -127,50 +127,50 @@ let ``Event.split works``() = Event.add (fun n -> result2 <- n) source2 source.Trigger 6 source.Trigger 2 - + equal 6 result1 - equal 12 result2 - + equal 12 result2 + [] let ``IEvent.add works``() = - let mutable result = 0 - + let mutable result = 0 + let source = Event<_> () source.Publish.Add(fun n -> result <- n) - + source.Trigger 6 equal 6 result - + [] let ``IEvent.Subscribe works``() = - let mutable result = 0 - - let source = Event<_> () + let mutable result = 0 + + let source = Event<_> () source.Publish.Subscribe(fun n -> result <- n) |> ignore - + source.Trigger 6 equal 6 result [] let ``IEvent.AddHandler works``() = - let mutable result = 0 - - let source = Event<_> () + let mutable result = 0 + + let source = Event<_> () source.Publish.AddHandler(new Handler<_>(fun sender n -> result <- n)) |> ignore - + source.Trigger 6 equal 6 result - + [] let ``IEvent.RemoveHandler works``() = - let mutable result = 0 - + let mutable result = 0 + let handler = new Handler<_>(fun sender n -> result <- n) - - let source = Event<_> () + + let source = Event<_> () source.Publish.AddHandler(handler) |> ignore source.Publish.RemoveHandler(handler) - + source.Trigger 6 equal 0 result @@ -202,5 +202,5 @@ let ``Classes can trigger non-CLI events``() = let disp = classWithEvent.Event.Subscribe(fun (sender, arg) -> result <- arg) classWithEvent.TestEvent("Hello") disp.Dispose() - classWithEvent.TestEvent("Bye") + classWithEvent.TestEvent("Bye") equal "Hello" result diff --git a/src/tests/Other/Fable.Tests.Clamp.fsproj b/src/tests/Main/Fable.Tests.fsproj similarity index 87% rename from src/tests/Other/Fable.Tests.Clamp.fsproj rename to src/tests/Main/Fable.Tests.fsproj index 462ca2f3b7..80add10b40 100644 --- a/src/tests/Other/Fable.Tests.Clamp.fsproj +++ b/src/tests/Main/Fable.Tests.fsproj @@ -1,56 +1,90 @@ - + - + Fable.Tests + Fable.Tests + Fable.Tests Debug AnyCPU 2.0 - 1e44403b-7834-4842-91b1-53a5fa731c58 + 6ef06954-fbdf-42c7-815c-b13ba2926c93 Library - Fable.Tests.Clamped - Fable.Tests.Clamped v4.5 - true 4.4.0.0 - Fable.Tests.Clamp true - full + Full false false bin\Debug\ DEBUG;TRACE 3 - AnyCPU - true - pdbonly + PdbOnly true true bin\Release\ TRACE 3 - AnyCPU - true - - True - + + ../../../build/fable-core/Fable.Core.dll + + + ../../../build/tests_dll/Fable.Tests.DllRef.dll + - - + + Fable.Tests.Spaces.fsproj + {1e44403b-7834-4842-91b1-53a5fa731c58} + + + Fable.Tests.External.fsproj + {c842c174-2ce4-4d85-b694-7a5f1c357ee4} + - - 11 - + + + + + + + + + + + + @@ -64,13 +98,6 @@ - @@ -82,6 +109,71 @@ + + + + + ..\..\..\packages\FSharp.Core\lib\net20\FSharp.Core.dll + True + True + + + + + + + ..\..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll + True + True + + + + + + + ..\..\..\packages\FSharp.Core\lib\portable-net45+monoandroid10+monotouch10+xamarinios10\FSharp.Core.dll + True + True + + + + + + + ..\..\..\packages\FSharp.Core\lib\portable-net45+netcore45\FSharp.Core.dll + True + True + + + + + + + ..\..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wp8\FSharp.Core.dll + True + True + + + + + + + ..\..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wpa81+wp8\FSharp.Core.dll + True + True + + + + + + + ..\..\..\packages\FSharp.Core\lib\portable-net45+sl5+netcore45\FSharp.Core.dll + True + True + + + + diff --git a/src/tests/HashSetTests.fs b/src/tests/Main/HashSetTests.fs similarity index 89% rename from src/tests/HashSetTests.fs rename to src/tests/Main/HashSetTests.fs index 01ebac013c..5cd3e8b8a6 100644 --- a/src/tests/HashSetTests.fs +++ b/src/tests/Main/HashSetTests.fs @@ -1,6 +1,6 @@ -[] +[] module Fable.Tests.HashSets -open NUnit.Framework +open Util.Testing open Fable.Tests.Util open System.Collections.Generic @@ -30,19 +30,19 @@ let ``HashSet.Add returns false if already present``() = [] let ``HashSet.Remove works when item is present``() = - let xs = set [1] + let xs = set [1] xs.Remove 1 |> equal true xs.Count |> equal 0 [] let ``HashSet.Remove works when item is not present``() = - let xs = set [1; 2] + let xs = set [1; 2] xs.Remove 3 |> equal false xs.Count |> equal 2 [] let ``HashSet.UnionWith works``() = - let xs = set [1; 2] + let xs = set [1; 2] let ys = set [2; 4] xs.UnionWith ys (xs.Contains 1 && xs.Contains 2 && xs.Contains 4) @@ -50,7 +50,7 @@ let ``HashSet.UnionWith works``() = [] let ``HashSet.IntersectWith works``() = - let xs = set [1; 2] + let xs = set [1; 2] let ys = set [2; 4] xs.IntersectWith ys xs.Contains 1 |> equal false @@ -58,7 +58,7 @@ let ``HashSet.IntersectWith works``() = [] let ``HashSet.ExceptWith works``() = - let xs = set [1; 2] + let xs = set [1; 2] let ys = set [2; 4] xs.ExceptWith ys xs.Contains 1 |> equal true @@ -99,7 +99,7 @@ let ``HashSet.Count works``() = let zs = set [1; 1] zs.Count |> equal 1 let zs' = set [1; 2] - zs'.Count |> equal 2 + zs'.Count |> equal 2 [] let ``HashSet.Add works``() = @@ -122,7 +122,7 @@ let ``HashSet.Contains works``() = hs.Add("Hello") |> equal true hs.Add("World!") |> equal true hs.Contains("Hello") |> equal true - hs.Contains("Everybody!") |> equal false + hs.Contains("Everybody!") |> equal false [] let ``HashSet.CopyTo works``() = @@ -163,12 +163,12 @@ let ``HashSet can be JSON serialized forth and back``() = x.Add(1) |> ignore x.Add(2) |> ignore #if FABLE_COMPILER - let json = Fable.Core.Serialize.toJson x - let x2 = Fable.Core.Serialize.ofJson> json + let json = Fable.Core.JsInterop.toJson x + let x2 = Fable.Core.JsInterop.ofJson> json x2.IsSubsetOf x |> equal true (0, x2) ||> Seq.fold (fun acc v -> acc + v) |> equal 3 - let json = Fable.Core.Serialize.toJsonWithTypeInfo x - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo> json + let json = Fable.Core.JsInterop.toJsonWithTypeInfo x + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo> json #else let json = Newtonsoft.Json.JsonConvert.SerializeObject x let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject> json @@ -184,7 +184,7 @@ let ``HashSet serialized with Json.NET can be deserialized``() = // let json = JsonConvert.SerializeObject(x, JsonSerializerSettings(TypeNameHandling=TypeNameHandling.All)) let json = """{"$type":"System.Collections.Generic.HashSet`1[[Fable.Tests.HashSets+R, Fable.Tests]], FSharp.Core","$values":[{"$type":"Fable.Tests.HashSets+R, Fable.Tests","i":1,"s":"1"},{"$type":"Fable.Tests.HashSets+R, Fable.Tests","i":2,"s":"2"}]}""" #if FABLE_COMPILER - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo> json + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo> json #else let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject> json #endif diff --git a/src/tests/JsonTests.fs b/src/tests/Main/JsonTests.fs similarity index 75% rename from src/tests/JsonTests.fs rename to src/tests/Main/JsonTests.fs index 973d6d7750..e00dcdd40c 100644 --- a/src/tests/JsonTests.fs +++ b/src/tests/Main/JsonTests.fs @@ -1,17 +1,15 @@ -[] +[] module Fable.Tests.Json -open NUnit.Framework +open Util.Testing open Fable.Tests.Util -open Newtonsoft.Json -type S = #if FABLE_COMPILER - static member toJson(x) = Fable.Core.Serialize.toJson(x) - static member ofJson<'T>(x, []?t) = - Fable.Core.Serialize.ofJson<'T>(x, ?t=t) +let inline toJson(x) = Fable.Core.JsInterop.toJson(x) +let inline ofJson<'T>(x) = Fable.Core.JsInterop.ofJson<'T>(x) #else - static member toJson x = JsonConvert.SerializeObject(x, Fable.JsonConverter()) - static member ofJson<'T> x = JsonConvert.DeserializeObject<'T>(x, Fable.JsonConverter()) +open Newtonsoft.Json +let toJson x = JsonConvert.SerializeObject(x, Fable.JsonConverter()) +let ofJson<'T> x = JsonConvert.DeserializeObject<'T>(x, Fable.JsonConverter()) #endif type Child = @@ -37,13 +35,13 @@ type C<'T> = {c: B<'T>} [] let ``Nested generics``() = let x = { c={ b={ a=R() } } } - let json = S.toJson x - let x2 = S.ofJson> json + let json = toJson x + let x2 = ofJson> json x2.c.b.a.Foo() |> equal "foo" [] let ``Records``() = - let json = + let json = """ { "Name": "foo", @@ -53,70 +51,70 @@ let ``Records``() = } } """ - let result: Simple = S.ofJson json + let result: Simple = ofJson json result.Name |> equal "foo" // Use the built in compare to ensure the fields are being hooked up. // Should compile to something like: result.Child.Equals(new Child("Hi", 10)) - result.Child = {a="Hi"; b=10} |> equal true + result.Child = {a="Hi"; b=10} |> equal true -[] +[] let ``Date``() = let d = System.DateTime(2016, 1, 1, 0, 0, 0, System.DateTimeKind.Utc) - let json = d |> S.toJson - let result : System.DateTime = S.ofJson json + let json = d |> toJson + let result : System.DateTime = ofJson json result.Year |> equal 2016 -type JsonDate = { +type JsonDate = { Date : System.DateTime } - -[] + +[] let ``Child Date``() = let d = System.DateTime(2016, 1, 1, 0, 0, 0, System.DateTimeKind.Utc) - let json = { Date = d } |> S.toJson - let result : JsonDate = S.ofJson json + let json = { Date = d } |> toJson + let result : JsonDate = ofJson json result.Date.Year |> equal 2016 type JsonArray = { Name : string } -[] +[] let ``Arrays``() = let json = """[{ "Name": "a" }, { "Name": "b" }]""" - let result : JsonArray[] = S.ofJson json + let result : JsonArray[] = ofJson json result |> Array.length |> equal 2 - result.[1] = { Name="b" } |> equal true + result.[1] = { Name="b" } |> equal true type ChildArray = { Children : JsonArray[] } -[] +[] let ``Child Array``() = let json = """{ "Children": [{ "Name": "a" }, { "Name": "b" }] }""" - let result : ChildArray = S.ofJson json + let result : ChildArray = ofJson json result.Children |> Array.length |> equal 2 result.Children.[1] = { Name="b" } |> equal true -[] +[] let ``String Generic List``() = let json = """["a","b"]""" - let result : System.Collections.Generic.List = S.ofJson json + let result : System.Collections.Generic.List = ofJson json result.Count |> equal 2 result.[1] |> equal "b" -[] +[] let ``Child Generic List``() = let json = """[{ "Name": "a" }, { "Name": "b" }]""" - let result : System.Collections.Generic.List = S.ofJson json + let result : System.Collections.Generic.List = ofJson json result.Count |> equal 2 - result.[1] = { Name="b" } |> equal true + result.[1] = { Name="b" } |> equal true -[] +[] let ``Lists``() = let json = """["a","b"]""" - let result : string list = S.ofJson json + let result : string list = ofJson json result |> List.length |> equal 2 result.Tail |> List.length |> equal 1 result.[1] |> equal "b" @@ -127,16 +125,16 @@ type ChildList = { Children : JsonArray list } -[] +[] let ``Child List``() = let json = """{ "Children": [{ "Name": "a" }, { "Name": "b" }] }""" - let result : ChildList = S.ofJson json + let result : ChildList = ofJson json result.Children |> List.length |> equal 2 result.Children.[1] = { Name="b" } |> equal true type Wrapper<'T> = { thing : 'T } -let inline parseAndUnwrap json: 'T = (S.ofJson> json).thing +let inline parseAndUnwrap json: 'T = (ofJson> json).thing [] let ``generic`` () = @@ -149,7 +147,7 @@ let ``generic`` () = result3 = {a = "a"; b = 1} |> equal true // let result4 : Child = parseAndUnwrap """ {"$type":"Fable.Tests.Json+Wrapper`1[[Fable.Tests.Json+Child, Fable.Tests]], Fable.Tests","thing":{"$type":"Fable.Tests.Json+Child, Fable.Tests","a":"a","b":1}} """ // if result4 <> {a = "a"; b = 1} then - // invalidOp "things not equal" + // invalidOp "things not equal" type OptionJson = { a: int option } @@ -157,9 +155,9 @@ type OptionJson = [] let ``Option Some`` () = let json1 = """ {"a":1 } """ - let result1 : OptionJson = S.ofJson json1 + let result1 : OptionJson = ofJson json1 let json2 = """ {"a":null } """ - let result2 : OptionJson = S.ofJson json2 + let result2 : OptionJson = ofJson json2 match result1.a, result2.a with | Some v, None -> v | _ -> -1 @@ -171,7 +169,7 @@ type ComplexOptionJson = [] let ``Complex Option Some`` () = let json = """ {"a":{"a":"John","b":14}} """ - let result : ComplexOptionJson = S.ofJson json + let result : ComplexOptionJson = ofJson json match result.a with | Some v -> v = {a="John";b=14} | None -> false @@ -183,7 +181,7 @@ type TupleJson = [] let ``Tuple`` () = let json = """ {"a":[1,2]} """ - let result : TupleJson = S.ofJson json + let result : TupleJson = ofJson json result.a = (1, 2) |> equal true type TupleComplexJson = @@ -192,7 +190,7 @@ type TupleComplexJson = [] let ``Complex Tuple`` () = let json = """ {"a":[1,{"a":"A","b":1}]} """ - let result : TupleComplexJson = S.ofJson json + let result : TupleComplexJson = ofJson json snd result.a = { a = "A"; b = 1 } |> equal true type SetJson = @@ -201,7 +199,7 @@ type SetJson = [] let ``Sets`` () = let json = """ {"a":["a","b"]} """ - let result : SetJson = S.ofJson json + let result : SetJson = ofJson json result.a |> Set.contains "b" |> equal true type MapJson = @@ -210,17 +208,17 @@ type MapJson = [] let ``Maps`` () = let json = """ {"a":{"a":{"a":"aa","b":1},"b":{"a":"bb","b":2}}} """ - let result : MapJson = S.ofJson json + let result : MapJson = ofJson json result.a.Count |> equal 2 result.a.["b"] = { a="bb"; b=2 } |> equal true - + type DictionaryJson = { a: System.Collections.Generic.Dictionary } [] let ``Dictionaries`` () = let json = """ {"a":{"a":{"a":"aa","b":1},"b":{"a":"bb","b":2}}} """ - let result : DictionaryJson = S.ofJson json + let result : DictionaryJson = ofJson json result.a.Count |> equal 2 result.a.["b"] = { a="bb"; b=2 } |> equal true @@ -232,7 +230,7 @@ type PropertyJson() = [] let ``Properties`` () = let json = """ {"Prop1": { "a":"aa", "b": 1 }} """ - let result : PropertyJson = S.ofJson json + let result : PropertyJson = ofJson json result.Prop1.a |> equal "aa" result.Prop1.b |> equal 1 #endif @@ -242,10 +240,10 @@ let ``Union of list``() = let u = CaseB [{Name="Sarah";Child={a="John";b=14}}] // Providing type parameters when treating method as a first class value // isn't supported in AppVeyor, see http://stackoverflow.com/a/2743479 - let json = S.toJson u - let u2: U = S.ofJson json + let json = toJson u + let u2: U = ofJson json u = u2 |> equal true - let u3: U = S.ofJson """{"CaseB":[{"Name":"Sarah","Child":{"a":"John","b":14}}]}""" + let u3: U = ofJson """{"CaseB":[{"Name":"Sarah","Child":{"a":"John","b":14}}]}""" u = u3 |> equal true type UnionJson = @@ -258,11 +256,11 @@ type UnionHolder = [] let ``Union of record`` () = let json = """ {"a":{"Type2": {"a":"a","b":1} }} """ - let result : UnionHolder = S.ofJson json + let result : UnionHolder = ofJson json match result.a with | Type2 t -> t = { a="a"; b=1 } | Type1 _ -> false - |> equal true + |> equal true type MultiUnion = | EmptyCase @@ -271,17 +269,17 @@ type MultiUnion = [] let ``Union case with no fields``() = - let u: MultiUnion = S.ofJson """ "EmptyCase" """ + let u: MultiUnion = ofJson """ "EmptyCase" """ u = EmptyCase |> equal true [] let ``Union case with single field``() = - let u: MultiUnion = S.ofJson """ {"SingleCase": 100} """ + let u: MultiUnion = ofJson """ {"SingleCase": 100} """ u = (SingleCase 100) |> equal true [] let ``Union case with multiple fields``() = - let u: MultiUnion = S.ofJson """ {"MultiCase": ["foo",{"a":"John","b":14}]} """ + let u: MultiUnion = ofJson """ {"MultiCase": ["foo",{"a":"John","b":14}]} """ let u2 = MultiCase("foo", {a="John"; b=14}) u = u2 |> equal true @@ -305,6 +303,6 @@ let ``Generics with interface`` () = // { name = "three"; data = { kind = "text"; text = "yo!" } } ] // let json = Newtonsoft.Json.JsonConvert.SerializeObject(x, Newtonsoft.Json.JsonSerializerSettings(TypeNameHandling=Newtonsoft.Json.TypeNameHandling.All)) let json = """ {"$type":"Microsoft.FSharp.Collections.FSharpList`1[[Fable.Tests.Json+Things, Fable.Tests]], FSharp.Core","$values":[{"$type":"Fable.Tests.Json+Things, Fable.Tests","name":"one","data":{"$type":"Fable.Tests.Json+Numbered, Fable.Tests","kind":"number","number":4}},{"$type":"Fable.Tests.Json+Things, Fable.Tests","name":"two","data":{"$type":"Fable.Tests.Json+Numbered, Fable.Tests","kind":"number","number":3}},{"$type":"Fable.Tests.Json+Things, Fable.Tests","name":"three","data":{"$type":"Fable.Tests.Json+Text, Fable.Tests","kind":"text","text":"yo!"}}]} """ - let result : Things list = Fable.Core.Serialize.ofJsonWithTypeInfo json + let result : Things list = Fable.Core.JsInterop.ofJsonWithTypeInfo json result.[1].data = ({ kind = "number"; number = 3 } :> IData) |> equal true #endif \ No newline at end of file diff --git a/src/tests/ListTests.fs b/src/tests/Main/ListTests.fs similarity index 94% rename from src/tests/ListTests.fs rename to src/tests/Main/ListTests.fs index 4c04b65b06..79a58ee7e1 100644 --- a/src/tests/ListTests.fs +++ b/src/tests/Main/ListTests.fs @@ -1,6 +1,6 @@ -[] +[] module Fable.Tests.Lists -open NUnit.Framework +open Util.Testing open Fable.Tests.Util [] @@ -47,7 +47,7 @@ let ``List slice works``() = xs.[..2] |> List.sum |> equal 6 xs.[2..] |> List.sum |> equal 7 xs.[1..2] |> List.sum |> equal 5 - + [] let ``List cons works``() = let xs = [1; 2; 3; 4] @@ -86,7 +86,7 @@ let ``List.choose works``() = let xs = [1; 2; 3; 4] let result = xs |> List.choose (fun x -> if x > 2 then Some x - else None) + else None) result.Head + result.Tail.Head |> equal 7 @@ -193,7 +193,7 @@ let ``List.tryFindIndexBack works``() = let xs = [1.; 2.; 3.; 4.] xs |> List.tryFindIndex ((>) 4.) |> equal (Some 0) xs |> List.tryFindIndexBack ((>) 4.) |> equal (Some 2) - xs |> List.tryFindIndexBack ((=) 5.) |> equal None + xs |> List.tryFindIndexBack ((=) 5.) |> equal None [] let ``List.fold works``() = @@ -212,7 +212,7 @@ let ``List.fold2 works``() = let ``List.foldBack works``() = [1; 2; 3; 4] |> List.foldBack (fun x acc -> acc - x) <| 100 - |> equal 90 + |> equal 90 [] let ``List.foldBack with composition works``() = @@ -294,7 +294,7 @@ let ``List.iteri2 works``() = [] let ``List.length works``() = let xs = [1; 2; 3; 4] - List.length xs + List.length xs |> equal 4 [] @@ -308,7 +308,7 @@ let ``List.mapi works``() = let xs = [1] let ys = xs |> List.mapi (fun i x -> i * x) equal 0 ys.Head - + [] let ``List.map2 works``() = let xs = [1;2] @@ -333,14 +333,14 @@ let ``List.mapi2 works``() = List.sum zs |> equal 16 [] -let ``List.mapFold works`` () = +let ``List.mapFold works`` () = let xs = [1y; 2y; 3y; 4y] let result = xs |> List.mapFold (fun acc x -> (x * 2y, acc + x)) 0y fst result |> List.sum |> equal 20y snd result |> equal 10y [] -let ``List.mapFoldBack works`` () = +let ``List.mapFoldBack works`` () = let xs = [1.; 2.; 3.; 4.] let result = List.mapFoldBack (fun x acc -> (x * -2., acc - x)) xs 0. fst result |> List.sum |> equal -20. @@ -397,7 +397,7 @@ let ``List.partition works``() = List.sum zs |> equal 9 equal 2 ys.[0] equal 5 zs.[2] - + [] let ``List.permute works``() = let xs = [1; 2; 3; 4; 5; 6] @@ -412,7 +412,7 @@ let ``List.pick works``() = match x with | 2 -> Some x | _ -> None) - |> equal 2 + |> equal 2 [] let ``List.range works``() = @@ -433,7 +433,7 @@ let ``List.reduce works``() = let ``List.reduceBack works``() = let xs = [1; 2] xs |> List.reduceBack (+) - |> equal 3 + |> equal 3 [] let ``List.replicate works``() = @@ -452,7 +452,7 @@ let ``List.scan works``() = let ys = (0, xs) ||> List.scan (fun acc x -> acc - x) ys.[3] + ys.[4] |> equal -16 - + [] let ``List.scanBack works``() = @@ -466,14 +466,14 @@ let ``List.sort works``() = let xs = [3; 4; 1; -3; 2; 10] xs |> List.sort |> List.take 3 |> List.sum |> equal 0 let ys = ["a"; "c"; "B"; "d"] - ys |> List.sort |> List.item 1 |> equal "a" + ys |> List.sort |> List.item 1 |> equal "a" [] let ``List.sortDescending works``() = let xs = [3; 4; 1; -3; 2; 10] xs |> List.sortDescending |> List.take 3 |> List.sum |> equal 17 let ys = ["a"; "c"; "B"; "d"] - ys |> List.sortDescending |> List.item 1 |> equal "c" + ys |> List.sortDescending |> List.item 1 |> equal "c" [] let ``List.sortBy works``() = @@ -518,7 +518,7 @@ let ``List.toSeq works``() = |> List.toSeq |> Seq.tail |> Seq.head |> equal 2 - + [] let ``List.tryPick works``() = [1; 2] @@ -541,7 +541,7 @@ let ``List.tryFindIndex works``() = let xs = [1; 2] let ys = xs |> List.tryFindIndex ((=) 2) ys.Value |> equal 1 - xs |> List.tryFindIndex ((=) 5) |> equal None + xs |> List.tryFindIndex ((=) 5) |> equal None [] @@ -604,7 +604,7 @@ let ``List.last works``() = let xs = [1.; 2.; 3.; 4.] xs |> List.last |> equal 4. - + [] let ``List.tryLast works``() = let xs = [1.; 2.; 3.; 4.] @@ -614,7 +614,7 @@ let ``List.tryLast works``() = [] let ``List.groupBy returns valid list``() = let xs = [1; 2] - let worked = + let worked = match List.groupBy (fun _ -> true) xs with | [true, [1; 2]] -> true | _ -> false @@ -623,24 +623,24 @@ let ``List.groupBy returns valid list``() = [] let ``List.unfold works``() = let xs = 0. |> List.unfold (fun n -> if n < 3.0 then Some(n+1., n+1.) else None) - let sum = - match xs with + let sum = + match xs with | n1::n2::n3::[] -> n1 + n2 + n3 | _ -> 0.0 sum |> equal 6.0 - + type R = { i: int; s: string } [] let ``Lists can be JSON serialized forth and back``() = let x = [{ i=1; s="1" }; { i=2; s="2" }] #if FABLE_COMPILER - let json = Fable.Core.Serialize.toJson x - let x2 = Fable.Core.Serialize.ofJson json + let json = Fable.Core.JsInterop.toJson x + let x2 = Fable.Core.JsInterop.ofJson json match x2 with _::[{ i=2; s="2" }] -> true | _ -> false |> equal true - let json = Fable.Core.Serialize.toJsonWithTypeInfo x - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo json + let json = Fable.Core.JsInterop.toJsonWithTypeInfo x + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo json #else let json = Newtonsoft.Json.JsonConvert.SerializeObject x let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject json @@ -652,11 +652,11 @@ let ``Lists can be JSON serialized forth and back``() = [] let ``Lists serialized with Json.NET can be deserialized``() = - // let x = [{ i=1; s="1" }; { i=2; s="2" }] + // let x = [{ i=1; s="1" }; { i=2; s="2" }] // let json = JsonConvert.SerializeObject(x, JsonSerializerSettings(TypeNameHandling=TypeNameHandling.All)) let json = """{"$type":"Microsoft.FSharp.Collections.FSharpList`1[[Fable.Tests.Lists+R, Fable.Tests]], FSharp.Core","$values":[{"$type":"Fable.Tests.Lists+R, Fable.Tests","i":1,"s":"1"},{"$type":"Fable.Tests.Lists+R, Fable.Tests","i":2,"s":"2"}]}""" #if FABLE_COMPILER - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo json + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo json #else let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject json #endif @@ -671,7 +671,7 @@ type List(x: int) = [] let ``Types with same name as imports work``() = let li = [List 5] - equal 5 li.Head.Value + equal 5 li.Head.Value type ExceptFoo = { Bar:string } [] diff --git a/src/tests/MapTests.fs b/src/tests/Main/MapTests.fs similarity index 92% rename from src/tests/MapTests.fs rename to src/tests/Main/MapTests.fs index 1c35252986..8907e82090 100644 --- a/src/tests/MapTests.fs +++ b/src/tests/Main/MapTests.fs @@ -1,6 +1,6 @@ -[] +[] module Fable.Tests.Maps -open NUnit.Framework +open Util.Testing open Fable.Tests.Util [] @@ -75,7 +75,7 @@ let ``Map.forAll works``() = let xs = Map [1.,1.; 2.,4.; 3.,9.; 4.,16.] xs |> Map.forall (fun x y -> x < 5.) |> equal true - + [] let ``Map.exists works``() = let xs = Map [1,1.; 2,4.; 3,9.; 4,16.] @@ -93,9 +93,9 @@ let ``Map.filter works``() = let ``Map.partition works``() = let xs = Map [1,1.; 2,4.; 3,9.; 4,16.] let ys, zs = xs |> Map.partition (fun x y -> x % 2 = 0) - ys.Count + zs.Count + ys.Count + zs.Count |> equal 4 - + [] let ``Map.fold works``() = let xs = Map [1,1.; 2,4.; 3,9.; 4,16.] @@ -144,7 +144,7 @@ let ``Map.tryFindKey works``() = [] let ``Map.pick works``() = let xs = Map [1,1.; 2,4.; 3,9.; 4,16.] - let y = xs |> Map.pick (fun k v -> + let y = xs |> Map.pick (fun k v -> match k with | 3 -> Some 10 | _ -> None) @@ -153,7 +153,7 @@ let ``Map.pick works``() = [] let ``Map.tryPick works``() = let xs = Map [1,1.; 2,4.; 3,9.; 4,16.] - let y = xs |> Map.tryPick (fun k v -> + let y = xs |> Map.tryPick (fun k v -> match k with | 3 -> Some 11 | _ -> None) @@ -204,11 +204,11 @@ type R = { i: int; s: string } let ``Maps can be JSON serialized forth and back``() = let x = ["a", { i=1; s="1" }; "b", { i=2; s="2" } ] |> Map #if FABLE_COMPILER - let json = Fable.Core.Serialize.toJson x - let x2 = Fable.Core.Serialize.ofJson> json + let json = Fable.Core.JsInterop.toJson x + let x2 = Fable.Core.JsInterop.ofJson> json (0, x2) ||> Map.fold (fun acc k v -> acc + v.i) |> equal 3 - let json = Fable.Core.Serialize.toJsonWithTypeInfo x - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo> json + let json = Fable.Core.JsInterop.toJsonWithTypeInfo x + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo> json #else let json = Newtonsoft.Json.JsonConvert.SerializeObject x let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject> json @@ -218,11 +218,11 @@ let ``Maps can be JSON serialized forth and back``() = [] let ``Maps serialized with Json.NET can be deserialized``() = - // let x = ["a", { i=1; s="1" }; "b", { i=2; s="2" } ] |> Map + // let x = ["a", { i=1; s="1" }; "b", { i=2; s="2" } ] |> Map // let json = JsonConvert.SerializeObject(x, JsonSerializerSettings(TypeNameHandling=TypeNameHandling.All)) let json = """{"$type":"Microsoft.FSharp.Collections.FSharpMap`2[[System.String, mscorlib],[Fable.Tests.Maps+R, Fable.Tests]], FSharp.Core","a":{"$type":"Fable.Tests.Maps+R, Fable.Tests","i":1,"s":"1"},"b":{"$type":"Fable.Tests.Maps+R, Fable.Tests","i":2,"s":"2"}}""" #if FABLE_COMPILER - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo> json + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo> json #else let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject> json #endif diff --git a/src/tests/MiscTests.fs b/src/tests/Main/MiscTests.fs similarity index 98% rename from src/tests/MiscTests.fs rename to src/tests/Main/MiscTests.fs index 98af388950..cbfaa87e2e 100644 --- a/src/tests/MiscTests.fs +++ b/src/tests/Main/MiscTests.fs @@ -1,8 +1,8 @@ -[] +[] module Fable.Tests.Misc open System -open NUnit.Framework +open Util.Testing open Fable.Tests.Util [] @@ -124,7 +124,7 @@ let ``Lambdas are converted to delegates with dynamic operators``() = #if !DOTNETCORE [] let ``Symbols in external projects work``() = - equal "Fable Rocks!" Clamp.Helper.ConditionalExternalValue + equal "Fable Rocks!" Spaces.Helper.ConditionalExternalValue #endif [] @@ -673,19 +673,33 @@ let ``use calls Dispose at the end of the scope`` () = res |> equal 10 !cell |> equal 20 -#if FABLE_COMPILER [] let ``Referencing a Fable project through a dll works``() = Fable.Tests.DllRef.Util.add2 5 |> equal 7 open Fable.Tests.DllRef +#if FABLE_COMPILER [] let ``Root members with JS non-valid chars work``() = // See #207 Lib.足す 3 2 |> equal 5 Lib.引く 3 2 |> equal 1 Lib.モジュール.ファンクション 0 |> equal false +[] +let ``Identifiers are encoded correctly``() = // See #482 + equal "bar1" Lib.``$5EAfoo`` + equal "bar2" Lib.``$5E$Afoo`` + equal "bar3" Lib.``$5EA$foo`` + equal "bar4" Lib.``^Afoo`` + equal "bar5" Lib.``תfoo`` + equal "bar6" Lib.``foo$5EA`` + equal "bar7" Lib.``foo$5E$A`` + equal "bar8" Lib.``foo$5EA$`` + equal "bar9" Lib.``foo^A`` + equal "bar10" Lib.``fooת`` +#endif + [] let ``Unchecked.defaultof works`` () = Unchecked.defaultof |> equal 0 @@ -749,6 +763,7 @@ let ``Pattern matching optimization works (switch expression)``() = | _ -> failwith "never" |> equal "One" +#if FABLE_COMPILER type IFooImported = abstract foo: string @@ -778,10 +793,10 @@ let ``Import with relative paths from external files works``() = [] let ``Import with relative paths from referenced dll works``() = - DllRef.Lib.モジュール.one |> equal 1 - DllRef.Lib.モジュール.three |> equal 3 - DllRef.Util.two |> equal 2 - DllRef.Util.four |> equal 4 + Lib.モジュール.one |> equal 1 + Lib.モジュール.three |> equal 3 + Util.two |> equal 2 + Util.four |> equal 4 [] let ``JS accepts any object as exception``() = @@ -791,19 +806,4 @@ let ``JS accepts any object as exception``() = with ex -> ex.Message |> equal """{"foo":3}""" - -[] -let ``Identifiers are encoded correctly``() = // See #482 - equal "bar1" Lib.``$5EAfoo`` - equal "bar2" Lib.``$5E$Afoo`` - equal "bar3" Lib.``$5EA$foo`` - equal "bar4" Lib.``^Afoo`` - equal "bar5" Lib.``תfoo`` - equal "bar6" Lib.``foo$5EA`` - equal "bar7" Lib.``foo$5E$A`` - equal "bar8" Lib.``foo$5EA$`` - equal "bar9" Lib.``foo^A`` - equal "bar10" Lib.``fooת`` - - #endif // FABLE_COMPILER diff --git a/src/tests/ObservableTests.fs b/src/tests/Main/ObservableTests.fs similarity index 96% rename from src/tests/ObservableTests.fs rename to src/tests/Main/ObservableTests.fs index 0693bff215..f35af62938 100644 --- a/src/tests/ObservableTests.fs +++ b/src/tests/Main/ObservableTests.fs @@ -1,7 +1,7 @@ -[] +[] module Fable.Tests.Observable open System -open NUnit.Framework +open Util.Testing open Fable.Tests.Util type MyObserver<'T>(f) = @@ -9,7 +9,7 @@ type MyObserver<'T>(f) = member x.OnNext v = f v member x.OnError e = () member x.OnCompleted() = () - + type MyObservable<'T>() = let listeners = ResizeArray>() member x.Trigger v = @@ -18,7 +18,7 @@ type MyObservable<'T>() = interface IObservable<'T> with member x.Subscribe w = listeners.Add(w) - { new IDisposable with + { new IDisposable with member x.Dispose() = listeners.Remove(w) |> ignore } [] @@ -43,7 +43,7 @@ let ``Disposing IObservable works``() = disp.Dispose() source.Trigger 5 equal 5 !res - + [] let ``Observable.add works``() = let source = MyObservable() diff --git a/src/tests/RecordTypeTests.fs b/src/tests/Main/RecordTypeTests.fs similarity index 82% rename from src/tests/RecordTypeTests.fs rename to src/tests/Main/RecordTypeTests.fs index 8452c23a74..0da82d8ef8 100644 --- a/src/tests/RecordTypeTests.fs +++ b/src/tests/Main/RecordTypeTests.fs @@ -1,21 +1,21 @@ -[] +[] module Fable.Tests.RecordTypes -open NUnit.Framework +open Util.Testing open Fable.Tests.Util -type RecursiveRecord = +type RecursiveRecord = { things : RecursiveRecord list } - + type Person = { name: string; mutable luckyNumber: int } member x.LuckyDay = x.luckyNumber % 30 member x.SignDoc str = str + " by " + x.name [] -let ``Recursive record does not cause issues``() = +let ``Recursive record does not cause issues``() = let r = { things = [ { things = [] } ] } equal r.things.Length 1 - + [] let ``Record property access can be generated``() = let x = { name = "Alfonso"; luckyNumber = 7 } @@ -66,18 +66,18 @@ type Parent = [] let ``Records can be JSON serialized forth and back``() = let parent = { children=[|{a="3";b=5}; {b=7;a="1"} |] } - let sum1 = parent.Sum() + let sum1 = parent.Sum() #if FABLE_COMPILER - let json = Fable.Core.Serialize.toJson parent - let parent2 = Fable.Core.Serialize.ofJson json + let json = Fable.Core.JsInterop.toJson parent + let parent2 = Fable.Core.JsInterop.ofJson json let sum2 = parent.Sum() equal true (box parent2 :? Parent) // Type is kept equal true (sum1 = sum2) // Prototype methods can be accessed - let json = Fable.Core.Serialize.toJsonWithTypeInfo parent - let parent2 = Fable.Core.Serialize.ofJsonWithTypeInfo json + let json = Fable.Core.JsInterop.toJsonWithTypeInfo parent + let parent2 = Fable.Core.JsInterop.ofJsonWithTypeInfo json #else let json = Newtonsoft.Json.JsonConvert.SerializeObject parent - let parent2 = Newtonsoft.Json.JsonConvert.DeserializeObject json + let parent2 = Newtonsoft.Json.JsonConvert.DeserializeObject json #endif let sum2 = parent.Sum() equal true (box parent2 :? Parent) // Type is kept @@ -89,7 +89,7 @@ let ``Records serialized with Json.NET can be deserialized``() = // let json = JsonConvert.SerializeObject(x, JsonSerializerSettings(TypeNameHandling=TypeNameHandling.All)) let json = """{"$type":"Fable.Tests.RecordTypes+Child","a":"Hi","b":10}""" #if FABLE_COMPILER - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo json + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo json #else let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject json #endif @@ -104,20 +104,20 @@ let ``Trying to deserialize a JSON with unexpected $type info throws an exceptio try f() |> ignore; true with _ -> false let child = {a="3";b=5} - let json = Serialize.toJsonWithTypeInfo child - success (fun () -> Serialize.ofJsonWithTypeInfo json) + let json = JsInterop.toJsonWithTypeInfo child + success (fun () -> JsInterop.ofJsonWithTypeInfo json) |> equal false - success (fun () -> Serialize.ofJsonWithTypeInfo json) + success (fun () -> JsInterop.ofJsonWithTypeInfo json) |> equal true - success (fun () -> Serialize.ofJsonWithTypeInfo json) + success (fun () -> JsInterop.ofJsonWithTypeInfo json) |> equal true [] let ``POJOS can be inflated``() = let x = Fable.Import.JS.JSON.parse """{"a":"Hi","b":10}""" - let x2: Child = Serialize.inflate x + let x2: Child = JsInterop.inflate x x2.a |> equal "Hi" - x2.b |> equal 10 + x2.b |> equal 10 [] #endif diff --git a/src/tests/Main/ReflectionTests.fs b/src/tests/Main/ReflectionTests.fs new file mode 100644 index 0000000000..6279468cfd --- /dev/null +++ b/src/tests/Main/ReflectionTests.fs @@ -0,0 +1,91 @@ +[] +module Fable.Tests.Reflection + +#if DOTNETCORE && !FABLE_COMPILER +open System.Reflection +module System = + type System.Type with + member this.IsGenericType = this.GetTypeInfo().IsGenericType +#endif + +open System +open Util.Testing +open Fable.Tests.Util + +type TestType = + | Union1 of string + +type TestType2 = + | Union2 of string + +type GenericRecord<'A,'B> = { a: 'A; b: 'B } + +// #if FABLE_COMPILER +// open Fable.Core +// type GenericParamTest = +// static member Foo<'T>(x: int, [] ?t: Type) = t.Value +// static member Bar<'T,'U>([] ?t1: Type, [] ?t2: Type) = t1.Value, t2.Value + +// [] +// let ``GenericParamAttribute works``() = +// let t = GenericParamTest.Foo(5) +// let t1, t2 = GenericParamTest.Bar() +// box t |> equal (box "string") +// box t1 |> equal (box "boolean") +// box t2 |> equal (box typeof) +// #endif + +// type GenericParamTest2 = +// static member OnlyAccept<'T>(msg: obj, [] ?t: Type) = +// #if FABLE_COMPILER +// let t = t.Value +// #else +// let t = typeof<'T> +// #endif +// t = typeof || msg.GetType() = t + +// [] +// let ``Comparing types works with primitives``() = +// GenericParamTest2.OnlyAccept(43) |> equal true +// GenericParamTest2.OnlyAccept("hi") |> equal true +// GenericParamTest2.OnlyAccept(43) |> equal false + +// [] +// let ``Comparing types works with custom types``() = +// GenericParamTest2.OnlyAccept(Union1 "bye") |> equal true +// GenericParamTest2.OnlyAccept(Union2 "bye") |> equal false +// GenericParamTest2.OnlyAccept("I'll accept anything") |> equal true + +[] +let ``typedefof works``() = + let tdef1 = typedefof + let tdef2 = typedefof + equal tdef1 tdef2 + +[] +let ``IsGenericType works``() = + typeof.IsGenericType |> equal true + typeof.IsGenericType |> equal false + let t1 = typeof + let t2 = typeof + let t3 = typeof + t1.IsGenericType |> equal true + t2.IsGenericType |> equal false + t3.IsGenericType |> equal false + +[] +let ``GetGenericTypeDefinition works``() = + let tdef1 = typedefof + let tdef2 = typeof.GetGenericTypeDefinition() + let t = typeof + let tdef3 = t.GetGenericTypeDefinition() + equal tdef1 tdef2 + equal tdef1 tdef3 + +[] +let ``Comparing generic types works``() = + let t1 = typeof> + let t2 = typeof> + let t3 = typeof> + t1 = t2 |> equal true + t1 = t3 |> equal false diff --git a/src/tests/RegexTests.fs b/src/tests/Main/RegexTests.fs similarity index 99% rename from src/tests/RegexTests.fs rename to src/tests/Main/RegexTests.fs index ecf1719e44..3af2e4dc76 100644 --- a/src/tests/RegexTests.fs +++ b/src/tests/Main/RegexTests.fs @@ -1,6 +1,6 @@ -[] +[] module Fable.Tests.Regex -open NUnit.Framework +open Util.Testing open Fable.Tests.Util open System.Text.RegularExpressions @@ -10,7 +10,7 @@ let ``Regex.Options works``() = let option2 = int RegexOptions.ECMAScript let options = option1 ||| option2 let r = Regex("[a-z]", unbox options) - int r.Options |> equal 257 + int r.Options |> equal 257 [] let ``Regex.IsMatch with IgnoreCase and Multiline works``() = diff --git a/src/tests/ResizeArrayTests.fs b/src/tests/Main/ResizeArrayTests.fs similarity index 88% rename from src/tests/ResizeArrayTests.fs rename to src/tests/Main/ResizeArrayTests.fs index 7f5298021a..5309a81b99 100644 --- a/src/tests/ResizeArrayTests.fs +++ b/src/tests/Main/ResizeArrayTests.fs @@ -1,6 +1,6 @@ -[] +[] module Fable.Tests.ResizeArrays -open NUnit.Framework +open Util.Testing open Fable.Tests.Util [] @@ -34,7 +34,7 @@ let ``ResizeArray casting to seq works``() = [] let ``ResizeArray iteration works``() = let li = ResizeArray<_>() - li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) + li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) let acc = ref 0. for i in li do acc := !acc + i @@ -53,14 +53,14 @@ let ``ResizeArray iteration with index works``() = [] let ``ResizeArray folding works``() = let li = ResizeArray<_>() - li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) + li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) li |> Seq.fold (fun acc item -> acc + item) 0. |> equal 15. [] let ``ResizeArray.Count works``() = let li = ResizeArray<_>() - li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) + li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) equal 5 li.Count [] @@ -85,27 +85,27 @@ let ``ResizeArray.FindLast works``() = [] let ``ResizeArray indexer getter works``() = let li = ResizeArray<_>() - li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) + li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) equal 2. li.[1] [] let ``ResizeArray indexer setter works``() = let li = ResizeArray<_>() - li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) + li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) li.[3] <- 10. equal 10. li.[3] [] let ``ResizeArray.Clear works``() = let li = ResizeArray<_>() - li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) + li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) li.Clear() equal 0 li.Count [] let ``ResizeArray.Add works``() = let li = ResizeArray<_>() - li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) + li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) li.Add(6.) equal 6 li.Count @@ -142,7 +142,7 @@ let ``ResizeArray.Remove works``() = [] let ``ResizeArray.RemoveAt works``() = let li = ResizeArray<_>() - li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) + li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) li.RemoveAt(2) equal 4. li.[2] @@ -156,7 +156,7 @@ let ``ResizeArray.Insert works``() = [] let ``ResizeArray.ReverseInPlace works``() = let li = ResizeArray<_>() - li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) + li.Add(1.); li.Add(2.); li.Add(3.); li.Add(4.); li.Add(5.) li.Reverse() equal 2. li.[3] diff --git a/src/tests/SeqExpressionTests.fs b/src/tests/Main/SeqExpressionTests.fs similarity index 87% rename from src/tests/SeqExpressionTests.fs rename to src/tests/Main/SeqExpressionTests.fs index 50f44a8f6d..7e27bd78f3 100644 --- a/src/tests/SeqExpressionTests.fs +++ b/src/tests/Main/SeqExpressionTests.fs @@ -1,7 +1,7 @@ -[] +[] module Fable.Tests.``Seq Expressions`` open System -open NUnit.Framework +open Util.Testing open Fable.Tests.Util [] @@ -22,36 +22,36 @@ let ``yield from in seq expressions works``() = [] let ``infinite seq expressions work``() = - let rec green () = seq { + let rec green () = seq { yield "green" yield! yellow() } - and yellow () = seq { + and yellow () = seq { yield "yellow" yield! red() } - and red () = seq { - yield "red" + and red () = seq { + yield "red" yield! green() } green() |> Seq.item 12 |> equal "green" - + [] let ``combine in seq expressions works``() = seq { yield 1; yield 2 } - |> Seq.length |> equal 2 + |> Seq.length |> equal 2 [] let ``multiple yields in seq expressions work``() = let upTo n = seq { for i = 1 to n do yield n } - let numbers () = seq { + let numbers () = seq { yield 8 - yield! upTo 5 + yield! upTo 5 yield 4 yield! upTo 3 yield 2 } numbers() |> Seq.sum |> equal 48 - + [] let ``for in seq expressions works``() = seq { for x in 1 .. 10 do yield x } @@ -72,7 +72,7 @@ type 'a Tree = [] let ``recursive seq expressions work``() = - let rec traverse t = seq { + let rec traverse t = seq { match t with | Leaf -> () | Node(xs, y, zs) -> @@ -86,10 +86,10 @@ let ``recursive seq expressions work``() = [] let ``try...finally in seq expressions works``() = let mutable n = 0 - try seq { - try + try seq { + try raise (exn "My message") - finally + finally n <- n + 1 } |> Seq.iter ignore with _ -> () @@ -103,7 +103,7 @@ type DisposableAction(f) = [] let ``use in seq expressions works``() = let mutable n = 0 - seq { + seq { use x = new DisposableAction(fun () -> n <- n + 1) ignore x diff --git a/src/tests/SeqTests.fs b/src/tests/Main/SeqTests.fs similarity index 98% rename from src/tests/SeqTests.fs rename to src/tests/Main/SeqTests.fs index b49de1b02c..d5d824f279 100644 --- a/src/tests/SeqTests.fs +++ b/src/tests/Main/SeqTests.fs @@ -1,6 +1,6 @@ -[] +[] module Fable.Tests.Seqs -open NUnit.Framework +open Util.Testing open Fable.Tests.Util let sumFirstTwo (zs: seq) = @@ -132,14 +132,14 @@ let ``Seq.tryFindBack works``() = let xs = [1.; 2.; 3.; 4.] xs |> Seq.tryFind ((>) 4.) |> equal (Some 1.) xs |> Seq.tryFindBack ((>) 4.) |> equal (Some 3.) - xs |> Seq.tryFindBack ((=) 5.) |> equal None + xs |> Seq.tryFindBack ((=) 5.) |> equal None [] let ``Seq.tryFindIndexBack works``() = let xs = [1.; 2.; 3.; 4.] xs |> Seq.tryFindIndex ((>) 4.) |> equal (Some 0) xs |> Seq.tryFindIndexBack ((>) 4.) |> equal (Some 2) - xs |> Seq.tryFindIndexBack ((=) 5.) |> equal None + xs |> Seq.tryFindIndexBack ((=) 5.) |> equal None [] let ``Seq.fold works``() = @@ -496,7 +496,7 @@ let ``Seq.tryFind works``() = |> Seq.tryFind ((=) 1.) |> Option.isSome |> equal true - [1.; 2.] |> Seq.tryFind ((=) 5.) |> equal None + [1.; 2.] |> Seq.tryFind ((=) 5.) |> equal None [] let ``Seq.tryFindIndex works``() = @@ -504,7 +504,7 @@ let ``Seq.tryFindIndex works``() = |> Seq.tryFindIndex ((=) 2.) |> Option.get |> equal 1 - [1.; 2.] |> Seq.tryFindIndex ((=) 5.) |> equal None + [1.; 2.] |> Seq.tryFindIndex ((=) 5.) |> equal None [] let ``Seq.tryPick works``() = @@ -704,7 +704,7 @@ let ``Seq.except works``() = Seq.except [Map.empty |> (fun m -> m.Add(1, 2))] [Map.ofList [(1, 2)]] |> Seq.isEmpty |> equal true Seq.except [|49|] [|7; 49|] |> Seq.last|> equal 7 Seq.except [{ Bar= "test" }] [{ Bar = "test" }] |> Seq.isEmpty |> equal true - + [] let ``Seq.item throws exception when index is out of range`` () = let xs = [0] diff --git a/src/tests/SetTests.fs b/src/tests/Main/SetTests.fs similarity index 94% rename from src/tests/SetTests.fs rename to src/tests/Main/SetTests.fs index 09c5f21e12..4a4cbd53d3 100644 --- a/src/tests/SetTests.fs +++ b/src/tests/Main/SetTests.fs @@ -1,6 +1,6 @@ -[] +[] module Fable.Tests.Sets -open NUnit.Framework +open Util.Testing open Fable.Tests.Util [] @@ -34,7 +34,7 @@ let ``Set.add works``() = let xs = Set.empty |> Set.add 1 Set.count xs |> equal 1 - + [] let ``Set.Add works``() = let xs = Set.empty.Add 1 @@ -106,7 +106,7 @@ let ``Set.intersectMany works``() = let xs = set [1; 2] let ys = Set.singleton 2 let zs = set [2; 3] - let ks = Set.intersectMany [xs; ys; zs] + let ks = Set.intersectMany [xs; ys; zs] (ks.Contains 2 && not(ks.Contains 1 || ks.Contains 3)) |> equal true @@ -277,7 +277,7 @@ let ``Set.toList works``() = let zs = Set.toList ys xs.[2] = zs.[2] |> equal true - + [] let ``Set.toArray works``() = let xs = [|1.; 2.; 3.; 4.|] @@ -300,12 +300,12 @@ type R = { i: int; s: string } let ``Sets can be JSON serialized forth and back``() = let x = [{ i=1; s="1" }; { i=2; s="2" } ] |> set #if FABLE_COMPILER - let json = Fable.Core.Serialize.toJson x - let x2 = Fable.Core.Serialize.ofJson> json + let json = Fable.Core.JsInterop.toJson x + let x2 = Fable.Core.JsInterop.ofJson> json x2.IsSubsetOf x |> equal true (0, x2) ||> Set.fold (fun acc v -> acc + v.i) |> equal 3 - let json = Fable.Core.Serialize.toJsonWithTypeInfo x - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo> json + let json = Fable.Core.JsInterop.toJsonWithTypeInfo x + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo> json #else let json = Newtonsoft.Json.JsonConvert.SerializeObject x let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject> json @@ -316,14 +316,13 @@ let ``Sets can be JSON serialized forth and back``() = [] let ``Sets serialized with Json.NET can be deserialized``() = - // let x = ["a", { i=1; s="1" }; "b", { i=2; s="2" } ] |> Map + // let x = ["a", { i=1; s="1" }; "b", { i=2; s="2" } ] |> Map // let json = JsonConvert.SerializeObject(x, JsonSerializerSettings(TypeNameHandling=TypeNameHandling.All)) let json = """{"$type":"Microsoft.FSharp.Collections.FSharpSet`1[[Fable.Tests.Sets+R, Fable.Tests]], FSharp.Core","$values":[{"$type":"Fable.Tests.Sets+R, Fable.Tests","i":1,"s":"1"},{"$type":"Fable.Tests.Sets+R, Fable.Tests","i":2,"s":"2"}]}""" #if FABLE_COMPILER - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo> json + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo> json #else let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject> json #endif (0, x2) ||> Set.fold (fun acc v -> acc + v.i) |> equal 3 - \ No newline at end of file diff --git a/src/tests/StringTests.fs b/src/tests/Main/StringTests.fs similarity index 95% rename from src/tests/StringTests.fs rename to src/tests/Main/StringTests.fs index c42cc8b288..1d5729d171 100644 --- a/src/tests/StringTests.fs +++ b/src/tests/Main/StringTests.fs @@ -1,10 +1,10 @@ -[] -#if !DOTNETCORE +[] +#if !DOTNETCORE && !FABLE_COMPILER [] #endif module Fable.Tests.Strings open System -open NUnit.Framework +open Util.Testing open Fable.Tests.Util // Format @@ -17,7 +17,7 @@ let ``sprintf works``() = // Curried let printer = sprintf "Hi %s, good %s!" let printer = printer "Alfonso" - printer "morning" |> equal "Hi Alfonso, good morning!" + printer "morning" |> equal "Hi Alfonso, good morning!" printer "evening" |> equal "Hi Alfonso, good evening!" [] @@ -78,7 +78,7 @@ let ``String.Format with extra formatting works``() = let dt = DateTime(2014, 9, 26).AddMinutes(19.) String.Format("{0:F2} {0:P2} {1:yyyy-MM-dd HH:mm}", i, dt) |> equal "0.55 54.67 % 2014-09-26 00:19" - + [] let ``Padding works``() = "3.14".PadLeft(10) |> equal " 3.14" @@ -86,7 +86,7 @@ let ``Padding works``() = "22".PadLeft(10, '0') |> equal "0000000022" "-22".PadRight(10, 'X') |> equal "-22XXXXXXX" "333".PadLeft(1) |> equal "333" - + [] let ``Padding with sprintf works``() = sprintf "%10.1f" 3.14 |> equal " 3.1" @@ -256,7 +256,7 @@ let ``String.IndexOf works``() = "abcd".IndexOf("bc") * 100 + "abcd".IndexOf("bd") |> equal 99 -[] +[] let ``String.IndexOf works with offset``() = "abcdbc".IndexOf("bc", 3) |> equal 4 @@ -266,7 +266,7 @@ let ``String.LastIndexOf works``() = "abcdbc".LastIndexOf("bc") * 100 + "abcd".LastIndexOf("bd") |> equal 399 -[] +[] let ``String.LastIndexOf works with offset``() = "abcdbcebc".LastIndexOf("bc", 3) |> equal 1 @@ -343,7 +343,7 @@ let ``String.Length works``() = let ``String item works``() = "AbC".[1] |> equal 'b' -[] +[] let ``String.ToCharArray works``() = let arr = "abcd".ToCharArray() equal "c" (string arr.[2]) @@ -392,33 +392,33 @@ let ``String.concat works``() = [] let ``String.forall and exists work``() = - "!!!" |> String.forall (fun c -> c = '!') |> equal true - "a!a" |> String.forall (fun c -> c = '!') |> equal false - "aaa" |> String.forall (fun c -> c = '!') |> equal false + "!!!" |> String.forall (fun c -> c = '!') |> equal true + "a!a" |> String.forall (fun c -> c = '!') |> equal false + "aaa" |> String.forall (fun c -> c = '!') |> equal false [] let ``String.init works``() = String.init 3 (fun i -> "a") - |> equal "aaa" + |> equal "aaa" [] let ``String.collect works``() = "abc" |> String.collect (fun c -> "bcd") - |> equal "bcdbcdbcd" + |> equal "bcdbcdbcd" [] let ``String.iter works``() = let res = ref "" "Hello world!" |> String.iter (fun c -> res := !res + c.ToString()) - equal "Hello world!" !res + equal "Hello world!" !res [] let ``String.iteri works``() = let mutable res = "" "Hello world!" |> String.iteri (fun c i -> res <- res + i.ToString() + c.ToString()) - equal "H0e1l2l3o4 5w6o7r8l9d10!11" res + equal "H0e1l2l3o4 5w6o7r8l9d10!11" res [] let ``String.length (function) works``() = @@ -428,17 +428,17 @@ let ``String.length (function) works``() = [] let ``String.map works``() = "Hello world!" |> String.map (fun c -> if c = 'H' then '_' else c) - |> equal "_ello world!" + |> equal "_ello world!" [] let ``String.mapi works``() = "Hello world!" |> String.mapi (fun i c -> if i = 1 || c = 'H' then '_' else c) - |> equal "__llo world!" + |> equal "__llo world!" [] let ``String.replicate works``() = String.replicate 3 "hi there" - |> equal "hi therehi therehi there" + |> equal "hi therehi therehi there" // String to number convertion diff --git a/src/tests/SudokuTest.fs b/src/tests/Main/SudokuTest.fs similarity index 82% rename from src/tests/SudokuTest.fs rename to src/tests/Main/SudokuTest.fs index 4bb5dddf34..37cff7b1c8 100644 --- a/src/tests/SudokuTest.fs +++ b/src/tests/Main/SudokuTest.fs @@ -1,8 +1,8 @@ /// This module tests a couple of collection functions in a more complex setting. -[] +[] module Fable.Tests.Sudoku -open NUnit.Framework +open Util.Testing open Fable.Tests.Util open System @@ -17,12 +17,12 @@ let cols (sudoku:Sudoku) = sudoku |> Array.mapi (fun a row -> row |> Array.mapi (fun b cell -> sudoku.[b].[a])) -let getBoxIndex count row col = +let getBoxIndex count row col = let n = row/count let m = col/count n * count + m -let boxes (sudoku:Sudoku) = +let boxes (sudoku:Sudoku) = let d = sudoku |> Array.length |> float |> System.Math.Sqrt |> int let list = new List<_>() for a in 0..(d*d) - 1 do list.Add(new List<_>()) @@ -31,10 +31,10 @@ let boxes (sudoku:Sudoku) = for b in 0..(Array.length sudoku - 1) do list.[getBoxIndex d a b].Add(sudoku.[a].[b]) - list + list |> Seq.map Seq.toArray -let toSudoku x : Sudoku = +let toSudoku x : Sudoku = x |> Seq.map Seq.toArray |> Seq.toArray @@ -51,18 +51,18 @@ let solvable sudoku = |> Seq.append (boxes sudoku) |> Seq.forall allUnique -let replaceAtPos (x:Sudoku) row col newValue :Sudoku = +let replaceAtPos (x:Sudoku) row col newValue :Sudoku = [| for a in 0..(Array.length x - 1) -> - [| for b in 0..(Array.length x - 1) -> + [| for b in 0..(Array.length x - 1) -> if a = row && b = col then newValue else x.[a].[b] |] |] -let rec substitute row col (x:Sudoku) = +let rec substitute row col (x:Sudoku) = let a,b = if col >= Array.length x then row+1,0 else row,col if a >= Array.length x then seq { yield x } else - if x.[a].[b] = 0 then - [1..Array.length x] - |> Seq.map (replaceAtPos x a b) - |> Seq.filter solvable + if x.[a].[b] = 0 then + [1..Array.length x] + |> Seq.map (replaceAtPos x a b) + |> Seq.filter solvable |> Seq.map (substitute a (b+1)) |> Seq.concat else substitute a (b+1) x @@ -85,7 +85,7 @@ let ``creating a solution``() = [0; 0; 3; 0; 5; 0; 0; 0; 2] [0; 5; 0; 0; 0; 0; 0; 7; 4]] |> toSudoku - |> getFirstSolution + |> getFirstSolution let expectedSolution = [[1; 2; 8; 3; 4; 5; 6; 9; 7] diff --git a/src/tests/TupleTypeTests.fs b/src/tests/Main/TupleTypeTests.fs similarity index 87% rename from src/tests/TupleTypeTests.fs rename to src/tests/Main/TupleTypeTests.fs index 6d1f571e04..a6ae5ee7b9 100644 --- a/src/tests/TupleTypeTests.fs +++ b/src/tests/Main/TupleTypeTests.fs @@ -1,6 +1,6 @@ -[] +[] module Fable.Tests.TupleTypes -open NUnit.Framework +open Util.Testing open Fable.Tests.Util [] diff --git a/src/tests/TypeTests.fs b/src/tests/Main/TypeTests.fs similarity index 91% rename from src/tests/TypeTests.fs rename to src/tests/Main/TypeTests.fs index 2957713d4d..5caab887ba 100644 --- a/src/tests/TypeTests.fs +++ b/src/tests/Main/TypeTests.fs @@ -1,8 +1,8 @@ -[] +[] module Fable.Tests.TypeTests open System -open NUnit.Framework +open Util.Testing open Fable.Tests.Util type ITest = interface end @@ -15,7 +15,7 @@ type TestType = type TestType2 = | Union2 of string interface ITest - + type TestType3() = member __.Value = "Hi" interface ITest @@ -29,7 +29,7 @@ type TestType5(greeting: string) = member __.Value = greeting member __.Overload(x) = x + x member __.Overload(x, y) = x + y - + let normalize (x: string) = #if FABLE_COMPILER x @@ -49,7 +49,7 @@ let ``Type Namespace``() = equal "Fable.Tests.TypeTests" x #else equal "Fable.Tests" x - #endif + #endif [] let ``Type FullName``() = @@ -78,7 +78,7 @@ let ``Interface testing``() = x :? ITest2 |> equal false y :? ITest |> equal true y :? ITest2 |> equal false - + [] let ``Type testing in pattern matching``() = let x = Union1 "test" :> obj @@ -128,23 +128,23 @@ let ``Get fullname of generic types with inline function``() = fullname() |> equal "Fable.Tests.TypeTests.TestType4" let inline create<'T when 'T:(new : unit -> 'T)> () = new 'T() - + [] let ``Create new generic objects with inline function``() = create().Value |> equal "Hi" create().Value2 |> equal "Bye" - // create() // Doesn't compile + // create() // Doesn't compile let inline create2<'T> (args: obj[]) = System.Activator.CreateInstance(typeof<'T>, args) :?> 'T - + [] let ``Create new generic objects with System.Activator``() = (create2 [||]).Value |> equal "Hi" (create2 [||]).Value2 |> equal "Bye" (create2 [|"Yo"|]).Value |> equal "Yo" - -type RenderState = + +type RenderState = { Now : int Players : Map Map : string } @@ -154,8 +154,8 @@ let ``Property names don't clash with built-in JS objects``() = // See #168 let gameState = { Now = 1 Map = "dungeon" - Players = Map.empty - } + Players = Map.empty + } gameState.Players.ContainsKey(1) |> equal false [] @@ -163,7 +163,7 @@ let ``Overloads work``() = let t = TestType5("") t.Overload(2) |> equal 4 t.Overload(2, 3) |> equal 5 - + type T4 = TestType4 [] @@ -194,7 +194,7 @@ let ``Getter and Setter work``() = type TestType7(a1, a2, a3) = let arr = [|a1; a2; a3|] - member __.Value with get(i) = arr.[i] and set(i) (v) = arr.[i] <- v + member __.Value with get(i) = arr.[i] and set(i) (v) = arr.[i] <- v [] let ``Getter and Setter with indexer work``() = @@ -253,7 +253,7 @@ let ``Guid.Empty works``() = [] let ``lazy works``() = - let mutable snitch = 0 + let mutable snitch = 0 let lazyVal = lazy snitch <- snitch + 1 @@ -266,7 +266,7 @@ let ``lazy works``() = [] let ``Lazy.CreateFromValue works``() = - let mutable snitch = 0 + let mutable snitch = 0 let lazyVal = Lazy<_>.CreateFromValue( snitch <- snitch + 1 @@ -277,7 +277,7 @@ let ``Lazy.CreateFromValue works``() = [] let ``lazy.IsValueCreated works``() = - let mutable snitch = 0 + let mutable snitch = 0 let lazyVal = Lazy<_>.Create(fun () -> snitch <- snitch + 1 @@ -305,12 +305,12 @@ type Serializable(?i: int) = let ``Classes can be JSON serialized forth and back``() = let x = Serializable(5) #if FABLE_COMPILER - let json = Fable.Core.Serialize.toJson x - let x2 = Fable.Core.Serialize.ofJson json + let json = Fable.Core.JsInterop.toJson x + let x2 = Fable.Core.JsInterop.ofJson json string x |> equal "Public: 1 - Private: 5 - Deserialized: false" string x2 |> equal "Public: 1 - Private: 0 - Deserialized: true" - let json = Fable.Core.Serialize.toJsonWithTypeInfo x - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo json + let json = Fable.Core.JsInterop.toJsonWithTypeInfo x + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo json #else let json = Newtonsoft.Json.JsonConvert.SerializeObject x let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject json @@ -322,11 +322,11 @@ let ``Classes can be JSON serialized forth and back``() = let ``Null values can be JSON serialized forth and back``() = let x: Serializable = null #if FABLE_COMPILER - let json = Fable.Core.Serialize.toJson x - let x2 = Fable.Core.Serialize.ofJson json + let json = Fable.Core.JsInterop.toJson x + let x2 = Fable.Core.JsInterop.ofJson json equal x2 null - let json = Fable.Core.Serialize.toJsonWithTypeInfo x - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo json + let json = Fable.Core.JsInterop.toJsonWithTypeInfo x + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo json #else let json = Newtonsoft.Json.JsonConvert.SerializeObject x let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject json @@ -339,9 +339,9 @@ let ``Classes serialized with Json.NET can be deserialized``() = // let json = JsonConvert.SerializeObject(x, JsonSerializerSettings(TypeNameHandling=TypeNameHandling.All)) let json = """{"$type":"Fable.Tests.TypeTests+Serializable","PublicValue":1}""" #if FABLE_COMPILER - let x2 = Fable.Core.Serialize.ofJson json + let x2 = Fable.Core.JsInterop.ofJson json string x2 |> equal "Public: 1 - Private: 0 - Deserialized: true" - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo json + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo json #else let x2 = Newtonsoft.Json.JsonConvert.DeserializeObject json #endif diff --git a/src/tests/UnionTypeTests.fs b/src/tests/Main/UnionTypeTests.fs similarity index 95% rename from src/tests/UnionTypeTests.fs rename to src/tests/Main/UnionTypeTests.fs index 0a2dcb02ce..19b76f8195 100644 --- a/src/tests/UnionTypeTests.fs +++ b/src/tests/Main/UnionTypeTests.fs @@ -1,6 +1,6 @@ -[] +[] module Fable.Tests.UnionTypes -open NUnit.Framework +open Util.Testing open Fable.Tests.Util type Gender = Male | Female @@ -31,10 +31,10 @@ let ``Union cases matches with one argument can be generated``() = [] let ``Union methods can be generated``() = - let x = Left 5 + let x = Left 5 x.ToString() |> equal "5" - + [] let ``Nested pattern matching works``() = let x = Right(Left 5) @@ -195,20 +195,20 @@ type Tree = member this.Sum() = match this with | Leaf i -> i - | Branch trees -> trees |> Seq.map (fun x -> x.Sum()) |> Seq.sum + | Branch trees -> trees |> Seq.map (fun x -> x.Sum()) |> Seq.sum [] let ``Unions can be JSON serialized forth and back``() = let tree = Branch [|Leaf 1; Leaf 2; Branch [|Leaf 3; Leaf 4|]|] let sum1 = tree.Sum() #if FABLE_COMPILER - let json = Fable.Core.Serialize.toJson tree - let tree2 = Fable.Core.Serialize.ofJson json + let json = Fable.Core.JsInterop.toJson tree + let tree2 = Fable.Core.JsInterop.ofJson json let sum2 = tree2.Sum() equal true (box tree2 :? Tree) // Type is kept equal true (sum1 = sum2) // Prototype methods can be accessed - let json = Fable.Core.Serialize.toJsonWithTypeInfo tree - let tree2 = Fable.Core.Serialize.ofJsonWithTypeInfo json + let json = Fable.Core.JsInterop.toJsonWithTypeInfo tree + let tree2 = Fable.Core.JsInterop.ofJsonWithTypeInfo json #else let json = Newtonsoft.Json.JsonConvert.SerializeObject tree let tree2 = Newtonsoft.Json.JsonConvert.DeserializeObject json @@ -249,10 +249,10 @@ type UnionTypeInfoConverter() = #endif [] -let ``Unions serialized with Json.NET can be deserialized``() = +let ``Unions serialized with Json.NET can be deserialized``() = #if FABLE_COMPILER let json = """{"$type":"Fable.Tests.UnionTypes+Tree","Case":"Leaf","Fields":[5]}""" - let x2 = Fable.Core.Serialize.ofJsonWithTypeInfo json + let x2 = Fable.Core.JsInterop.ofJsonWithTypeInfo json #else let x = Leaf 5 let settings = @@ -309,7 +309,7 @@ let ``Option.bind works``() = [] let ``Option.filter works``() = // See #390 - let optionToString opt = + let optionToString opt = match opt with | None -> "None" | Some value -> sprintf "Some %s" value @@ -323,7 +323,7 @@ type OptTest = OptTest of int option [] let ``Different ways of providing None to a union case should be equal``() = // See #231 let value = None - equal true ((OptTest None) = (value |> OptTest)) + equal true ((OptTest None) = (value |> OptTest)) [] let ``Different ways of providing None to a function should be equal``() = // See #231 @@ -346,7 +346,7 @@ let ``Accessing an option value gives correct expression type``() = // See #285 [] let ``Mixing refs and options works``() = // See #238 let res = ref 0 - let setter, getter = + let setter, getter = let slot = ref None (fun f -> slot.Value <- Some f), (fun v -> slot.Value.Value v) @@ -386,7 +386,7 @@ let ``Erased union type testing works``() = let toString (arg: U3) = match arg with | U3.Case1 s -> s - | U3.Case2 i -> i * 2 |> string + | U3.Case2 i -> i * 2 |> string | U3.Case3 t -> t.Value U3.Case1 "HELLO" |> toString |> equal "HELLO" U3.Case2 3 |> toString |> equal "6" diff --git a/src/tests/Util/Util.fs b/src/tests/Main/Util/Util.fs similarity index 63% rename from src/tests/Util/Util.fs rename to src/tests/Main/Util/Util.fs index d1b51a97b7..d520d324ac 100644 --- a/src/tests/Util/Util.fs +++ b/src/tests/Main/Util/Util.fs @@ -1,7 +1,19 @@ module Fable.Tests.Util open System -open NUnit.Framework + +module Testing = + #if FABLE_COMPILER + type Assert = Fable.Core.Testing.Assert + type TestAttribute = Fable.Core.Testing.TestAttribute + type TestFixtureAttribute = Fable.Core.Testing.TestFixtureAttribute + #else + type Assert = NUnit.Framework.Assert + type TestAttribute = NUnit.Framework.TestAttribute + type TestFixtureAttribute = NUnit.Framework.TestFixtureAttribute + #endif + +open Testing #if FABLE_COMPILER let foo: string = Fable.Core.JsInterop.importMember "../js/foo.js" @@ -12,7 +24,7 @@ let foo2: string = failwith "JS only" let equal (expected: 'T) (actual: 'T) = Assert.AreEqual(expected, actual) - + let rec sumFirstSeq (zs: seq) (n: int): float = match n with | 0 -> 0. @@ -28,19 +40,19 @@ let rec sumFirstList (zs: float list) (n: int): float = let f2 a b = a + b let mutable a = 10 -module B = +module B = let c = a a <- a + 5 let mutable a = 20 let d = f2 2 2 let f2 a b = a - b - - module D = + + module D = let d = a a <- a + 5 let e = f2 2 2 -// Test members with names conflicting with JS +// Test members with names conflicting with JS let Int32Array = [|1;2|] module Float64Array = diff --git a/src/tests/Util/Util2.fs b/src/tests/Main/Util/Util2.fs similarity index 77% rename from src/tests/Util/Util2.fs rename to src/tests/Main/Util/Util2.fs index afb5e15295..c0b9ddb13b 100644 --- a/src/tests/Util/Util2.fs +++ b/src/tests/Main/Util/Util2.fs @@ -10,11 +10,11 @@ type Helper = #if !DOTNETCORE type Helper2 = // Check that project references from folders work - static member CreateClampedArray() = - Fable.Tests.Clamp.Helper.CreateClampedArray() + static member CreateArray() = + Fable.Tests.Spaces.Helper.CreateArray() #endif - + type Helper3(i: int) = member x.Value = string i - + type H = Helper3 \ No newline at end of file diff --git a/src/tests/js/foo.js b/src/tests/Main/js/foo.js similarity index 100% rename from src/tests/js/foo.js rename to src/tests/Main/js/foo.js diff --git a/src/tests/paket.references b/src/tests/Main/paket.references similarity index 100% rename from src/tests/paket.references rename to src/tests/Main/paket.references diff --git a/src/tests/Other/fableconfig.json b/src/tests/Other/fableconfig.json deleted file mode 100644 index 6acb2ade8c..0000000000 --- a/src/tests/Other/fableconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "projFile": "Fable.Tests.Clamp.fsproj", - "outDir": "../../../build/tests/Another Project", - "coreLib": "../../../build/fable-core", - "clamp": true -} \ No newline at end of file diff --git a/src/tests/Project With Spaces/Fable.Tests.Spaces.fsproj b/src/tests/Project With Spaces/Fable.Tests.Spaces.fsproj new file mode 100644 index 0000000000..2cdab081b1 --- /dev/null +++ b/src/tests/Project With Spaces/Fable.Tests.Spaces.fsproj @@ -0,0 +1,74 @@ + + + + + Debug + AnyCPU + 2.0 + 1e44403b-7834-4842-91b1-53a5fa731c58 + Library + Fable.Tests.Spaces + Fable.Tests.Spaces + v4.5 + true + 4.4.0.0 + Fable.Tests.Spaces + + + true + full + false + false + bin\Debug\ + DEBUG;TRACE + 3 + AnyCPU + true + + + pdbonly + true + true + bin\Release\ + TRACE + 3 + AnyCPU + true + + + + + True + + + + + + + + + + + 11 + + + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + + + + \ No newline at end of file diff --git a/src/tests/Other/Util/Util.fs b/src/tests/Project With Spaces/Util/Util.fs similarity index 67% rename from src/tests/Other/Util/Util.fs rename to src/tests/Project With Spaces/Util/Util.fs index 37df578573..1dbb38982c 100644 --- a/src/tests/Other/Util/Util.fs +++ b/src/tests/Project With Spaces/Util/Util.fs @@ -1,8 +1,8 @@ -namespace Fable.Tests.Clamp +namespace Fable.Tests.Spaces // Check that project references to folders work type [] Helper = - static member CreateClampedArray() = [|5uy|] + static member CreateArray() = [|5uy|] #if FABLE_COMPILER static member ConditionalExternalValue = "Fable Rocks!" #endif diff --git a/src/tests/Other/Util/Util.fsi b/src/tests/Project With Spaces/Util/Util.fsi similarity index 67% rename from src/tests/Other/Util/Util.fsi rename to src/tests/Project With Spaces/Util/Util.fsi index d997ad8d2a..1f41aca6eb 100644 --- a/src/tests/Other/Util/Util.fsi +++ b/src/tests/Project With Spaces/Util/Util.fsi @@ -1,8 +1,8 @@ -namespace Fable.Tests.Clamp +namespace Fable.Tests.Spaces // Check that projects with signature files compile correctly (see #143) type [] Helper = - static member CreateClampedArray: unit -> byte array + static member CreateArray: unit -> byte array #if FABLE_COMPILER static member ConditionalExternalValue: string #endif diff --git a/src/tests/ReflectionTests.fs b/src/tests/ReflectionTests.fs deleted file mode 100644 index fa0824bc79..0000000000 --- a/src/tests/ReflectionTests.fs +++ /dev/null @@ -1,91 +0,0 @@ -[] -module Fable.Tests.Reflection - -#if DOTNETCORE && !FABLE_COMPILER -open System.Reflection -module System = - type System.Type with - member this.IsGenericType = this.GetTypeInfo().IsGenericType -#endif - -open System -open NUnit.Framework -open Fable.Tests.Util - -type TestType = - | Union1 of string - -type TestType2 = - | Union2 of string - -type GenericRecord<'A,'B> = { a: 'A; b: 'B } - -#if FABLE_COMPILER -open Fable.Core -type GenericParamTest = - static member Foo<'T>(x: int, [] ?t: Type) = t.Value - static member Bar<'T,'U>([] ?t1: Type, [] ?t2: Type) = t1.Value, t2.Value - -[] -let ``GenericParamAttribute works``() = - let t = GenericParamTest.Foo(5) - let t1, t2 = GenericParamTest.Bar() - box t |> equal (box "string") - box t1 |> equal (box "boolean") - box t2 |> equal (box typeof) -#endif - -type GenericParamTest2 = - static member OnlyAccept<'T>(msg: obj, [] ?t: Type) = - #if FABLE_COMPILER - let t = t.Value - #else - let t = typeof<'T> - #endif - t = typeof || msg.GetType() = t - -[] -let ``Comparing types works with primitives``() = - GenericParamTest2.OnlyAccept(43) |> equal true - GenericParamTest2.OnlyAccept("hi") |> equal true - GenericParamTest2.OnlyAccept(43) |> equal false - -[] -let ``Comparing types works with custom types``() = - GenericParamTest2.OnlyAccept(Union1 "bye") |> equal true - GenericParamTest2.OnlyAccept(Union2 "bye") |> equal false - GenericParamTest2.OnlyAccept("I'll accept anything") |> equal true - -[] -let ``typedefof works``() = - let tdef1 = typedefof - let tdef2 = typedefof - equal tdef1 tdef2 - -[] -let ``IsGenericType works``() = - typeof.IsGenericType |> equal true - typeof.IsGenericType |> equal false - let t1 = typeof - let t2 = typeof - let t3 = typeof - t1.IsGenericType |> equal true - t2.IsGenericType |> equal false - t3.IsGenericType |> equal false - -[] -let ``GetGenericTypeDefinition works``() = - let tdef1 = typedefof - let tdef2 = typeof.GetGenericTypeDefinition() - let t = typeof - let tdef3 = t.GetGenericTypeDefinition() - equal tdef1 tdef2 - equal tdef1 tdef3 - -[] -let ``Comparing generic types works``() = - let t1 = typeof> - let t2 = typeof> - let t3 = typeof> - t1 = t2 |> equal true - t1 = t3 |> equal false diff --git a/src/tests/fableconfig.json b/src/tests/fableconfig.json index c85ad9d7aa..e67985f3ec 100644 --- a/src/tests/fableconfig.json +++ b/src/tests/fableconfig.json @@ -1,12 +1,12 @@ { - "projFile": "Fable.Tests.fsproj", + "projFile": [ + "Project With Spaces/Fable.Tests.Spaces.fsproj", + "../tests_external/Fable.Tests.External.fsproj", + "Main/Fable.Tests.fsproj" + ], "outDir": "../../build/tests", "coreLib": "../../build/fable-core", - "module": "commonjs", "plugins": ["../plugins/nunit/Fable.Plugins.NUnit.dll"], - "refs": { - "Fable.Tests.Clamp": "../../build/tests/Another Project" - }, "targets": { "netcore": { "projFile": "tests.fsx", diff --git a/src/tests/package.json b/src/tests/package.json index bc0f8e094e..cceff5abad 100644 --- a/src/tests/package.json +++ b/src/tests/package.json @@ -5,7 +5,7 @@ "description": "Tests for fable-compiler", "main": "index.js", "scripts": { - "test": "mocha .", + "test": "mocha Main", "test-debug": "mocha . --debug-brk" }, "repository": { diff --git a/src/tests/project.json b/src/tests/project.json deleted file mode 100644 index 5153484960..0000000000 --- a/src/tests/project.json +++ /dev/null @@ -1,86 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "debugType": "portable", - "compilerName": "fsc", - "compile": { - "includeFiles": [ - "DllRef/Util/Util.fs", - "DllRef/Lib.fs", - "Other/Util/Util.fs", - "Util/Util.fs", - "Util/Util2.fs", - "../tests_external/Util3.fs", - "../tests_external/Util4.fs", - "ArithmeticTests.fs", - "ArrayTests.fs", - "AsyncTests.fs", - "ComparisonTests.fs", - "ConvertTests.fs", - "DateTimeTests.fs", - "DictionaryTests.fs", - "EnumerableTests.fs", - "EnumTests.fs", - "EventTests.fs", - "HashSetTests.fs", - "JsonTests.fs", - "ListTests.fs", - "MapTests.fs", - "MiscTests.fs", - "ObservableTests.fs", - "RecordTypeTests.fs", - "ReflectionTests.fs", - "RegexTests.fs", - "ResizeArrayTests.fs", - "SeqExpressionTests.fs", - "SeqTests.fs", - "SetTests.fs", - "StringTests.fs", - "SudokuTest.fs", - "TupleTypeTests.fs", - "TypeTests.fs", - "UnionTypeTests.fs" - ] - }, - "define": [ - "DOTNETCORE", - "TRACE" - ], - "nowarn": [ - "44" - ], - "xmlDoc": true, - "delaySign": true, - "warningsAsErrors": true, - "additionalArguments": [ - "--fullpaths", - "--flaterrors" - ] - }, - "dependencies": { - "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-*", - "Newtonsoft.Json": "9.0.1", - "NUnit": "3.4.1", - "dotnet-test-nunit": "3.4.0-beta-2", - "Fable.Core": { "target": "project" }, - "Fable.JsonConverter": { "target": "project" } - }, - "testRunner": "nunit", - "frameworks": { - "netcoreapp1.0": { - "imports": "portable-net45+win8", - "dependencies": { - "Microsoft.NETCore.App": { - "version": "1.0.0-*", - "type": "platform" - } - } - } - }, - "tools": { - "dotnet-compile-fsc": { - "version": "1.0.0-preview2-*", - "imports": "dnxcore50" - } - } -} \ No newline at end of file diff --git a/src/tests/tests.fsx b/src/tests/tests.fsx deleted file mode 100644 index 089fbabd93..0000000000 --- a/src/tests/tests.fsx +++ /dev/null @@ -1,46 +0,0 @@ -// This file is a replacemente for Fable.Tests.fsproj -// as Fable NetCore version cannot read fsproj files - -#r "System.Threading.dll" -#r "System.Text.RegularExpressions.dll" -#r "../../packages/NUnit/lib/dotnet/nunit.framework.dll" -#r "../../packages/Newtonsoft.Json/lib/netstandard1.0/Newtonsoft.Json.dll" -#r "../../build/fable/bin/Fable.Core.dll" -//#r "./bin/Release/netcoreapp1.0/Fable.Core.dll" - -#load - "DllRef/Util/Util.fs" - "DllRef/Lib.fs" - "Other/Util/Util.fs" - "Util/Util.fs" - "Util/Util2.fs" - "../tests_external/Util3.fs" - "../tests_external/Util4.fs" - "ArithmeticTests.fs" - "ArrayTests.fs" - "AsyncTests.fs" - "ComparisonTests.fs" - "ConvertTests.fs" - "DateTimeTests.fs" - "DictionaryTests.fs" - "EnumerableTests.fs" - "EnumTests.fs" - "EventTests.fs" - "HashSetTests.fs" - "JsonTests.fs" - "ListTests.fs" - "MapTests.fs" - "MiscTests.fs" - "ObservableTests.fs" - "RecordTypeTests.fs" - "ReflectionTests.fs" - "RegexTests.fs" - "ResizeArrayTests.fs" - "SeqExpressionTests.fs" - "SeqTests.fs" - "SetTests.fs" - "StringTests.fs" - "SudokuTest.fs" - "TupleTypeTests.fs" - "TypeTests.fs" - "UnionTypeTests.fs" \ No newline at end of file diff --git a/src/tests_external/Fable.Tests.External.fsproj b/src/tests_external/Fable.Tests.External.fsproj new file mode 100644 index 0000000000..fb914f6123 --- /dev/null +++ b/src/tests_external/Fable.Tests.External.fsproj @@ -0,0 +1,60 @@ + + + + Fable.Tests.External + Fable.Tests.External + Fable.Tests.External + Debug + AnyCPU + 2.0 + c842c174-2ce4-4d85-b694-7a5f1c357ee4 + Library + v4.5 + true + 4.4.0.0 + + + true + Full + false + false + bin\$(Configuration)\ + DEBUG;TRACE + 3 + + + PdbOnly + true + true + bin\$(Configuration)\ + TRACE + 3 + + + + + True + + + + + + + + + + + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\4.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + \ No newline at end of file diff --git a/src/tests_external/Util4.fs b/src/tests_external/Util4.fs index e0de3417be..1950053fb4 100644 --- a/src/tests_external/Util4.fs +++ b/src/tests_external/Util4.fs @@ -3,7 +3,7 @@ module Fable.Tests.Util4 open Fable.Core #if FABLE_COMPILER -let foo: string = JsInterop.importMember "../tests/js/foo.js" +let foo: string = JsInterop.importMember "../tests/Main/js/foo.js" let bar: int = JsInterop.importMember "./bar.js"