tests/PSTS.YamlParsing.Tests.ps1

Import-module ../private/_PSTSYaml.ps1

InModuleScope PSTS {
    #describe '_fromYAML' {

        # Act
    # _fromYAML -Path ".\assets\template.yaml" -verbose


    # it "should return $true" {
    # $true | should -Be $true

    # }
    #}


    describe 'yaml-include-function' {

        # Act
       $ret =  _fromYAML -Path "./assets//test-include/test-include.yaml" -verbose


         it "should return $true" {
            $true | should -Be $true

        }
    }

    describe 'yaml-scalar-Value' {

        # Act
       $ret =  _fromYAML -Path "./assets/test-scalar/test-scalar.yaml" -verbose


         it "should return String" {
            $ret.stringValue.GetType().Name | should -Be "String"

         }

         it "should return Boolean" {
            $ret.boolValue.GetType().Name | should -Be "Boolean"

         }
         it "should return Boolean" {
            $ret.yesBoolValue.GetType().Name | should -Be "Boolean"

         }
         it "should return Boolean" {
            $ret.onBoolValue.GetType().Name | should -Be "Boolean"

         }
         it "should return Boolean" {
            $ret.offBoolValue.GetType().Name | should -Be "Boolean"

         }
         it "should return Boolean" {
            $ret.noBoolValue.GetType().Name | should -Be "Boolean"

         }
         it "should return Int32" {
            $ret.intValue.GetType().Name | should -Be "Int32"

         }
         it "should return Decimal" {
            $ret.decimalValue.GetType().Name | should -Be "Decimal"

         }
         it "should return Single" {
            $ret.singleValue.GetType().Name | should -Be "Single"

         }

    }

    describe 'yaml-get-function' {

        # Act
       $ret = _fromYAML -Path "./assets/test-get/test-get.yaml" -verbose


        it "should return MSA" {
           $ret.notnull| should -Be "MSA"
        }

        it "should return null" {
            $ret.nullToleration | should -Be $null
        }

        it "should return authorizedValue" {
            $ret.notnullRuleSetPass | should -Be "MSA"
        }

        it "should return subValue" {
            $ret.notnullsubValue | should -Be "test"
        }

        it "should return 2" {
            $ret.notnullsubseqValues.count | should -Be 2
        }


        it "should return 2" {
            $ret.notnullseqValues.count | should -Be 2
        }

        it "should return projet MSA with wildcard" {
            $ret.wildcard.project | should -Be "MSA"
        }

    }

    describe 'yaml-get-function-toleration-failure' {
        # Act
       { _fromYAML -Path "./assets/test-get/test-get-toleration-failure.yaml" } | should Throw "Null value returned for fakeValue with no toleration set"
    }

    describe 'yaml-get-function-ruleset-failure' {
        # Act
       { _fromYAML -Path "./assets/test-get/test-get-ruleset-failure.yaml" } | should Throw "ruleset matched a forbidden string on MSA"

    }

    describe 'yaml-foreach' {
        # Act
        $ret = _fromYAML -Path "./assets/test-foreach/test-foreach.yaml"

        it "should return val2" {
           $ret.seq1.Item(1)["seqItem"] | should -Be "val2"
        }

        it "should return value2" {
           $ret.seq.Item(1)["seqItem"] | should -Be "value2"
        }


        it "should return 2" {
           $ret.seq2.Item(1)["seqItem"] | should -Be 2
        }

        it "should return overridedValue1" {
            $ret.seq2.Item(0)["seqItem"] | should -Be "overridedValue1"
        }

        it "should return overridedValue1" {
            $ret.seq.Item(0)["seqItem"] | should -Be "overridedValue1"
        }

    }


    describe 'yaml-if' {
        # Act
       $ret = _fromYAML -Path "./assets/test-if/test-if.yaml"

        it "should return true" {
            $ret.if.BoolhasBeenProcessed | should -Be $true
        }

        it "should return true" {
            $ret.if.StringhasBeenProcessed | should -Be $true
        }

        it "should return null" {
            $ret.if.NotProcessed | should -Be $null
        }
    }

    describe 'yaml-add-function' {
        $ret = _fromYAML -Path './assets/test-add/test-add.yaml'

        it "should return 2 terms addition result" {
            $ret.addition | Should -Be 7
        }
        it "should return multiples terms addition result" {
            $ret.addition2 | Should -Be 55
        }
    }

    describe 'yaml-add-function-failure' {
        it "should throw with array" {
            { _fromYAML -Path "./assets/test-add/test-add-array-failure.yaml" } | should Throw "Invalid value"
        }
        it "should throw with mapping" {
            { _fromYAML -Path "./assets/test-add/test-add-mapping-failure.yaml" } | should Throw "Invalid value"
        }
        it "should throw with not numeric scalar" {
            { _fromYAML -Path "./assets/test-add/test-add-NaN-failure.yaml" } | should Throw "Invalid value"
        }
    }

    describe 'yaml-mul-function' {
        $ret = _fromYAML -Path './assets/test-mul/test-mul.yaml'

        it "should return 2 terms multiplication result" {
            $ret.multiplication | Should -Be 10
        }
        it "should return multiples terms multiplication result" {
            $ret.multiplication2 | Should -Be 1000
        }
    }

    describe 'yaml-mul-function-failure' {
        it "should throw with array" {
            { _fromYAML -Path "./assets/test-mul/test-mul-array-failure.yaml" } | should Throw "Invalid value"
        }
        it "should throw with mapping" {
            { _fromYAML -Path "./assets/test-mul/test-mul-array-failure.yaml" } | should Throw "Invalid value"
        }
        it "should throw with not numeric scalar" {
            { _fromYAML -Path "./assets/test-mul/test-mul-NaN-failure.yaml" } | should Throw "Invalid value"
        }
    }

    describe 'yaml-tolower-function' {
        $ret = _fromYAML -Path './assets/test-tolower/test-tolower.yaml'

        it "should return the lowered string" {
            $ret.lowered | Should -Be "an upper string lowered"
        }
    }

    describe 'yaml-tolower-function-failure' {
       # it "should throw if multiple param are given" {
       # { _fromYAML -Path "./assets/test-tolower/test-tolower-multiple-elements-failure.yaml" } | should Throw "Too many strings to lower"
       # }
        it "should throw if not a string" {
            { _fromYAML -Path "./assets/test-tolower/test-tolower-not-string-failure.yaml" } | should Throw "is not a string"
        }
    }

    describe 'yaml-toupper-function' {
        $ret = _fromYAML -Path './assets/test-toupper/test-toupper.yaml'

        it "should return the upped string" {
            $ret.upped | Should -Be "A LOWER STRING UPPED"
        }
    }

    describe 'yaml-toupper-function-failure' {
        #it "should throw if multiple param are given" {
        # { _fromYAML -Path "./assets/test-toupper/test-toupper-multiple-elements-failure.yaml" } | should Throw "Too many strings to upper"
        #}
        it "should throw if not a string" {
            { _fromYAML -Path "./assets/test-toupper/test-toupper-not-string-failure.yaml" } | should Throw "is not a string"
        }
    }

    describe 'yaml-format-function' {
        $ret = _fromYAML -Path './assets/test-format/test-format.yaml'

        it "should format the string" {
            $ret.formated | Should -Be "test - envname"
        }
        it "should format the string with numerics" {
            $ret.formated2 | Should -Be "the number is - 1575"
        }
        it "should format the string with mixed order" {
            $ret.formated3 | Should -Be "one three zero two"
        }
    }

    describe 'yaml-concat-function' {
        $ret = _fromYAML -Path './assets/test-concat/test-concat.yaml'

        it "should return concatenated value" {
            $ret.concatenated | Should -Be "overcome"
        }
        it "should return concatenated value from string and numerics" {
            $ret.concatenated2 | Should -Be "5 is bigger than 3"
        }
        it "should return concatenated value from a string array" {
            $ret.concatenated3 | Should -Be "this is in an array but not this part"
        }
    }

    describe 'yaml-count-function' {
        $ret = _fromYAML -Path './assets/test-count/test-count.yaml'

        it "should return count value from array" {
            $ret.counted | Should -Be 3
        }
        it "should return count value from mapping" {
            $ret.counted2 | Should -Be 2
        }
    }

    describe 'yaml-export-append' {
        # Act
       $ret = _fromYAML -Path "./assets/test-export/test-export-append.yaml"

        it "should return overridedValue1 value2" {
           $ret.final  | should -Be "overridedValue1 value2"
        }

    }

    describe 'yaml-export-noappend' {
        # Act
       $ret = _fromYAML -Path "./assets/test-export/test-export-noappend.yaml"

        it "should return value2" {
           $ret.final  | should -Be "value2"
        }

    }

    describe 'yaml-ruleset-function' {
        $ret = _fromYAML -Path './assets/test-ruleset/test-ruleset-pass.yaml'

        it "should return the pass" {
            $ret.pass | Should -Be "pass"
        }

        it "should throw forbidden string" {
            { _fromYAML -Path './assets/test-ruleset/test-ruleset-nopass.yaml'} | should Throw "ruleset matched a forbidden string on pa?ss ."
        }
    }

}