text_start_new_inst_test.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include <string>
  15. #include "test/unit_spirv.h"
  16. namespace spvtools {
  17. namespace {
  18. using spvtest::AutoText;
  19. TEST(TextStartsWithOp, YesAtStart) {
  20. EXPECT_TRUE(AssemblyContext(AutoText("OpFoo"), nullptr).isStartOfNewInst());
  21. EXPECT_TRUE(AssemblyContext(AutoText("OpFoo"), nullptr).isStartOfNewInst());
  22. EXPECT_TRUE(AssemblyContext(AutoText("OpEnCL"), nullptr).isStartOfNewInst());
  23. }
  24. TEST(TextStartsWithOp, YesAtMiddle) {
  25. {
  26. AutoText text(" OpFoo");
  27. AssemblyContext dat(text, nullptr);
  28. dat.seekForward(2);
  29. EXPECT_TRUE(dat.isStartOfNewInst());
  30. }
  31. {
  32. AutoText text("xx OpFoo");
  33. AssemblyContext dat(text, nullptr);
  34. dat.seekForward(2);
  35. EXPECT_TRUE(dat.isStartOfNewInst());
  36. }
  37. }
  38. TEST(TextStartsWithOp, NoIfTooFar) {
  39. AutoText text(" OpFoo");
  40. AssemblyContext dat(text, nullptr);
  41. dat.seekForward(3);
  42. EXPECT_FALSE(dat.isStartOfNewInst());
  43. }
  44. TEST(TextStartsWithOp, NoRegular) {
  45. EXPECT_FALSE(
  46. AssemblyContext(AutoText("Fee Fi Fo Fum"), nullptr).isStartOfNewInst());
  47. EXPECT_FALSE(AssemblyContext(AutoText("123456"), nullptr).isStartOfNewInst());
  48. EXPECT_FALSE(AssemblyContext(AutoText("123456"), nullptr).isStartOfNewInst());
  49. EXPECT_FALSE(AssemblyContext(AutoText("OpenCL"), nullptr).isStartOfNewInst());
  50. }
  51. TEST(TextStartsWithOp, YesForValueGenerationForm) {
  52. EXPECT_TRUE(
  53. AssemblyContext(AutoText("%foo = OpAdd"), nullptr).isStartOfNewInst());
  54. EXPECT_TRUE(
  55. AssemblyContext(AutoText("%foo = OpAdd"), nullptr).isStartOfNewInst());
  56. }
  57. TEST(TextStartsWithOp, NoForNearlyValueGeneration) {
  58. EXPECT_FALSE(
  59. AssemblyContext(AutoText("%foo = "), nullptr).isStartOfNewInst());
  60. EXPECT_FALSE(AssemblyContext(AutoText("%foo "), nullptr).isStartOfNewInst());
  61. EXPECT_FALSE(AssemblyContext(AutoText("%foo"), nullptr).isStartOfNewInst());
  62. }
  63. } // namespace
  64. } // namespace spvtools