From 54b2ea1088b249aca6ed12c5098a00b412ea9ecd Mon Sep 17 00:00:00 2001 From: David Neto Date: Mon, 28 Sep 2015 10:56:16 -0400 Subject: [PATCH] Assembler test for optional operands of OpSource These are the first tests to cover OperandOptionalId and OperandOptionalLiteralString from the grammar in opcode.inc --- test/TextToBinary.Debug.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/TextToBinary.Debug.cpp b/test/TextToBinary.Debug.cpp index 1165423..d1369a5 100644 --- a/test/TextToBinary.Debug.cpp +++ b/test/TextToBinary.Debug.cpp @@ -81,6 +81,25 @@ TEST_P(OpSourceTest, AnyLanguage) { INSTANTIATE_TEST_CASE_P(TextToBinaryTestDebug, OpSourceTest, ::testing::ValuesIn(kLanguageCases)); +TEST_F(TextToBinaryTest, OpSourceAcceptsOptionalFileId) { + // In the grammar, the file id is an OperandOptionalId. + std::string input = "OpSource GLSL 450 %file_id"; + EXPECT_THAT( + CompiledInstructions(input), + Eq(MakeInstruction(spv::OpSource, {spv::SourceLanguageGLSL, 450, 1}))); +}; + +TEST_F(TextToBinaryTest, OpSourceAcceptsOptionalSourceText) { + std::string fake_source = "To be or not to be"; + std::string input = "OpSource GLSL 450 %file_id \"" + fake_source + "\""; + std::vector expected_operands = {spv::SourceLanguageGLSL, 450, 1}; + std::vector encoded_source = MakeVector(fake_source); + expected_operands.insert(expected_operands.end(), encoded_source.begin(), + encoded_source.end()); + EXPECT_THAT(CompiledInstructions(input), + Eq(MakeInstruction(spv::OpSource, expected_operands))); +}; + // Test OpSourceContinued using OpSourceContinuedTest = -- 2.7.4