@@ -1427,8 +1427,220 @@ TEST_F(CommentParserTest, Deprecated) {
1427
1427
}
1428
1428
}
1429
1429
1430
+ TEST_F (CommentParserTest, ThrowsCommandHasArg1) {
1431
+ const char *Sources[] = {
1432
+ " /// @throws int This function throws an integer" ,
1433
+ (" /// @throws\n "
1434
+ " /// int This function throws an integer" ),
1435
+ (" /// @throws \n "
1436
+ " /// int This function throws an integer" ),
1437
+ (" /// @throws\n "
1438
+ " /// int\n "
1439
+ " /// This function throws an integer" ),
1440
+ (" /// @throws \n "
1441
+ " /// int \n "
1442
+ " /// This function throws an integer" ),
1443
+ };
1444
+
1445
+ for (size_t i = 0 , e = std::size (Sources); i != e; i++) {
1446
+ FullComment *FC = parseString (Sources[i]);
1447
+ ASSERT_TRUE (HasChildCount (FC, 2 ));
1448
+
1449
+ ASSERT_TRUE (HasParagraphCommentAt (FC, 0 , " " ));
1450
+ {
1451
+ BlockCommandComment *BCC;
1452
+ ParagraphComment *PC;
1453
+ ASSERT_TRUE (HasBlockCommandAt (FC, Traits, 1 , BCC, " throws" , PC));
1454
+ ASSERT_TRUE (HasChildCount (PC, 1 ));
1455
+ ASSERT_TRUE (BCC->getNumArgs () == 1 );
1456
+ ASSERT_TRUE (BCC->getArgText (0 ) == " int" );
1457
+ }
1458
+ }
1459
+ }
1460
+
1461
+ TEST_F (CommentParserTest, ThrowsCommandHasArg2) {
1462
+ const char *Sources[] = {
1463
+ " /// @throws int** This function throws a double pointer to an integer" ,
1464
+ };
1465
+
1466
+ for (size_t i = 0 , e = std::size (Sources); i != e; i++) {
1467
+ FullComment *FC = parseString (Sources[i]);
1468
+ ASSERT_TRUE (HasChildCount (FC, 2 ));
1469
+
1470
+ ASSERT_TRUE (HasParagraphCommentAt (FC, 0 , " " ));
1471
+ {
1472
+ BlockCommandComment *BCC;
1473
+ ParagraphComment *PC;
1474
+ ASSERT_TRUE (HasBlockCommandAt (FC, Traits, 1 , BCC, " throws" , PC));
1475
+ ASSERT_TRUE (HasChildCount (PC, 1 ));
1476
+ ASSERT_TRUE (BCC->getNumArgs () == 1 );
1477
+ ASSERT_TRUE (BCC->getArgText (0 ) == " int**" );
1478
+ }
1479
+ }
1480
+ }
1481
+
1482
+ TEST_F (CommentParserTest, ThrowsCommandHasArg3) {
1483
+ const char *Sources[] = {
1484
+ " /// @throws Error<T> error of type Error<T>" ,
1485
+ };
1486
+
1487
+ for (size_t i = 0 , e = std::size (Sources); i != e; i++) {
1488
+ FullComment *FC = parseString (Sources[i]);
1489
+ ASSERT_TRUE (HasChildCount (FC, 2 ));
1490
+
1491
+ ASSERT_TRUE (HasParagraphCommentAt (FC, 0 , " " ));
1492
+ {
1493
+ BlockCommandComment *BCC;
1494
+ ParagraphComment *PC;
1495
+ ASSERT_TRUE (HasBlockCommandAt (FC, Traits, 1 , BCC, " throws" , PC));
1496
+ ASSERT_TRUE (HasChildCount (PC, 3 )); // Extra children because <T> is parsed
1497
+ // as a series of TextComments
1498
+ ASSERT_TRUE (BCC->getNumArgs () == 1 );
1499
+ ASSERT_TRUE (BCC->getArgText (0 ) == " Error<T>" );
1500
+ }
1501
+ }
1502
+ }
1503
+
1504
+ TEST_F (CommentParserTest, ThrowsCommandHasArg4) {
1505
+ const char *Sources[] = {
1506
+ " /// @throws Error<Container<T>> nested templates" ,
1507
+ };
1508
+
1509
+ for (size_t i = 0 , e = std::size (Sources); i != e; i++) {
1510
+ FullComment *FC = parseString (Sources[i]);
1511
+ ASSERT_TRUE (HasChildCount (FC, 2 ));
1512
+
1513
+ ASSERT_TRUE (HasParagraphCommentAt (FC, 0 , " " ));
1514
+ {
1515
+ BlockCommandComment *BCC;
1516
+ ParagraphComment *PC;
1517
+ ASSERT_TRUE (HasBlockCommandAt (FC, Traits, 1 , BCC, " throws" , PC));
1518
+ ASSERT_TRUE (HasChildCount (PC, 1 ));
1519
+ ASSERT_TRUE (BCC->getNumArgs () == 1 );
1520
+ ASSERT_TRUE (BCC->getArgText (0 ) == " Error<Container<T>>" );
1521
+ }
1522
+ }
1523
+ }
1524
+
1525
+ TEST_F (CommentParserTest, ThrowsCommandHasArg5) {
1526
+ const char *Sources[] = {
1527
+ " /// @throws Error<Ts...> variadic templates" ,
1528
+ };
1529
+
1530
+ for (size_t i = 0 , e = std::size (Sources); i != e; i++) {
1531
+ FullComment *FC = parseString (Sources[i]);
1532
+ ASSERT_TRUE (HasChildCount (FC, 2 ));
1533
+
1534
+ ASSERT_TRUE (HasParagraphCommentAt (FC, 0 , " " ));
1535
+ {
1536
+ BlockCommandComment *BCC;
1537
+ ParagraphComment *PC;
1538
+ ASSERT_TRUE (HasBlockCommandAt (FC, Traits, 1 , BCC, " throws" , PC));
1539
+ ASSERT_TRUE (HasChildCount (PC, 1 ));
1540
+ ASSERT_TRUE (BCC->getNumArgs () == 1 );
1541
+ ASSERT_TRUE (BCC->getArgText (0 ) == " Error<Ts...>" );
1542
+ }
1543
+ }
1544
+ }
1545
+
1546
+ TEST_F (CommentParserTest, ThrowsCommandHasArg6) {
1547
+ const char *Sources[] = {
1548
+ " /// @throws Foo<(1 > 0)> typo1" ,
1549
+ };
1550
+
1551
+ for (size_t i = 0 , e = std::size (Sources); i != e; i++) {
1552
+ FullComment *FC = parseString (Sources[i]);
1553
+ ASSERT_TRUE (HasChildCount (FC, 2 ));
1554
+
1555
+ ASSERT_TRUE (HasParagraphCommentAt (FC, 0 , " " ));
1556
+ {
1557
+ BlockCommandComment *BCC;
1558
+ ParagraphComment *PC;
1559
+ ASSERT_TRUE (HasBlockCommandAt (FC, Traits, 1 , BCC, " throws" , PC));
1560
+ ASSERT_TRUE (HasChildCount (PC, 1 ));
1561
+ ASSERT_TRUE (BCC->getNumArgs () == 1 );
1562
+ ASSERT_TRUE (BCC->getArgText (0 ) == " Foo<(1 >" );
1563
+ }
1564
+ }
1565
+ }
1566
+
1567
+ // No matter the number of (unmatched) opening brackets, no type is parsed.
1568
+ TEST_F (CommentParserTest, ThrowsCommandHasArg7) {
1569
+ const char *Sources[] = {
1570
+ " /// @throws Foo<" ,
1571
+ " /// @throws Foo<<<" ,
1572
+ " /// @throws Foo<<<<<<<" ,
1573
+ " /// @throws Foo<\n " ,
1574
+ " /// @throws Foo<<<\n " ,
1575
+ " /// @throws Foo<<<<<<<\n " ,
1576
+ };
1577
+
1578
+ for (size_t i = 0 , e = std::size (Sources); i != e; i++) {
1579
+ FullComment *FC = parseString (Sources[i]);
1580
+ ASSERT_TRUE (HasChildCount (FC, 2 ));
1581
+
1582
+ ASSERT_TRUE (HasParagraphCommentAt (FC, 0 , " " ));
1583
+ {
1584
+ BlockCommandComment *BCC;
1585
+ ParagraphComment *PC;
1586
+ ASSERT_TRUE (HasBlockCommandAt (FC, Traits, 1 , BCC, " throws" , PC));
1587
+ ASSERT_TRUE (HasChildCount (PC, 0 ));
1588
+ ASSERT_TRUE (BCC->getNumArgs () == 0 );
1589
+ }
1590
+ }
1591
+ }
1592
+
1593
+ // Types with a non-matching closing bracket are parsed as if they are a type
1594
+ TEST_F (CommentParserTest, ThrowsCommandHasArg8) {
1595
+ const char *Sources[] = {
1596
+ " /// @throws Foo>" ,
1597
+ " /// @throws Foo>\n " ,
1598
+ };
1599
+
1600
+ for (size_t i = 0 , e = std::size (Sources); i != e; i++) {
1601
+ FullComment *FC = parseString (Sources[i]);
1602
+ ASSERT_TRUE (HasChildCount (FC, 2 ));
1603
+
1604
+ ASSERT_TRUE (HasParagraphCommentAt (FC, 0 , " " ));
1605
+ {
1606
+ BlockCommandComment *BCC;
1607
+ ParagraphComment *PC;
1608
+ ASSERT_TRUE (HasBlockCommandAt (FC, Traits, 1 , BCC, " throws" , PC));
1609
+ ASSERT_TRUE (HasChildCount (PC, 0 ));
1610
+ ASSERT_TRUE (BCC->getNumArgs () == 1 );
1611
+ ASSERT_TRUE (BCC->getArgText (0 ) == " Foo>" );
1612
+ }
1613
+ }
1614
+ }
1615
+
1616
+ // Everying up until the end of the paragraph comment will be
1617
+ // eaten up if the template sequence is unterminated (i.e. number of
1618
+ // opening and closing brackets is not equal).
1619
+ TEST_F (CommentParserTest, ThrowsCommandHasArg9) {
1620
+ const char *Sources[] = {
1621
+ " /// @throws Foo<Bar<t>\n "
1622
+ " /// Aaa\n "
1623
+ " ///\n "
1624
+ " /// Bbb\n "
1625
+ };
1626
+
1627
+ for (size_t i = 0 , e = std::size (Sources); i != e; i++) {
1628
+ FullComment *FC = parseString (Sources[i]);
1629
+ ASSERT_TRUE (HasChildCount (FC, 3 ));
1630
+
1631
+ ASSERT_TRUE (HasParagraphCommentAt (FC, 0 , " " ));
1632
+ {
1633
+ BlockCommandComment *BCC;
1634
+ ParagraphComment *PC;
1635
+ ASSERT_TRUE (HasBlockCommandAt (FC, Traits, 1 , BCC, " throws" , PC));
1636
+ ASSERT_TRUE (HasChildCount (PC, 0 ));
1637
+ ASSERT_TRUE (BCC->getNumArgs () == 0 );
1638
+ }
1639
+ }
1640
+ }
1641
+
1642
+
1430
1643
} // unnamed namespace
1431
1644
1432
1645
} // end namespace comments
1433
1646
} // end namespace clang
1434
-
0 commit comments