1fd4e5da5Sopenharmony_ci// Copyright (c) 2015-2016 The Khronos Group Inc. 2fd4e5da5Sopenharmony_ci// 3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License. 5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at 6fd4e5da5Sopenharmony_ci// 7fd4e5da5Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8fd4e5da5Sopenharmony_ci// 9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and 13fd4e5da5Sopenharmony_ci// limitations under the License. 14fd4e5da5Sopenharmony_ci 15fd4e5da5Sopenharmony_ci#include <string> 16fd4e5da5Sopenharmony_ci 17fd4e5da5Sopenharmony_ci#include "test/unit_spirv.h" 18fd4e5da5Sopenharmony_ci 19fd4e5da5Sopenharmony_cinamespace spvtools { 20fd4e5da5Sopenharmony_cinamespace { 21fd4e5da5Sopenharmony_ci 22fd4e5da5Sopenharmony_ciusing spvtest::AutoText; 23fd4e5da5Sopenharmony_ci 24fd4e5da5Sopenharmony_ciTEST(TextStartsWithOp, YesAtStart) { 25fd4e5da5Sopenharmony_ci EXPECT_TRUE(AssemblyContext(AutoText("OpFoo"), nullptr).isStartOfNewInst()); 26fd4e5da5Sopenharmony_ci EXPECT_TRUE(AssemblyContext(AutoText("OpFoo"), nullptr).isStartOfNewInst()); 27fd4e5da5Sopenharmony_ci EXPECT_TRUE(AssemblyContext(AutoText("OpEnCL"), nullptr).isStartOfNewInst()); 28fd4e5da5Sopenharmony_ci} 29fd4e5da5Sopenharmony_ci 30fd4e5da5Sopenharmony_ciTEST(TextStartsWithOp, YesAtMiddle) { 31fd4e5da5Sopenharmony_ci { 32fd4e5da5Sopenharmony_ci AutoText text(" OpFoo"); 33fd4e5da5Sopenharmony_ci AssemblyContext dat(text, nullptr); 34fd4e5da5Sopenharmony_ci dat.seekForward(2); 35fd4e5da5Sopenharmony_ci EXPECT_TRUE(dat.isStartOfNewInst()); 36fd4e5da5Sopenharmony_ci } 37fd4e5da5Sopenharmony_ci { 38fd4e5da5Sopenharmony_ci AutoText text("xx OpFoo"); 39fd4e5da5Sopenharmony_ci AssemblyContext dat(text, nullptr); 40fd4e5da5Sopenharmony_ci dat.seekForward(2); 41fd4e5da5Sopenharmony_ci EXPECT_TRUE(dat.isStartOfNewInst()); 42fd4e5da5Sopenharmony_ci } 43fd4e5da5Sopenharmony_ci} 44fd4e5da5Sopenharmony_ci 45fd4e5da5Sopenharmony_ciTEST(TextStartsWithOp, NoIfTooFar) { 46fd4e5da5Sopenharmony_ci AutoText text(" OpFoo"); 47fd4e5da5Sopenharmony_ci AssemblyContext dat(text, nullptr); 48fd4e5da5Sopenharmony_ci dat.seekForward(3); 49fd4e5da5Sopenharmony_ci EXPECT_FALSE(dat.isStartOfNewInst()); 50fd4e5da5Sopenharmony_ci} 51fd4e5da5Sopenharmony_ci 52fd4e5da5Sopenharmony_ciTEST(TextStartsWithOp, NoRegular) { 53fd4e5da5Sopenharmony_ci EXPECT_FALSE( 54fd4e5da5Sopenharmony_ci AssemblyContext(AutoText("Fee Fi Fo Fum"), nullptr).isStartOfNewInst()); 55fd4e5da5Sopenharmony_ci EXPECT_FALSE(AssemblyContext(AutoText("123456"), nullptr).isStartOfNewInst()); 56fd4e5da5Sopenharmony_ci EXPECT_FALSE(AssemblyContext(AutoText("123456"), nullptr).isStartOfNewInst()); 57fd4e5da5Sopenharmony_ci EXPECT_FALSE(AssemblyContext(AutoText("OpenCL"), nullptr).isStartOfNewInst()); 58fd4e5da5Sopenharmony_ci} 59fd4e5da5Sopenharmony_ci 60fd4e5da5Sopenharmony_ciTEST(TextStartsWithOp, YesForValueGenerationForm) { 61fd4e5da5Sopenharmony_ci EXPECT_TRUE( 62fd4e5da5Sopenharmony_ci AssemblyContext(AutoText("%foo = OpAdd"), nullptr).isStartOfNewInst()); 63fd4e5da5Sopenharmony_ci EXPECT_TRUE( 64fd4e5da5Sopenharmony_ci AssemblyContext(AutoText("%foo = OpAdd"), nullptr).isStartOfNewInst()); 65fd4e5da5Sopenharmony_ci} 66fd4e5da5Sopenharmony_ci 67fd4e5da5Sopenharmony_ciTEST(TextStartsWithOp, NoForNearlyValueGeneration) { 68fd4e5da5Sopenharmony_ci EXPECT_FALSE( 69fd4e5da5Sopenharmony_ci AssemblyContext(AutoText("%foo = "), nullptr).isStartOfNewInst()); 70fd4e5da5Sopenharmony_ci EXPECT_FALSE(AssemblyContext(AutoText("%foo "), nullptr).isStartOfNewInst()); 71fd4e5da5Sopenharmony_ci EXPECT_FALSE(AssemblyContext(AutoText("%foo"), nullptr).isStartOfNewInst()); 72fd4e5da5Sopenharmony_ci} 73fd4e5da5Sopenharmony_ci 74fd4e5da5Sopenharmony_ci} // namespace 75fd4e5da5Sopenharmony_ci} // namespace spvtools 76