agentmap 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +12 -4
- package/dist/cli.js.map +1 -1
- package/dist/extract/definitions.d.ts.map +1 -1
- package/dist/extract/definitions.js +195 -316
- package/dist/extract/definitions.js.map +1 -1
- package/dist/extract/definitions.test.js +749 -20
- package/dist/extract/definitions.test.js.map +1 -1
- package/dist/extract/markdown.d.ts.map +1 -1
- package/dist/extract/markdown.js +13 -1
- package/dist/extract/markdown.js.map +1 -1
- package/dist/extract/marker.d.ts.map +1 -1
- package/dist/extract/marker.js +87 -6
- package/dist/extract/marker.js.map +1 -1
- package/dist/extract/marker.test.js +142 -4
- package/dist/extract/marker.test.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -1
- package/dist/index.js.map +1 -1
- package/dist/languages/cpp.d.ts +30 -0
- package/dist/languages/cpp.d.ts.map +1 -0
- package/dist/languages/cpp.js +116 -0
- package/dist/languages/cpp.js.map +1 -0
- package/dist/languages/go.d.ts +26 -0
- package/dist/languages/go.d.ts.map +1 -0
- package/dist/languages/go.js +65 -0
- package/dist/languages/go.js.map +1 -0
- package/dist/languages/index.d.ts +90 -0
- package/dist/languages/index.d.ts.map +1 -0
- package/dist/languages/index.js +209 -0
- package/dist/languages/index.js.map +1 -0
- package/dist/languages/javascript.d.ts +18 -0
- package/dist/languages/javascript.d.ts.map +1 -0
- package/dist/languages/javascript.js +23 -0
- package/dist/languages/javascript.js.map +1 -0
- package/dist/languages/python.d.ts +23 -0
- package/dist/languages/python.d.ts.map +1 -0
- package/dist/languages/python.js +35 -0
- package/dist/languages/python.js.map +1 -0
- package/dist/languages/rust.d.ts +26 -0
- package/dist/languages/rust.d.ts.map +1 -0
- package/dist/languages/rust.js +65 -0
- package/dist/languages/rust.js.map +1 -0
- package/dist/languages/typescript.d.ts +30 -0
- package/dist/languages/typescript.d.ts.map +1 -0
- package/dist/languages/typescript.js +68 -0
- package/dist/languages/typescript.js.map +1 -0
- package/dist/languages/zig.d.ts +38 -0
- package/dist/languages/zig.d.ts.map +1 -0
- package/dist/languages/zig.js +104 -0
- package/dist/languages/zig.js.map +1 -0
- package/dist/map/builder.d.ts.map +1 -1
- package/dist/map/builder.js +4 -1
- package/dist/map/builder.js.map +1 -1
- package/dist/parser/languages.d.ts +2 -4
- package/dist/parser/languages.d.ts.map +1 -1
- package/dist/parser/languages.js +4 -29
- package/dist/parser/languages.js.map +1 -1
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.js +27 -49
- package/dist/scanner.js.map +1 -1
- package/dist/types.d.ts +6 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
|
@@ -762,7 +762,7 @@ describe('Rust', () => {
|
|
|
762
762
|
"exported": false,
|
|
763
763
|
"line": 1,
|
|
764
764
|
"name": "Config",
|
|
765
|
-
"type": "
|
|
765
|
+
"type": "struct",
|
|
766
766
|
},
|
|
767
767
|
]
|
|
768
768
|
`);
|
|
@@ -791,17 +791,7 @@ describe('Rust', () => {
|
|
|
791
791
|
}
|
|
792
792
|
}`;
|
|
793
793
|
const defs = await getDefinitions(code, 'rust');
|
|
794
|
-
expect(defs).toMatchInlineSnapshot(`
|
|
795
|
-
[
|
|
796
|
-
{
|
|
797
|
-
"endLine": 14,
|
|
798
|
-
"exported": false,
|
|
799
|
-
"line": 1,
|
|
800
|
-
"name": "Calculator",
|
|
801
|
-
"type": "class",
|
|
802
|
-
},
|
|
803
|
-
]
|
|
804
|
-
`);
|
|
794
|
+
expect(defs).toMatchInlineSnapshot(`[]`);
|
|
805
795
|
});
|
|
806
796
|
test('large trait', async () => {
|
|
807
797
|
const code = `trait Processor {
|
|
@@ -822,7 +812,7 @@ describe('Rust', () => {
|
|
|
822
812
|
"exported": false,
|
|
823
813
|
"line": 1,
|
|
824
814
|
"name": "Processor",
|
|
825
|
-
"type": "
|
|
815
|
+
"type": "trait",
|
|
826
816
|
},
|
|
827
817
|
]
|
|
828
818
|
`);
|
|
@@ -905,7 +895,7 @@ describe('Rust', () => {
|
|
|
905
895
|
[
|
|
906
896
|
{
|
|
907
897
|
"endLine": 8,
|
|
908
|
-
"exported":
|
|
898
|
+
"exported": true,
|
|
909
899
|
"line": 1,
|
|
910
900
|
"name": "public_handler",
|
|
911
901
|
"type": "function",
|
|
@@ -996,7 +986,7 @@ describe('Go', () => {
|
|
|
996
986
|
[
|
|
997
987
|
{
|
|
998
988
|
"endLine": 8,
|
|
999
|
-
"exported":
|
|
989
|
+
"exported": true,
|
|
1000
990
|
"line": 1,
|
|
1001
991
|
"name": "Process",
|
|
1002
992
|
"type": "function",
|
|
@@ -1014,7 +1004,7 @@ describe('Go', () => {
|
|
|
1014
1004
|
[
|
|
1015
1005
|
{
|
|
1016
1006
|
"endLine": 4,
|
|
1017
|
-
"exported":
|
|
1007
|
+
"exported": true,
|
|
1018
1008
|
"line": 1,
|
|
1019
1009
|
"name": "Config",
|
|
1020
1010
|
"type": "type",
|
|
@@ -1031,7 +1021,7 @@ describe('Go', () => {
|
|
|
1031
1021
|
[
|
|
1032
1022
|
{
|
|
1033
1023
|
"endLine": 3,
|
|
1034
|
-
"exported":
|
|
1024
|
+
"exported": true,
|
|
1035
1025
|
"line": 1,
|
|
1036
1026
|
"name": "Reader",
|
|
1037
1027
|
"type": "type",
|
|
@@ -1046,7 +1036,7 @@ describe('Go', () => {
|
|
|
1046
1036
|
[
|
|
1047
1037
|
{
|
|
1048
1038
|
"endLine": 1,
|
|
1049
|
-
"exported":
|
|
1039
|
+
"exported": true,
|
|
1050
1040
|
"line": 1,
|
|
1051
1041
|
"name": "MaxRetries",
|
|
1052
1042
|
"type": "const",
|
|
@@ -1061,7 +1051,7 @@ describe('Go', () => {
|
|
|
1061
1051
|
[
|
|
1062
1052
|
{
|
|
1063
1053
|
"endLine": 1,
|
|
1064
|
-
"exported":
|
|
1054
|
+
"exported": true,
|
|
1065
1055
|
"line": 1,
|
|
1066
1056
|
"name": "DefaultTimeout",
|
|
1067
1057
|
"type": "const",
|
|
@@ -1084,7 +1074,7 @@ describe('Go', () => {
|
|
|
1084
1074
|
[
|
|
1085
1075
|
{
|
|
1086
1076
|
"endLine": 9,
|
|
1087
|
-
"exported":
|
|
1077
|
+
"exported": true,
|
|
1088
1078
|
"line": 1,
|
|
1089
1079
|
"name": "ProcessData",
|
|
1090
1080
|
"type": "function",
|
|
@@ -1411,4 +1401,743 @@ declare const CONFIG: { url: string }`;
|
|
|
1411
1401
|
`);
|
|
1412
1402
|
});
|
|
1413
1403
|
});
|
|
1404
|
+
// ============================================================================
|
|
1405
|
+
// Zig Tests
|
|
1406
|
+
// ============================================================================
|
|
1407
|
+
describe('Zig', () => {
|
|
1408
|
+
test('pub function is exported', async () => {
|
|
1409
|
+
const code = `pub fn calculate(a: i32, b: i32) i32 {
|
|
1410
|
+
const sum = a + b;
|
|
1411
|
+
const product = a * b;
|
|
1412
|
+
const diff = a - b;
|
|
1413
|
+
const result = sum + product;
|
|
1414
|
+
return result + diff;
|
|
1415
|
+
}`;
|
|
1416
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1417
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1418
|
+
[
|
|
1419
|
+
{
|
|
1420
|
+
"endLine": 7,
|
|
1421
|
+
"exported": true,
|
|
1422
|
+
"line": 1,
|
|
1423
|
+
"name": "calculate",
|
|
1424
|
+
"type": "function",
|
|
1425
|
+
},
|
|
1426
|
+
]
|
|
1427
|
+
`);
|
|
1428
|
+
});
|
|
1429
|
+
test('private function not exported', async () => {
|
|
1430
|
+
const code = `fn helper(x: i32) i32 {
|
|
1431
|
+
const a = x * 2;
|
|
1432
|
+
const b = a + 1;
|
|
1433
|
+
const c = b - 3;
|
|
1434
|
+
const d = c * 4;
|
|
1435
|
+
return d;
|
|
1436
|
+
}`;
|
|
1437
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1438
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1439
|
+
[
|
|
1440
|
+
{
|
|
1441
|
+
"endLine": 7,
|
|
1442
|
+
"exported": false,
|
|
1443
|
+
"line": 1,
|
|
1444
|
+
"name": "helper",
|
|
1445
|
+
"type": "function",
|
|
1446
|
+
},
|
|
1447
|
+
]
|
|
1448
|
+
`);
|
|
1449
|
+
});
|
|
1450
|
+
test('pub const is exported', async () => {
|
|
1451
|
+
const code = `pub const MAX_SIZE: usize = 1024;`;
|
|
1452
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1453
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1454
|
+
[
|
|
1455
|
+
{
|
|
1456
|
+
"endLine": 1,
|
|
1457
|
+
"exported": true,
|
|
1458
|
+
"line": 1,
|
|
1459
|
+
"name": "MAX_SIZE",
|
|
1460
|
+
"type": "const",
|
|
1461
|
+
},
|
|
1462
|
+
]
|
|
1463
|
+
`);
|
|
1464
|
+
});
|
|
1465
|
+
test('private const not included', async () => {
|
|
1466
|
+
const code = `const internal_value: i32 = 42;`;
|
|
1467
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1468
|
+
expect(defs).toMatchInlineSnapshot(`[]`);
|
|
1469
|
+
});
|
|
1470
|
+
test('pub var not included (only const)', async () => {
|
|
1471
|
+
const code = `pub var mutable_value: i32 = 42;`;
|
|
1472
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1473
|
+
expect(defs).toMatchInlineSnapshot(`[]`);
|
|
1474
|
+
});
|
|
1475
|
+
test('struct declaration is class', async () => {
|
|
1476
|
+
const code = `pub const Config = struct {
|
|
1477
|
+
name: []const u8,
|
|
1478
|
+
value: i32,
|
|
1479
|
+
enabled: bool,
|
|
1480
|
+
};`;
|
|
1481
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1482
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1483
|
+
[
|
|
1484
|
+
{
|
|
1485
|
+
"endLine": 5,
|
|
1486
|
+
"exported": true,
|
|
1487
|
+
"line": 1,
|
|
1488
|
+
"name": "Config",
|
|
1489
|
+
"type": "struct",
|
|
1490
|
+
},
|
|
1491
|
+
]
|
|
1492
|
+
`);
|
|
1493
|
+
});
|
|
1494
|
+
test('enum declaration', async () => {
|
|
1495
|
+
const code = `pub const Status = enum {
|
|
1496
|
+
pending,
|
|
1497
|
+
running,
|
|
1498
|
+
completed,
|
|
1499
|
+
failed,
|
|
1500
|
+
};`;
|
|
1501
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1502
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1503
|
+
[
|
|
1504
|
+
{
|
|
1505
|
+
"endLine": 6,
|
|
1506
|
+
"exported": true,
|
|
1507
|
+
"line": 1,
|
|
1508
|
+
"name": "Status",
|
|
1509
|
+
"type": "enum",
|
|
1510
|
+
},
|
|
1511
|
+
]
|
|
1512
|
+
`);
|
|
1513
|
+
});
|
|
1514
|
+
test('union declaration is class', async () => {
|
|
1515
|
+
const code = `pub const Result = union(enum) {
|
|
1516
|
+
ok: i32,
|
|
1517
|
+
err: []const u8,
|
|
1518
|
+
};`;
|
|
1519
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1520
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1521
|
+
[
|
|
1522
|
+
{
|
|
1523
|
+
"endLine": 4,
|
|
1524
|
+
"exported": true,
|
|
1525
|
+
"line": 1,
|
|
1526
|
+
"name": "Result",
|
|
1527
|
+
"type": "union",
|
|
1528
|
+
},
|
|
1529
|
+
]
|
|
1530
|
+
`);
|
|
1531
|
+
});
|
|
1532
|
+
test('test declaration with string name', async () => {
|
|
1533
|
+
const code = `test "add function" {
|
|
1534
|
+
const result = add(2, 3);
|
|
1535
|
+
const expected = 5;
|
|
1536
|
+
const check = result == expected;
|
|
1537
|
+
const msg = "test failed";
|
|
1538
|
+
try std.testing.expect(check);
|
|
1539
|
+
}`;
|
|
1540
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1541
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1542
|
+
[
|
|
1543
|
+
{
|
|
1544
|
+
"endLine": 7,
|
|
1545
|
+
"exported": false,
|
|
1546
|
+
"line": 1,
|
|
1547
|
+
"name": "add function",
|
|
1548
|
+
"type": "function",
|
|
1549
|
+
},
|
|
1550
|
+
]
|
|
1551
|
+
`);
|
|
1552
|
+
});
|
|
1553
|
+
test('small function excluded', async () => {
|
|
1554
|
+
const code = `pub fn add(a: i32, b: i32) i32 {
|
|
1555
|
+
return a + b;
|
|
1556
|
+
}`;
|
|
1557
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1558
|
+
expect(defs).toMatchInlineSnapshot(`[]`);
|
|
1559
|
+
});
|
|
1560
|
+
test('comptime function', async () => {
|
|
1561
|
+
const code = `pub fn comptimeFunc(comptime T: type) type {
|
|
1562
|
+
return struct {
|
|
1563
|
+
value: T,
|
|
1564
|
+
count: usize,
|
|
1565
|
+
flag: bool,
|
|
1566
|
+
};
|
|
1567
|
+
}`;
|
|
1568
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1569
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1570
|
+
[
|
|
1571
|
+
{
|
|
1572
|
+
"endLine": 7,
|
|
1573
|
+
"exported": true,
|
|
1574
|
+
"line": 1,
|
|
1575
|
+
"name": "comptimeFunc",
|
|
1576
|
+
"type": "function",
|
|
1577
|
+
},
|
|
1578
|
+
]
|
|
1579
|
+
`);
|
|
1580
|
+
});
|
|
1581
|
+
test('extern function', async () => {
|
|
1582
|
+
const code = `pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;`;
|
|
1583
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1584
|
+
expect(defs).toMatchInlineSnapshot(`[]`);
|
|
1585
|
+
});
|
|
1586
|
+
test('error set', async () => {
|
|
1587
|
+
const code = `pub const FileError = error{
|
|
1588
|
+
NotFound,
|
|
1589
|
+
AccessDenied,
|
|
1590
|
+
OutOfMemory,
|
|
1591
|
+
InvalidPath,
|
|
1592
|
+
};`;
|
|
1593
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1594
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1595
|
+
[
|
|
1596
|
+
{
|
|
1597
|
+
"endLine": 6,
|
|
1598
|
+
"exported": true,
|
|
1599
|
+
"line": 1,
|
|
1600
|
+
"name": "FileError",
|
|
1601
|
+
"type": "const",
|
|
1602
|
+
},
|
|
1603
|
+
]
|
|
1604
|
+
`);
|
|
1605
|
+
});
|
|
1606
|
+
test('packed struct', async () => {
|
|
1607
|
+
const code = `pub const PackedData = packed struct {
|
|
1608
|
+
flags: u4,
|
|
1609
|
+
count: u4,
|
|
1610
|
+
value: u8,
|
|
1611
|
+
extra: u16,
|
|
1612
|
+
};`;
|
|
1613
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1614
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1615
|
+
[
|
|
1616
|
+
{
|
|
1617
|
+
"endLine": 6,
|
|
1618
|
+
"exported": true,
|
|
1619
|
+
"line": 1,
|
|
1620
|
+
"name": "PackedData",
|
|
1621
|
+
"type": "struct",
|
|
1622
|
+
},
|
|
1623
|
+
]
|
|
1624
|
+
`);
|
|
1625
|
+
});
|
|
1626
|
+
test('multiple definitions in file', async () => {
|
|
1627
|
+
const code = `pub const MAX_SIZE: usize = 1024;
|
|
1628
|
+
pub const Config = struct {
|
|
1629
|
+
name: []const u8,
|
|
1630
|
+
value: i32,
|
|
1631
|
+
};
|
|
1632
|
+
pub fn process(cfg: Config) void {
|
|
1633
|
+
const x = cfg.value;
|
|
1634
|
+
const y = x * 2;
|
|
1635
|
+
const z = y + 1;
|
|
1636
|
+
_ = z;
|
|
1637
|
+
return;
|
|
1638
|
+
}`;
|
|
1639
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1640
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1641
|
+
[
|
|
1642
|
+
{
|
|
1643
|
+
"endLine": 1,
|
|
1644
|
+
"exported": true,
|
|
1645
|
+
"line": 1,
|
|
1646
|
+
"name": "MAX_SIZE",
|
|
1647
|
+
"type": "const",
|
|
1648
|
+
},
|
|
1649
|
+
{
|
|
1650
|
+
"endLine": 5,
|
|
1651
|
+
"exported": true,
|
|
1652
|
+
"line": 2,
|
|
1653
|
+
"name": "Config",
|
|
1654
|
+
"type": "struct",
|
|
1655
|
+
},
|
|
1656
|
+
{
|
|
1657
|
+
"endLine": 12,
|
|
1658
|
+
"exported": true,
|
|
1659
|
+
"line": 6,
|
|
1660
|
+
"name": "process",
|
|
1661
|
+
"type": "function",
|
|
1662
|
+
},
|
|
1663
|
+
]
|
|
1664
|
+
`);
|
|
1665
|
+
});
|
|
1666
|
+
test('extern function has extern flag', async () => {
|
|
1667
|
+
const code = `pub extern "c" fn processData(data: [*]u8, len: usize) callconv(.C) void {
|
|
1668
|
+
var i: usize = 0;
|
|
1669
|
+
while (i < len) : (i += 1) {
|
|
1670
|
+
data[i] = 0;
|
|
1671
|
+
}
|
|
1672
|
+
return;
|
|
1673
|
+
}`;
|
|
1674
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1675
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1676
|
+
[
|
|
1677
|
+
{
|
|
1678
|
+
"endLine": 7,
|
|
1679
|
+
"exported": true,
|
|
1680
|
+
"extern": true,
|
|
1681
|
+
"line": 1,
|
|
1682
|
+
"name": "processData",
|
|
1683
|
+
"type": "function",
|
|
1684
|
+
},
|
|
1685
|
+
]
|
|
1686
|
+
`);
|
|
1687
|
+
});
|
|
1688
|
+
test('non-extern function has no extern flag', async () => {
|
|
1689
|
+
const code = `pub fn normalFunction(x: i32) i32 {
|
|
1690
|
+
const a = x * 2;
|
|
1691
|
+
const b = a + 1;
|
|
1692
|
+
const c = b - 3;
|
|
1693
|
+
const d = c * 4;
|
|
1694
|
+
return d;
|
|
1695
|
+
}`;
|
|
1696
|
+
const defs = await getDefinitions(code, 'zig');
|
|
1697
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1698
|
+
[
|
|
1699
|
+
{
|
|
1700
|
+
"endLine": 7,
|
|
1701
|
+
"exported": true,
|
|
1702
|
+
"line": 1,
|
|
1703
|
+
"name": "normalFunction",
|
|
1704
|
+
"type": "function",
|
|
1705
|
+
},
|
|
1706
|
+
]
|
|
1707
|
+
`);
|
|
1708
|
+
});
|
|
1709
|
+
});
|
|
1710
|
+
// C/C++ Tests
|
|
1711
|
+
// ============================================================================
|
|
1712
|
+
describe('C++', () => {
|
|
1713
|
+
test('large function', async () => {
|
|
1714
|
+
const code = `int calculateSum(int arr[], int size) {
|
|
1715
|
+
int sum = 0;
|
|
1716
|
+
for (int i = 0; i < size; i++) {
|
|
1717
|
+
sum += arr[i];
|
|
1718
|
+
}
|
|
1719
|
+
return sum;
|
|
1720
|
+
}`;
|
|
1721
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1722
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1723
|
+
[
|
|
1724
|
+
{
|
|
1725
|
+
"endLine": 7,
|
|
1726
|
+
"exported": false,
|
|
1727
|
+
"line": 1,
|
|
1728
|
+
"name": "calculateSum",
|
|
1729
|
+
"type": "function",
|
|
1730
|
+
},
|
|
1731
|
+
]
|
|
1732
|
+
`);
|
|
1733
|
+
});
|
|
1734
|
+
test('small function excluded', async () => {
|
|
1735
|
+
const code = `int add(int a, int b) {
|
|
1736
|
+
return a + b;
|
|
1737
|
+
}`;
|
|
1738
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1739
|
+
expect(defs).toMatchInlineSnapshot(`[]`);
|
|
1740
|
+
});
|
|
1741
|
+
test('class definition', async () => {
|
|
1742
|
+
const code = `class Calculator {
|
|
1743
|
+
public:
|
|
1744
|
+
int add(int a, int b) {
|
|
1745
|
+
return a + b;
|
|
1746
|
+
}
|
|
1747
|
+
private:
|
|
1748
|
+
int result;
|
|
1749
|
+
};`;
|
|
1750
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1751
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1752
|
+
[
|
|
1753
|
+
{
|
|
1754
|
+
"endLine": 8,
|
|
1755
|
+
"exported": false,
|
|
1756
|
+
"line": 1,
|
|
1757
|
+
"name": "Calculator",
|
|
1758
|
+
"type": "class",
|
|
1759
|
+
},
|
|
1760
|
+
]
|
|
1761
|
+
`);
|
|
1762
|
+
});
|
|
1763
|
+
test('struct definition', async () => {
|
|
1764
|
+
const code = `struct Point {
|
|
1765
|
+
int x;
|
|
1766
|
+
int y;
|
|
1767
|
+
int z;
|
|
1768
|
+
int w;
|
|
1769
|
+
int v;
|
|
1770
|
+
};`;
|
|
1771
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1772
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1773
|
+
[
|
|
1774
|
+
{
|
|
1775
|
+
"endLine": 7,
|
|
1776
|
+
"exported": false,
|
|
1777
|
+
"line": 1,
|
|
1778
|
+
"name": "Point",
|
|
1779
|
+
"type": "struct",
|
|
1780
|
+
},
|
|
1781
|
+
]
|
|
1782
|
+
`);
|
|
1783
|
+
});
|
|
1784
|
+
test('enum definition', async () => {
|
|
1785
|
+
const code = `enum Color {
|
|
1786
|
+
RED,
|
|
1787
|
+
GREEN,
|
|
1788
|
+
BLUE,
|
|
1789
|
+
ALPHA
|
|
1790
|
+
};`;
|
|
1791
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1792
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1793
|
+
[
|
|
1794
|
+
{
|
|
1795
|
+
"endLine": 6,
|
|
1796
|
+
"exported": false,
|
|
1797
|
+
"line": 1,
|
|
1798
|
+
"name": "Color",
|
|
1799
|
+
"type": "enum",
|
|
1800
|
+
},
|
|
1801
|
+
]
|
|
1802
|
+
`);
|
|
1803
|
+
});
|
|
1804
|
+
test('enum class (C++11)', async () => {
|
|
1805
|
+
const code = `enum class Status {
|
|
1806
|
+
Pending,
|
|
1807
|
+
Running,
|
|
1808
|
+
Complete,
|
|
1809
|
+
Failed
|
|
1810
|
+
};`;
|
|
1811
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1812
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1813
|
+
[
|
|
1814
|
+
{
|
|
1815
|
+
"endLine": 6,
|
|
1816
|
+
"exported": false,
|
|
1817
|
+
"line": 1,
|
|
1818
|
+
"name": "Status",
|
|
1819
|
+
"type": "enum",
|
|
1820
|
+
},
|
|
1821
|
+
]
|
|
1822
|
+
`);
|
|
1823
|
+
});
|
|
1824
|
+
test('typedef', async () => {
|
|
1825
|
+
const code = `typedef unsigned long ulong;`;
|
|
1826
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1827
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1828
|
+
[
|
|
1829
|
+
{
|
|
1830
|
+
"endLine": 1,
|
|
1831
|
+
"exported": false,
|
|
1832
|
+
"line": 1,
|
|
1833
|
+
"name": "ulong",
|
|
1834
|
+
"type": "type",
|
|
1835
|
+
},
|
|
1836
|
+
]
|
|
1837
|
+
`);
|
|
1838
|
+
});
|
|
1839
|
+
test('using alias (C++11)', async () => {
|
|
1840
|
+
const code = `using StringList = std::vector<std::string>;`;
|
|
1841
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1842
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1843
|
+
[
|
|
1844
|
+
{
|
|
1845
|
+
"endLine": 1,
|
|
1846
|
+
"exported": false,
|
|
1847
|
+
"line": 1,
|
|
1848
|
+
"name": "StringList",
|
|
1849
|
+
"type": "type",
|
|
1850
|
+
},
|
|
1851
|
+
]
|
|
1852
|
+
`);
|
|
1853
|
+
});
|
|
1854
|
+
test('template function', async () => {
|
|
1855
|
+
const code = `template<typename T>
|
|
1856
|
+
T maximum(T a, T b) {
|
|
1857
|
+
if (a > b) {
|
|
1858
|
+
return a;
|
|
1859
|
+
} else {
|
|
1860
|
+
return b;
|
|
1861
|
+
}
|
|
1862
|
+
}`;
|
|
1863
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1864
|
+
expect(defs).toMatchInlineSnapshot(`[]`);
|
|
1865
|
+
});
|
|
1866
|
+
test('template class', async () => {
|
|
1867
|
+
const code = `template<typename T>
|
|
1868
|
+
class Container {
|
|
1869
|
+
public:
|
|
1870
|
+
T value;
|
|
1871
|
+
void set(T v) { value = v; }
|
|
1872
|
+
T get() { return value; }
|
|
1873
|
+
};`;
|
|
1874
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1875
|
+
expect(defs).toMatchInlineSnapshot(`[]`);
|
|
1876
|
+
});
|
|
1877
|
+
test('namespace function', async () => {
|
|
1878
|
+
const code = `namespace utils {
|
|
1879
|
+
int helper(int x) {
|
|
1880
|
+
int a = x * 2;
|
|
1881
|
+
int b = a + 1;
|
|
1882
|
+
int c = b - 3;
|
|
1883
|
+
return c;
|
|
1884
|
+
}
|
|
1885
|
+
}`;
|
|
1886
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1887
|
+
expect(defs).toMatchInlineSnapshot(`[]`);
|
|
1888
|
+
});
|
|
1889
|
+
test('static function', async () => {
|
|
1890
|
+
const code = `static int internalFunc(int x) {
|
|
1891
|
+
int result = x;
|
|
1892
|
+
result *= 2;
|
|
1893
|
+
result += 10;
|
|
1894
|
+
result -= 5;
|
|
1895
|
+
return result;
|
|
1896
|
+
}`;
|
|
1897
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1898
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1899
|
+
[
|
|
1900
|
+
{
|
|
1901
|
+
"endLine": 7,
|
|
1902
|
+
"exported": false,
|
|
1903
|
+
"line": 1,
|
|
1904
|
+
"name": "internalFunc",
|
|
1905
|
+
"type": "function",
|
|
1906
|
+
},
|
|
1907
|
+
]
|
|
1908
|
+
`);
|
|
1909
|
+
});
|
|
1910
|
+
test('const global', async () => {
|
|
1911
|
+
const code = `const int MAX_SIZE = 1024;`;
|
|
1912
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1913
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1914
|
+
[
|
|
1915
|
+
{
|
|
1916
|
+
"endLine": 1,
|
|
1917
|
+
"exported": false,
|
|
1918
|
+
"line": 1,
|
|
1919
|
+
"name": "MAX_SIZE",
|
|
1920
|
+
"type": "const",
|
|
1921
|
+
},
|
|
1922
|
+
]
|
|
1923
|
+
`);
|
|
1924
|
+
});
|
|
1925
|
+
test('multiple definitions', async () => {
|
|
1926
|
+
const code = `struct Point {
|
|
1927
|
+
int x;
|
|
1928
|
+
int y;
|
|
1929
|
+
int z;
|
|
1930
|
+
int w;
|
|
1931
|
+
};
|
|
1932
|
+
|
|
1933
|
+
enum Color { RED, GREEN, BLUE };
|
|
1934
|
+
|
|
1935
|
+
int distance(Point a, Point b) {
|
|
1936
|
+
int dx = a.x - b.x;
|
|
1937
|
+
int dy = a.y - b.y;
|
|
1938
|
+
int dz = a.z - b.z;
|
|
1939
|
+
return dx + dy + dz;
|
|
1940
|
+
}`;
|
|
1941
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1942
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1943
|
+
[
|
|
1944
|
+
{
|
|
1945
|
+
"endLine": 6,
|
|
1946
|
+
"exported": false,
|
|
1947
|
+
"line": 1,
|
|
1948
|
+
"name": "Point",
|
|
1949
|
+
"type": "struct",
|
|
1950
|
+
},
|
|
1951
|
+
{
|
|
1952
|
+
"endLine": 8,
|
|
1953
|
+
"exported": false,
|
|
1954
|
+
"line": 8,
|
|
1955
|
+
"name": "Color",
|
|
1956
|
+
"type": "enum",
|
|
1957
|
+
},
|
|
1958
|
+
{
|
|
1959
|
+
"endLine": 15,
|
|
1960
|
+
"exported": false,
|
|
1961
|
+
"line": 10,
|
|
1962
|
+
"name": "distance",
|
|
1963
|
+
"type": "function",
|
|
1964
|
+
},
|
|
1965
|
+
]
|
|
1966
|
+
`);
|
|
1967
|
+
});
|
|
1968
|
+
test('forward declaration ignored', async () => {
|
|
1969
|
+
const code = `class ForwardDeclared;
|
|
1970
|
+
struct AnotherForward;`;
|
|
1971
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1972
|
+
expect(defs).toMatchInlineSnapshot(`[]`);
|
|
1973
|
+
});
|
|
1974
|
+
test('function with pointer return', async () => {
|
|
1975
|
+
const code = `int* createArray(int size) {
|
|
1976
|
+
int* arr = new int[size];
|
|
1977
|
+
for (int i = 0; i < size; i++) {
|
|
1978
|
+
arr[i] = 0;
|
|
1979
|
+
}
|
|
1980
|
+
return arr;
|
|
1981
|
+
}`;
|
|
1982
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
1983
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
1984
|
+
[
|
|
1985
|
+
{
|
|
1986
|
+
"endLine": 7,
|
|
1987
|
+
"exported": false,
|
|
1988
|
+
"line": 1,
|
|
1989
|
+
"name": "createArray",
|
|
1990
|
+
"type": "function",
|
|
1991
|
+
},
|
|
1992
|
+
]
|
|
1993
|
+
`);
|
|
1994
|
+
});
|
|
1995
|
+
test('virtual method in class', async () => {
|
|
1996
|
+
const code = `class Base {
|
|
1997
|
+
public:
|
|
1998
|
+
virtual void process() {
|
|
1999
|
+
int x = 1;
|
|
2000
|
+
int y = 2;
|
|
2001
|
+
int z = x + y;
|
|
2002
|
+
}
|
|
2003
|
+
virtual ~Base() {}
|
|
2004
|
+
};`;
|
|
2005
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
2006
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
2007
|
+
[
|
|
2008
|
+
{
|
|
2009
|
+
"endLine": 9,
|
|
2010
|
+
"exported": false,
|
|
2011
|
+
"line": 1,
|
|
2012
|
+
"name": "Base",
|
|
2013
|
+
"type": "class",
|
|
2014
|
+
},
|
|
2015
|
+
]
|
|
2016
|
+
`);
|
|
2017
|
+
});
|
|
2018
|
+
test('C-style header declarations', async () => {
|
|
2019
|
+
const code = `#ifndef HEADER_H
|
|
2020
|
+
#define HEADER_H
|
|
2021
|
+
|
|
2022
|
+
typedef struct {
|
|
2023
|
+
int x;
|
|
2024
|
+
int y;
|
|
2025
|
+
int z;
|
|
2026
|
+
int w;
|
|
2027
|
+
} Point;
|
|
2028
|
+
|
|
2029
|
+
int add(int a, int b);
|
|
2030
|
+
void process(Point* p);
|
|
2031
|
+
|
|
2032
|
+
#endif`;
|
|
2033
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
2034
|
+
expect(defs).toMatchInlineSnapshot(`[]`);
|
|
2035
|
+
});
|
|
2036
|
+
test('lambda not captured as function', async () => {
|
|
2037
|
+
const code = `auto lambda = [](int x) {
|
|
2038
|
+
return x * 2;
|
|
2039
|
+
};`;
|
|
2040
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
2041
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
2042
|
+
[
|
|
2043
|
+
{
|
|
2044
|
+
"endLine": 3,
|
|
2045
|
+
"exported": false,
|
|
2046
|
+
"line": 1,
|
|
2047
|
+
"name": "lambda",
|
|
2048
|
+
"type": "const",
|
|
2049
|
+
},
|
|
2050
|
+
]
|
|
2051
|
+
`);
|
|
2052
|
+
});
|
|
2053
|
+
test('constructor and destructor', async () => {
|
|
2054
|
+
const code = `class Resource {
|
|
2055
|
+
public:
|
|
2056
|
+
Resource() {
|
|
2057
|
+
data = new int[100];
|
|
2058
|
+
size = 100;
|
|
2059
|
+
count = 0;
|
|
2060
|
+
}
|
|
2061
|
+
~Resource() {
|
|
2062
|
+
delete[] data;
|
|
2063
|
+
data = nullptr;
|
|
2064
|
+
size = 0;
|
|
2065
|
+
}
|
|
2066
|
+
private:
|
|
2067
|
+
int* data;
|
|
2068
|
+
int size;
|
|
2069
|
+
int count;
|
|
2070
|
+
};`;
|
|
2071
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
2072
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
2073
|
+
[
|
|
2074
|
+
{
|
|
2075
|
+
"endLine": 17,
|
|
2076
|
+
"exported": false,
|
|
2077
|
+
"line": 1,
|
|
2078
|
+
"name": "Resource",
|
|
2079
|
+
"type": "class",
|
|
2080
|
+
},
|
|
2081
|
+
]
|
|
2082
|
+
`);
|
|
2083
|
+
});
|
|
2084
|
+
test('extern "C" function has extern flag', async () => {
|
|
2085
|
+
const code = `extern "C" void c_callback(int code) {
|
|
2086
|
+
int result = code;
|
|
2087
|
+
result *= 2;
|
|
2088
|
+
result += 10;
|
|
2089
|
+
result -= 5;
|
|
2090
|
+
printf("%d", result);
|
|
2091
|
+
}`;
|
|
2092
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
2093
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
2094
|
+
[
|
|
2095
|
+
{
|
|
2096
|
+
"endLine": 7,
|
|
2097
|
+
"exported": false,
|
|
2098
|
+
"extern": true,
|
|
2099
|
+
"line": 1,
|
|
2100
|
+
"name": "c_callback",
|
|
2101
|
+
"type": "function",
|
|
2102
|
+
},
|
|
2103
|
+
]
|
|
2104
|
+
`);
|
|
2105
|
+
});
|
|
2106
|
+
test('extern variable has extern flag', async () => {
|
|
2107
|
+
const code = `extern int global_counter;`;
|
|
2108
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
2109
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
2110
|
+
[
|
|
2111
|
+
{
|
|
2112
|
+
"endLine": 1,
|
|
2113
|
+
"exported": false,
|
|
2114
|
+
"extern": true,
|
|
2115
|
+
"line": 1,
|
|
2116
|
+
"name": "global_counter",
|
|
2117
|
+
"type": "const",
|
|
2118
|
+
},
|
|
2119
|
+
]
|
|
2120
|
+
`);
|
|
2121
|
+
});
|
|
2122
|
+
test('non-extern function has no extern flag', async () => {
|
|
2123
|
+
const code = `void regularFunc(int x) {
|
|
2124
|
+
int a = x * 2;
|
|
2125
|
+
int b = a + 1;
|
|
2126
|
+
int c = b - 3;
|
|
2127
|
+
printf("%d", c);
|
|
2128
|
+
}`;
|
|
2129
|
+
const defs = await getDefinitions(code, 'cpp');
|
|
2130
|
+
expect(defs).toMatchInlineSnapshot(`
|
|
2131
|
+
[
|
|
2132
|
+
{
|
|
2133
|
+
"endLine": 6,
|
|
2134
|
+
"exported": false,
|
|
2135
|
+
"line": 1,
|
|
2136
|
+
"name": "regularFunc",
|
|
2137
|
+
"type": "function",
|
|
2138
|
+
},
|
|
2139
|
+
]
|
|
2140
|
+
`);
|
|
2141
|
+
});
|
|
2142
|
+
});
|
|
1414
2143
|
//# sourceMappingURL=definitions.test.js.map
|