1 // Copyright (c) 2015-2016 The Khronos Group Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <string>
16
17 #include "gmock/gmock.h"
18 #include "source/util/string_utils.h"
19 #include "test/test_fixture.h"
20 #include "test/unit_spirv.h"
21
22 namespace spvtools {
23 namespace {
24
25 using spvtest::Concatenate;
26 using spvtest::MakeInstruction;
27 using utils::MakeVector;
28 using spvtest::TextToBinaryTest;
29 using testing::Eq;
30
TEST_F(TextToBinaryTest,Whitespace)31 TEST_F(TextToBinaryTest, Whitespace) {
32 std::string input = R"(
33 ; I'm a proud comment at the beginning of the file
34 ; I hide: OpCapability Shader
35 OpMemoryModel Logical Simple ; comment after instruction
36 ;;;;;;;; many ;'s
37 %glsl450 = OpExtInstImport "GLSL.std.450"
38 ; comment indented
39 )";
40
41 EXPECT_THAT(
42 CompiledInstructions(input),
43 Eq(Concatenate({MakeInstruction(SpvOpMemoryModel,
44 {uint32_t(SpvAddressingModelLogical),
45 uint32_t(SpvMemoryModelSimple)}),
46 MakeInstruction(SpvOpExtInstImport, {1},
47 MakeVector("GLSL.std.450"))})));
48 }
49
50 } // namespace
51 } // namespace spvtools
52