Assembler test for optional operands of OpSource
authorDavid Neto <dneto@google.com>
Mon, 28 Sep 2015 14:56:16 +0000 (10:56 -0400)
committerDavid Neto <dneto@google.com>
Mon, 26 Oct 2015 16:55:33 +0000 (12:55 -0400)
These are the first tests to cover OperandOptionalId
and OperandOptionalLiteralString from the grammar in
opcode.inc

test/TextToBinary.Debug.cpp

index 1165423..d1369a5 100644 (file)
@@ -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<uint32_t> expected_operands = {spv::SourceLanguageGLSL, 450, 1};
+  std::vector<uint32_t> 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 =