@@ -69,7 +69,8 @@ class AlignmentTestFixture : public ::testing::Test,
69
69
public UnwrappedLineMemoryHandler {
70
70
public:
71
71
explicit AlignmentTestFixture (absl::string_view text)
72
- : sample_(text),
72
+ : sample_backing_(text),
73
+ sample_(sample_backing_),
73
74
tokens_(absl::StrSplit(sample_, absl::ByAnyChar(" \n " ),
74
75
absl::SkipEmpty())) {
75
76
for (const auto token : tokens_) {
@@ -80,7 +81,8 @@ class AlignmentTestFixture : public ::testing::Test,
80
81
}
81
82
82
83
protected:
83
- const std::string sample_;
84
+ const std::string sample_backing_;
85
+ const absl::string_view sample_;
84
86
const std::vector<absl::string_view> tokens_;
85
87
std::vector<TokenInfo> ftokens_;
86
88
};
@@ -271,7 +273,7 @@ TEST_F(Sparse3x3MatrixAlignmentTest, AlignmentPolicyFlushLeft) {
271
273
272
274
TEST_F (Sparse3x3MatrixAlignmentTest, AlignmentPolicyPreserve) {
273
275
// Set previous-token string pointers to preserve spaces.
274
- ConnectPreFormatTokensPreservedSpaceStarts (sample_.data (),
276
+ ConnectPreFormatTokensPreservedSpaceStarts (sample_.begin (),
275
277
&pre_format_tokens_);
276
278
277
279
TabularAlignTokens (40 , sample_, ByteOffsetSet (), kPreserveAlignmentHandler ,
@@ -391,7 +393,7 @@ TEST_F(Sparse3x3MatrixAlignmentTest, IgnoreCommentLine) {
391
393
392
394
TEST_F (Sparse3x3MatrixAlignmentTest, CompletelyDisabledNoAlignment) {
393
395
// Disabled ranges use original spacing
394
- ConnectPreFormatTokensPreservedSpaceStarts (sample_.data (),
396
+ ConnectPreFormatTokensPreservedSpaceStarts (sample_.begin (),
395
397
&pre_format_tokens_);
396
398
397
399
// Require 1 space between tokens.
@@ -413,7 +415,7 @@ TEST_F(Sparse3x3MatrixAlignmentTest, CompletelyDisabledNoAlignment) {
413
415
414
416
TEST_F (Sparse3x3MatrixAlignmentTest, CompletelyDisabledNoAlignmentWithIndent) {
415
417
// Disabled ranges use original spacing
416
- ConnectPreFormatTokensPreservedSpaceStarts (sample_.data (),
418
+ ConnectPreFormatTokensPreservedSpaceStarts (sample_.begin (),
417
419
&pre_format_tokens_);
418
420
419
421
// Require 1 space between tokens.
@@ -445,7 +447,7 @@ class Sparse3x3MatrixAlignmentMoreSpacesTest
445
447
Sparse3x3MatrixAlignmentMoreSpacesTest ()
446
448
: Sparse3x3MatrixAlignmentTest(" one two\n three four\n five six" ) {
447
449
// This is needed for preservation of original spacing.
448
- ConnectPreFormatTokensPreservedSpaceStarts (sample_.data (),
450
+ ConnectPreFormatTokensPreservedSpaceStarts (sample_.begin (),
449
451
&pre_format_tokens_);
450
452
}
451
453
};
@@ -480,7 +482,7 @@ TEST_F(Sparse3x3MatrixAlignmentMoreSpacesTest,
480
482
481
483
TEST_F (Sparse3x3MatrixAlignmentTest, PartiallyDisabledNoAlignment) {
482
484
// Disabled ranges use original spacing
483
- ConnectPreFormatTokensPreservedSpaceStarts (sample_.data (),
485
+ ConnectPreFormatTokensPreservedSpaceStarts (sample_.begin (),
484
486
&pre_format_tokens_);
485
487
486
488
// Require 1 space between tokens.
@@ -865,7 +867,7 @@ class Dense2x2MatrixAlignmentTest : public MatrixTreeAlignmentTestFixture {
865
867
CHECK_EQ (tokens_.size (), 4 );
866
868
867
869
// Need to know original spacing to be able to infer user-intent.
868
- ConnectPreFormatTokensPreservedSpaceStarts (sample_.data (),
870
+ ConnectPreFormatTokensPreservedSpaceStarts (sample_.begin (),
869
871
&pre_format_tokens_);
870
872
871
873
// Require 1 space between tokens.
@@ -1170,7 +1172,7 @@ TEST_F(SubcolumnsTreeAlignmentTest, AlignmentPolicyFlushLeft) {
1170
1172
}
1171
1173
1172
1174
TEST_F (SubcolumnsTreeAlignmentTest, AlignmentPolicyPreserve) {
1173
- ConnectPreFormatTokensPreservedSpaceStarts (sample_.data (),
1175
+ ConnectPreFormatTokensPreservedSpaceStarts (sample_.begin (),
1174
1176
&pre_format_tokens_);
1175
1177
1176
1178
TabularAlignTokens (40 , sample_, ByteOffsetSet (),
@@ -1332,7 +1334,7 @@ class InferSubcolumnsTreeAlignmentTest : public SubcolumnsTreeAlignmentTest {
1332
1334
" ( eleven nineteen-ninety-nine 2k )\n " )
1333
1335
: SubcolumnsTreeAlignmentTest(text) {
1334
1336
// Need to know original spacing to be able to infer user-intent.
1335
- ConnectPreFormatTokensPreservedSpaceStarts (sample_.data (),
1337
+ ConnectPreFormatTokensPreservedSpaceStarts (sample_.begin (),
1336
1338
&pre_format_tokens_);
1337
1339
1338
1340
// Require 1 space between tokens.
@@ -1497,15 +1499,16 @@ class FormatUsingOriginalSpacingTest : public ::testing::Test,
1497
1499
" \n <1NL+7Spaces>\n <1nl+7spaces>"
1498
1500
" \n\n <2NL+2Spaces>\n\n <2nl+2spaces>"
1499
1501
" \n \n\n <1NL+1Space+2NL+2Spaces>\n \n\n <1nl+1space+2nl+2spaces>" )
1500
- : sample_(text),
1502
+ : sample_backing_(text),
1503
+ sample_(sample_backing_),
1501
1504
tokens_(absl::StrSplit(sample_, OutsideCharPairs(' <' , ' >' ),
1502
1505
absl::SkipEmpty())) {
1503
1506
for (const auto token : tokens_) {
1504
1507
ftokens_.emplace_back (1 , token);
1505
1508
}
1506
1509
// sample_ is the memory-owning string buffer
1507
1510
CreateTokenInfosExternalStringBuffer (ftokens_);
1508
- ConnectPreFormatTokensPreservedSpaceStarts (sample_.data (),
1511
+ ConnectPreFormatTokensPreservedSpaceStarts (sample_.begin (),
1509
1512
&pre_format_tokens_);
1510
1513
}
1511
1514
@@ -1518,7 +1521,8 @@ class FormatUsingOriginalSpacingTest : public ::testing::Test,
1518
1521
EXPECT_PRED_FORMAT2 (TokenPartitionTreesEqualPredFormat, nodes[0 ], expected);
1519
1522
}
1520
1523
1521
- const std::string sample_;
1524
+ const std::string sample_backing_;
1525
+ const absl::string_view sample_;
1522
1526
const std::vector<absl::string_view> tokens_;
1523
1527
std::vector<TokenInfo> ftokens_;
1524
1528
};
0 commit comments