<commit_before>package gorethink

import (
	test "launchpad.net/gocheck"
)

func (s *RethinkSuite) TestManipulationDocField(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1}).Do(Row.Field("a"))

	var response int
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, 1)
}

func (s *RethinkSuite) TestManipulationPluck(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1, "b": 2, "c": 3}).Pluck("a", "c")

	var response map[string]interface{}
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, map[string]interface{}{"a": 1, "c": 3})
}

func (s *RethinkSuite) TestManipulationWithout(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1, "b": 2, "c": 3}).Pluck("a", "c")

	var response map[string]interface{}
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, map[string]interface{}{"a": 1, "c": 3})
}

func (s *RethinkSuite) TestManipulationMerge(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1, "c": 3}).Merge(map[string]interface{}{"b": 2})

	var response map[string]interface{}
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, map[string]interface{}{"a": 1, "b": 2, "c": 3})
}

func (s *RethinkSuite) TestManipulationMergeLiteral(c *test.C) {
	query := Expr(map[string]interface{}{
		"a": map[string]interface{}{
			"aa": map[string]interface{}{
				"aaa": 1,
				"aab": 2,
			},
			"ab": map[string]interface{}{
				"aba": 3,
				"abb": 4,
			},
		},
	}).Merge(map[string]interface{}{"a": map[string]interface{}{"ab": Literal()}})

	var response map[string]interface{}
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, map[string]interface{}{"a": map[string]interface{}{"aa": map[string]interface{}{"aab": 2, "aaa": 1}}})
}

func (s *RethinkSuite) TestManipulationAppend(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).Append(4).Append(5)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 2, 3, 4, 5})
}

func (s *RethinkSuite) TestManipulationPrepend(c *test.C) {
	query := Expr([]interface{}{3, 4, 5}).Prepend(2).Prepend(1)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 2, 3, 4, 5})
}

func (s *RethinkSuite) TestManipulationDifference(c *test.C) {
	query := Expr([]interface{}{3, 4, 5}).Difference([]interface{}{3, 4})

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{5})
}

func (s *RethinkSuite) TestManipulationSetInsert(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).SetInsert(3).SetInsert(4)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 2, 3, 4})
}

func (s *RethinkSuite) TestManipulationSetUnion(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).SetUnion([]interface{}{3, 4})

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 2, 3, 4})
}

func (s *RethinkSuite) TestManipulationSetIntersection(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).SetIntersection([]interface{}{2, 3, 3, 4})

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{2, 3})
}

func (s *RethinkSuite) TestManipulationSetDifference(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).SetDifference([]interface{}{2, 3, 4, 4})

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1})
}

func (s *RethinkSuite) TestManipulationHasFieldsTrue(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1}).HasFields("a")

	var response bool
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, true)
}

func (s *RethinkSuite) TestManipulationHasFieldsNested(c *test.C) {
	query := Expr(map[string]interface{}{"a": map[string]interface{}{"b": 1}}).HasFields(map[string]interface{}{"a": map[string]interface{}{"b": true}})

	var response bool
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, true)
}

func (s *RethinkSuite) TestManipulationHasFieldsNestedShort(c *test.C) {
	query := Expr(map[string]interface{}{"a": map[string]interface{}{"b": 1}}).HasFields(map[string]interface{}{"a": "b"})

	var response bool
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, true)
}

func (s *RethinkSuite) TestManipulationHasFieldsFalse(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1}).HasFields("b")

	var response bool
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, false)
}

func (s *RethinkSuite) TestManipulationInsertAt(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).InsertAt(1, 1.5)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 1.5, 2, 3})
}

func (s *RethinkSuite) TestManipulationSpliceAt(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).SpliceAt(1, []interface{}{1.25, 1.5, 1.75})

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 1.25, 1.5, 1.75, 2, 3})
}

func (s *RethinkSuite) TestManipulationDeleteAt(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).DeleteAt(1)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 3})
}

func (s *RethinkSuite) TestManipulationDeleteAtRange(c *test.C) {
	query := Expr([]interface{}{1, 2, 3, 4}).DeleteAtRange(1, 3)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 4})
}

func (s *RethinkSuite) TestManipulationChangeAt(c *test.C) {
	query := Expr([]interface{}{1, 5, 3, 4}).ChangeAt(1, 2)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 2, 3, 4})
}

func (s *RethinkSuite) TestManipulationKeys(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1, "b": 2, "c": 3}).Keys()

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{"a", "b", "c"})
}

func (s *RethinkSuite) TestManipulationObject(c *test.C) {
	query := Object("a", 1, "b", 2)

	var response map[interface{}]interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, map[interface{}]interface{}{
		"a": 1,
		"b": 2,
	})
}<commit_msg>Fixed test<commit_after>package gorethink

import (
	test "launchpad.net/gocheck"
)

func (s *RethinkSuite) TestManipulationDocField(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1}).Do(Row.Field("a"))

	var response int
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, 1)
}

func (s *RethinkSuite) TestManipulationPluck(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1, "b": 2, "c": 3}).Pluck("a", "c")

	var response map[string]interface{}
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, map[string]interface{}{"a": 1, "c": 3})
}

func (s *RethinkSuite) TestManipulationWithout(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1, "b": 2, "c": 3}).Pluck("a", "c")

	var response map[string]interface{}
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, map[string]interface{}{"a": 1, "c": 3})
}

func (s *RethinkSuite) TestManipulationMerge(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1, "c": 3}).Merge(map[string]interface{}{"b": 2})

	var response map[string]interface{}
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, map[string]interface{}{"a": 1, "b": 2, "c": 3})
}

func (s *RethinkSuite) TestManipulationMergeLiteral(c *test.C) {
	query := Expr(map[string]interface{}{
		"a": map[string]interface{}{
			"aa": map[string]interface{}{
				"aaa": 1,
				"aab": 2,
			},
			"ab": map[string]interface{}{
				"aba": 3,
				"abb": 4,
			},
		},
	}).Merge(map[string]interface{}{"a": map[string]interface{}{"ab": Literal()}})

	var response map[string]interface{}
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, map[string]interface{}{"a": map[string]interface{}{"aa": map[string]interface{}{"aab": 2, "aaa": 1}}})
}

func (s *RethinkSuite) TestManipulationAppend(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).Append(4).Append(5)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 2, 3, 4, 5})
}

func (s *RethinkSuite) TestManipulationPrepend(c *test.C) {
	query := Expr([]interface{}{3, 4, 5}).Prepend(2).Prepend(1)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 2, 3, 4, 5})
}

func (s *RethinkSuite) TestManipulationDifference(c *test.C) {
	query := Expr([]interface{}{3, 4, 5}).Difference([]interface{}{3, 4})

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{5})
}

func (s *RethinkSuite) TestManipulationSetInsert(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).SetInsert(3).SetInsert(4)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 2, 3, 4})
}

func (s *RethinkSuite) TestManipulationSetUnion(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).SetUnion([]interface{}{3, 4})

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 2, 3, 4})
}

func (s *RethinkSuite) TestManipulationSetIntersection(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).SetIntersection([]interface{}{2, 3, 3, 4})

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{2, 3})
}

func (s *RethinkSuite) TestManipulationSetDifference(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).SetDifference([]interface{}{2, 3, 4, 4})

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1})
}

func (s *RethinkSuite) TestManipulationHasFieldsTrue(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1}).HasFields("a")

	var response bool
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, true)
}

func (s *RethinkSuite) TestManipulationHasFieldsNested(c *test.C) {
	query := Expr(map[string]interface{}{"a": map[string]interface{}{"b": 1}}).HasFields(map[string]interface{}{"a": map[string]interface{}{"b": true}})

	var response bool
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, true)
}

func (s *RethinkSuite) TestManipulationHasFieldsNestedShort(c *test.C) {
	query := Expr(map[string]interface{}{"a": map[string]interface{}{"b": 1}}).HasFields(map[string]interface{}{"a": "b"})

	var response bool
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, true)
}

func (s *RethinkSuite) TestManipulationHasFieldsFalse(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1}).HasFields("b")

	var response bool
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, false)
}

func (s *RethinkSuite) TestManipulationInsertAt(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).InsertAt(1, 1.5)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 1.5, 2, 3})
}

func (s *RethinkSuite) TestManipulationSpliceAt(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).SpliceAt(1, []interface{}{1.25, 1.5, 1.75})

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 1.25, 1.5, 1.75, 2, 3})
}

func (s *RethinkSuite) TestManipulationDeleteAt(c *test.C) {
	query := Expr([]interface{}{1, 2, 3}).DeleteAt(1)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 3})
}

func (s *RethinkSuite) TestManipulationDeleteAtRange(c *test.C) {
	query := Expr([]interface{}{1, 2, 3, 4}).DeleteAtRange(1, 3)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 4})
}

func (s *RethinkSuite) TestManipulationChangeAt(c *test.C) {
	query := Expr([]interface{}{1, 5, 3, 4}).ChangeAt(1, 2)

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{1, 2, 3, 4})
}

func (s *RethinkSuite) TestManipulationKeys(c *test.C) {
	query := Expr(map[string]interface{}{"a": 1, "b": 2, "c": 3}).Keys()

	var response []interface{}
	r, err := query.Run(sess)
	c.Assert(err, test.IsNil)

	err = r.ScanAll(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, []interface{}{"a", "b", "c"})
}

func (s *RethinkSuite) TestManipulationObject(c *test.C) {
	query := Object("a", 1, "b", 2)

	var response interface{}
	r, err := query.RunRow(sess)
	c.Assert(err, test.IsNil)

	err = r.Scan(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, JsonEquals, map[string]interface{}{
		"a": 1,
		"b": 2,
	})
}
{'fraction_non_alphanumeric': 0.20666666666666667, 'fraction_numerical': 0.019012345679012346, 'mean_word_length': 5.274593338497289, 'pattern_counts': {'":': 88, '<': 3, '<?xml version=': 0, '>': 3, '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': '893705', 'n_tokens_mistral': 6868, 'n_tokens_neox': 6450, 'n_words': 1305}