Skip to content

Commit

Permalink
Fix bug in boolean conversion and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tpetricek committed Jan 16, 2013
1 parent 4744e41 commit e5b7e82
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Providers/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ module Conversions =
| StringEquals "#N/A" -> Some Double.NaN
| _ -> Double.TryParse(s, NumberStyles.Any, culture) |> asOption)
text
static member ConvertBoolean = Option.bind (fun (s:string) ->
static member ConvertBoolean b = b |> Option.bind (fun (s:string) ->
match s.Trim() with
| StringEquals "true" | StringEquals "yes" -> Some true
| StringEquals "false" | StringEquals "no" -> Some false
Expand Down
32 changes: 32 additions & 0 deletions tests/CsvProvider.Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// --------------------------------------------------------------------------------------
// Tests for the CSV parsing code
// --------------------------------------------------------------------------------------

namespace FSharp.Data.Tests

open NUnit.Framework
open System.IO
open FSharp.Data

module CsvSimple =

let [<Literal>] simpleCsv = """
Column1,Column2,Column3
TRUE,no,3
"yes", "false", 1.92 """

type SimpleCsv = CsvProvider<simpleCsv>

[<Test>]
let ``Bool column correctly infered and accessed`` () =
let csv = SimpleCsv.Parse(simpleCsv)
let first = csv.Data |> Seq.head
let actual:bool = first.Column1
Assert.AreEqual(true, actual)

[<Test>]
let ``Decimal column correctly infered and accessed`` () =
let csv = SimpleCsv.Parse(simpleCsv)
let first = csv.Data |> Seq.head
let actual:decimal = first.Column3
Assert.AreEqual(3.0M, actual)
1 change: 1 addition & 0 deletions tests/FSharp.Data.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" />
<ItemGroup>
<Compile Include="CsvProvider.Parsing.fs" />
<Compile Include="CsvProvider.Tests.fs" />
<Compile Include="JsonProvider.Tests.fs" />
<Compile Include="Providers.NameUtils.fs" />
<Compile Include="Providers.Inference.fs" />
Expand Down

0 comments on commit e5b7e82

Please sign in to comment.