Search code examples
f#fsunit

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"

Solution

  • 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"