Skip to content

Commit

Permalink
update (20 Aug 2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Aug 19, 2023
1 parent af1cf59 commit 7a53122
Show file tree
Hide file tree
Showing 22 changed files with 2,165 additions and 565 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
contents: read

jobs:

test:
name: Test
runs-on: ubuntu-latest

strategy:
matrix:
go_version: [1.21.x]
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go_version }}

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Test
run: go test -v ./...
71 changes: 71 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '24 11 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
230 changes: 107 additions & 123 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,115 @@ func (a *Array) Element(index int) *Value {
return a.Value(index)
}

// First returns a new Value instance for the first element of array.
// HasValue succeeds if array's value at the given index is equal to given value.
//
// If given array is empty, First reports failure and returns empty
// (but non-nil) instance.
// Before comparison, both values are converted to canonical form. value should be
// map[string]interface{} or struct.
//
// Example:
//
// array := NewArray(t, []interface{}{"foo", 123})
// array.First().String().IsEqual("foo")
// array := NewArray(t, []interface{}{"foo", "123"})
// array.HasValue(1, 123)
func (a *Array) HasValue(index int, value interface{}) *Array {
opChain := a.chain.enter("HasValue(%d)", index)
defer opChain.leave()

if opChain.failed() {
return a
}

if index < 0 || index >= len(a.value) {
opChain.fail(AssertionFailure{
Type: AssertInRange,
Actual: &AssertionValue{index},
Expected: &AssertionValue{AssertionRange{
Min: 0,
Max: len(a.value) - 1,
}},
Errors: []error{
errors.New("expected: valid element index"),
},
})
return a
}

expected, ok := canonValue(opChain, value)
if !ok {
return a
}

if !reflect.DeepEqual(expected, a.value[index]) {
opChain.fail(AssertionFailure{
Type: AssertEqual,
Actual: &AssertionValue{a.value[index]},
Expected: &AssertionValue{value},
Errors: []error{
fmt.Errorf(
"expected: array value at index %d is equal to given value",
index),
},
})
return a
}

return a
}

// NotHasValue succeeds if array's value at the given index is not equal to given value.
//
// Before comparison, both values are converted to canonical form. value should be
// map[string]interface{} or struct.
//
// Example:
//
// array := NewArray(t, []interface{}{"foo", "123"})
// array.NotHasValue(1, 234)
func (a *Array) NotHasValue(index int, value interface{}) *Array {
opChain := a.chain.enter("NotHasValue(%d)", index)
defer opChain.leave()

if opChain.failed() {
return a
}

if index < 0 || index >= len(a.value) {
opChain.fail(AssertionFailure{
Type: AssertInRange,
Actual: &AssertionValue{index},
Expected: &AssertionValue{AssertionRange{
Min: 0,
Max: len(a.value) - 1,
}},
Errors: []error{
errors.New("expected: valid element index"),
},
})
return a
}

expected, ok := canonValue(opChain, value)
if !ok {
return a
}

if reflect.DeepEqual(expected, a.value[index]) {
opChain.fail(AssertionFailure{
Type: AssertNotEqual,
Actual: &AssertionValue{a.value[index]},
Expected: &AssertionValue{value},
Errors: []error{
fmt.Errorf(
"expected: array value at index %d is not equal to given value",
index),
},
})
return a
}

return a
}

// Deprecated: use Value or HasValue instead.
func (a *Array) First() *Value {
opChain := a.chain.enter("First()")
defer opChain.leave()
Expand All @@ -222,15 +322,7 @@ func (a *Array) First() *Value {
return newValue(opChain, a.value[0])
}

// Last returns a new Value instance for the last element of array.
//
// If given array is empty, Last reports failure and returns empty
// (but non-nil) instance.
//
// Example:
//
// array := NewArray(t, []interface{}{"foo", 123})
// array.Last().Number().IsEqual(123)
// Deprecated: use Value or HasValue instead.
func (a *Array) Last() *Value {
opChain := a.chain.enter("Last()")
defer opChain.leave()
Expand Down Expand Up @@ -261,7 +353,7 @@ func (a *Array) Last() *Value {
// array := NewArray(t, strings)
//
// for index, value := range array.Iter() {
// value.String().IsEqual(strings[index])
// value.String().IsEqual(strings[index])
// }
func (a *Array) Iter() []Value {
opChain := a.chain.enter("Iter()")
Expand Down Expand Up @@ -1452,114 +1544,6 @@ func (a *Array) NotContainsOnly(values ...interface{}) *Array {
return a
}

// IsValueEqual succeeds if array's value at the given index is equal to given value.
//
// Before comparison, both values are converted to canonical form. value should be
// map[string]interface{} or struct.
//
// Example:
//
// array := NewArray(t, []interface{}{"foo", "123"})
// array.IsValueEqual(1, 123)
func (a *Array) IsValueEqual(index int, value interface{}) *Array {
opChain := a.chain.enter("IsValueEqual(%d)", index)
defer opChain.leave()

if opChain.failed() {
return a
}

if index < 0 || index >= len(a.value) {
opChain.fail(AssertionFailure{
Type: AssertInRange,
Actual: &AssertionValue{index},
Expected: &AssertionValue{AssertionRange{
Min: 0,
Max: len(a.value) - 1,
}},
Errors: []error{
errors.New("expected: valid element index"),
},
})
return a
}

expected, ok := canonValue(opChain, value)
if !ok {
return a
}

if !reflect.DeepEqual(expected, a.value[index]) {
opChain.fail(AssertionFailure{
Type: AssertEqual,
Actual: &AssertionValue{a.value[index]},
Expected: &AssertionValue{value},
Errors: []error{
fmt.Errorf(
"expected: array value at index %d is equal to given value",
index),
},
})
return a
}

return a
}

// NotValueEqual succeeds if array's value at the given index is not equal to given value.
//
// Before comparison, both values are converted to canonical form. value should be
// map[string]interface{} or struct.
//
// Example:
//
// array := NewArray(t, []interface{}{"foo", "123"})
// array.NotValueEqual(1, 234)
func (a *Array) NotValueEqual(index int, value interface{}) *Array {
opChain := a.chain.enter("NotValueEqual(%d)", index)
defer opChain.leave()

if opChain.failed() {
return a
}

if index < 0 || index >= len(a.value) {
opChain.fail(AssertionFailure{
Type: AssertInRange,
Actual: &AssertionValue{index},
Expected: &AssertionValue{AssertionRange{
Min: 0,
Max: len(a.value) - 1,
}},
Errors: []error{
errors.New("expected: valid element index"),
},
})
return a
}

expected, ok := canonValue(opChain, value)
if !ok {
return a
}

if reflect.DeepEqual(expected, a.value[index]) {
opChain.fail(AssertionFailure{
Type: AssertNotEqual,
Actual: &AssertionValue{a.value[index]},
Expected: &AssertionValue{value},
Errors: []error{
fmt.Errorf(
"expected: array value at index %d is not equal to given value",
index),
},
})
return a
}

return a
}

// IsOrdered succeeds if every element is not less than the previous element
// as defined on the given `less` comparator function.
// For default, it will use built-in comparator function for each data type.
Expand Down
7 changes: 7 additions & 0 deletions assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ type AssertionContext struct {
// Environment shared between tests
// Comes from Expect instance
Environment *Environment

// Whether reporter is known to output to testing.TB
// For example, true when reporter is testing.T or testify-based reporter.
TestingTB bool
}

// AssertionFailure provides detailed information about failed assertion.
Expand Down Expand Up @@ -188,6 +192,9 @@ type AssertionFailure struct {

// Allowed delta between actual and expected
Delta *AssertionValue

// Stacktrace of the failure
Stacktrace []StacktraceEntry
}

// AssertionValue holds expected or actual value
Expand Down
Loading

0 comments on commit 7a53122

Please sign in to comment.