ASSERT_EQ(SPV_END_OF_STREAM, data.advance());
}
+// Invokes AssemblyContext::advance() on text, asserts success, and returns
+// AssemblyContext::position().
+spv_position_t PositionAfterAdvance(const char* text) {
+ AutoText input(text);
+ AssemblyContext data(input, nullptr);
+ EXPECT_EQ(SPV_SUCCESS, data.advance());
+ return data.position();
+}
+
+TEST(TextAdvance, SkipOverCR) {
+ const auto pos = PositionAfterAdvance("\rWord");
+ EXPECT_EQ(1u, pos.column);
+ EXPECT_EQ(0u, pos.line);
+ EXPECT_EQ(1u, pos.index);
+}
+
+TEST(TextAdvance, SkipOverCRs) {
+ const auto pos = PositionAfterAdvance("\r\r\rWord");
+ EXPECT_EQ(3u, pos.column);
+ EXPECT_EQ(0u, pos.line);
+ EXPECT_EQ(3u, pos.index);
+}
+
+TEST(TextAdvance, SkipOverCRLF) {
+ const auto pos = PositionAfterAdvance("\r\nWord");
+ EXPECT_EQ(0u, pos.column);
+ EXPECT_EQ(1u, pos.line);
+ EXPECT_EQ(2u, pos.index);
+}
+
+TEST(TextAdvance, SkipOverCRLFs) {
+ const auto pos = PositionAfterAdvance("\r\n\r\nWord");
+ EXPECT_EQ(0u, pos.column);
+ EXPECT_EQ(2u, pos.line);
+ EXPECT_EQ(4u, pos.index);
+}
} // anonymous namespace
EXPECT_EQ(6u, diagnostic->position.column + 1);
}
+TEST_F(TextToBinaryTest, CRLF) {
+ const std::string input =
+ "%i32 = OpTypeInt 32 1\r\n%c = OpConstant %i32 123\r\n";
+ EXPECT_THAT(CompiledInstructions(input),
+ Eq(Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 1}),
+ MakeInstruction(SpvOpConstant, {1, 2, 123})})));
+}
+
using TextToBinaryFloatValueTest = spvtest::TextToBinaryTestBase<
::testing::TestWithParam<std::pair<std::string, uint32_t>>>;
ASSERT_STREQ("word" BACKSLASH BACKSLASH, word.c_str());
}
+TEST(TextWordGet, CRLF) {
+ AutoText input("abc\r\nd");
+ AssemblyContext data(input, nullptr);
+ std::string word;
+ spv_position_t pos = {};
+ ASSERT_EQ(SPV_SUCCESS, data.getWord(&word, &pos));
+ EXPECT_EQ(3u, pos.column);
+ EXPECT_STREQ("abc", word.c_str());
+ data.setPosition(pos);
+ data.advance();
+ ASSERT_EQ(SPV_SUCCESS, data.getWord(&word, &pos));
+ EXPECT_EQ(1u, pos.column);
+ EXPECT_STREQ("d", word.c_str());
+}
+
} // anonymous namespace