<commit_before>package shape

import (
	"os"
	"strings"
	"testing"

	"github.com/codingconcepts/shape/test"
)

func TestEnvBool(t *testing.T) {
	os.Setenv("PROP", "true")

	config := struct {
		Prop bool `env:"PROP"`
	}{}

	test.ErrorNil(t, Env(&config))
	test.Equals(t, true, config.Prop)
}

func TestEnvIntegers(t *testing.T) {
	os.Setenv("PROP", "123")

	config := struct {
		PropInt   int   `env:"PROP"`
		PropInt8  int8  `env:"PROP"`
		PropInt16 int16 `env:"PROP"`
		PropInt32 int32 `env:"PROP"`
		PropInt64 int64 `env:"PROP"`
	}{}

	test.ErrorNil(t, Env(&config))
	test.Equals(t, int(123), config.PropInt)
	test.Equals(t, int8(123), config.PropInt8)
	test.Equals(t, int16(123), config.PropInt16)
	test.Equals(t, int32(123), config.PropInt32)
	test.Equals(t, int64(123), config.PropInt64)
}

func TestEnvUnsignedIntegers(t *testing.T) {
	os.Setenv("PROP", "123")

	config := struct {
		PropUint   uint   `env:"PROP"`
		PropUint8  uint8  `env:"PROP"`
		PropUint16 uint16 `env:"PROP"`
		PropUint32 uint32 `env:"PROP"`
		PropUint64 uint64 `env:"PROP"`
	}{}

	test.ErrorNil(t, Env(&config))
	test.Equals(t, uint(123), config.PropUint)
	test.Equals(t, uint8(123), config.PropUint8)
	test.Equals(t, uint16(123), config.PropUint16)
	test.Equals(t, uint32(123), config.PropUint32)
	test.Equals(t, uint64(123), config.PropUint64)
}

func TestEnvFloats(t *testing.T) {
	os.Setenv("PROP", "1.23")

	config := struct {
		PropFloat32 float32 `env:"PROP"`
		PropFloat64 float64 `env:"PROP"`
	}{}

	test.ErrorNil(t, Env(&config))
	test.Equals(t, float32(1.23), config.PropFloat32)
	test.Equals(t, float64(1.23), config.PropFloat64)
}

func TestEnvString(t *testing.T) {
	os.Setenv("PROP", "}D-Z2P£T!E*#zE=.gc@")

	config := struct {
		Prop string `env:"PROP"`
	}{}

	test.ErrorNil(t, Env(&config))
	test.Equals(t, "}D-Z2P£T!E*#zE=.gc@", config.Prop)
}

func TestEnvSetUnexportedRequiredProperty(t *testing.T) {
	os.Setenv("PROP", "hello")
<commit_msg>Fixed bad name for test method<commit_after>package shape

import (
	"os"
	"strings"
	"testing"

	"github.com/codingconcepts/shape/test"
)

func TestEnvBool(t *testing.T) {
	os.Setenv("PROP", "true")

	config := struct {
		Prop bool `env:"PROP"`
	}{}

	test.ErrorNil(t, Env(&config))
	test.Equals(t, true, config.Prop)
}

func TestEnvIntegers(t *testing.T) {
	os.Setenv("PROP", "123")

	config := struct {
		PropInt   int   `env:"PROP"`
		PropInt8  int8  `env:"PROP"`
		PropInt16 int16 `env:"PROP"`
		PropInt32 int32 `env:"PROP"`
		PropInt64 int64 `env:"PROP"`
	}{}

	test.ErrorNil(t, Env(&config))
	test.Equals(t, int(123), config.PropInt)
	test.Equals(t, int8(123), config.PropInt8)
	test.Equals(t, int16(123), config.PropInt16)
	test.Equals(t, int32(123), config.PropInt32)
	test.Equals(t, int64(123), config.PropInt64)
}

func TestEnvUnsignedIntegers(t *testing.T) {
	os.Setenv("PROP", "123")

	config := struct {
		PropUint   uint   `env:"PROP"`
		PropUint8  uint8  `env:"PROP"`
		PropUint16 uint16 `env:"PROP"`
		PropUint32 uint32 `env:"PROP"`
		PropUint64 uint64 `env:"PROP"`
	}{}

	test.ErrorNil(t, Env(&config))
	test.Equals(t, uint(123), config.PropUint)
	test.Equals(t, uint8(123), config.PropUint8)
	test.Equals(t, uint16(123), config.PropUint16)
	test.Equals(t, uint32(123), config.PropUint32)
	test.Equals(t, uint64(123), config.PropUint64)
}

func TestEnvFloats(t *testing.T) {
	os.Setenv("PROP", "1.23")

	config := struct {
		PropFloat32 float32 `env:"PROP"`
		PropFloat64 float64 `env:"PROP"`
	}{}

	test.ErrorNil(t, Env(&config))
	test.Equals(t, float32(1.23), config.PropFloat32)
	test.Equals(t, float64(1.23), config.PropFloat64)
}

func TestEnvString(t *testing.T) {
	os.Setenv("PROP", "}D-Z2P£T!E*#zE=.gc@")

	config := struct {
		Prop string `env:"PROP"`
	}{}

	test.ErrorNil(t, Env(&config))
	test.Equals(t, "}D-Z2P£T!E*#zE=.gc@", config.Prop)
}

func TestEnvSetUnexportedProperty(t *testing.T) {
	os.Setenv("PROP", "hello")

{'fraction_non_alphanumeric': 0.18812644564379338, 'fraction_numerical': 0.06116679516833719, 'mean_word_length': 4.987692307692308, 'pattern_counts': {'":': 0, '<': 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': '2916607', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1596, 'n_words': 287}