New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC FS-1004] FSharpResult type with a few tests #964
Changes from 3 commits
6e0923a
af39ca8
1a7f21d
e862e75
12734f7
3d324d1
008465a
6105902
4abfbdb
7b131d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. --> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
|
@@ -84,7 +84,7 @@ | |
<Compile Include="FSharp.Core\Microsoft.FSharp.Collections\HashIdentityModule.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Collections\ListModule.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Collections\ListModule2.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Collections\ObsoleteListFunctions.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Collections\ObsoleteListFunctions.fs" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to minimize diff revert this line |
||
<Compile Include="FSharp.Core\Microsoft.FSharp.Collections\ListType.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Collections\ListProperties.fs" Condition="'$(TargetFramework)' != 'portable47' AND '$(TargetFramework)' != 'net20'" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Collections\MapModule.fs" /> | ||
|
@@ -99,13 +99,14 @@ | |
<Compile Include="FSharp.Core\Microsoft.FSharp.Collections\StringModule.fs" /> | ||
<Compile Include="FSharp.Core\PrimTypes.fs" /> | ||
<Compile Include="FSharp.Core\ComparersRegression.fs" /> | ||
<Compile Include="FSharp.Core\DiscrimantedUnionType.fs" /> | ||
<Compile Include="FSharp.Core\DiscrimantedUnionType.fs" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to minimize diff revert this line |
||
<Compile Include="FSharp.Core\Microsoft.FSharp.Core\BigIntType.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Core\IntConversions.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Core\IntConversionsGenerated.fs" /> | ||
<None Include="FSharp.Core\Microsoft.FSharp.Core\IntConversionsTestGenerator.fsx" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Core\OptionModule.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Core\PrintfTests.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Core\ResultTests.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Control\Cancellation.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Control\AsyncType.fs" /> | ||
<Compile Include="FSharp.Core\Microsoft.FSharp.Control\LazyType.fs" /> | ||
|
@@ -121,6 +122,6 @@ | |
<CustomCopyLocal Include="FSharp.Core.Unittests.dll.config"> | ||
<TargetFilename>FSharp.Core.Unittests.dll.config</TargetFilename> | ||
</CustomCopyLocal> | ||
</ItemGroup> | ||
</ItemGroup> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to minimize diff revert this line |
||
<Import Project="$(FSharpSourcesRoot)\FSharpSource.targets" /> | ||
</Project> | ||
</Project> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to minimize diff revert this line |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
// Various tests for: | ||
// Microsoft.FSharp.Core.ExtraTopLevelOperators.printf | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please adjust this comment to match the test target. |
||
|
||
namespace FSharp.Core.Unittests.FSharp_Core.Microsoft_FSharp_Core | ||
|
||
open System | ||
open FSharp.Core.Unittests.LibraryTestFx | ||
open NUnit.Framework | ||
|
||
type EmailValidation= | ||
| Empty | ||
| NoAt | ||
|
||
module Results= | ||
let bind f m = match m with Error e -> Error e | Success x -> f x | ||
|
||
open Results | ||
|
||
[<TestFixture>] | ||
type ResultTests() = | ||
|
||
let fail_if_empty email= | ||
if String.IsNullOrEmpty(email) then Error Empty else Success email | ||
|
||
let fail_if_not_at (email:string)= | ||
if (email.Contains("@")) then Success email else Error NoAt | ||
|
||
let validate_email = | ||
fail_if_empty | ||
>> bind fail_if_not_at | ||
|
||
let test_validate_email email (expected:Result<string,EmailValidation>) = | ||
let actual = validate_email email | ||
Assert.AreEqual(expected, actual) | ||
|
||
|
||
[<Test>] | ||
member this.CanChainTogetherSuccessiveValidations() = | ||
test_validate_email "" (Error Empty) | ||
test_validate_email "something_else" (Error NoAt) | ||
test_validate_email "some@email.com" (Success "some@email.com") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to minimize diff revert this line