@@ -327,6 +327,45 @@ TEST(RangeSelectorTest, EncloseOpGeneralParsed) {
327327 EXPECT_THAT_EXPECTED (select (*R, Match), HasValue (" 3, 7" ));
328328}
329329
330+ TEST (RangeSelectorTest, MergeOp) {
331+ StringRef Code = R"cc(
332+ int f(int x, int y, int z) { return 3; }
333+ int g() { return f(/* comment */ 3, 7 /* comment */, 9); }
334+ )cc" ;
335+ auto Matcher = callExpr (hasArgument (0 , expr ().bind (" a0" )),
336+ hasArgument (1 , expr ().bind (" a1" )),
337+ hasArgument (2 , expr ().bind (" a2" )));
338+ RangeSelector R = merge (node (" a0" ), node (" a1" ));
339+ TestMatch Match = matchCode (Code, Matcher);
340+ EXPECT_THAT_EXPECTED (select (R, Match), HasValue (" 3, 7" ));
341+ // Test the merge of two non-contiguous and out-of-order token-ranges.
342+ R = merge (node (" a2" ), node (" a0" ));
343+ EXPECT_THAT_EXPECTED (select (R, Match), HasValue (" 3, 7 /* comment */, 9" ));
344+ // Test the merge of a token-range (expr node) with a char-range (before).
345+ R = merge (node (" a1" ), before (node (" a0" )));
346+ EXPECT_THAT_EXPECTED (select (R, Match), HasValue (" 3, 7" ));
347+ // Test the merge of two char-ranges.
348+ R = merge (before (node (" a0" )), before (node (" a1" )));
349+ EXPECT_THAT_EXPECTED (select (R, Match), HasValue (" 3, " ));
350+ }
351+
352+ TEST (RangeSelectorTest, MergeOpParsed) {
353+ StringRef Code = R"cc(
354+ int f(int x, int y, int z) { return 3; }
355+ int g() { return f(/* comment */ 3, 7 /* comment */, 9); }
356+ )cc" ;
357+ auto Matcher = callExpr (hasArgument (0 , expr ().bind (" a0" )),
358+ hasArgument (1 , expr ().bind (" a1" )),
359+ hasArgument (2 , expr ().bind (" a2" )));
360+ auto R = parseRangeSelector (R"rs( merge(node("a0"), node("a1")))rs" );
361+ ASSERT_THAT_EXPECTED (R, llvm::Succeeded ());
362+ TestMatch Match = matchCode (Code, Matcher);
363+ EXPECT_THAT_EXPECTED (select (*R, Match), HasValue (" 3, 7" ));
364+ R = parseRangeSelector (R"rs( merge(node("a2"), node("a1")))rs" );
365+ ASSERT_THAT_EXPECTED (R, llvm::Succeeded ());
366+ EXPECT_THAT_EXPECTED (select (*R, Match), HasValue (" 7 /* comment */, 9" ));
367+ }
368+
330369TEST (RangeSelectorTest, NodeOpStatement) {
331370 StringRef Code = " int f() { return 3; }" ;
332371 TestMatch Match = matchCode (Code, returnStmt ().bind (" id" ));
0 commit comments