Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Suggest to add Should-Match to Pester v6 #2533

@johlju

Description

@johlju

Checklist

Summary of the feature request

Currently the new assertions for Pester v6 does not support regular expression matching like Should -Match or Should -MatchExactly in v5. Suggest adding a command Should-Match and Should-NotMatch, or possibly add a parameter RegularExpression to the commands Should-BeLikeString and Should-NotBeLikeString.

How should it work?

The commands Should-Match and Should-NotMatch should have the same named and positional parameters as the command Should-NotBeLikeString.

It 'Should match regular expression` {
    '[value]' | Should-Match '^\[.+\]$'
}

It 'Should match regular expression` {
    'Should-Match '^\[.+\]$' '[value]'
}

It 'Should match regular expression` {
    'Should-Match -Expected '^\[.+\]$' -Actual '[value]' -CaseSensitive -Because 'must start and end with brackets' 
}

It 'Should match regular expression` {
    'Should-NotMatch -Expected '^\[.+\]$' -Actual 'value' -CaseSensitive -Because 'must not start and end with brackets' 
}

If we reuse existing commands Should-BeLikeString and Should-NotBeLikeString by adding a new switch parameter.

It 'Should match regular expression` {
    '[value]' | Should-BeLikeString '^\[.+\]$' -RegularExpression
}

It 'Should match regular expression` {
    'Should-BeLikeString '^\[.+\]$' '[value]' -RegularExpression
}

It 'Should match regular expression` {
    'Should-BeLikeString -RegularExpression -Expected '^\[.+\]$' -Actual '[value]' -CaseSensitive -Because 'must start and end with brackets' 
}

It 'Should match regular expression` {
    'Should-NotBeLikeString -Expected '^\[.+\]$' -Actual 'value' -CaseSensitive -Because 'must not start and end with brackets'  -RegularExpression
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    AssertionsFor issues related with assertionsFeature

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions