mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Build: Updates goconvey to work on go1.12 (#16483)
This commit is contained in:
parent
2d7fc55df7
commit
4f46e739a2
19
Gopkg.lock
generated
19
Gopkg.lock
generated
@ -346,12 +346,11 @@
|
||||
revision = "c2b33e84"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:6ddab442e52381bab82fb6c07ef3f4b565ff7ec4b8fae96d8dd4b8573a460597"
|
||||
digest = "1:395b1480ae42c3fec6fff19823e66e173819f85826811387f9045c88515a7f0f"
|
||||
name = "github.com/jtolds/gls"
|
||||
packages = ["."]
|
||||
pruneopts = "NUT"
|
||||
revision = "77f18212c9c7edc9bd6a33d383a7b545ce62f064"
|
||||
version = "v4.2.1"
|
||||
revision = "b4936e06046bbecbb94cae9c18127ebe510a2cb9"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:1da1796a71eb70f1e3e085984d044f67840bb0326816ec8276231aa87b1b9fc3"
|
||||
@ -546,19 +545,19 @@
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:1f0b284a6858827de4c27c66b49b2b25df3e16b031c2b57b7892273131e7dd2b"
|
||||
digest = "1:a0509115762ee481fd95b60521b4dcc5ad226c54b741a4924f4f28c0cc6aabc8"
|
||||
name = "github.com/smartystreets/assertions"
|
||||
packages = [
|
||||
".",
|
||||
"internal/go-diff/diffmatchpatch",
|
||||
"internal/go-render/render",
|
||||
"internal/oglematchers",
|
||||
]
|
||||
pruneopts = "NUT"
|
||||
revision = "7678a5452ebea5b7090a6b163f844c133f523da2"
|
||||
version = "1.8.3"
|
||||
revision = "f487f9de1cd36ebab28235b9373028812fb47cbd"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:7efd0b2309cdd6468029fa30c808c50a820c9344df07e1a4bbdaf18f282907aa"
|
||||
digest = "1:4dccd132a83155851c5e9faaa134ee3a931965c666b6b3c076e238fe9b3577a4"
|
||||
name = "github.com/smartystreets/goconvey"
|
||||
packages = [
|
||||
"convey",
|
||||
@ -566,8 +565,7 @@
|
||||
"convey/reporting",
|
||||
]
|
||||
pruneopts = "NUT"
|
||||
revision = "9e8dc3f972df6c8fcc0375ef492c24d0bb204857"
|
||||
version = "1.6.3"
|
||||
revision = "68dc04aab96ae4326137d6b77330c224063a927e"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
@ -909,6 +907,7 @@
|
||||
"github.com/hashicorp/go-plugin",
|
||||
"github.com/hashicorp/go-version",
|
||||
"github.com/inconshreveable/log15",
|
||||
"github.com/jtolds/gls",
|
||||
"github.com/lib/pq",
|
||||
"github.com/mattn/go-isatty",
|
||||
"github.com/mattn/go-sqlite3",
|
||||
@ -916,7 +915,6 @@
|
||||
"github.com/opentracing/opentracing-go/ext",
|
||||
"github.com/opentracing/opentracing-go/log",
|
||||
"github.com/patrickmn/go-cache",
|
||||
"github.com/pkg/errors",
|
||||
"github.com/prometheus/client_golang/api",
|
||||
"github.com/prometheus/client_golang/api/prometheus/v1",
|
||||
"github.com/prometheus/client_golang/prometheus",
|
||||
@ -924,6 +922,7 @@
|
||||
"github.com/prometheus/client_model/go",
|
||||
"github.com/prometheus/common/expfmt",
|
||||
"github.com/prometheus/common/model",
|
||||
"github.com/smartystreets/assertions",
|
||||
"github.com/smartystreets/goconvey/convey",
|
||||
"github.com/teris-io/shortid",
|
||||
"github.com/uber/jaeger-client-go/config",
|
||||
|
17
Gopkg.toml
17
Gopkg.toml
@ -19,12 +19,26 @@
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
|
||||
required = ["github.com/smartystreets/assertions", "github.com/jtolds/gls"]
|
||||
|
||||
ignored = [
|
||||
"github.com/grafana/grafana/data/*",
|
||||
"github.com/grafana/grafana/public/*",
|
||||
"github.com/grafana/grafana/node_modules/*"
|
||||
]
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/smartystreets/goconvey"
|
||||
revision = "68dc04aab96ae4326137d6b77330c224063a927e"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/smartystreets/assertions"
|
||||
revision = "f487f9de1cd36ebab28235b9373028812fb47cbd"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/jtolds/gls"
|
||||
revision = "b4936e06046bbecbb94cae9c18127ebe510a2cb9"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/BurntSushi/toml"
|
||||
version = "0.3.0"
|
||||
@ -151,9 +165,6 @@ ignored = [
|
||||
branch = "master"
|
||||
name = "github.com/prometheus/common"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/smartystreets/goconvey"
|
||||
version = "1.6.3"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/uber/jaeger-client-go"
|
||||
|
34
vendor/github.com/jtolds/gls/stack_tags.go
generated
vendored
34
vendor/github.com/jtolds/gls/stack_tags.go
generated
vendored
@ -51,22 +51,56 @@ func addStackTag(tag uint, context_call func()) {
|
||||
|
||||
// these private methods are named this horrendous name so gopherjs support
|
||||
// is easier. it shouldn't add any runtime cost in non-js builds.
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_markS(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_mark0(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_mark1(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_mark2(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_mark3(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_mark4(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_mark5(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_mark6(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_mark7(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_mark8(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_mark9(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_markA(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_markB(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_markC(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_markD(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_markE(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
//go:noinline
|
||||
func github_com_jtolds_gls_markF(tag uint, cb func()) { _m(tag, cb) }
|
||||
|
||||
func _m(tag_remainder uint, cb func()) {
|
||||
|
4
vendor/github.com/smartystreets/assertions/collections.go
generated
vendored
4
vendor/github.com/smartystreets/assertions/collections.go
generated
vendored
@ -227,7 +227,7 @@ func ShouldHaveLength(actual interface{}, expected ...interface{}) string {
|
||||
if int64(value.Len()) == expectedLen {
|
||||
return success
|
||||
} else {
|
||||
return fmt.Sprintf(shouldHaveHadLength, actual, value.Len(), expectedLen)
|
||||
return fmt.Sprintf(shouldHaveHadLength, expectedLen, value.Len(), actual)
|
||||
}
|
||||
case reflect.Ptr:
|
||||
elem := value.Elem()
|
||||
@ -236,7 +236,7 @@ func ShouldHaveLength(actual interface{}, expected ...interface{}) string {
|
||||
if int64(elem.Len()) == expectedLen {
|
||||
return success
|
||||
} else {
|
||||
return fmt.Sprintf(shouldHaveHadLength, actual, elem.Len(), expectedLen)
|
||||
return fmt.Sprintf(shouldHaveHadLength, expectedLen, elem.Len(), actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
87
vendor/github.com/smartystreets/assertions/equality.go
generated
vendored
87
vendor/github.com/smartystreets/assertions/equality.go
generated
vendored
@ -1,6 +1,7 @@
|
||||
package assertions
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
@ -25,30 +26,31 @@ func ShouldEqual(actual interface{}, expected ...interface{}) string {
|
||||
func shouldEqual(actual, expected interface{}) (message string) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
message = serializer.serialize(expected, actual, fmt.Sprintf(shouldHaveBeenEqual, expected, actual))
|
||||
message = serializer.serialize(expected, actual, composeEqualityMismatchMessage(expected, actual))
|
||||
}
|
||||
}()
|
||||
|
||||
if specification := newEqualityMethodSpecification(expected, actual); specification.IsSatisfied() {
|
||||
if specification.AreEqual() {
|
||||
return success
|
||||
} else {
|
||||
message = fmt.Sprintf(shouldHaveBeenEqual, expected, actual)
|
||||
return serializer.serialize(expected, actual, message)
|
||||
}
|
||||
}
|
||||
if matchError := oglematchers.Equals(expected).Matches(actual); matchError != nil {
|
||||
expectedSyntax := fmt.Sprintf("%v", expected)
|
||||
actualSyntax := fmt.Sprintf("%v", actual)
|
||||
if expectedSyntax == actualSyntax && reflect.TypeOf(expected) != reflect.TypeOf(actual) {
|
||||
message = fmt.Sprintf(shouldHaveBeenEqualTypeMismatch, expected, expected, actual, actual)
|
||||
} else {
|
||||
message = fmt.Sprintf(shouldHaveBeenEqual, expected, actual)
|
||||
}
|
||||
return serializer.serialize(expected, actual, message)
|
||||
if spec := newEqualityMethodSpecification(expected, actual); spec.IsSatisfied() && spec.AreEqual() {
|
||||
return success
|
||||
} else if matchError := oglematchers.Equals(expected).Matches(actual); matchError == nil {
|
||||
return success
|
||||
}
|
||||
|
||||
return success
|
||||
return serializer.serialize(expected, actual, composeEqualityMismatchMessage(expected, actual))
|
||||
}
|
||||
func composeEqualityMismatchMessage(expected, actual interface{}) string {
|
||||
var (
|
||||
renderedExpected = fmt.Sprintf("%v", expected)
|
||||
renderedActual = fmt.Sprintf("%v", actual)
|
||||
)
|
||||
|
||||
if renderedExpected != renderedActual {
|
||||
return fmt.Sprintf(shouldHaveBeenEqual+composePrettyDiff(renderedExpected, renderedActual), expected, actual)
|
||||
} else if reflect.TypeOf(expected) != reflect.TypeOf(actual) {
|
||||
return fmt.Sprintf(shouldHaveBeenEqualTypeMismatch, expected, expected, actual, actual)
|
||||
} else {
|
||||
return fmt.Sprintf(shouldHaveBeenEqualNoResemblance, renderedExpected)
|
||||
}
|
||||
}
|
||||
|
||||
// ShouldNotEqual receives exactly two parameters and does an inequality check.
|
||||
@ -149,6 +151,34 @@ func getFloat(num interface{}) (float64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// ShouldEqualJSON receives exactly two parameters and does an equality check by marshalling to JSON
|
||||
func ShouldEqualJSON(actual interface{}, expected ...interface{}) string {
|
||||
if message := need(1, expected); message != success {
|
||||
return message
|
||||
}
|
||||
|
||||
expectedString, expectedErr := remarshal(expected[0].(string))
|
||||
if expectedErr != nil {
|
||||
return "Expected value not valid JSON: " + expectedErr.Error()
|
||||
}
|
||||
|
||||
actualString, actualErr := remarshal(actual.(string))
|
||||
if actualErr != nil {
|
||||
return "Actual value not valid JSON: " + actualErr.Error()
|
||||
}
|
||||
|
||||
return ShouldEqual(actualString, expectedString)
|
||||
}
|
||||
func remarshal(value string) (string, error) {
|
||||
var structured interface{}
|
||||
err := json.Unmarshal([]byte(value), &structured)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
canonical, _ := json.Marshal(structured)
|
||||
return string(canonical), nil
|
||||
}
|
||||
|
||||
// ShouldResemble receives exactly two parameters and does a deep equal check (see reflect.DeepEqual)
|
||||
func ShouldResemble(actual interface{}, expected ...interface{}) string {
|
||||
if message := need(1, expected); message != success {
|
||||
@ -156,8 +186,10 @@ func ShouldResemble(actual interface{}, expected ...interface{}) string {
|
||||
}
|
||||
|
||||
if matchError := oglematchers.DeepEquals(expected[0]).Matches(actual); matchError != nil {
|
||||
return serializer.serializeDetailed(expected[0], actual,
|
||||
fmt.Sprintf(shouldHaveResembled, render.Render(expected[0]), render.Render(actual)))
|
||||
renderedExpected, renderedActual := render.Render(expected[0]), render.Render(actual)
|
||||
message := fmt.Sprintf(shouldHaveResembled, renderedExpected, renderedActual) +
|
||||
composePrettyDiff(renderedExpected, renderedActual)
|
||||
return serializer.serializeDetailed(expected[0], actual, message)
|
||||
}
|
||||
|
||||
return success
|
||||
@ -284,3 +316,16 @@ func ShouldBeZeroValue(actual interface{}, expected ...interface{}) string {
|
||||
}
|
||||
return success
|
||||
}
|
||||
|
||||
// ShouldBeZeroValue receives a single parameter and ensures that it is NOT
|
||||
// the Go equivalent of the default value, or "zero" value.
|
||||
func ShouldNotBeZeroValue(actual interface{}, expected ...interface{}) string {
|
||||
if fail := need(0, expected); fail != success {
|
||||
return fail
|
||||
}
|
||||
zeroVal := reflect.Zero(reflect.TypeOf(actual)).Interface()
|
||||
if reflect.DeepEqual(zeroVal, actual) {
|
||||
return serializer.serialize(zeroVal, actual, fmt.Sprintf(shouldNotHaveBeenZeroValue, actual))
|
||||
}
|
||||
return success
|
||||
}
|
||||
|
37
vendor/github.com/smartystreets/assertions/equality_diff.go
generated
vendored
Normal file
37
vendor/github.com/smartystreets/assertions/equality_diff.go
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
package assertions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch"
|
||||
)
|
||||
|
||||
func composePrettyDiff(expected, actual string) string {
|
||||
diff := diffmatchpatch.New()
|
||||
diffs := diff.DiffMain(expected, actual, false)
|
||||
if prettyDiffIsLikelyToBeHelpful(diffs) {
|
||||
return fmt.Sprintf("\nDiff: '%s'", diff.DiffPrettyText(diffs))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// prettyDiffIsLikelyToBeHelpful returns true if the diff listing contains
|
||||
// more 'equal' segments than 'deleted'/'inserted' segments.
|
||||
func prettyDiffIsLikelyToBeHelpful(diffs []diffmatchpatch.Diff) bool {
|
||||
equal, deleted, inserted := measureDiffTypeLengths(diffs)
|
||||
return equal > deleted && equal > inserted
|
||||
}
|
||||
|
||||
func measureDiffTypeLengths(diffs []diffmatchpatch.Diff) (equal, deleted, inserted int) {
|
||||
for _, segment := range diffs {
|
||||
switch segment.Type {
|
||||
case diffmatchpatch.DiffEqual:
|
||||
equal += len(segment.Text)
|
||||
case diffmatchpatch.DiffDelete:
|
||||
deleted += len(segment.Text)
|
||||
case diffmatchpatch.DiffInsert:
|
||||
inserted += len(segment.Text)
|
||||
}
|
||||
}
|
||||
return equal, deleted, inserted
|
||||
}
|
2
vendor/github.com/smartystreets/assertions/filter.go
generated
vendored
2
vendor/github.com/smartystreets/assertions/filter.go
generated
vendored
@ -17,7 +17,7 @@ func need(needed int, expected []interface{}) string {
|
||||
}
|
||||
|
||||
func atLeast(minimum int, expected []interface{}) string {
|
||||
if len(expected) < 1 {
|
||||
if len(expected) < minimum {
|
||||
return needNonEmptyCollection
|
||||
}
|
||||
return success
|
||||
|
25
vendor/github.com/smartystreets/assertions/internal/go-diff/AUTHORS
generated
vendored
Normal file
25
vendor/github.com/smartystreets/assertions/internal/go-diff/AUTHORS
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
# This is the official list of go-diff authors for copyright purposes.
|
||||
# This file is distinct from the CONTRIBUTORS files.
|
||||
# See the latter for an explanation.
|
||||
|
||||
# Names should be added to this file as
|
||||
# Name or Organization <email address>
|
||||
# The email address is not required for organizations.
|
||||
|
||||
# Please keep the list sorted.
|
||||
|
||||
Danny Yoo <dannyyoo@google.com>
|
||||
James Kolb <jkolb@google.com>
|
||||
Jonathan Amsterdam <jba@google.com>
|
||||
Markus Zimmermann <markus.zimmermann@nethead.at> <markus.zimmermann@symflower.com> <zimmski@gmail.com>
|
||||
Matt Kovars <akaskik@gmail.com>
|
||||
Örjan Persson <orjan@spotify.com>
|
||||
Osman Masood <oamasood@gmail.com>
|
||||
Robert Carlsen <rwcarlsen@gmail.com>
|
||||
Rory Flynn <roryflynn@users.noreply.github.com>
|
||||
Sergi Mansilla <sergi.mansilla@gmail.com>
|
||||
Shatrugna Sadhu <ssadhu@apcera.com>
|
||||
Shawn Smith <shawnpsmith@gmail.com>
|
||||
Stas Maksimov <maksimov@gmail.com>
|
||||
Tor Arvid Lund <torarvid@gmail.com>
|
||||
Zac Bergquist <zbergquist99@gmail.com>
|
32
vendor/github.com/smartystreets/assertions/internal/go-diff/CONTRIBUTORS
generated
vendored
Normal file
32
vendor/github.com/smartystreets/assertions/internal/go-diff/CONTRIBUTORS
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
# This is the official list of people who can contribute
|
||||
# (and typically have contributed) code to the go-diff
|
||||
# repository.
|
||||
#
|
||||
# The AUTHORS file lists the copyright holders; this file
|
||||
# lists people. For example, ACME Inc. employees would be listed here
|
||||
# but not in AUTHORS, because ACME Inc. would hold the copyright.
|
||||
#
|
||||
# When adding J Random Contributor's name to this file,
|
||||
# either J's name or J's organization's name should be
|
||||
# added to the AUTHORS file.
|
||||
#
|
||||
# Names should be added to this file like so:
|
||||
# Name <email address>
|
||||
#
|
||||
# Please keep the list sorted.
|
||||
|
||||
Danny Yoo <dannyyoo@google.com>
|
||||
James Kolb <jkolb@google.com>
|
||||
Jonathan Amsterdam <jba@google.com>
|
||||
Markus Zimmermann <markus.zimmermann@nethead.at> <markus.zimmermann@symflower.com> <zimmski@gmail.com>
|
||||
Matt Kovars <akaskik@gmail.com>
|
||||
Örjan Persson <orjan@spotify.com>
|
||||
Osman Masood <oamasood@gmail.com>
|
||||
Robert Carlsen <rwcarlsen@gmail.com>
|
||||
Rory Flynn <roryflynn@users.noreply.github.com>
|
||||
Sergi Mansilla <sergi.mansilla@gmail.com>
|
||||
Shatrugna Sadhu <ssadhu@apcera.com>
|
||||
Shawn Smith <shawnpsmith@gmail.com>
|
||||
Stas Maksimov <maksimov@gmail.com>
|
||||
Tor Arvid Lund <torarvid@gmail.com>
|
||||
Zac Bergquist <zbergquist99@gmail.com>
|
20
vendor/github.com/smartystreets/assertions/internal/go-diff/LICENSE
generated
vendored
Normal file
20
vendor/github.com/smartystreets/assertions/internal/go-diff/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
Copyright (c) 2012-2016 The go-diff Authors. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
1345
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/diff.go
generated
vendored
Normal file
1345
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/diff.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
46
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/diffmatchpatch.go
generated
vendored
Normal file
46
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/diffmatchpatch.go
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
|
||||
// https://github.com/sergi/go-diff
|
||||
// See the included LICENSE file for license details.
|
||||
//
|
||||
// go-diff is a Go implementation of Google's Diff, Match, and Patch library
|
||||
// Original library is Copyright (c) 2006 Google Inc.
|
||||
// http://code.google.com/p/google-diff-match-patch/
|
||||
|
||||
// Package diffmatchpatch offers robust algorithms to perform the operations required for synchronizing plain text.
|
||||
package diffmatchpatch
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// DiffMatchPatch holds the configuration for diff-match-patch operations.
|
||||
type DiffMatchPatch struct {
|
||||
// Number of seconds to map a diff before giving up (0 for infinity).
|
||||
DiffTimeout time.Duration
|
||||
// Cost of an empty edit operation in terms of edit characters.
|
||||
DiffEditCost int
|
||||
// How far to search for a match (0 = exact location, 1000+ = broad match). A match this many characters away from the expected location will add 1.0 to the score (0.0 is a perfect match).
|
||||
MatchDistance int
|
||||
// When deleting a large block of text (over ~64 characters), how close do the contents have to be to match the expected contents. (0.0 = perfection, 1.0 = very loose). Note that MatchThreshold controls how closely the end points of a delete need to match.
|
||||
PatchDeleteThreshold float64
|
||||
// Chunk size for context length.
|
||||
PatchMargin int
|
||||
// The number of bits in an int.
|
||||
MatchMaxBits int
|
||||
// At what point is no match declared (0.0 = perfection, 1.0 = very loose).
|
||||
MatchThreshold float64
|
||||
}
|
||||
|
||||
// New creates a new DiffMatchPatch object with default parameters.
|
||||
func New() *DiffMatchPatch {
|
||||
// Defaults.
|
||||
return &DiffMatchPatch{
|
||||
DiffTimeout: time.Second,
|
||||
DiffEditCost: 4,
|
||||
MatchThreshold: 0.5,
|
||||
MatchDistance: 1000,
|
||||
PatchDeleteThreshold: 0.5,
|
||||
PatchMargin: 4,
|
||||
MatchMaxBits: 32,
|
||||
}
|
||||
}
|
160
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/match.go
generated
vendored
Normal file
160
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/match.go
generated
vendored
Normal file
@ -0,0 +1,160 @@
|
||||
// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
|
||||
// https://github.com/sergi/go-diff
|
||||
// See the included LICENSE file for license details.
|
||||
//
|
||||
// go-diff is a Go implementation of Google's Diff, Match, and Patch library
|
||||
// Original library is Copyright (c) 2006 Google Inc.
|
||||
// http://code.google.com/p/google-diff-match-patch/
|
||||
|
||||
package diffmatchpatch
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
// MatchMain locates the best instance of 'pattern' in 'text' near 'loc'.
|
||||
// Returns -1 if no match found.
|
||||
func (dmp *DiffMatchPatch) MatchMain(text, pattern string, loc int) int {
|
||||
// Check for null inputs not needed since null can't be passed in C#.
|
||||
|
||||
loc = int(math.Max(0, math.Min(float64(loc), float64(len(text)))))
|
||||
if text == pattern {
|
||||
// Shortcut (potentially not guaranteed by the algorithm)
|
||||
return 0
|
||||
} else if len(text) == 0 {
|
||||
// Nothing to match.
|
||||
return -1
|
||||
} else if loc+len(pattern) <= len(text) && text[loc:loc+len(pattern)] == pattern {
|
||||
// Perfect match at the perfect spot! (Includes case of null pattern)
|
||||
return loc
|
||||
}
|
||||
// Do a fuzzy compare.
|
||||
return dmp.MatchBitap(text, pattern, loc)
|
||||
}
|
||||
|
||||
// MatchBitap locates the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm.
|
||||
// Returns -1 if no match was found.
|
||||
func (dmp *DiffMatchPatch) MatchBitap(text, pattern string, loc int) int {
|
||||
// Initialise the alphabet.
|
||||
s := dmp.MatchAlphabet(pattern)
|
||||
|
||||
// Highest score beyond which we give up.
|
||||
scoreThreshold := dmp.MatchThreshold
|
||||
// Is there a nearby exact match? (speedup)
|
||||
bestLoc := indexOf(text, pattern, loc)
|
||||
if bestLoc != -1 {
|
||||
scoreThreshold = math.Min(dmp.matchBitapScore(0, bestLoc, loc,
|
||||
pattern), scoreThreshold)
|
||||
// What about in the other direction? (speedup)
|
||||
bestLoc = lastIndexOf(text, pattern, loc+len(pattern))
|
||||
if bestLoc != -1 {
|
||||
scoreThreshold = math.Min(dmp.matchBitapScore(0, bestLoc, loc,
|
||||
pattern), scoreThreshold)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialise the bit arrays.
|
||||
matchmask := 1 << uint((len(pattern) - 1))
|
||||
bestLoc = -1
|
||||
|
||||
var binMin, binMid int
|
||||
binMax := len(pattern) + len(text)
|
||||
lastRd := []int{}
|
||||
for d := 0; d < len(pattern); d++ {
|
||||
// Scan for the best match; each iteration allows for one more error. Run a binary search to determine how far from 'loc' we can stray at this error level.
|
||||
binMin = 0
|
||||
binMid = binMax
|
||||
for binMin < binMid {
|
||||
if dmp.matchBitapScore(d, loc+binMid, loc, pattern) <= scoreThreshold {
|
||||
binMin = binMid
|
||||
} else {
|
||||
binMax = binMid
|
||||
}
|
||||
binMid = (binMax-binMin)/2 + binMin
|
||||
}
|
||||
// Use the result from this iteration as the maximum for the next.
|
||||
binMax = binMid
|
||||
start := int(math.Max(1, float64(loc-binMid+1)))
|
||||
finish := int(math.Min(float64(loc+binMid), float64(len(text))) + float64(len(pattern)))
|
||||
|
||||
rd := make([]int, finish+2)
|
||||
rd[finish+1] = (1 << uint(d)) - 1
|
||||
|
||||
for j := finish; j >= start; j-- {
|
||||
var charMatch int
|
||||
if len(text) <= j-1 {
|
||||
// Out of range.
|
||||
charMatch = 0
|
||||
} else if _, ok := s[text[j-1]]; !ok {
|
||||
charMatch = 0
|
||||
} else {
|
||||
charMatch = s[text[j-1]]
|
||||
}
|
||||
|
||||
if d == 0 {
|
||||
// First pass: exact match.
|
||||
rd[j] = ((rd[j+1] << 1) | 1) & charMatch
|
||||
} else {
|
||||
// Subsequent passes: fuzzy match.
|
||||
rd[j] = ((rd[j+1]<<1)|1)&charMatch | (((lastRd[j+1] | lastRd[j]) << 1) | 1) | lastRd[j+1]
|
||||
}
|
||||
if (rd[j] & matchmask) != 0 {
|
||||
score := dmp.matchBitapScore(d, j-1, loc, pattern)
|
||||
// This match will almost certainly be better than any existing match. But check anyway.
|
||||
if score <= scoreThreshold {
|
||||
// Told you so.
|
||||
scoreThreshold = score
|
||||
bestLoc = j - 1
|
||||
if bestLoc > loc {
|
||||
// When passing loc, don't exceed our current distance from loc.
|
||||
start = int(math.Max(1, float64(2*loc-bestLoc)))
|
||||
} else {
|
||||
// Already passed loc, downhill from here on in.
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if dmp.matchBitapScore(d+1, loc, loc, pattern) > scoreThreshold {
|
||||
// No hope for a (better) match at greater error levels.
|
||||
break
|
||||
}
|
||||
lastRd = rd
|
||||
}
|
||||
return bestLoc
|
||||
}
|
||||
|
||||
// matchBitapScore computes and returns the score for a match with e errors and x location.
|
||||
func (dmp *DiffMatchPatch) matchBitapScore(e, x, loc int, pattern string) float64 {
|
||||
accuracy := float64(e) / float64(len(pattern))
|
||||
proximity := math.Abs(float64(loc - x))
|
||||
if dmp.MatchDistance == 0 {
|
||||
// Dodge divide by zero error.
|
||||
if proximity == 0 {
|
||||
return accuracy
|
||||
}
|
||||
|
||||
return 1.0
|
||||
}
|
||||
return accuracy + (proximity / float64(dmp.MatchDistance))
|
||||
}
|
||||
|
||||
// MatchAlphabet initialises the alphabet for the Bitap algorithm.
|
||||
func (dmp *DiffMatchPatch) MatchAlphabet(pattern string) map[byte]int {
|
||||
s := map[byte]int{}
|
||||
charPattern := []byte(pattern)
|
||||
for _, c := range charPattern {
|
||||
_, ok := s[c]
|
||||
if !ok {
|
||||
s[c] = 0
|
||||
}
|
||||
}
|
||||
i := 0
|
||||
|
||||
for _, c := range charPattern {
|
||||
value := s[c] | int(uint(1)<<uint((len(pattern)-i-1)))
|
||||
s[c] = value
|
||||
i++
|
||||
}
|
||||
return s
|
||||
}
|
23
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/mathutil.go
generated
vendored
Normal file
23
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/mathutil.go
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
|
||||
// https://github.com/sergi/go-diff
|
||||
// See the included LICENSE file for license details.
|
||||
//
|
||||
// go-diff is a Go implementation of Google's Diff, Match, and Patch library
|
||||
// Original library is Copyright (c) 2006 Google Inc.
|
||||
// http://code.google.com/p/google-diff-match-patch/
|
||||
|
||||
package diffmatchpatch
|
||||
|
||||
func min(x, y int) int {
|
||||
if x < y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
func max(x, y int) int {
|
||||
if x > y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
17
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/operation_string.go
generated
vendored
Normal file
17
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/operation_string.go
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Code generated by "stringer -type=Operation -trimprefix=Diff"; DO NOT EDIT.
|
||||
|
||||
package diffmatchpatch
|
||||
|
||||
import "fmt"
|
||||
|
||||
const _Operation_name = "DeleteEqualInsert"
|
||||
|
||||
var _Operation_index = [...]uint8{0, 6, 11, 17}
|
||||
|
||||
func (i Operation) String() string {
|
||||
i -= -1
|
||||
if i < 0 || i >= Operation(len(_Operation_index)-1) {
|
||||
return fmt.Sprintf("Operation(%d)", i+-1)
|
||||
}
|
||||
return _Operation_name[_Operation_index[i]:_Operation_index[i+1]]
|
||||
}
|
556
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/patch.go
generated
vendored
Normal file
556
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/patch.go
generated
vendored
Normal file
@ -0,0 +1,556 @@
|
||||
// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
|
||||
// https://github.com/sergi/go-diff
|
||||
// See the included LICENSE file for license details.
|
||||
//
|
||||
// go-diff is a Go implementation of Google's Diff, Match, and Patch library
|
||||
// Original library is Copyright (c) 2006 Google Inc.
|
||||
// http://code.google.com/p/google-diff-match-patch/
|
||||
|
||||
package diffmatchpatch
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"math"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Patch represents one patch operation.
|
||||
type Patch struct {
|
||||
diffs []Diff
|
||||
Start1 int
|
||||
Start2 int
|
||||
Length1 int
|
||||
Length2 int
|
||||
}
|
||||
|
||||
// String emulates GNU diff's format.
|
||||
// Header: @@ -382,8 +481,9 @@
|
||||
// Indices are printed as 1-based, not 0-based.
|
||||
func (p *Patch) String() string {
|
||||
var coords1, coords2 string
|
||||
|
||||
if p.Length1 == 0 {
|
||||
coords1 = strconv.Itoa(p.Start1) + ",0"
|
||||
} else if p.Length1 == 1 {
|
||||
coords1 = strconv.Itoa(p.Start1 + 1)
|
||||
} else {
|
||||
coords1 = strconv.Itoa(p.Start1+1) + "," + strconv.Itoa(p.Length1)
|
||||
}
|
||||
|
||||
if p.Length2 == 0 {
|
||||
coords2 = strconv.Itoa(p.Start2) + ",0"
|
||||
} else if p.Length2 == 1 {
|
||||
coords2 = strconv.Itoa(p.Start2 + 1)
|
||||
} else {
|
||||
coords2 = strconv.Itoa(p.Start2+1) + "," + strconv.Itoa(p.Length2)
|
||||
}
|
||||
|
||||
var text bytes.Buffer
|
||||
_, _ = text.WriteString("@@ -" + coords1 + " +" + coords2 + " @@\n")
|
||||
|
||||
// Escape the body of the patch with %xx notation.
|
||||
for _, aDiff := range p.diffs {
|
||||
switch aDiff.Type {
|
||||
case DiffInsert:
|
||||
_, _ = text.WriteString("+")
|
||||
case DiffDelete:
|
||||
_, _ = text.WriteString("-")
|
||||
case DiffEqual:
|
||||
_, _ = text.WriteString(" ")
|
||||
}
|
||||
|
||||
_, _ = text.WriteString(strings.Replace(url.QueryEscape(aDiff.Text), "+", " ", -1))
|
||||
_, _ = text.WriteString("\n")
|
||||
}
|
||||
|
||||
return unescaper.Replace(text.String())
|
||||
}
|
||||
|
||||
// PatchAddContext increases the context until it is unique, but doesn't let the pattern expand beyond MatchMaxBits.
|
||||
func (dmp *DiffMatchPatch) PatchAddContext(patch Patch, text string) Patch {
|
||||
if len(text) == 0 {
|
||||
return patch
|
||||
}
|
||||
|
||||
pattern := text[patch.Start2 : patch.Start2+patch.Length1]
|
||||
padding := 0
|
||||
|
||||
// Look for the first and last matches of pattern in text. If two different matches are found, increase the pattern length.
|
||||
for strings.Index(text, pattern) != strings.LastIndex(text, pattern) &&
|
||||
len(pattern) < dmp.MatchMaxBits-2*dmp.PatchMargin {
|
||||
padding += dmp.PatchMargin
|
||||
maxStart := max(0, patch.Start2-padding)
|
||||
minEnd := min(len(text), patch.Start2+patch.Length1+padding)
|
||||
pattern = text[maxStart:minEnd]
|
||||
}
|
||||
// Add one chunk for good luck.
|
||||
padding += dmp.PatchMargin
|
||||
|
||||
// Add the prefix.
|
||||
prefix := text[max(0, patch.Start2-padding):patch.Start2]
|
||||
if len(prefix) != 0 {
|
||||
patch.diffs = append([]Diff{Diff{DiffEqual, prefix}}, patch.diffs...)
|
||||
}
|
||||
// Add the suffix.
|
||||
suffix := text[patch.Start2+patch.Length1 : min(len(text), patch.Start2+patch.Length1+padding)]
|
||||
if len(suffix) != 0 {
|
||||
patch.diffs = append(patch.diffs, Diff{DiffEqual, suffix})
|
||||
}
|
||||
|
||||
// Roll back the start points.
|
||||
patch.Start1 -= len(prefix)
|
||||
patch.Start2 -= len(prefix)
|
||||
// Extend the lengths.
|
||||
patch.Length1 += len(prefix) + len(suffix)
|
||||
patch.Length2 += len(prefix) + len(suffix)
|
||||
|
||||
return patch
|
||||
}
|
||||
|
||||
// PatchMake computes a list of patches.
|
||||
func (dmp *DiffMatchPatch) PatchMake(opt ...interface{}) []Patch {
|
||||
if len(opt) == 1 {
|
||||
diffs, _ := opt[0].([]Diff)
|
||||
text1 := dmp.DiffText1(diffs)
|
||||
return dmp.PatchMake(text1, diffs)
|
||||
} else if len(opt) == 2 {
|
||||
text1 := opt[0].(string)
|
||||
switch t := opt[1].(type) {
|
||||
case string:
|
||||
diffs := dmp.DiffMain(text1, t, true)
|
||||
if len(diffs) > 2 {
|
||||
diffs = dmp.DiffCleanupSemantic(diffs)
|
||||
diffs = dmp.DiffCleanupEfficiency(diffs)
|
||||
}
|
||||
return dmp.PatchMake(text1, diffs)
|
||||
case []Diff:
|
||||
return dmp.patchMake2(text1, t)
|
||||
}
|
||||
} else if len(opt) == 3 {
|
||||
return dmp.PatchMake(opt[0], opt[2])
|
||||
}
|
||||
return []Patch{}
|
||||
}
|
||||
|
||||
// patchMake2 computes a list of patches to turn text1 into text2.
|
||||
// text2 is not provided, diffs are the delta between text1 and text2.
|
||||
func (dmp *DiffMatchPatch) patchMake2(text1 string, diffs []Diff) []Patch {
|
||||
// Check for null inputs not needed since null can't be passed in C#.
|
||||
patches := []Patch{}
|
||||
if len(diffs) == 0 {
|
||||
return patches // Get rid of the null case.
|
||||
}
|
||||
|
||||
patch := Patch{}
|
||||
charCount1 := 0 // Number of characters into the text1 string.
|
||||
charCount2 := 0 // Number of characters into the text2 string.
|
||||
// Start with text1 (prepatchText) and apply the diffs until we arrive at text2 (postpatchText). We recreate the patches one by one to determine context info.
|
||||
prepatchText := text1
|
||||
postpatchText := text1
|
||||
|
||||
for i, aDiff := range diffs {
|
||||
if len(patch.diffs) == 0 && aDiff.Type != DiffEqual {
|
||||
// A new patch starts here.
|
||||
patch.Start1 = charCount1
|
||||
patch.Start2 = charCount2
|
||||
}
|
||||
|
||||
switch aDiff.Type {
|
||||
case DiffInsert:
|
||||
patch.diffs = append(patch.diffs, aDiff)
|
||||
patch.Length2 += len(aDiff.Text)
|
||||
postpatchText = postpatchText[:charCount2] +
|
||||
aDiff.Text + postpatchText[charCount2:]
|
||||
case DiffDelete:
|
||||
patch.Length1 += len(aDiff.Text)
|
||||
patch.diffs = append(patch.diffs, aDiff)
|
||||
postpatchText = postpatchText[:charCount2] + postpatchText[charCount2+len(aDiff.Text):]
|
||||
case DiffEqual:
|
||||
if len(aDiff.Text) <= 2*dmp.PatchMargin &&
|
||||
len(patch.diffs) != 0 && i != len(diffs)-1 {
|
||||
// Small equality inside a patch.
|
||||
patch.diffs = append(patch.diffs, aDiff)
|
||||
patch.Length1 += len(aDiff.Text)
|
||||
patch.Length2 += len(aDiff.Text)
|
||||
}
|
||||
if len(aDiff.Text) >= 2*dmp.PatchMargin {
|
||||
// Time for a new patch.
|
||||
if len(patch.diffs) != 0 {
|
||||
patch = dmp.PatchAddContext(patch, prepatchText)
|
||||
patches = append(patches, patch)
|
||||
patch = Patch{}
|
||||
// Unlike Unidiff, our patch lists have a rolling context. http://code.google.com/p/google-diff-match-patch/wiki/Unidiff Update prepatch text & pos to reflect the application of the just completed patch.
|
||||
prepatchText = postpatchText
|
||||
charCount1 = charCount2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the current character count.
|
||||
if aDiff.Type != DiffInsert {
|
||||
charCount1 += len(aDiff.Text)
|
||||
}
|
||||
if aDiff.Type != DiffDelete {
|
||||
charCount2 += len(aDiff.Text)
|
||||
}
|
||||
}
|
||||
|
||||
// Pick up the leftover patch if not empty.
|
||||
if len(patch.diffs) != 0 {
|
||||
patch = dmp.PatchAddContext(patch, prepatchText)
|
||||
patches = append(patches, patch)
|
||||
}
|
||||
|
||||
return patches
|
||||
}
|
||||
|
||||
// PatchDeepCopy returns an array that is identical to a given an array of patches.
|
||||
func (dmp *DiffMatchPatch) PatchDeepCopy(patches []Patch) []Patch {
|
||||
patchesCopy := []Patch{}
|
||||
for _, aPatch := range patches {
|
||||
patchCopy := Patch{}
|
||||
for _, aDiff := range aPatch.diffs {
|
||||
patchCopy.diffs = append(patchCopy.diffs, Diff{
|
||||
aDiff.Type,
|
||||
aDiff.Text,
|
||||
})
|
||||
}
|
||||
patchCopy.Start1 = aPatch.Start1
|
||||
patchCopy.Start2 = aPatch.Start2
|
||||
patchCopy.Length1 = aPatch.Length1
|
||||
patchCopy.Length2 = aPatch.Length2
|
||||
patchesCopy = append(patchesCopy, patchCopy)
|
||||
}
|
||||
return patchesCopy
|
||||
}
|
||||
|
||||
// PatchApply merges a set of patches onto the text. Returns a patched text, as well as an array of true/false values indicating which patches were applied.
|
||||
func (dmp *DiffMatchPatch) PatchApply(patches []Patch, text string) (string, []bool) {
|
||||
if len(patches) == 0 {
|
||||
return text, []bool{}
|
||||
}
|
||||
|
||||
// Deep copy the patches so that no changes are made to originals.
|
||||
patches = dmp.PatchDeepCopy(patches)
|
||||
|
||||
nullPadding := dmp.PatchAddPadding(patches)
|
||||
text = nullPadding + text + nullPadding
|
||||
patches = dmp.PatchSplitMax(patches)
|
||||
|
||||
x := 0
|
||||
// delta keeps track of the offset between the expected and actual location of the previous patch. If there are patches expected at positions 10 and 20, but the first patch was found at 12, delta is 2 and the second patch has an effective expected position of 22.
|
||||
delta := 0
|
||||
results := make([]bool, len(patches))
|
||||
for _, aPatch := range patches {
|
||||
expectedLoc := aPatch.Start2 + delta
|
||||
text1 := dmp.DiffText1(aPatch.diffs)
|
||||
var startLoc int
|
||||
endLoc := -1
|
||||
if len(text1) > dmp.MatchMaxBits {
|
||||
// PatchSplitMax will only provide an oversized pattern in the case of a monster delete.
|
||||
startLoc = dmp.MatchMain(text, text1[:dmp.MatchMaxBits], expectedLoc)
|
||||
if startLoc != -1 {
|
||||
endLoc = dmp.MatchMain(text,
|
||||
text1[len(text1)-dmp.MatchMaxBits:], expectedLoc+len(text1)-dmp.MatchMaxBits)
|
||||
if endLoc == -1 || startLoc >= endLoc {
|
||||
// Can't find valid trailing context. Drop this patch.
|
||||
startLoc = -1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
startLoc = dmp.MatchMain(text, text1, expectedLoc)
|
||||
}
|
||||
if startLoc == -1 {
|
||||
// No match found. :(
|
||||
results[x] = false
|
||||
// Subtract the delta for this failed patch from subsequent patches.
|
||||
delta -= aPatch.Length2 - aPatch.Length1
|
||||
} else {
|
||||
// Found a match. :)
|
||||
results[x] = true
|
||||
delta = startLoc - expectedLoc
|
||||
var text2 string
|
||||
if endLoc == -1 {
|
||||
text2 = text[startLoc:int(math.Min(float64(startLoc+len(text1)), float64(len(text))))]
|
||||
} else {
|
||||
text2 = text[startLoc:int(math.Min(float64(endLoc+dmp.MatchMaxBits), float64(len(text))))]
|
||||
}
|
||||
if text1 == text2 {
|
||||
// Perfect match, just shove the Replacement text in.
|
||||
text = text[:startLoc] + dmp.DiffText2(aPatch.diffs) + text[startLoc+len(text1):]
|
||||
} else {
|
||||
// Imperfect match. Run a diff to get a framework of equivalent indices.
|
||||
diffs := dmp.DiffMain(text1, text2, false)
|
||||
if len(text1) > dmp.MatchMaxBits && float64(dmp.DiffLevenshtein(diffs))/float64(len(text1)) > dmp.PatchDeleteThreshold {
|
||||
// The end points match, but the content is unacceptably bad.
|
||||
results[x] = false
|
||||
} else {
|
||||
diffs = dmp.DiffCleanupSemanticLossless(diffs)
|
||||
index1 := 0
|
||||
for _, aDiff := range aPatch.diffs {
|
||||
if aDiff.Type != DiffEqual {
|
||||
index2 := dmp.DiffXIndex(diffs, index1)
|
||||
if aDiff.Type == DiffInsert {
|
||||
// Insertion
|
||||
text = text[:startLoc+index2] + aDiff.Text + text[startLoc+index2:]
|
||||
} else if aDiff.Type == DiffDelete {
|
||||
// Deletion
|
||||
startIndex := startLoc + index2
|
||||
text = text[:startIndex] +
|
||||
text[startIndex+dmp.DiffXIndex(diffs, index1+len(aDiff.Text))-index2:]
|
||||
}
|
||||
}
|
||||
if aDiff.Type != DiffDelete {
|
||||
index1 += len(aDiff.Text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
x++
|
||||
}
|
||||
// Strip the padding off.
|
||||
text = text[len(nullPadding) : len(nullPadding)+(len(text)-2*len(nullPadding))]
|
||||
return text, results
|
||||
}
|
||||
|
||||
// PatchAddPadding adds some padding on text start and end so that edges can match something.
|
||||
// Intended to be called only from within patchApply.
|
||||
func (dmp *DiffMatchPatch) PatchAddPadding(patches []Patch) string {
|
||||
paddingLength := dmp.PatchMargin
|
||||
nullPadding := ""
|
||||
for x := 1; x <= paddingLength; x++ {
|
||||
nullPadding += string(x)
|
||||
}
|
||||
|
||||
// Bump all the patches forward.
|
||||
for i := range patches {
|
||||
patches[i].Start1 += paddingLength
|
||||
patches[i].Start2 += paddingLength
|
||||
}
|
||||
|
||||
// Add some padding on start of first diff.
|
||||
if len(patches[0].diffs) == 0 || patches[0].diffs[0].Type != DiffEqual {
|
||||
// Add nullPadding equality.
|
||||
patches[0].diffs = append([]Diff{Diff{DiffEqual, nullPadding}}, patches[0].diffs...)
|
||||
patches[0].Start1 -= paddingLength // Should be 0.
|
||||
patches[0].Start2 -= paddingLength // Should be 0.
|
||||
patches[0].Length1 += paddingLength
|
||||
patches[0].Length2 += paddingLength
|
||||
} else if paddingLength > len(patches[0].diffs[0].Text) {
|
||||
// Grow first equality.
|
||||
extraLength := paddingLength - len(patches[0].diffs[0].Text)
|
||||
patches[0].diffs[0].Text = nullPadding[len(patches[0].diffs[0].Text):] + patches[0].diffs[0].Text
|
||||
patches[0].Start1 -= extraLength
|
||||
patches[0].Start2 -= extraLength
|
||||
patches[0].Length1 += extraLength
|
||||
patches[0].Length2 += extraLength
|
||||
}
|
||||
|
||||
// Add some padding on end of last diff.
|
||||
last := len(patches) - 1
|
||||
if len(patches[last].diffs) == 0 || patches[last].diffs[len(patches[last].diffs)-1].Type != DiffEqual {
|
||||
// Add nullPadding equality.
|
||||
patches[last].diffs = append(patches[last].diffs, Diff{DiffEqual, nullPadding})
|
||||
patches[last].Length1 += paddingLength
|
||||
patches[last].Length2 += paddingLength
|
||||
} else if paddingLength > len(patches[last].diffs[len(patches[last].diffs)-1].Text) {
|
||||
// Grow last equality.
|
||||
lastDiff := patches[last].diffs[len(patches[last].diffs)-1]
|
||||
extraLength := paddingLength - len(lastDiff.Text)
|
||||
patches[last].diffs[len(patches[last].diffs)-1].Text += nullPadding[:extraLength]
|
||||
patches[last].Length1 += extraLength
|
||||
patches[last].Length2 += extraLength
|
||||
}
|
||||
|
||||
return nullPadding
|
||||
}
|
||||
|
||||
// PatchSplitMax looks through the patches and breaks up any which are longer than the maximum limit of the match algorithm.
|
||||
// Intended to be called only from within patchApply.
|
||||
func (dmp *DiffMatchPatch) PatchSplitMax(patches []Patch) []Patch {
|
||||
patchSize := dmp.MatchMaxBits
|
||||
for x := 0; x < len(patches); x++ {
|
||||
if patches[x].Length1 <= patchSize {
|
||||
continue
|
||||
}
|
||||
bigpatch := patches[x]
|
||||
// Remove the big old patch.
|
||||
patches = append(patches[:x], patches[x+1:]...)
|
||||
x--
|
||||
|
||||
Start1 := bigpatch.Start1
|
||||
Start2 := bigpatch.Start2
|
||||
precontext := ""
|
||||
for len(bigpatch.diffs) != 0 {
|
||||
// Create one of several smaller patches.
|
||||
patch := Patch{}
|
||||
empty := true
|
||||
patch.Start1 = Start1 - len(precontext)
|
||||
patch.Start2 = Start2 - len(precontext)
|
||||
if len(precontext) != 0 {
|
||||
patch.Length1 = len(precontext)
|
||||
patch.Length2 = len(precontext)
|
||||
patch.diffs = append(patch.diffs, Diff{DiffEqual, precontext})
|
||||
}
|
||||
for len(bigpatch.diffs) != 0 && patch.Length1 < patchSize-dmp.PatchMargin {
|
||||
diffType := bigpatch.diffs[0].Type
|
||||
diffText := bigpatch.diffs[0].Text
|
||||
if diffType == DiffInsert {
|
||||
// Insertions are harmless.
|
||||
patch.Length2 += len(diffText)
|
||||
Start2 += len(diffText)
|
||||
patch.diffs = append(patch.diffs, bigpatch.diffs[0])
|
||||
bigpatch.diffs = bigpatch.diffs[1:]
|
||||
empty = false
|
||||
} else if diffType == DiffDelete && len(patch.diffs) == 1 && patch.diffs[0].Type == DiffEqual && len(diffText) > 2*patchSize {
|
||||
// This is a large deletion. Let it pass in one chunk.
|
||||
patch.Length1 += len(diffText)
|
||||
Start1 += len(diffText)
|
||||
empty = false
|
||||
patch.diffs = append(patch.diffs, Diff{diffType, diffText})
|
||||
bigpatch.diffs = bigpatch.diffs[1:]
|
||||
} else {
|
||||
// Deletion or equality. Only take as much as we can stomach.
|
||||
diffText = diffText[:min(len(diffText), patchSize-patch.Length1-dmp.PatchMargin)]
|
||||
|
||||
patch.Length1 += len(diffText)
|
||||
Start1 += len(diffText)
|
||||
if diffType == DiffEqual {
|
||||
patch.Length2 += len(diffText)
|
||||
Start2 += len(diffText)
|
||||
} else {
|
||||
empty = false
|
||||
}
|
||||
patch.diffs = append(patch.diffs, Diff{diffType, diffText})
|
||||
if diffText == bigpatch.diffs[0].Text {
|
||||
bigpatch.diffs = bigpatch.diffs[1:]
|
||||
} else {
|
||||
bigpatch.diffs[0].Text =
|
||||
bigpatch.diffs[0].Text[len(diffText):]
|
||||
}
|
||||
}
|
||||
}
|
||||
// Compute the head context for the next patch.
|
||||
precontext = dmp.DiffText2(patch.diffs)
|
||||
precontext = precontext[max(0, len(precontext)-dmp.PatchMargin):]
|
||||
|
||||
postcontext := ""
|
||||
// Append the end context for this patch.
|
||||
if len(dmp.DiffText1(bigpatch.diffs)) > dmp.PatchMargin {
|
||||
postcontext = dmp.DiffText1(bigpatch.diffs)[:dmp.PatchMargin]
|
||||
} else {
|
||||
postcontext = dmp.DiffText1(bigpatch.diffs)
|
||||
}
|
||||
|
||||
if len(postcontext) != 0 {
|
||||
patch.Length1 += len(postcontext)
|
||||
patch.Length2 += len(postcontext)
|
||||
if len(patch.diffs) != 0 && patch.diffs[len(patch.diffs)-1].Type == DiffEqual {
|
||||
patch.diffs[len(patch.diffs)-1].Text += postcontext
|
||||
} else {
|
||||
patch.diffs = append(patch.diffs, Diff{DiffEqual, postcontext})
|
||||
}
|
||||
}
|
||||
if !empty {
|
||||
x++
|
||||
patches = append(patches[:x], append([]Patch{patch}, patches[x:]...)...)
|
||||
}
|
||||
}
|
||||
}
|
||||
return patches
|
||||
}
|
||||
|
||||
// PatchToText takes a list of patches and returns a textual representation.
|
||||
func (dmp *DiffMatchPatch) PatchToText(patches []Patch) string {
|
||||
var text bytes.Buffer
|
||||
for _, aPatch := range patches {
|
||||
_, _ = text.WriteString(aPatch.String())
|
||||
}
|
||||
return text.String()
|
||||
}
|
||||
|
||||
// PatchFromText parses a textual representation of patches and returns a List of Patch objects.
|
||||
func (dmp *DiffMatchPatch) PatchFromText(textline string) ([]Patch, error) {
|
||||
patches := []Patch{}
|
||||
if len(textline) == 0 {
|
||||
return patches, nil
|
||||
}
|
||||
text := strings.Split(textline, "\n")
|
||||
textPointer := 0
|
||||
patchHeader := regexp.MustCompile("^@@ -(\\d+),?(\\d*) \\+(\\d+),?(\\d*) @@$")
|
||||
|
||||
var patch Patch
|
||||
var sign uint8
|
||||
var line string
|
||||
for textPointer < len(text) {
|
||||
|
||||
if !patchHeader.MatchString(text[textPointer]) {
|
||||
return patches, errors.New("Invalid patch string: " + text[textPointer])
|
||||
}
|
||||
|
||||
patch = Patch{}
|
||||
m := patchHeader.FindStringSubmatch(text[textPointer])
|
||||
|
||||
patch.Start1, _ = strconv.Atoi(m[1])
|
||||
if len(m[2]) == 0 {
|
||||
patch.Start1--
|
||||
patch.Length1 = 1
|
||||
} else if m[2] == "0" {
|
||||
patch.Length1 = 0
|
||||
} else {
|
||||
patch.Start1--
|
||||
patch.Length1, _ = strconv.Atoi(m[2])
|
||||
}
|
||||
|
||||
patch.Start2, _ = strconv.Atoi(m[3])
|
||||
|
||||
if len(m[4]) == 0 {
|
||||
patch.Start2--
|
||||
patch.Length2 = 1
|
||||
} else if m[4] == "0" {
|
||||
patch.Length2 = 0
|
||||
} else {
|
||||
patch.Start2--
|
||||
patch.Length2, _ = strconv.Atoi(m[4])
|
||||
}
|
||||
textPointer++
|
||||
|
||||
for textPointer < len(text) {
|
||||
if len(text[textPointer]) > 0 {
|
||||
sign = text[textPointer][0]
|
||||
} else {
|
||||
textPointer++
|
||||
continue
|
||||
}
|
||||
|
||||
line = text[textPointer][1:]
|
||||
line = strings.Replace(line, "+", "%2b", -1)
|
||||
line, _ = url.QueryUnescape(line)
|
||||
if sign == '-' {
|
||||
// Deletion.
|
||||
patch.diffs = append(patch.diffs, Diff{DiffDelete, line})
|
||||
} else if sign == '+' {
|
||||
// Insertion.
|
||||
patch.diffs = append(patch.diffs, Diff{DiffInsert, line})
|
||||
} else if sign == ' ' {
|
||||
// Minor equality.
|
||||
patch.diffs = append(patch.diffs, Diff{DiffEqual, line})
|
||||
} else if sign == '@' {
|
||||
// Start of next patch.
|
||||
break
|
||||
} else {
|
||||
// WTF?
|
||||
return patches, errors.New("Invalid patch mode '" + string(sign) + "' in: " + string(line))
|
||||
}
|
||||
textPointer++
|
||||
}
|
||||
|
||||
patches = append(patches, patch)
|
||||
}
|
||||
return patches, nil
|
||||
}
|
88
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/stringutil.go
generated
vendored
Normal file
88
vendor/github.com/smartystreets/assertions/internal/go-diff/diffmatchpatch/stringutil.go
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
|
||||
// https://github.com/sergi/go-diff
|
||||
// See the included LICENSE file for license details.
|
||||
//
|
||||
// go-diff is a Go implementation of Google's Diff, Match, and Patch library
|
||||
// Original library is Copyright (c) 2006 Google Inc.
|
||||
// http://code.google.com/p/google-diff-match-patch/
|
||||
|
||||
package diffmatchpatch
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// unescaper unescapes selected chars for compatibility with JavaScript's encodeURI.
|
||||
// In speed critical applications this could be dropped since the receiving application will certainly decode these fine. Note that this function is case-sensitive. Thus "%3F" would not be unescaped. But this is ok because it is only called with the output of HttpUtility.UrlEncode which returns lowercase hex. Example: "%3f" -> "?", "%24" -> "$", etc.
|
||||
var unescaper = strings.NewReplacer(
|
||||
"%21", "!", "%7E", "~", "%27", "'",
|
||||
"%28", "(", "%29", ")", "%3B", ";",
|
||||
"%2F", "/", "%3F", "?", "%3A", ":",
|
||||
"%40", "@", "%26", "&", "%3D", "=",
|
||||
"%2B", "+", "%24", "$", "%2C", ",", "%23", "#", "%2A", "*")
|
||||
|
||||
// indexOf returns the first index of pattern in str, starting at str[i].
|
||||
func indexOf(str string, pattern string, i int) int {
|
||||
if i > len(str)-1 {
|
||||
return -1
|
||||
}
|
||||
if i <= 0 {
|
||||
return strings.Index(str, pattern)
|
||||
}
|
||||
ind := strings.Index(str[i:], pattern)
|
||||
if ind == -1 {
|
||||
return -1
|
||||
}
|
||||
return ind + i
|
||||
}
|
||||
|
||||
// lastIndexOf returns the last index of pattern in str, starting at str[i].
|
||||
func lastIndexOf(str string, pattern string, i int) int {
|
||||
if i < 0 {
|
||||
return -1
|
||||
}
|
||||
if i >= len(str) {
|
||||
return strings.LastIndex(str, pattern)
|
||||
}
|
||||
_, size := utf8.DecodeRuneInString(str[i:])
|
||||
return strings.LastIndex(str[:i+size], pattern)
|
||||
}
|
||||
|
||||
// runesIndexOf returns the index of pattern in target, starting at target[i].
|
||||
func runesIndexOf(target, pattern []rune, i int) int {
|
||||
if i > len(target)-1 {
|
||||
return -1
|
||||
}
|
||||
if i <= 0 {
|
||||
return runesIndex(target, pattern)
|
||||
}
|
||||
ind := runesIndex(target[i:], pattern)
|
||||
if ind == -1 {
|
||||
return -1
|
||||
}
|
||||
return ind + i
|
||||
}
|
||||
|
||||
func runesEqual(r1, r2 []rune) bool {
|
||||
if len(r1) != len(r2) {
|
||||
return false
|
||||
}
|
||||
for i, c := range r1 {
|
||||
if c != r2[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// runesIndex is the equivalent of strings.Index for rune slices.
|
||||
func runesIndex(r1, r2 []rune) int {
|
||||
last := len(r1) - len(r2)
|
||||
for i := 0; i <= last; i++ {
|
||||
if runesEqual(r1[i:i+len(r2)], r2) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
130
vendor/github.com/smartystreets/assertions/messages.go
generated
vendored
130
vendor/github.com/smartystreets/assertions/messages.go
generated
vendored
@ -1,75 +1,85 @@
|
||||
package assertions
|
||||
|
||||
const ( // equality
|
||||
shouldHaveBeenEqual = "Expected: '%v'\nActual: '%v'\n(Should be equal)"
|
||||
shouldNotHaveBeenEqual = "Expected '%v'\nto NOT equal '%v'\n(but it did)!"
|
||||
shouldHaveBeenEqualTypeMismatch = "Expected: '%v' (%T)\nActual: '%v' (%T)\n(Should be equal, type mismatch)"
|
||||
shouldHaveBeenAlmostEqual = "Expected '%v' to almost equal '%v' (but it didn't)!"
|
||||
shouldHaveNotBeenAlmostEqual = "Expected '%v' to NOT almost equal '%v' (but it did)!"
|
||||
shouldHaveResembled = "Expected: '%s'\nActual: '%s'\n(Should resemble)!"
|
||||
shouldNotHaveResembled = "Expected '%#v'\nto NOT resemble '%#v'\n(but it did)!"
|
||||
shouldBePointers = "Both arguments should be pointers "
|
||||
shouldHaveBeenNonNilPointer = shouldBePointers + "(the %s was %s)!"
|
||||
shouldHavePointedTo = "Expected '%+v' (address: '%v') and '%+v' (address: '%v') to be the same address (but their weren't)!"
|
||||
shouldNotHavePointedTo = "Expected '%+v' and '%+v' to be different references (but they matched: '%v')!"
|
||||
shouldHaveBeenNil = "Expected: nil\nActual: '%v'"
|
||||
shouldNotHaveBeenNil = "Expected '%+v' to NOT be nil (but it was)!"
|
||||
shouldHaveBeenTrue = "Expected: true\nActual: %v"
|
||||
shouldHaveBeenFalse = "Expected: false\nActual: %v"
|
||||
shouldHaveBeenZeroValue = "'%+v' should have been the zero value" //"Expected: (zero value)\nActual: %v"
|
||||
)
|
||||
const (
|
||||
shouldHaveBeenEqual = "Expected: '%v'\nActual: '%v'\n(Should be equal)"
|
||||
shouldHaveBeenEqualNoResemblance = "Both the actual and expected values render equally ('%s') and their types are the same. Try using ShouldResemble instead."
|
||||
shouldNotHaveBeenEqual = "Expected '%v'\nto NOT equal '%v'\n(but it did)!"
|
||||
shouldHaveBeenEqualTypeMismatch = "Expected: '%v' (%T)\nActual: '%v' (%T)\n(Should be equal, type mismatch)"
|
||||
|
||||
shouldHaveBeenAlmostEqual = "Expected '%v' to almost equal '%v' (but it didn't)!"
|
||||
shouldHaveNotBeenAlmostEqual = "Expected '%v' to NOT almost equal '%v' (but it did)!"
|
||||
|
||||
shouldHaveResembled = "Expected: '%s'\nActual: '%s'\n(Should resemble)!"
|
||||
shouldNotHaveResembled = "Expected '%#v'\nto NOT resemble '%#v'\n(but it did)!"
|
||||
|
||||
shouldBePointers = "Both arguments should be pointers "
|
||||
shouldHaveBeenNonNilPointer = shouldBePointers + "(the %s was %s)!"
|
||||
shouldHavePointedTo = "Expected '%+v' (address: '%v') and '%+v' (address: '%v') to be the same address (but their weren't)!"
|
||||
shouldNotHavePointedTo = "Expected '%+v' and '%+v' to be different references (but they matched: '%v')!"
|
||||
|
||||
shouldHaveBeenNil = "Expected: nil\nActual: '%v'"
|
||||
shouldNotHaveBeenNil = "Expected '%+v' to NOT be nil (but it was)!"
|
||||
|
||||
shouldHaveBeenTrue = "Expected: true\nActual: %v"
|
||||
shouldHaveBeenFalse = "Expected: false\nActual: %v"
|
||||
|
||||
shouldHaveBeenZeroValue = "'%+v' should have been the zero value" //"Expected: (zero value)\nActual: %v"
|
||||
shouldNotHaveBeenZeroValue = "'%+v' should NOT have been the zero value"
|
||||
|
||||
shouldHaveBeenGreater = "Expected '%v' to be greater than '%v' (but it wasn't)!"
|
||||
shouldHaveBeenGreaterOrEqual = "Expected '%v' to be greater than or equal to '%v' (but it wasn't)!"
|
||||
|
||||
shouldHaveBeenLess = "Expected '%v' to be less than '%v' (but it wasn't)!"
|
||||
shouldHaveBeenLessOrEqual = "Expected '%v' to be less than or equal to '%v' (but it wasn't)!"
|
||||
|
||||
const ( // quantity comparisons
|
||||
shouldHaveBeenGreater = "Expected '%v' to be greater than '%v' (but it wasn't)!"
|
||||
shouldHaveBeenGreaterOrEqual = "Expected '%v' to be greater than or equal to '%v' (but it wasn't)!"
|
||||
shouldHaveBeenLess = "Expected '%v' to be less than '%v' (but it wasn't)!"
|
||||
shouldHaveBeenLessOrEqual = "Expected '%v' to be less than or equal to '%v' (but it wasn't)!"
|
||||
shouldHaveBeenBetween = "Expected '%v' to be between '%v' and '%v' (but it wasn't)!"
|
||||
shouldNotHaveBeenBetween = "Expected '%v' NOT to be between '%v' and '%v' (but it was)!"
|
||||
shouldHaveDifferentUpperAndLower = "The lower and upper bounds must be different values (they were both '%v')."
|
||||
shouldHaveBeenBetweenOrEqual = "Expected '%v' to be between '%v' and '%v' or equal to one of them (but it wasn't)!"
|
||||
shouldNotHaveBeenBetweenOrEqual = "Expected '%v' NOT to be between '%v' and '%v' or equal to one of them (but it was)!"
|
||||
)
|
||||
|
||||
const ( // collections
|
||||
shouldHaveBeenBetweenOrEqual = "Expected '%v' to be between '%v' and '%v' or equal to one of them (but it wasn't)!"
|
||||
shouldNotHaveBeenBetweenOrEqual = "Expected '%v' NOT to be between '%v' and '%v' or equal to one of them (but it was)!"
|
||||
|
||||
shouldHaveContained = "Expected the container (%v) to contain: '%v' (but it didn't)!"
|
||||
shouldNotHaveContained = "Expected the container (%v) NOT to contain: '%v' (but it did)!"
|
||||
shouldHaveContainedKey = "Expected the %v to contain the key: %v (but it didn't)!"
|
||||
shouldNotHaveContainedKey = "Expected the %v NOT to contain the key: %v (but it did)!"
|
||||
shouldHaveBeenIn = "Expected '%v' to be in the container (%v), but it wasn't!"
|
||||
shouldNotHaveBeenIn = "Expected '%v' NOT to be in the container (%v), but it was!"
|
||||
shouldHaveBeenAValidCollection = "You must provide a valid container (was %v)!"
|
||||
shouldHaveBeenAValidMap = "You must provide a valid map type (was %v)!"
|
||||
shouldHaveBeenEmpty = "Expected %+v to be empty (but it wasn't)!"
|
||||
shouldNotHaveBeenEmpty = "Expected %+v to NOT be empty (but it was)!"
|
||||
shouldHaveBeenAValidInteger = "You must provide a valid integer (was %v)!"
|
||||
shouldHaveBeenAValidLength = "You must provide a valid positive integer (was %v)!"
|
||||
shouldHaveHadLength = "Expected %+v (length: %v) to have length equal to '%v', but it wasn't!"
|
||||
)
|
||||
|
||||
const ( // strings
|
||||
shouldHaveStartedWith = "Expected '%v'\nto start with '%v'\n(but it didn't)!"
|
||||
shouldNotHaveStartedWith = "Expected '%v'\nNOT to start with '%v'\n(but it did)!"
|
||||
shouldHaveEndedWith = "Expected '%v'\nto end with '%v'\n(but it didn't)!"
|
||||
shouldNotHaveEndedWith = "Expected '%v'\nNOT to end with '%v'\n(but it did)!"
|
||||
shouldAllBeStrings = "All arguments to this assertion must be strings (you provided: %v)."
|
||||
shouldBothBeStrings = "Both arguments to this assertion must be strings (you provided %v and %v)."
|
||||
shouldBeString = "The argument to this assertion must be a string (you provided %v)."
|
||||
shouldHaveContainedKey = "Expected the %v to contain the key: %v (but it didn't)!"
|
||||
shouldNotHaveContainedKey = "Expected the %v NOT to contain the key: %v (but it did)!"
|
||||
shouldHaveBeenAValidMap = "You must provide a valid map type (was %v)!"
|
||||
|
||||
shouldHaveBeenIn = "Expected '%v' to be in the container (%v), but it wasn't!"
|
||||
shouldNotHaveBeenIn = "Expected '%v' NOT to be in the container (%v), but it was!"
|
||||
|
||||
shouldHaveBeenEmpty = "Expected %+v to be empty (but it wasn't)!"
|
||||
shouldNotHaveBeenEmpty = "Expected %+v to NOT be empty (but it was)!"
|
||||
|
||||
shouldHaveBeenAValidInteger = "You must provide a valid integer (was %v)!"
|
||||
shouldHaveBeenAValidLength = "You must provide a valid positive integer (was %v)!"
|
||||
shouldHaveHadLength = "Expected collection to have length equal to [%v], but it's length was [%v] instead! contents: %+v"
|
||||
|
||||
shouldHaveStartedWith = "Expected '%v'\nto start with '%v'\n(but it didn't)!"
|
||||
shouldNotHaveStartedWith = "Expected '%v'\nNOT to start with '%v'\n(but it did)!"
|
||||
|
||||
shouldHaveEndedWith = "Expected '%v'\nto end with '%v'\n(but it didn't)!"
|
||||
shouldNotHaveEndedWith = "Expected '%v'\nNOT to end with '%v'\n(but it did)!"
|
||||
|
||||
shouldAllBeStrings = "All arguments to this assertion must be strings (you provided: %v)."
|
||||
shouldBothBeStrings = "Both arguments to this assertion must be strings (you provided %v and %v)."
|
||||
|
||||
shouldHaveContainedSubstring = "Expected '%s' to contain substring '%s' (but it didn't)!"
|
||||
shouldNotHaveContainedSubstring = "Expected '%s' NOT to contain substring '%s' (but it did)!"
|
||||
shouldHaveBeenBlank = "Expected '%s' to be blank (but it wasn't)!"
|
||||
shouldNotHaveBeenBlank = "Expected value to NOT be blank (but it was)!"
|
||||
)
|
||||
|
||||
const ( // panics
|
||||
shouldBeString = "The argument to this assertion must be a string (you provided %v)."
|
||||
shouldHaveBeenBlank = "Expected '%s' to be blank (but it wasn't)!"
|
||||
shouldNotHaveBeenBlank = "Expected value to NOT be blank (but it was)!"
|
||||
|
||||
shouldUseVoidNiladicFunction = "You must provide a void, niladic function as the first argument!"
|
||||
shouldHavePanickedWith = "Expected func() to panic with '%v' (but it panicked with '%v')!"
|
||||
shouldHavePanicked = "Expected func() to panic (but it didn't)!"
|
||||
shouldNotHavePanicked = "Expected func() NOT to panic (error: '%+v')!"
|
||||
shouldNotHavePanickedWith = "Expected func() NOT to panic with '%v' (but it did)!"
|
||||
)
|
||||
|
||||
const ( // type checking
|
||||
shouldHavePanickedWith = "Expected func() to panic with '%v' (but it panicked with '%v')!"
|
||||
shouldNotHavePanickedWith = "Expected func() NOT to panic with '%v' (but it did)!"
|
||||
|
||||
shouldHaveBeenA = "Expected '%v' to be: '%v' (but was: '%v')!"
|
||||
shouldNotHaveBeenA = "Expected '%v' to NOT be: '%v' (but it was)!"
|
||||
|
||||
@ -80,17 +90,17 @@ const ( // type checking
|
||||
|
||||
shouldBeError = "Expected an error value (but was '%v' instead)!"
|
||||
shouldBeErrorInvalidComparisonValue = "The final argument to this assertion must be a string or an error value (you provided: '%v')."
|
||||
)
|
||||
|
||||
const ( // time comparisons
|
||||
shouldUseTimes = "You must provide time instances as arguments to this assertion."
|
||||
shouldUseTimeSlice = "You must provide a slice of time instances as the first argument to this assertion."
|
||||
shouldUseDurationAndTime = "You must provide a duration and a time as arguments to this assertion."
|
||||
shouldUseTimes = "You must provide time instances as arguments to this assertion."
|
||||
shouldUseTimeSlice = "You must provide a slice of time instances as the first argument to this assertion."
|
||||
shouldUseDurationAndTime = "You must provide a duration and a time as arguments to this assertion."
|
||||
|
||||
shouldHaveHappenedBefore = "Expected '%v' to happen before '%v' (it happened '%v' after)!"
|
||||
shouldHaveHappenedAfter = "Expected '%v' to happen after '%v' (it happened '%v' before)!"
|
||||
shouldHaveHappenedBetween = "Expected '%v' to happen between '%v' and '%v' (it happened '%v' outside threshold)!"
|
||||
shouldNotHaveHappenedOnOrBetween = "Expected '%v' to NOT happen on or between '%v' and '%v' (but it did)!"
|
||||
|
||||
// format params: incorrect-index, previous-index, previous-time, incorrect-index, incorrect-time
|
||||
shouldHaveBeenChronological = "The 'Time' at index [%d] should have happened after the previous one (but it didn't!):\n [%d]: %s\n [%d]: %s (see, it happened before!)"
|
||||
shouldHaveBeenChronological = "The 'Time' at index [%d] should have happened after the previous one (but it didn't!):\n [%d]: %s\n [%d]: %s (see, it happened before!)"
|
||||
shouldNotHaveBeenchronological = "The provided times should NOT be chronological, but they were."
|
||||
)
|
||||
|
7
vendor/github.com/smartystreets/assertions/serializer.go
generated
vendored
7
vendor/github.com/smartystreets/assertions/serializer.go
generated
vendored
@ -3,6 +3,7 @@ package assertions
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/smartystreets/assertions/internal/go-render/render"
|
||||
)
|
||||
@ -15,6 +16,9 @@ type Serializer interface {
|
||||
type failureSerializer struct{}
|
||||
|
||||
func (self *failureSerializer) serializeDetailed(expected, actual interface{}, message string) string {
|
||||
if index := strings.Index(message, " Diff:"); index > 0 {
|
||||
message = message[:index]
|
||||
}
|
||||
view := FailureView{
|
||||
Message: message,
|
||||
Expected: render.Render(expected),
|
||||
@ -25,6 +29,9 @@ func (self *failureSerializer) serializeDetailed(expected, actual interface{}, m
|
||||
}
|
||||
|
||||
func (self *failureSerializer) serialize(expected, actual interface{}, message string) string {
|
||||
if index := strings.Index(message, " Diff:"); index > 0 {
|
||||
message = message[:index]
|
||||
}
|
||||
view := FailureView{
|
||||
Message: message,
|
||||
Expected: fmt.Sprintf("%+v", expected),
|
||||
|
18
vendor/github.com/smartystreets/assertions/time.go
generated
vendored
18
vendor/github.com/smartystreets/assertions/time.go
generated
vendored
@ -178,7 +178,7 @@ func ShouldNotHappenWithin(actual interface{}, expected ...interface{}) string {
|
||||
return ShouldNotHappenOnOrBetween(actualTime, min, max)
|
||||
}
|
||||
|
||||
// ShouldBeChronological receives a []time.Time slice and asserts that the are
|
||||
// ShouldBeChronological receives a []time.Time slice and asserts that they are
|
||||
// in chronological order starting with the first time.Time as the earliest.
|
||||
func ShouldBeChronological(actual interface{}, expected ...interface{}) string {
|
||||
if fail := need(0, expected); fail != success {
|
||||
@ -200,3 +200,19 @@ func ShouldBeChronological(actual interface{}, expected ...interface{}) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ShouldNotBeChronological receives a []time.Time slice and asserts that they are
|
||||
// NOT in chronological order.
|
||||
func ShouldNotBeChronological(actual interface{}, expected ...interface{}) string {
|
||||
if fail := need(0, expected); fail != success {
|
||||
return fail
|
||||
}
|
||||
if _, ok := actual.([]time.Time); !ok {
|
||||
return shouldUseTimeSlice
|
||||
}
|
||||
result := ShouldBeChronological(actual, expected...)
|
||||
if result != "" {
|
||||
return ""
|
||||
}
|
||||
return shouldNotHaveBeenchronological
|
||||
}
|
||||
|
1
vendor/github.com/smartystreets/goconvey/convey/assertions.go
generated
vendored
1
vendor/github.com/smartystreets/goconvey/convey/assertions.go
generated
vendored
@ -16,6 +16,7 @@ var (
|
||||
ShouldBeTrue = assertions.ShouldBeTrue
|
||||
ShouldBeFalse = assertions.ShouldBeFalse
|
||||
ShouldBeZeroValue = assertions.ShouldBeZeroValue
|
||||
ShouldNotBeZeroValue = assertions.ShouldNotBeZeroValue
|
||||
|
||||
ShouldBeGreaterThan = assertions.ShouldBeGreaterThan
|
||||
ShouldBeGreaterThanOrEqualTo = assertions.ShouldBeGreaterThanOrEqualTo
|
||||
|
2
vendor/github.com/smartystreets/goconvey/convey/gotest/utils.go
generated
vendored
2
vendor/github.com/smartystreets/goconvey/convey/gotest/utils.go
generated
vendored
@ -19,7 +19,7 @@ func ResolveExternalCaller() (file string, line int, name string) {
|
||||
return
|
||||
}
|
||||
}
|
||||
file, line, name = "<unkown file>", -1, "<unknown name>"
|
||||
file, line, name = "<unknown file>", -1, "<unknown name>"
|
||||
return // panic?
|
||||
}
|
||||
|
||||
|
2
vendor/github.com/smartystreets/goconvey/convey/init.go
generated
vendored
2
vendor/github.com/smartystreets/goconvey/convey/init.go
generated
vendored
@ -20,7 +20,7 @@ func init() {
|
||||
func declareFlags() {
|
||||
flag.BoolVar(&json, "convey-json", false, "When true, emits results in JSON blocks. Default: 'false'")
|
||||
flag.BoolVar(&silent, "convey-silent", false, "When true, all output from GoConvey is suppressed.")
|
||||
flag.BoolVar(&story, "convey-story", false, "When true, emits story output, otherwise emits dot output. When not provided, this flag mirros the value of the '-test.v' flag")
|
||||
flag.BoolVar(&story, "convey-story", false, "When true, emits story output, otherwise emits dot output. When not provided, this flag mirrors the value of the '-test.v' flag")
|
||||
|
||||
if noStoryFlagProvided() {
|
||||
story = verboseEnabled
|
||||
|
2
vendor/github.com/smartystreets/goconvey/convey/reporting/init.go
generated
vendored
2
vendor/github.com/smartystreets/goconvey/convey/reporting/init.go
generated
vendored
@ -56,7 +56,7 @@ var (
|
||||
dotError = "E"
|
||||
dotSkip = "S"
|
||||
errorTemplate = "* %s \nLine %d: - %v \n%s\n"
|
||||
failureTemplate = "* %s \nLine %d:\n%s\n"
|
||||
failureTemplate = "* %s \nLine %d:\n%s\n%s\n"
|
||||
)
|
||||
|
||||
var (
|
||||
|
5
vendor/github.com/smartystreets/goconvey/convey/reporting/printer.go
generated
vendored
5
vendor/github.com/smartystreets/goconvey/convey/reporting/printer.go
generated
vendored
@ -30,12 +30,15 @@ func (self *Printer) format(message string, values ...interface{}) string {
|
||||
if len(values) == 0 {
|
||||
formatted = self.prefix + message
|
||||
} else {
|
||||
formatted = self.prefix + fmt.Sprintf(message, values...)
|
||||
formatted = self.prefix + fmt_Sprintf(message, values...)
|
||||
}
|
||||
indented := strings.Replace(formatted, newline, newline+self.prefix, -1)
|
||||
return strings.TrimRight(indented, space)
|
||||
}
|
||||
|
||||
// Extracting fmt.Sprintf to a separate variable circumvents go vet, which, as of go 1.10 is run with go test.
|
||||
var fmt_Sprintf = fmt.Sprintf
|
||||
|
||||
func (self *Printer) Indent() {
|
||||
self.prefix += pad
|
||||
}
|
||||
|
2
vendor/github.com/smartystreets/goconvey/convey/reporting/problems.go
generated
vendored
2
vendor/github.com/smartystreets/goconvey/convey/reporting/problems.go
generated
vendored
@ -53,7 +53,7 @@ func (self *problem) showFailures() {
|
||||
self.out.Println("\nFailures:\n")
|
||||
self.out.Indent()
|
||||
}
|
||||
self.out.Println(failureTemplate, f.File, f.Line, f.Failure)
|
||||
self.out.Println(failureTemplate, f.File, f.Line, f.Failure, f.StackTrace)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user