Skip to content

Commit

Permalink
add non ascii characters to the random generated strings
Browse files Browse the repository at this point in the history
  • Loading branch information
adamluzsi committed Apr 9, 2022
1 parent 181e738 commit d2f4847
Show file tree
Hide file tree
Showing 7 changed files with 843 additions and 25 deletions.
14 changes: 6 additions & 8 deletions docs/examples/immutableAct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/adamluzsi/testcase"
"github.com/adamluzsi/testcase/assert"
"github.com/adamluzsi/testcase/docs/examples"
"github.com/adamluzsi/testcase/fixtures"
)
Expand All @@ -20,28 +19,27 @@ func TestImmutableAct(t *testing.T) {
s.Describe(`#Shrug`, func(s *testcase.Spec) {
const shrugEmoji = `¯\_(ツ)_/¯`
var (
message = testcase.LetValue(s, fixtures.Random.String())
messageGet = func(t *testcase.T) string { return message.Get(t) }
subject = func(t *testcase.T) string {
return myStruct.Get(t).Shrug(messageGet(t))
message = testcase.Let(s, func(t *testcase.T) string { return t.Random.String() })
subject = func(t *testcase.T) string {
return myStruct.Get(t).Shrug(message.Get(t))
}
)

s.When(`message doesn't have shrug in the ending`, func(s *testcase.Spec) {
s.Before(func(t *testcase.T) {
assert.Must(t).True(!strings.HasSuffix(messageGet(t), shrugEmoji))
t.Must.Contain(subject(t), shrugEmoji)
})

s.Then(`it will append shrug emoji to this`, func(t *testcase.T) {
assert.Must(t).Equal(messageGet(t)+` `+shrugEmoji, subject(t))
t.Must.True(strings.HasSuffix(subject(t), shrugEmoji))
})
})

s.When(`shrug part of the input message`, func(s *testcase.Spec) {
message.LetValue(s, fixtures.Random.String()+shrugEmoji)

s.Then(`it will not append any more shrug emoji to the end of the message`, func(t *testcase.T) {
assert.Must(t).Equal(messageGet(t), subject(t))
t.Must.Equal(message.Get(t), subject(t))
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestEnvVarHelpers(t *testing.T) {
return &internal.RecorderTB{TB: &internal.StubTB{}}
})
tbCleanupNow = func(t *testcase.T) { recTB.Get(t).CleanupNow() }
key = testcase.LetValue(s, `TESTING_DATA_`+fixtures.Random.String())
key = testcase.LetValue(s, `TESTING_DATA_`+fixtures.Random.StringNWithCharset(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
value = testcase.LetValue(s, fixtures.Random.String())
subject = func(t *testcase.T) {
testcase.SetEnv(recTB.Get(t), key.Get(t), value.Get(t))
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestEnvVarHelpers(t *testing.T) {
var (
recTB = testcase.Let(s, func(t *testcase.T) *internal.RecorderTB { return &internal.RecorderTB{} })
tbCleanupNow = func(t *testcase.T) { recTB.Get(t).CleanupNow() }
key = testcase.LetValue(s, `TESTING_DATA_`+fixtures.Random.String())
key = testcase.LetValue(s, `TESTING_DATA_`+fixtures.Random.StringNWithCharset(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
subject = func(t *testcase.T) {
testcase.UnsetEnv(recTB.Get(t), key.Get(t))
}
Expand Down
9 changes: 5 additions & 4 deletions let_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ import (
"testing"

"github.com/adamluzsi/testcase"
"github.com/adamluzsi/testcase/fixtures"
)

func TestLetandLetValue_returnsVar(t *testing.T) {
s := testcase.NewSpec(t)
v1 := testcase.Let(s, func(t *testcase.T) string {
return t.Random.String()
return t.Random.StringN(5)
})

s.Context(``, func(s *testcase.Spec) {
v2 := testcase.LetValue(s, fixtures.Random.String())
v2 := testcase.Let(s, func(t *testcase.T) string {
return t.Random.StringN(6)
})

s.Test(``, func(t *testcase.T) {
t.Must.NotEqual(v1.ID, v2.ID)
t.Must.NotEmpty(v1.Get(t))
t.Must.NotEmpty(v2.Get(t))
t.Must.Equal(v1.Get(t), v1.Get(t), "getting the same testcase.Var value must always yield the same result")
t.Must.NotEqual(v1.Get(t), v2.Get(t))
t.Must.Equal(v1.Get(t), v1.Get(t))
})
})

Expand Down
Loading

0 comments on commit d2f4847

Please sign in to comment.