mwjackson
mwjackson

Reputation: 5451

Scoping & Indentation in fsunit

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"

Upvotes: 1

Views: 154

Answers (2)

Ramon Snir
Ramon Snir

Reputation: 7560

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"

Upvotes: 2

Gus
Gus

Reputation: 26184

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"

Upvotes: 4

Related Questions