<commit_before>// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.

package resmap_test

import (
	"testing"

	"sigs.k8s.io/kustomize/api/resid"
	. "sigs.k8s.io/kustomize/api/resmap"
	"sigs.k8s.io/kustomize/api/types"
)

func setupRMForPatchTargets(t *testing.T) ResMap {
	result, err := rmF.NewResMapFromBytes([]byte(`
apiVersion: group1/v1
kind: Kind1
metadata:
  name: name1
  namespace: ns1
  labels:
    app: name1
  annotations:
    foo: bar
---
apiVersion: group1/v1
kind: Kind1
metadata:
  name: name2
  namespace: default
  labels:
    app: name2
  annotations:
    foo: bar
---
apiVersion: group1/v1
kind: Kind2
metadata:
  name: name3
  labels:
    app: name3
  annotations:
    bar: baz
---
apiVersion: group1/v1
kind: Kind2
metadata:
  name: x-name1
  namespace: x-default
`))
	if err != nil {
		t.Fatalf("unexpected error %v", err)
	}
	return result
}

func TestFindPatchTargets(t *testing.T) {
	rm := setupRMForPatchTargets(t)
	testcases := []struct {
		target types.Selector
		count  int
	}{
		{
			target: types.Selector{
				Name: "name.*",
			},
			count: 3,
		},
		{
			target: types.Selector{
				Name:               "name.*",
				AnnotationSelector: "foo=bar",
			},
			count: 2,
		},
		{
			target: types.Selector{
				LabelSelector: "app=name1",
			},
			count: 1,
		},
		{
			target: types.Selector{
				Gvk: resid.Gvk{
					Kind: "Kind1",
				},
				Name: "name.*",
			},
			count: 2,
		},
		{
			target: types.Selector{
				Name: "NotMatched",
			},
			count: 0,
		},
		{
			target: types.Selector{
				Name: "",
			},
			count: 4,
		},
		{
			target: types.Selector{
				Namespace: "default",
			},
			count: 2,
		},
		{
			target: types.Selector{
				Namespace: "",
			},
			count: 4,
		},
		{
			target: types.Selector{
				Namespace: "default",
				Name:      "name.*",
				Gvk: resid.Gvk{
					Kind: "Kind1",
				},
			},
			count: 1,
		},
		{
			target: types.Selector{
				Name: "^name.*",
			},
			count: 3,
		},
		{
			target: types.Selector{
				Name: "name.*$",
			},
			count: 3,
		},
		{
			target: types.Selector{
				Name: "^name.*$",
			},
			count: 3,
		},
		{
			target: types.Selector{
				Namespace: "^def.*",
			},
			count: 2,
		},
		{
			target: types.Selector{
				Namespace: "def.*$",
			},
			count: 2,
		},
		{
			target: types.Selector{
				Namespace: "^def.*$",
			},
			count: 2,
		},
		{
			target: types.Selector{
				Namespace: "default",
			},
			count: 2,
		},
		{
			target: types.Selector{
				Namespace: "NotMatched",
			},
			count: 0,
		},
		{
			target: types.Selector{
				Namespace: "ns1",
			},
			count: 1,
		},
	}
	for _, testcase := range testcases {
		actual, err := rm.Select(testcase.target)
		if err != nil {
			t.Errorf("unexpected error %v", err)
		}
		if len(actual) != testcase.count {
			t.Errorf("expected %d objects, but got %d:\n%v", testcase.count, len(actual), actual)
		}
	}

}<commit_msg>Clean up selector test.<commit_after>// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.

package resmap_test

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"sigs.k8s.io/kustomize/api/resid"
	. "sigs.k8s.io/kustomize/api/resmap"
	"sigs.k8s.io/kustomize/api/types"
)

func setupRMForPatchTargets(t *testing.T) ResMap {
	result, err := rmF.NewResMapFromBytes([]byte(`
apiVersion: group1/v1
kind: Kind1
metadata:
  name: name1
  namespace: ns1
  labels:
    app: name1
  annotations:
    foo: bar
---
apiVersion: group1/v1
kind: Kind1
metadata:
  name: name2
  namespace: default
  labels:
    app: name2
  annotations:
    foo: bar
---
apiVersion: group1/v1
kind: Kind2
metadata:
  name: name3
  labels:
    app: name3
  annotations:
    bar: baz
---
apiVersion: group1/v1
kind: Kind2
metadata:
  name: x-name1
  namespace: x-default
`))
	assert.NoError(t, err)
	return result
}

func TestFindPatchTargets(t *testing.T) {
	rm := setupRMForPatchTargets(t)
	testcases := map[string]struct {
		target types.Selector
		count  int
	}{
		"select_01": {
			target: types.Selector{
				Name: "name.*",
			},
			count: 3,
		},
		"select_02": {
			target: types.Selector{
				Name:               "name.*",
				AnnotationSelector: "foo=bar",
			},
			count: 2,
		},
		"select_03": {
			target: types.Selector{
				LabelSelector: "app=name1",
			},
			count: 1,
		},
		"select_04": {
			target: types.Selector{
				Gvk: resid.Gvk{
					Kind: "Kind1",
				},
				Name: "name.*",
			},
			count: 2,
		},
		"select_05": {
			target: types.Selector{
				Name: "NotMatched",
			},
			count: 0,
		},
		"select_06": {
			target: types.Selector{
				Name: "",
			},
			count: 4,
		},
		"select_07": {
			target: types.Selector{
				Namespace: "default",
			},
			count: 2,
		},
		"select_08": {
			target: types.Selector{
				Namespace: "",
			},
			count: 4,
		},
		"select_09": {
			target: types.Selector{
				Namespace: "default",
				Name:      "name.*",
				Gvk: resid.Gvk{
					Kind: "Kind1",
				},
			},
			count: 1,
		},
		"select_10": {
			target: types.Selector{
				Name: "^name.*",
			},
			count: 3,
		},
		"select_11": {
			target: types.Selector{
				Name: "name.*$",
			},
			count: 3,
		},
		"select_12": {
			target: types.Selector{
				Name: "^name.*$",
			},
			count: 3,
		},
		"select_13": {
			target: types.Selector{
				Namespace: "^def.*",
			},
			count: 2,
		},
		"select_14": {
			target: types.Selector{
				Namespace: "def.*$",
			},
			count: 2,
		},
		"select_15": {
			target: types.Selector{
				Namespace: "^def.*$",
			},
			count: 2,
		},
		"select_16": {
			target: types.Selector{
				Namespace: "default",
			},
			count: 2,
		},
		"select_17": {
			target: types.Selector{
				Namespace: "NotMatched",
			},
			count: 0,
		},
		"select_18": {
			target: types.Selector{
				Namespace: "ns1",
			},
			count: 1,
		},
	}
	for n, testcase := range testcases {
		actual, err := rm.Select(testcase.target)
		assert.NoError(t, err)
		assert.Equalf(
			t, testcase.count, len(actual), "test=%s target=%v", n, testcase.target)
	}
}
{'fraction_non_alphanumeric': 0.16969798097780744, 'fraction_numerical': 0.02269314199899883, 'mean_word_length': 2.493006993006993, 'pattern_counts': {'":': 18, '<': 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': '4908929', 'n_tokens_mistral': 2891, 'n_tokens_neox': 2334, 'n_words': 485}