Skip to content

Commit

Permalink
#234 Move test cases to correct place.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzhang6222 committed May 12, 2020
1 parent 53cd164 commit cedb62b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
43 changes: 43 additions & 0 deletions syntax/std_seq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,46 @@ func TestSeqRepeat(t *testing.T) {
func TestSeqContains(t *testing.T) {
t.Parallel()
}

///////////////////
func TestStrSub(t *testing.T) {
t.Parallel()
AssertCodesEvalToSameValue(t,
`"this is a test"`,
`//str.sub("this is not a test", "is not", "is")`)
AssertCodesEvalToSameValue(t,
`"this is a test"`,
`//str.sub("this is not a test", "not ", "")`)
AssertCodesEvalToSameValue(t,
`"this is still a test"`,
`//str.sub("this is still a test", "doesn't matter", "hello there")`)
assertExprPanics(t, `//str.sub("hello there", "test", 1)`)
}

func TestStrSplit(t *testing.T) {
t.Parallel()
AssertCodesEvalToSameValue(t,
`["t", "h", "i", "s", " ", "i", "s", " ", "a", " ", "t", "e", "s", "t"]`,
`//str.split("this is a test", "")`)
AssertCodesEvalToSameValue(t, `["this", "is", "a", "test"]`, `//str.split("this is a test", " ") `)
AssertCodesEvalToSameValue(t, `["this is a test"] `, `//str.split("this is a test", ",") `)
AssertCodesEvalToSameValue(t, `["th", " ", " a test"] `, `//str.split("this is a test", "is")`)
assertExprPanics(t, `//str.split("this is a test", 1)`)
}

func TestStrContains(t *testing.T) {
t.Parallel()
AssertCodesEvalToSameValue(t, `true `, `//str.contains("this is a test", "") `)
AssertCodesEvalToSameValue(t, `true `, `//str.contains("this is a test", "is a test") `)
AssertCodesEvalToSameValue(t, `false`, `//str.contains("this is a test", "is not a test")`)
assertExprPanics(t, `//str.contains(123, 124)`)
}

func TestStrJoin(t *testing.T) {
t.Parallel()
AssertCodesEvalToSameValue(t, `"" `, `//str.join([], ",") `)
AssertCodesEvalToSameValue(t, `",," `, `//str.join(["", "", ""], ",") `)
AssertCodesEvalToSameValue(t, `"this is a test" `, `//str.join(["this", "is", "a", "test"], " ")`)
AssertCodesEvalToSameValue(t, `"this" `, `//str.join(["this"], ",") `)
assertExprPanics(t, `//str.join("this", 2)`)
}
42 changes: 0 additions & 42 deletions syntax/std_str_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,6 @@ import (
"github.com/stretchr/testify/assert"
)

func TestStrSub(t *testing.T) {
t.Parallel()
AssertCodesEvalToSameValue(t,
`"this is a test"`,
`//str.sub("this is not a test", "is not", "is")`)
AssertCodesEvalToSameValue(t,
`"this is a test"`,
`//str.sub("this is not a test", "not ", "")`)
AssertCodesEvalToSameValue(t,
`"this is still a test"`,
`//str.sub("this is still a test", "doesn't matter", "hello there")`)
assertExprPanics(t, `//str.sub("hello there", "test", 1)`)
}

func TestStrSplit(t *testing.T) {
t.Parallel()
AssertCodesEvalToSameValue(t,
`["t", "h", "i", "s", " ", "i", "s", " ", "a", " ", "t", "e", "s", "t"]`,
`//str.split("this is a test", "")`)
AssertCodesEvalToSameValue(t, `["this", "is", "a", "test"]`, `//str.split("this is a test", " ") `)
AssertCodesEvalToSameValue(t, `["this is a test"] `, `//str.split("this is a test", ",") `)
AssertCodesEvalToSameValue(t, `["th", " ", " a test"] `, `//str.split("this is a test", "is")`)
assertExprPanics(t, `//str.split("this is a test", 1)`)
}

func TestStrLower(t *testing.T) {
t.Parallel()
AssertCodesEvalToSameValue(t, `"" `, `//str.lower("") `)
Expand Down Expand Up @@ -58,23 +33,6 @@ func TestStrTitle(t *testing.T) {
assertExprPanics(t, `//str.title(123)`)
}

func TestStrContains(t *testing.T) {
t.Parallel()
AssertCodesEvalToSameValue(t, `true `, `//str.contains("this is a test", "") `)
AssertCodesEvalToSameValue(t, `true `, `//str.contains("this is a test", "is a test") `)
AssertCodesEvalToSameValue(t, `false`, `//str.contains("this is a test", "is not a test")`)
assertExprPanics(t, `//str.contains(123, 124)`)
}

func TestStrJoin(t *testing.T) {
t.Parallel()
AssertCodesEvalToSameValue(t, `"" `, `//str.join([], ",") `)
AssertCodesEvalToSameValue(t, `",," `, `//str.join(["", "", ""], ",") `)
AssertCodesEvalToSameValue(t, `"this is a test" `, `//str.join(["this", "is", "a", "test"], " ")`)
AssertCodesEvalToSameValue(t, `"this" `, `//str.join(["this"], ",") `)
assertExprPanics(t, `//str.join("this", 2)`)
}

func assertExprPanics(t *testing.T, code string) {
assert.Panics(t, func() { AssertCodesEvalToSameValue(t, `"doesn't matter"`, code) })
}

0 comments on commit cedb62b

Please sign in to comment.