<commit_before>package main

import (
	"fmt"
	"github.com/stretchr/testify/assert"
	"io/ioutil"
	"os"
	"testing"
)

var testText = `{{env "USER"}}
{{env "EMPTY_VALUE_FOR_TEST" "default"}}
{{ipv4 "127.0"}}
`

func TestExecute(t *testing.T) {
	// Create a temporary file and write test data
	f, err := ioutil.TempFile("", "pave-test-")
	assert.Nil(t, err)
	defer os.Remove(f.Name())

	f.Write([]byte(testText))
	f.Close()

	tmpl := NewTemplate(f.Name())
	tmpl.Execute()
	defer os.Remove(tmpl.Src)

	b, err := ioutil.ReadFile(tmpl.Src)
	assert.Nil(t, err)
	assert.Equal(t, testText, string(b))

	expect := fmt.Sprintf("%s\ndefault\n127.0.0.1\n", os.Getenv("USER"))
	b, err = ioutil.ReadFile(f.Name())
	assert.Nil(t, err)
	assert.Equal(t, expect, string(b))
}<commit_msg>add a test for an IP address<commit_after>package main

import (
	"bytes"
	"fmt"
	"github.com/stretchr/testify/assert"
	"io/ioutil"
	"net"
	"os"
	"testing"
)

var testText = `{{env "USER"}}
{{env "EMPTY_VALUE_FOR_TEST" "default"}}
{{ipv4 "127.0"}}
`

func TestExecute(t *testing.T) {
	// Create a temporary file and write test data
	f, err := ioutil.TempFile("", "pave-test-")
	assert.Nil(t, err)
	defer os.Remove(f.Name())

	f.Write([]byte(testText))
	f.Close()

	tmpl := NewTemplate(f.Name())
	tmpl.Execute()
	defer os.Remove(tmpl.Src)

	b, err := ioutil.ReadFile(tmpl.Src)
	assert.Nil(t, err)
	assert.Equal(t, testText, string(b))

	expect := fmt.Sprintf("%s\ndefault\n127.0.0.1\n", os.Getenv("USER"))
	b, err = ioutil.ReadFile(f.Name())
	assert.Nil(t, err)
	assert.Equal(t, expect, string(b))
}

func TestIP(t *testing.T) {
	nics, err := net.Interfaces()
	assert.Nil(t, err)
	assert.True(t, len(nics) > 0)

	var ipv4, ipv6 []string
	addrs, err := nics[0].Addrs()
	assert.Nil(t, err)
	for _, addr := range addrs {
		ip, _, err := net.ParseCIDR(addr.String())
		assert.Nil(t, err)
		if ip.To4() != nil {
			ipv4 = append(ipv4, ip.String())
		} else {
			ipv6 = append(ipv6, ip.String())
		}
	}
	ipv4, ipv6 = append(ipv4, ""), append(ipv6, "")

	w := new(bytes.Buffer)
	ifname := nics[0].Name
	tmpl := NewTemplate("")
	tmpl.parse(fmt.Sprintf(`{{ipv4 "%s"}}, {{ipv6 "%s"}}`, ifname, ifname))
	tmpl.tmpl.Execute(w, "")
	assert.Equal(t, fmt.Sprintf("%s, %s", ipv4[0], ipv6[0]), w.String())
}
{'fraction_non_alphanumeric': 0.212322695035461, 'fraction_numerical': 0.018617021276595744, 'mean_word_length': 4.261072261072261, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5348831', 'n_tokens_mistral': 1007, 'n_tokens_neox': 992, 'n_words': 194}