package password

import (
	"math/rand"
	"testing"

	uuid "github.com/satori/go.uuid"
	. "github.com/smartystreets/goconvey/convey"
)

func randomString(n int) string {
	var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

	s := make([]rune, n)
	for i := range s {
		s[i] = letters[rand.Intn(len(letters))]
	}
	return string(s)
}

func TestDecorate(t *testing.T) {
	Convey("TestDecorate", t, func() {
		cases := []string{
			"",
			"@simple-decoration-test@",
		}
		for i := 0; i < 100; i++ {
			cases = append(cases, uuid.NewV4().String())
			cases = append(cases, randomString(rand.Intn(100)))
		}
		for _, clear := range cases {
			decorated := Decorate(clear)
			recovered, err := ReverseDecorate(decorated)
			So(err, ShouldBeNil)
			So(clear, ShouldEqual, recovered)
		}
	})
}
