1

I can't seem to get the indentation right in my fsunit tests. I keep getting told to use the ML-style "use let ... in", but doing that means the compiler has trouble reading the name of the next test. Any suggestions ?

[<TestFixture>] 
module ``reading yaml files`` =
    let yamlReader = new yamlReader()
    let yamlConfig = yamlReader.read("./testFiles/config.yaml")

    [<Test>] ``should parse root property of a yaml file`` ()=
        yamlConfig.ContainsKey(new YamlScalar("token1")) |> should equal true
    [<Test>] ``should parse nested propery of a yaml file`` ()=
        let token1 = yamlConfig.[new YamlScalar("token1")] :?> YamlMapping
        let env3 = token1.[new YamlScalar("env3")] :?> YamlScalar
        env3.Value |> should equal "value3"
    [<Test>] ``should convert yamldocument to digestable format`` ()=
        let tokens = yamlReader.toTokens yamlConfig
        let firstToken = (Seq.head tokens)
        firstToken.name |> should equal "token2"
mwjackson
  • 5,403
  • 10
  • 53
  • 58
  • Have you written a Yaml parser in F#? If yes, is it available anywhere! :) – bentayloruk Nov 28 '12 at 10:15
  • 1
    No, I used an existing nuget package called YamlSerializer. You can get an idea about usage here: https://github.com/mwjackson/fsharp-config-transform – mwjackson Nov 28 '12 at 10:32

2 Answers2

4

You are missing the let keyword. Try this:

[<TestFixture>] 
module ``reading yaml files`` =
    let yamlReader = new yamlReader()
    let yamlConfig = yamlReader.read("./testFiles/config.yaml")

    [<Test>] 
    let ``should parse root property of a yaml file`` ()=
        yamlConfig.ContainsKey(new YamlScalar("token1")) |> should equal true
    [<Test>] 
    let ``should parse nested propery of a yaml file`` ()=
        let token1 = yamlConfig.[new YamlScalar("token1")] :?> YamlMapping
        let env3 = token1.[new YamlScalar("env3")] :?> YamlScalar
        env3.Value |> should equal "value3"
    [<Test>] 
    let ``should convert yamldocument to digestable format`` ()=
        let tokens = yamlReader.toTokens yamlConfig
        let firstToken = (Seq.head tokens)
        firstToken.name |> should equal "token2"
Gus
  • 25,839
  • 2
  • 51
  • 76
2

Gustavo's version is the better version (and what I usually use), but if you don't want to put the [<Test>] on a separate line:

[<TestFixture>] 
module ``reading yaml files`` =
    let yamlReader = new yamlReader()
    let yamlConfig = yamlReader.read("./testFiles/config.yaml")

    let [<Test>] ``should parse root property of a yaml file`` () =
        yamlConfig.ContainsKey(new YamlScalar("token1")) |> should equal true

    let [<Test>] ``should parse nested propery of a yaml file`` () =
        let token1 = yamlConfig.[new YamlScalar("token1")] :?> YamlMapping
        let env3 = token1.[new YamlScalar("env3")] :?> YamlScalar
        env3.Value |> should equal "value3"

    let [<Test>] ``should convert yamldocument to digestable format`` () =
        let tokens = yamlReader.toTokens yamlConfig
        let firstToken = (Seq.head tokens)
        firstToken.name |> should equal "token2"
Ramon Snir
  • 7,520
  • 3
  • 43
  • 61