Skip to content

Commit

Permalink
refactor: Combine loops in PrestoSerializerTest.validateLexer (facebo…
Browse files Browse the repository at this point in the history
…okincubator#11434)

Summary:
Combine multiple tests in separate loops to just one to improve readability.

Pull Request resolved: facebookincubator#11434

Reviewed By: kevinwilfong

Differential Revision: D65880657

Pulled By: Yuhta

fbshipit-source-id: 6c2c813e240206f894a2537eabd6ee3510233739
  • Loading branch information
aditi-pandit authored and facebook-github-bot committed Nov 13, 2024
1 parent 5ab1a8f commit 8b17175
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions velox/serializers/tests/PrestoSerializerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,20 @@ class PrestoSerializerTest
const auto status = serializer::presto::PrestoVectorSerde::lex(
input, tokens, &paramOptions);
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());
}
Expand Down

0 comments on commit 8b17175

Please sign in to comment.