<commit_before>package handler

import (
	"sort"

	. "github.com/oursky/skygear/ourtest"
	. "github.com/smartystreets/goconvey/convey"
	"testing"

	"github.com/oursky/skygear/handler/handlertest"
	"github.com/oursky/skygear/router"
	"github.com/oursky/skygear/skydb"
)

type testRelationConn struct {
	UserInfo     []skydb.UserInfo
	RelationName string
	addedID      string
	removeID     string
	addErr       error
	removeErr    error
	skydb.Conn
}

func (conn *testRelationConn) GetUser(id string, userinfo *skydb.UserInfo) error {
	userinfo.ID = id
	userinfo.Username = "testRelationConn"
	return nil
}

type sortByID []skydb.UserInfo

func (a sortByID) Len() int           { return len(a) }
func (a sortByID) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a sortByID) Less(i, j int) bool { return a[i].ID < a[j].ID }

func (conn *testRelationConn) QueryRelation(user string, name string, direction string, config skydb.QueryConfig) []skydb.UserInfo {
	conn.RelationName = name
	if conn.UserInfo == nil {
		return []skydb.UserInfo{}
	}

	sort.Sort(sortByID(conn.UserInfo))
	if config.Limit == 0 {
		return conn.UserInfo[config.Offset:]
	}

	if config.Offset+config.Limit-1 > uint64(len(conn.UserInfo)) {
		return conn.UserInfo[config.Offset:]
	}
	return conn.UserInfo[config.Offset : config.Offset+config.Limit]<commit_msg>Rename sortByID to sortableUserInfo<commit_after>package handler

import (
	"sort"

	. "github.com/oursky/skygear/ourtest"
	. "github.com/smartystreets/goconvey/convey"
	"testing"

	"github.com/oursky/skygear/handler/handlertest"
	"github.com/oursky/skygear/router"
	"github.com/oursky/skygear/skydb"
)

type testRelationConn struct {
	UserInfo     []skydb.UserInfo
	RelationName string
	addedID      string
	removeID     string
	addErr       error
	removeErr    error
	skydb.Conn
}

func (conn *testRelationConn) GetUser(id string, userinfo *skydb.UserInfo) error {
	userinfo.ID = id
	userinfo.Username = "testRelationConn"
	return nil
}

type sortableUserInfo []skydb.UserInfo

func (a sortableUserInfo) Len() int           { return len(a) }
func (a sortableUserInfo) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a sortableUserInfo) Less(i, j int) bool { return a[i].ID < a[j].ID }

func (conn *testRelationConn) QueryRelation(user string, name string, direction string, config skydb.QueryConfig) []skydb.UserInfo {
	conn.RelationName = name
	if conn.UserInfo == nil {
		return []skydb.UserInfo{}
	}

	sort.Sort(sortableUserInfo(conn.UserInfo))
	if config.Limit == 0 {
		return conn.UserInfo[config.Offset:]
	}

	if config.Offset+config.Limit-1 > uint64(len(conn.UserInfo)) {
		return conn.UserInfo[config.Offset:]
	}
	return conn.UserInfo[config.Offset : config.Offset+config.Limit]
{'fraction_non_alphanumeric': 0.1269258987527513, 'fraction_numerical': 0.00293470286133529, 'mean_word_length': 4.1647727272727275, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7286003', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1007, 'n_words': 208}