<commit_before>// Copyright (c) 2014 Dataence, LLC. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package xtld

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestXtldTldlen(t *testing.T) {
	var testdata map[string]string = map[string]string{
		"abc.com":       "com",
		"www.abc.com":   "com",
		"中国":            "中国",
		"england.co.uk": "co.uk",
		"xxxxx":         "",
	}

	for k, v := range testdata {
		require.Equal(t, TLDlen(k), len(v))
		require.Equal(t, TLD(k), v)
	}
}

func BenchmarkXtldTldLen(b *testing.B) {
	//ss := "england.co.uk"
	ss := "中国"
	for i := 0; i < b.N; i++ {
		TLDlen(ss)
	}
}<commit_msg>added golang/x/net/publicsuffix.PublicSuffix benchmark<commit_after>// Copyright (c) 2014 Dataence, LLC. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package xtld

import (
	"testing"

	"github.com/stretchr/testify/require"
	"golang.org/x/net/publicsuffix"
)

func TestXtldTldlen(t *testing.T) {
	testdata := map[string]string{
		"abc.com":       "com",
		"www.abc.com":   "com",
		"中国":            "中国",
		"england.co.uk": "co.uk",
		"xxxxx":         "",
	}

	for k, v := range testdata {
		sfx := TLD(k)
		require.Equal(t, sfx, v)
		require.Equal(t, len(sfx), len(v))

		// PublicSuffix fails for "xxxxx"
		//psfx, _ := publicsuffix.PublicSuffix(k)
		//require.Equal(t, sfx, psfx)
	}
}

func BenchmarkXtldTldLen(b *testing.B) {
	//ss := "england.co.uk"
	ss := "中国"
	for i := 0; i < b.N; i++ {
		TLDlen(ss)
	}
}

func BenchmarkXtldTld(b *testing.B) {
	//ss := "england.co.uk"
	ss := "中国"
	for i := 0; i < b.N; i++ {
		TLD(ss)
	}
}

func BenchmarkPublicsuffix(b *testing.B) {
	ss := "中国"
	for i := 0; i < b.N; i++ {
		publicsuffix.PublicSuffix(ss)
	}
}
{'fraction_non_alphanumeric': 0.15203193033381712, 'fraction_numerical': 0.00725689404934688, 'mean_word_length': 3.0905044510385755, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4694117', 'n_tokens_mistral': 1050, 'n_tokens_neox': 998, 'n_words': 304}