writer: Fix CaseStatment tests
Case statements cannot be used as regular statements. They must exist inside a switch. Change-Id: Ica2e0573ad926c3e257f02c95397a8666dfcd547 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57705 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com> Commit-Queue: James Price <jrprice@google.com> Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
8751227258
commit
3e27a20f31
|
@ -23,17 +23,15 @@ namespace {
|
|||
using HlslGeneratorImplTest_Case = TestHelper;
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
|
||||
auto* body = Block(create<ast::BreakStatement>());
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(Literal(5));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
WrapInFunction(c);
|
||||
auto* s = Switch(1, Case(Literal(5), Block(create<ast::BreakStatement>())),
|
||||
DefaultCase());
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
break;
|
||||
}
|
||||
|
@ -41,16 +39,14 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
|
|||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(Literal(5));
|
||||
auto* c = create<ast::CaseStatement>(lit, Block());
|
||||
WrapInFunction(c);
|
||||
auto* s = Switch(1, Case(Literal(5), Block()), DefaultCase());
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
break;
|
||||
}
|
||||
|
@ -58,17 +54,16 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
|
|||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
|
||||
auto* body = Block(create<ast::FallthroughStatement>());
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(Literal(5));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
WrapInFunction(c);
|
||||
auto* s =
|
||||
Switch(1, Case(Literal(5), Block(create<ast::FallthroughStatement>())),
|
||||
DefaultCase());
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
/* fallthrough */
|
||||
}
|
||||
|
@ -76,18 +71,16 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
|
|||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
|
||||
auto* body = Block(create<ast::BreakStatement>());
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(Literal(5));
|
||||
lit.push_back(Literal(6));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
WrapInFunction(c);
|
||||
auto* s = Switch(
|
||||
1, Case({Literal(5), Literal(6)}, Block(create<ast::BreakStatement>())),
|
||||
DefaultCase());
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5:
|
||||
case 6: {
|
||||
break;
|
||||
|
@ -96,15 +89,14 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
|
|||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) {
|
||||
auto* body = Block(create<ast::BreakStatement>());
|
||||
auto* c = create<ast::CaseStatement>(ast::CaseSelectorList{}, body);
|
||||
WrapInFunction(c);
|
||||
auto* s = Switch(1, DefaultCase(Block(create<ast::BreakStatement>())));
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( default: {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -23,17 +23,15 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Case) {
|
||||
auto* body = Block(create<ast::BreakStatement>());
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(Literal(5));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
WrapInFunction(c);
|
||||
auto* s = Switch(1, Case(Literal(5), Block(create<ast::BreakStatement>())),
|
||||
DefaultCase());
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
break;
|
||||
}
|
||||
|
@ -41,16 +39,14 @@ TEST_F(MslGeneratorImplTest, Emit_Case) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(Literal(5));
|
||||
auto* c = create<ast::CaseStatement>(lit, Block());
|
||||
WrapInFunction(c);
|
||||
auto* s = Switch(1, Case(Literal(5), Block()), DefaultCase());
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
break;
|
||||
}
|
||||
|
@ -58,17 +54,16 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
||||
auto* body = Block(create<ast::FallthroughStatement>());
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(Literal(5));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
WrapInFunction(c);
|
||||
auto* s =
|
||||
Switch(1, Case(Literal(5), Block(create<ast::FallthroughStatement>())),
|
||||
DefaultCase());
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
/* fallthrough */
|
||||
}
|
||||
|
@ -76,18 +71,16 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
||||
auto* body = Block(create<ast::BreakStatement>());
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(Literal(5));
|
||||
lit.push_back(Literal(6));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
WrapInFunction(c);
|
||||
auto* s = Switch(
|
||||
1, Case({Literal(5), Literal(6)}, Block(create<ast::BreakStatement>())),
|
||||
DefaultCase());
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5:
|
||||
case 6: {
|
||||
break;
|
||||
|
@ -96,15 +89,14 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Case_Default) {
|
||||
auto* body = Block(create<ast::BreakStatement>());
|
||||
auto* c = create<ast::CaseStatement>(ast::CaseSelectorList{}, body);
|
||||
WrapInFunction(c);
|
||||
auto* s = Switch(1, DefaultCase(Block(create<ast::BreakStatement>())));
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( default: {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -22,17 +22,15 @@ namespace {
|
|||
using WgslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Case) {
|
||||
auto* body = Block(create<ast::BreakStatement>());
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(Literal(5));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
WrapInFunction(c);
|
||||
auto* s = Switch(1, Case(Literal(5), Block(create<ast::BreakStatement>())),
|
||||
DefaultCase());
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
break;
|
||||
}
|
||||
|
@ -40,18 +38,16 @@ TEST_F(WgslGeneratorImplTest, Emit_Case) {
|
|||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
||||
auto* body = Block(create<ast::BreakStatement>());
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(Literal(5));
|
||||
lit.push_back(Literal(6));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
WrapInFunction(c);
|
||||
auto* s = Switch(
|
||||
1, Case({Literal(5), Literal(6)}, Block(create<ast::BreakStatement>())),
|
||||
DefaultCase());
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5, 6: {
|
||||
break;
|
||||
}
|
||||
|
@ -59,15 +55,14 @@ TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
|||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Case_Default) {
|
||||
auto* body = Block(create<ast::BreakStatement>());
|
||||
auto* c = create<ast::CaseStatement>(ast::CaseSelectorList{}, body);
|
||||
WrapInFunction(c);
|
||||
auto* s = Switch(1, DefaultCase(Block(create<ast::BreakStatement>())));
|
||||
WrapInFunction(s);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(s->body()[0])) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( default: {
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue