You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ke...@apache.org on 2023/10/08 22:57:39 UTC

[tinkerpop] 03/03: add support for comparing sets in feature tests for gremlingo

This is an automated email from the ASF dual-hosted git repository.

kenhuuu pushed a commit to branch gherkin-set-results
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit b0d4655f2beb7b1d91c76e76e966ad0e7ba38500
Author: Ken Hu <10...@users.noreply.github.com>
AuthorDate: Sun Oct 8 15:56:33 2023 -0700

    add support for comparing sets in feature tests for gremlingo
---
 gremlin-go/driver/cucumber/cucumberSteps_test.go | 32 ++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/gremlin-go/driver/cucumber/cucumberSteps_test.go b/gremlin-go/driver/cucumber/cucumberSteps_test.go
index 73855c31d5..e36a86ff24 100644
--- a/gremlin-go/driver/cucumber/cucumberSteps_test.go
+++ b/gremlin-go/driver/cucumber/cucumberSteps_test.go
@@ -24,15 +24,17 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
-	"github.com/apache/tinkerpop/gremlin-go/v3/driver"
-	"github.com/cucumber/godog"
 	"math"
 	"reflect"
 	"regexp"
+	"sort"
 	"strconv"
 	"strings"
 	"sync"
 	"testing"
+
+	gremlingo "github.com/apache/tinkerpop/gremlin-go/v3/driver"
+	"github.com/cucumber/godog"
 )
 
 type tinkerPopGraph struct {
@@ -652,6 +654,22 @@ func compareListEqualsWithoutOrder(expected []interface{}, actual []interface{})
 					break
 				}
 			}
+		} else if reflect.TypeOf(a).String() == "*gremlingo.SimpleSet" {
+			// Set is a special case here because there is no TypeOf().Kind() for sets.
+			actualStringArray := makeSortedStringArrayFromSet(a)
+
+			for i := len(expectedCopy) - 1; i >= 0; i-- {
+				curExpected := expectedCopy[i]
+				if curExpected != nil && reflect.TypeOf(curExpected).String() == "*gremlingo.SimpleSet" {
+					expectedStringArray := makeSortedStringArrayFromSet(curExpected)
+
+					if reflect.DeepEqual(actualStringArray, expectedStringArray) {
+						expectedCopy = append(expectedCopy[:i], expectedCopy[i+1:]...)
+						found = true
+						break
+					}
+				}
+			}
 		} else {
 			switch reflect.TypeOf(a).Kind() {
 			case reflect.Array, reflect.Slice:
@@ -761,6 +779,16 @@ func compareListEqualsWithOf(expected []interface{}, actual []interface{}) bool
 	return true
 }
 
+func makeSortedStringArrayFromSet(set interface{}) []string {
+	var sortedStrings []string
+	for _, element := range set.(*gremlingo.SimpleSet).ToSlice() {
+		sortedStrings = append(sortedStrings, fmt.Sprintf("%v", element))
+	}
+	sort.Sort(sort.StringSlice(sortedStrings))
+
+	return sortedStrings
+}
+
 func (tg *tinkerPopGraph) theTraversalOf(arg1 *godog.DocString) error {
 	traversal, err := GetTraversal(tg.scenario.Name, tg.g, tg.parameters)
 	if err != nil {