Re-land of skslc switch support
This reverts commit 7d975fc200bbbea991ec4c04c08f3a5ea7b847af.
BUG=skia:
Change-Id: I57521f7a291a35cfed58d623ea4f8da29582d2c5
Reviewed-on: https://skia-review.googlesource.com/8993
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/tests/SkSLErrorTest.cpp b/tests/SkSLErrorTest.cpp
index 301281c..bde5e70 100644
--- a/tests/SkSLErrorTest.cpp
+++ b/tests/SkSLErrorTest.cpp
@@ -337,6 +337,10 @@
test_failure(r,
"void main() { bool x; if (true && (false || x)) return; }",
"error: 1: 'x' has not been assigned\n1 error\n");
+ test_failure(r,
+ "void main() { int x; switch (3) { case 0: x = 0; case 1: x = 1; }"
+ "sk_FragColor = vec4(x); }",
+ "error: 1: 'x' has not been assigned\n1 error\n");
}
DEF_TEST(SkSLUnreachable, r) {
@@ -366,13 +370,16 @@
DEF_TEST(SkSLBreakOutsideLoop, r) {
test_failure(r,
"void foo() { while(true) {} if (true) break; }",
- "error: 1: break statement must be inside a loop\n1 error\n");
+ "error: 1: break statement must be inside a loop or switch\n1 error\n");
}
DEF_TEST(SkSLContinueOutsideLoop, r) {
test_failure(r,
"void foo() { for(;;); continue; }",
"error: 1: continue statement must be inside a loop\n1 error\n");
+ test_failure(r,
+ "void foo() { switch (1) { default: continue; } }",
+ "error: 1: continue statement must be inside a loop\n1 error\n");
}
DEF_TEST(SkSLStaticIfError, r) {
@@ -430,4 +437,25 @@
"error: 1: unknown identifier 'gl_FragColor'\n1 error\n");
}
+DEF_TEST(SkSLWrongSwitchTypes, r) {
+ test_failure(r,
+ "void main() { switch (vec2(1)) { case 1: break; } }",
+ "error: 1: expected 'int', but found 'vec2'\n1 error\n");
+ test_failure(r,
+ "void main() { switch (1) { case vec2(1): break; } }",
+ "error: 1: expected 'int', but found 'vec2'\n1 error\n");
+}
+
+DEF_TEST(SkSLNonConstantCase, r) {
+ test_failure(r,
+ "void main() { int x = 1; switch (1) { case x: break; } }",
+ "error: 1: case value must be a constant\n1 error\n");
+}
+
+DEF_TEST(SkSLDuplicateCase, r) {
+ test_failure(r,
+ "void main() { switch (1) { case 0: case 1: case 0: break; } }",
+ "error: 1: duplicate case value\n1 error\n");
+}
+
#endif