From 89b2aa1207169853f83c8c507c3a521e49080926 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 10 Mar 2020 19:18:29 +0000 Subject: [PATCH] Extend entry point to str testing This CL adds more tests for the entry point to str method. Bug: tint:11 Change-Id: I54bb349d606d05221d649215b7b2c6477cca6819 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/16480 Reviewed-by: David Neto --- src/ast/entry_point.cc | 7 +++++-- src/ast/entry_point_test.cc | 26 +++++++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/ast/entry_point.cc b/src/ast/entry_point.cc index a433be1e6a..69a449395e 100644 --- a/src/ast/entry_point.cc +++ b/src/ast/entry_point.cc @@ -42,8 +42,11 @@ bool EntryPoint::IsValid() const { void EntryPoint::to_str(std::ostream& out, size_t indent) const { make_indent(out, indent); - out << R"(EntryPoint{")" << stage_ << R"(" as ")" << name_ << R"(" = )" - << fn_name_ << "}" << std::endl; + out << "EntryPoint{" << stage_; + if (name_.length() > 0) + out << " as " << name_; + + out << " = " << fn_name_ << "}" << std::endl; } } // namespace ast diff --git a/src/ast/entry_point_test.cc b/src/ast/entry_point_test.cc index 57659248f9..3d8a1b555b 100644 --- a/src/ast/entry_point_test.cc +++ b/src/ast/entry_point_test.cc @@ -59,16 +59,8 @@ TEST_F(EntryPointTest, CreationEmpty) { EXPECT_EQ(e.column(), 4); } -TEST_F(EntryPointTest, to_str) { - EntryPoint e(PipelineStage::kVertex, "text", "vtx_main"); - std::ostringstream out; - e.to_str(out, 0); - EXPECT_EQ(out.str(), R"(EntryPoint{"vertex" as "text" = vtx_main} -)"); -} - TEST_F(EntryPointTest, IsValid) { - EntryPoint e(PipelineStage::kVertex, "main", "vtx_main"); + EntryPoint e(PipelineStage::kVertex, "", "vtx_main"); EXPECT_TRUE(e.IsValid()); } @@ -87,5 +79,21 @@ TEST_F(EntryPointTest, IsValid_MissingBoth) { EXPECT_FALSE(e.IsValid()); } +TEST_F(EntryPointTest, ToStr) { + EntryPoint e(PipelineStage::kVertex, "text", "vtx_main"); + std::ostringstream out; + e.to_str(out, 2); + EXPECT_EQ(out.str(), R"( EntryPoint{vertex as text = vtx_main} +)"); +} + +TEST_F(EntryPointTest, ToStr_NoName) { + EntryPoint e(PipelineStage::kVertex, "", "vtx_main"); + std::ostringstream out; + e.to_str(out, 2); + EXPECT_EQ(out.str(), R"( EntryPoint{vertex = vtx_main} +)"); +} + } // namespace ast } // namespace tint