Skip to content

Add BeASlice and BeAnArray matchers#906

Open
sanbricio wants to merge 1 commit intoonsi:masterfrom
sanbricio:feature/add-be-slice-and-array-matchers
Open

Add BeASlice and BeAnArray matchers#906
sanbricio wants to merge 1 commit intoonsi:masterfrom
sanbricio:feature/add-be-slice-and-array-matchers

Conversation

@sanbricio
Copy link
Copy Markdown

Summary

Implements BeASlice() and BeAnArray() matchers as requested in #584.

These matchers enable type assertions for slice and array types when working with interface{} values:

  • BeASlice(): Succeeds if actual is a slice type ([]T)
  • BeAnArray(): Succeeds if actual is an array type ([N]T)

Examples

var data any = []int{1, 2, 3}
Expect(data).Should(BeASlice())

var arr any = [3]int{1, 2, 3}
Expect(arr).Should(BeAnArray())

Expect("hello").ShouldNot(BeASlice())  // string is not a slice

Implementation

  • Added BeASliceMatcher and BeAnArrayMatcher structs in matchers package
  • Added constructor functions BeASlice() and BeAnArray() in root matchers.go
  • Full test coverage including:
    • Multiple slice/array element types
    • Nil slice handling
    • Type validation (error on nil literal)
    • Failure message verification
    • Negation tests

Testing

All 524 matchers tests pass
go vet ./... passes with no warnings
9 new specs covering both matchers

Implements matcher constructors to determine if a value is a slice or array type.
These matchers are useful when working with interface{} types and need to verify
the underlying type.

Fixes onsi#584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant