Skip to content

Commit edcddc1

Browse files
committed
Add tests (#41)
1 parent beda713 commit edcddc1

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

tests/const.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,38 @@ func testDefineConstantsInFunctionSuccess(t *testing.T, transpilerFunc transpile
3737
})
3838
}
3939

40+
func testDefineConstantsGroupedSuccess(t *testing.T, transpilerFunc transpilerFunc) {
41+
transpilerFunc(t, `
42+
const (
43+
a = 0
44+
b, c = 1, 2
45+
d = iota
46+
e = 4
47+
f
48+
g, h = iota, iota
49+
)
50+
51+
print(a, b, c, d, e, f, g, h)
52+
`, func(output string, err error) {
53+
require.Nil(t, err)
54+
require.Equal(t, "0 1 2 3 4 5 6 7", output)
55+
})
56+
}
57+
58+
func testDefineConstantsMissingValueFail(t *testing.T, transpilerFunc transpilerFunc) {
59+
transpilerFunc(t, `
60+
const (
61+
a = 0
62+
b, c = 1, 2
63+
d
64+
e = 4
65+
f, g = iota, iota
66+
)
67+
`, func(output string, err error) {
68+
require.EqualError(t, shortenError(err), "expected data type or value assignment")
69+
})
70+
}
71+
4072
func testDefineSameConstantFail(t *testing.T, transpilerFunc transpilerFunc) {
4173
transpilerFunc(t, `
4274
const a = 1

tests/const_linux_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ func TestDefineConstantsInFunctionSuccess(t *testing.T) {
1212
testDefineConstantsInFunctionSuccess(t, transpileBash)
1313
}
1414

15+
func TestDefineConstantsGroupedSuccess(t *testing.T) {
16+
testDefineConstantsGroupedSuccess(t, transpileBash)
17+
}
18+
19+
func TestDefineConstantsMissingValueFail(t *testing.T) {
20+
testDefineConstantsMissingValueFail(t, transpileBash)
21+
}
22+
1523
func TestDefineSameConstantFail(t *testing.T) {
1624
testDefineSameConstantFail(t, transpileBash)
1725
}

tests/const_windows_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ func TestDefineConstantsInFunctionSuccess(t *testing.T) {
1212
testDefineConstantsInFunctionSuccess(t, transpileBatch)
1313
}
1414

15+
func TestDefineConstantsGroupedSuccess(t *testing.T) {
16+
testDefineConstantsGroupedSuccess(t, transpileBatch)
17+
}
18+
19+
func TestDefineConstantsMissingValueFail(t *testing.T) {
20+
testDefineConstantsMissingValueFail(t, transpileBatch)
21+
}
22+
1523
func TestDefineSameConstantFail(t *testing.T) {
1624
testDefineSameConstantFail(t, transpileBatch)
1725
}

0 commit comments

Comments
 (0)