-
Notifications
You must be signed in to change notification settings - Fork 1
Assert BlockString
Asserts that a string, here-string or array of strings matches the expected string, here-string or array of strings.
Assert-BlockString [[-Actual] <Object>] [-Expected] <Object> [-Because <String>] [-Highlight <String>]
[<CommonParameters>]
The Assert-BlockString
command compares a string, here-string or array
of strings with the expected string, here-string or array of strings and
throws an error that includes the hex output if they are not equal.
The
comparison is case sensitive.
It is commonly used in unit testing scenarios
to verify the correctness of string outputs on byte level.
Assert-BlockString -Actual 'hello', 'world' -Expected 'Hello', 'World'
This example asserts that the array of strings 'hello' and 'world' matches the expected array of strings 'Hello' and 'World'. If the assertion fails, an error is thrown.
'hello', 'world' | Assert-BlockString -Expected 'Hello', 'World'
This example demonstrates the usage of pipeline input.
The block of strings
'Hello' and 'World' is piped to Assert-BlockString
and compared with the
expected strings 'Hello' and 'World'.
If the assertion fails, an error is
thrown.
The actual string, here-string or array of strings to be compared with the expected value. This parameter accepts pipeline input.
Type: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
An optional reason or explanation for the assertion.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
The expected string, here-string or array of strings that the actual value should match.
Type: Object
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
An optional ANSI color code to highlight the difference between the expected and actual strings. The default value is '31m' (red text).
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 31m
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
TODO: Is it possible to rename command to Should-BeBlockString
.
Pester handles Should verb with, not sure it possible to resolve here:
https://github.com/pester/Pester/commit/c8bc9679bed19c8fbc4229caa01dd083f2d03d4f#diff-b7592dd925696de2521c9b12b966d65519d502045462f002c343caa7c0986936
and
https://github.com/pester/Pester/commit/c8bc9679bed19c8fbc4229caa01dd083f2d03d4f#diff-460f64eafc16facefbed201eb00fb151c75eadf7cc58a504a01527015fb1c7cdR17