From 8b1717546378b554008af188707f5443220006bc Mon Sep 17 00:00:00 2001 From: aditi-pandit Date: Wed, 13 Nov 2024 11:10:35 -0800 Subject: [PATCH] refactor: Combine loops in PrestoSerializerTest.validateLexer (#11434) Summary: Combine multiple tests in separate loops to just one to improve readability. Pull Request resolved: https://github.com/facebookincubator/velox/pull/11434 Reviewed By: kevinwilfong Differential Revision: D65880657 Pulled By: Yuhta fbshipit-source-id: 6c2c813e240206f894a2537eabd6ee3510233739 --- .../tests/PrestoSerializerTest.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/velox/serializers/tests/PrestoSerializerTest.cpp b/velox/serializers/tests/PrestoSerializerTest.cpp index 1fda761a7be7..898939f97a27 100644 --- a/velox/serializers/tests/PrestoSerializerTest.cpp +++ b/velox/serializers/tests/PrestoSerializerTest.cpp @@ -180,17 +180,20 @@ class PrestoSerializerTest const auto status = serializer::presto::PrestoVectorSerde::lex( input, tokens, ¶mOptions); EXPECT_TRUE(status.ok()) << status.message(); + size_t tokenLengthSum = 0; - for (auto const& token : tokens) { - tokenLengthSum += token.length; - } - for (auto const& token : tokens) { + for (size_t i = 0; i < tokens.size(); ++i) { + const auto& token = tokens[i]; + // The lexer should not produce empty tokens EXPECT_NE(token.length, 0); - } - for (size_t i = 1; i < tokens.size(); ++i) { - // The lexer should merge consecutive tokens of the same type - EXPECT_NE(tokens[i].tokenType, tokens[i - 1].tokenType); + // Compute tokenLengthSum to validate with input.size(). + tokenLengthSum += token.length; + + if (i > 0) { + // The lexer should merge consecutive tokens of the same type + EXPECT_NE(token.tokenType, tokens[i - 1].tokenType); + } } EXPECT_EQ(tokenLengthSum, input.size()); }