cargo-json-docs 0.5.2 → 0.5.3
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/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +2 -2
- package/dist/lib.js.map +1 -1
- package/package.json +26 -26
- package/src/lib.ts +2 -2
- package/test/item.test.d.ts +1 -1
- package/test/item.test.js +106 -106
- package/test/json.test.d.ts +1 -1
- package/test/json.test.js +23 -23
- package/test/test_crate/Cargo.lock +74 -74
- package/test/test_crate/Cargo.toml +6 -6
- package/test/test_crate/src/lib.rs +49 -49
package/dist/lib.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DocumentationSource } from "./json";
|
|
1
|
+
import { DocumentationSource, getCargoBinPath } from "./json";
|
|
2
2
|
import { CrateDocs } from "./item";
|
|
3
3
|
import { ResolutionError, CargoFormatError } from "./errors";
|
|
4
|
-
export { DocumentationSource, CrateDocs, ResolutionError, CargoFormatError };
|
|
4
|
+
export { DocumentationSource, CrateDocs, ResolutionError, CargoFormatError, getCargoBinPath };
|
|
5
5
|
/**
|
|
6
6
|
* Loads a crate's documentation from source.
|
|
7
7
|
* @param name The name of the crate.
|
package/dist/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC;AAE9F;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAIjD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAG1F"}
|
package/dist/lib.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DocumentationSource } from "./json";
|
|
1
|
+
import { DocumentationSource, getCargoBinPath } from "./json";
|
|
2
2
|
import { CrateDocs } from "./item";
|
|
3
3
|
import { ResolutionError, CargoFormatError } from "./errors";
|
|
4
|
-
export { DocumentationSource, CrateDocs, ResolutionError, CargoFormatError };
|
|
4
|
+
export { DocumentationSource, CrateDocs, ResolutionError, CargoFormatError, getCargoBinPath };
|
|
5
5
|
/**
|
|
6
6
|
* Loads a crate's documentation from source.
|
|
7
7
|
* @param name The name of the crate.
|
package/dist/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC;AAE9F;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IAClC,MAAM,SAAS,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;IACvC,OAAO,IAAI,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AAC1E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,SAAiB,EAAE,IAAY;IAC3E,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cargo-json-docs",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "Programmatic access to Rust crate documentation via cargo JSON output",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"author": "Richard Carson",
|
|
7
|
-
"repository": "https://github.com/rscarson/cargo-json-docs",
|
|
8
|
-
"readme": "readme.md",
|
|
9
|
-
"type": "module",
|
|
10
|
-
"main": "dist/lib.js",
|
|
11
|
-
"types": "dist/lib.d.ts",
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "tsc",
|
|
14
|
-
"test": "vitest",
|
|
15
|
-
"prepublishOnly": "npm run build"
|
|
16
|
-
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"@types/jest": "^30.0.0",
|
|
19
|
-
"@types/node": "^25.0.3",
|
|
20
|
-
"jest": "^30.2.0",
|
|
21
|
-
"node-fetch": "^3.3.2",
|
|
22
|
-
"ts-node": "^10.9.2",
|
|
23
|
-
"typescript": "^5.9.3",
|
|
24
|
-
"vitest": "^4.0.16"
|
|
25
|
-
}
|
|
26
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "cargo-json-docs",
|
|
3
|
+
"version": "0.5.3",
|
|
4
|
+
"description": "Programmatic access to Rust crate documentation via cargo JSON output",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Richard Carson",
|
|
7
|
+
"repository": "https://github.com/rscarson/cargo-json-docs",
|
|
8
|
+
"readme": "readme.md",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "dist/lib.js",
|
|
11
|
+
"types": "dist/lib.d.ts",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"test": "vitest",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/jest": "^30.0.0",
|
|
19
|
+
"@types/node": "^25.0.3",
|
|
20
|
+
"jest": "^30.2.0",
|
|
21
|
+
"node-fetch": "^3.3.2",
|
|
22
|
+
"ts-node": "^10.9.2",
|
|
23
|
+
"typescript": "^5.9.3",
|
|
24
|
+
"vitest": "^4.0.16"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/lib.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DocumentationSource } from "./json";
|
|
1
|
+
import { DocumentationSource, getCargoBinPath } from "./json";
|
|
2
2
|
import { CrateDocs } from "./item";
|
|
3
3
|
import { ResolutionError, CargoFormatError } from "./errors";
|
|
4
4
|
|
|
5
|
-
export { DocumentationSource, CrateDocs, ResolutionError, CargoFormatError };
|
|
5
|
+
export { DocumentationSource, CrateDocs, ResolutionError, CargoFormatError, getCargoBinPath };
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Loads a crate's documentation from source.
|
package/test/item.test.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=item.test.d.ts.map
|
package/test/item.test.js
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
import { test, expect, afterAll } from 'vitest';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import fetch from 'node-fetch';
|
|
4
|
-
import { loadCrate } from '../src/lib';
|
|
5
|
-
import { DocumentationSource } from '../src/json';
|
|
6
|
-
const crateDocs = loadCrate('test/test_crate');
|
|
7
|
-
let testSet = {
|
|
8
|
-
'functions': [
|
|
9
|
-
{ path: 'add', kind: 'function', url: 'https://docs.rs/test_crate/latest/test_crate/fn.add.html' },
|
|
10
|
-
{ path: 'test_crate::add', kind: 'function', url: 'https://docs.rs/test_crate/latest/test_crate/fn.add.html' }
|
|
11
|
-
],
|
|
12
|
-
'external': [
|
|
13
|
-
{ path: 'Serialize', kind: 'trait', url: 'https://docs.rs/test_crate/latest/test_crate/trait.Serialize.html' }
|
|
14
|
-
],
|
|
15
|
-
'structures': [
|
|
16
|
-
{ path: 'TestStructPlain', kind: 'struct', url: 'https://docs.rs/test_crate/latest/test_crate/struct.TestStructPlain.html' },
|
|
17
|
-
{ path: 'TestStructPlain::new', kind: 'function', url: 'https://docs.rs/test_crate/latest/test_crate/struct.TestStructPlain.html#method.new' },
|
|
18
|
-
{ path: 'TestStructPlain::field1', kind: 'struct_field', url: 'https://docs.rs/test_crate/latest/test_crate/struct.TestStructPlain.html#structfield.field1' },
|
|
19
|
-
{ path: 'TestStructTuple::0', kind: 'struct_field', url: 'https://docs.rs/test_crate/latest/test_crate/struct.TestStructTuple.html#structfield.0' }
|
|
20
|
-
],
|
|
21
|
-
'enums': [
|
|
22
|
-
{ path: 'TestEnum', kind: 'enum', url: 'https://docs.rs/test_crate/latest/test_crate/enum.TestEnum.html' },
|
|
23
|
-
{ path: 'TestEnum::VariantThree', kind: 'variant', url: 'https://docs.rs/test_crate/latest/test_crate/enum.TestEnum.html#variant.VariantThree' },
|
|
24
|
-
{ path: 'TestEnum::describe', kind: 'function', url: 'https://docs.rs/test_crate/latest/test_crate/enum.TestEnum.html#method.describe' }
|
|
25
|
-
],
|
|
26
|
-
'modules': [
|
|
27
|
-
{ path: 'module_b', kind: 'module', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/index.html' },
|
|
28
|
-
{ path: 'module_b::inner_b', kind: 'module', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/index.html' }
|
|
29
|
-
],
|
|
30
|
-
'traits': [
|
|
31
|
-
{ path: 'module_b::inner_b::InnerBTrait', kind: 'trait', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/trait.InnerBTrait.html' },
|
|
32
|
-
{ path: 'module_b::inner_b::InnerBTrait::AssociatedType', kind: 'assoc_type', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/trait.InnerBTrait.html#associatedtype.AssociatedType' },
|
|
33
|
-
{ path: 'module_b::inner_b::InnerBTrait::ASSOCIATED_CONST', kind: 'assoc_const', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/trait.InnerBTrait.html#associatedconstant.ASSOCIATED_CONST' },
|
|
34
|
-
{ path: 'module_b::inner_b::InnerBTrait::inner_method', kind: 'functiontype', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/trait.InnerBTrait.html#tymethod.inner_method' },
|
|
35
|
-
{ path: 'module_b::inner_b::InnerBTrait::provided_method', kind: 'function', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/trait.InnerBTrait.html#method.provided_method' }
|
|
36
|
-
],
|
|
37
|
-
'constants': [
|
|
38
|
-
{ path: 'TEST_CONST', kind: 'constant', url: 'https://docs.rs/test_crate/latest/test_crate/constant.TEST_CONST.html' }
|
|
39
|
-
],
|
|
40
|
-
'types': [
|
|
41
|
-
{ path: 'TestTypeAlias', kind: 'type_alias', url: 'https://docs.rs/test_crate/latest/test_crate/type.TestTypeAlias.html' }
|
|
42
|
-
],
|
|
43
|
-
'macros': [
|
|
44
|
-
{ path: 'test_macro', kind: 'macro', url: 'https://docs.rs/test_crate/latest/test_crate/macro.test_macro.html' }
|
|
45
|
-
]
|
|
46
|
-
};
|
|
47
|
-
function testItem(itemPath, expectedKind, expectedUrl) {
|
|
48
|
-
let expectedName = itemPath.includes("::") ? itemPath.split("::").pop() : itemPath;
|
|
49
|
-
const item = crateDocs.get(itemPath);
|
|
50
|
-
expect(item).toBeDefined();
|
|
51
|
-
expect(item.name).toBe(expectedName);
|
|
52
|
-
expect(item.kind).toBe(expectedKind);
|
|
53
|
-
expect(item.url).toBe(expectedUrl);
|
|
54
|
-
}
|
|
55
|
-
function testItems(testCases) {
|
|
56
|
-
for (const testCase of testCases) {
|
|
57
|
-
testItem(testCase.path, testCase.kind, testCase.url);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
test('can get functions', () => testItems(testSet.functions));
|
|
61
|
-
test('can get external items', () => testItems(testSet.external));
|
|
62
|
-
test('can get structures', () => testItems(testSet.structures));
|
|
63
|
-
test('can get enums', () => testItems(testSet.enums));
|
|
64
|
-
test('can get modules', () => testItems(testSet.modules));
|
|
65
|
-
test('can get traits', () => testItems(testSet.traits));
|
|
66
|
-
test('can get constants', () => testItems(testSet.constants));
|
|
67
|
-
test('can get types', () => testItems(testSet.types));
|
|
68
|
-
test('can get macros', () => testItems(testSet.macros));
|
|
69
|
-
// After all tests, verify that the URLs actually exist
|
|
70
|
-
afterAll(() => {
|
|
71
|
-
const source = new DocumentationSource('test/test_crate');
|
|
72
|
-
let result = source.callCargo(['doc', '--no-deps', '--document-private-items', '--lib', '--quiet']);
|
|
73
|
-
expect(result).toBe(0);
|
|
74
|
-
let docPath = source.getDocPath();
|
|
75
|
-
for (const suite in testSet) {
|
|
76
|
-
for (const testCase of testSet[suite]) {
|
|
77
|
-
let url = testCase.url;
|
|
78
|
-
let item = crateDocs.get(testCase.path);
|
|
79
|
-
expect(item).toBeDefined();
|
|
80
|
-
let crate = item.path.split("::")[0];
|
|
81
|
-
if (crate == source.name) {
|
|
82
|
-
// Verify the file exists locally
|
|
83
|
-
let relativePath = url.replace(`https://docs.rs/${source.name}/latest/`, `${docPath}/`);
|
|
84
|
-
let hash = relativePath.split('#')[1] || '';
|
|
85
|
-
if (hash.length > 0) {
|
|
86
|
-
relativePath = relativePath.replace(`#${hash}`, '');
|
|
87
|
-
}
|
|
88
|
-
expect(fs.existsSync(relativePath), `[${suite}] File does not exist: ${relativePath}`).toBe(true);
|
|
89
|
-
// Should contain the hash if applicable
|
|
90
|
-
if (hash.length > 0) {
|
|
91
|
-
let fileContents = fs.readFileSync(relativePath, 'utf-8');
|
|
92
|
-
expect(fileContents.includes(`id="${hash}"`), `[${suite}] File does not contain id="${hash}": ${relativePath}`).toBe(true);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
// Fetch the URL to ensure it exists remotely
|
|
97
|
-
let url = item.url;
|
|
98
|
-
fetch(url).then(response => {
|
|
99
|
-
expect(response.status, `[${suite}] Failed to fetch ${url}`).toBe(200);
|
|
100
|
-
}).catch(err => {
|
|
101
|
-
throw new Error(`Failed to fetch ${url}: ${err}`);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
1
|
+
import { test, expect, afterAll } from 'vitest';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import fetch from 'node-fetch';
|
|
4
|
+
import { loadCrate } from '../src/lib';
|
|
5
|
+
import { DocumentationSource } from '../src/json';
|
|
6
|
+
const crateDocs = loadCrate('test/test_crate');
|
|
7
|
+
let testSet = {
|
|
8
|
+
'functions': [
|
|
9
|
+
{ path: 'add', kind: 'function', url: 'https://docs.rs/test_crate/latest/test_crate/fn.add.html' },
|
|
10
|
+
{ path: 'test_crate::add', kind: 'function', url: 'https://docs.rs/test_crate/latest/test_crate/fn.add.html' }
|
|
11
|
+
],
|
|
12
|
+
'external': [
|
|
13
|
+
{ path: 'Serialize', kind: 'trait', url: 'https://docs.rs/test_crate/latest/test_crate/trait.Serialize.html' }
|
|
14
|
+
],
|
|
15
|
+
'structures': [
|
|
16
|
+
{ path: 'TestStructPlain', kind: 'struct', url: 'https://docs.rs/test_crate/latest/test_crate/struct.TestStructPlain.html' },
|
|
17
|
+
{ path: 'TestStructPlain::new', kind: 'function', url: 'https://docs.rs/test_crate/latest/test_crate/struct.TestStructPlain.html#method.new' },
|
|
18
|
+
{ path: 'TestStructPlain::field1', kind: 'struct_field', url: 'https://docs.rs/test_crate/latest/test_crate/struct.TestStructPlain.html#structfield.field1' },
|
|
19
|
+
{ path: 'TestStructTuple::0', kind: 'struct_field', url: 'https://docs.rs/test_crate/latest/test_crate/struct.TestStructTuple.html#structfield.0' }
|
|
20
|
+
],
|
|
21
|
+
'enums': [
|
|
22
|
+
{ path: 'TestEnum', kind: 'enum', url: 'https://docs.rs/test_crate/latest/test_crate/enum.TestEnum.html' },
|
|
23
|
+
{ path: 'TestEnum::VariantThree', kind: 'variant', url: 'https://docs.rs/test_crate/latest/test_crate/enum.TestEnum.html#variant.VariantThree' },
|
|
24
|
+
{ path: 'TestEnum::describe', kind: 'function', url: 'https://docs.rs/test_crate/latest/test_crate/enum.TestEnum.html#method.describe' }
|
|
25
|
+
],
|
|
26
|
+
'modules': [
|
|
27
|
+
{ path: 'module_b', kind: 'module', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/index.html' },
|
|
28
|
+
{ path: 'module_b::inner_b', kind: 'module', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/index.html' }
|
|
29
|
+
],
|
|
30
|
+
'traits': [
|
|
31
|
+
{ path: 'module_b::inner_b::InnerBTrait', kind: 'trait', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/trait.InnerBTrait.html' },
|
|
32
|
+
{ path: 'module_b::inner_b::InnerBTrait::AssociatedType', kind: 'assoc_type', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/trait.InnerBTrait.html#associatedtype.AssociatedType' },
|
|
33
|
+
{ path: 'module_b::inner_b::InnerBTrait::ASSOCIATED_CONST', kind: 'assoc_const', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/trait.InnerBTrait.html#associatedconstant.ASSOCIATED_CONST' },
|
|
34
|
+
{ path: 'module_b::inner_b::InnerBTrait::inner_method', kind: 'functiontype', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/trait.InnerBTrait.html#tymethod.inner_method' },
|
|
35
|
+
{ path: 'module_b::inner_b::InnerBTrait::provided_method', kind: 'function', url: 'https://docs.rs/test_crate/latest/test_crate/module_b/inner_b/trait.InnerBTrait.html#method.provided_method' }
|
|
36
|
+
],
|
|
37
|
+
'constants': [
|
|
38
|
+
{ path: 'TEST_CONST', kind: 'constant', url: 'https://docs.rs/test_crate/latest/test_crate/constant.TEST_CONST.html' }
|
|
39
|
+
],
|
|
40
|
+
'types': [
|
|
41
|
+
{ path: 'TestTypeAlias', kind: 'type_alias', url: 'https://docs.rs/test_crate/latest/test_crate/type.TestTypeAlias.html' }
|
|
42
|
+
],
|
|
43
|
+
'macros': [
|
|
44
|
+
{ path: 'test_macro', kind: 'macro', url: 'https://docs.rs/test_crate/latest/test_crate/macro.test_macro.html' }
|
|
45
|
+
]
|
|
46
|
+
};
|
|
47
|
+
function testItem(itemPath, expectedKind, expectedUrl) {
|
|
48
|
+
let expectedName = itemPath.includes("::") ? itemPath.split("::").pop() : itemPath;
|
|
49
|
+
const item = crateDocs.get(itemPath);
|
|
50
|
+
expect(item).toBeDefined();
|
|
51
|
+
expect(item.name).toBe(expectedName);
|
|
52
|
+
expect(item.kind).toBe(expectedKind);
|
|
53
|
+
expect(item.url).toBe(expectedUrl);
|
|
54
|
+
}
|
|
55
|
+
function testItems(testCases) {
|
|
56
|
+
for (const testCase of testCases) {
|
|
57
|
+
testItem(testCase.path, testCase.kind, testCase.url);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
test('can get functions', () => testItems(testSet.functions));
|
|
61
|
+
test('can get external items', () => testItems(testSet.external));
|
|
62
|
+
test('can get structures', () => testItems(testSet.structures));
|
|
63
|
+
test('can get enums', () => testItems(testSet.enums));
|
|
64
|
+
test('can get modules', () => testItems(testSet.modules));
|
|
65
|
+
test('can get traits', () => testItems(testSet.traits));
|
|
66
|
+
test('can get constants', () => testItems(testSet.constants));
|
|
67
|
+
test('can get types', () => testItems(testSet.types));
|
|
68
|
+
test('can get macros', () => testItems(testSet.macros));
|
|
69
|
+
// After all tests, verify that the URLs actually exist
|
|
70
|
+
afterAll(() => {
|
|
71
|
+
const source = new DocumentationSource('test/test_crate');
|
|
72
|
+
let result = source.callCargo(['doc', '--no-deps', '--document-private-items', '--lib', '--quiet']);
|
|
73
|
+
expect(result).toBe(0);
|
|
74
|
+
let docPath = source.getDocPath();
|
|
75
|
+
for (const suite in testSet) {
|
|
76
|
+
for (const testCase of testSet[suite]) {
|
|
77
|
+
let url = testCase.url;
|
|
78
|
+
let item = crateDocs.get(testCase.path);
|
|
79
|
+
expect(item).toBeDefined();
|
|
80
|
+
let crate = item.path.split("::")[0];
|
|
81
|
+
if (crate == source.name) {
|
|
82
|
+
// Verify the file exists locally
|
|
83
|
+
let relativePath = url.replace(`https://docs.rs/${source.name}/latest/`, `${docPath}/`);
|
|
84
|
+
let hash = relativePath.split('#')[1] || '';
|
|
85
|
+
if (hash.length > 0) {
|
|
86
|
+
relativePath = relativePath.replace(`#${hash}`, '');
|
|
87
|
+
}
|
|
88
|
+
expect(fs.existsSync(relativePath), `[${suite}] File does not exist: ${relativePath}`).toBe(true);
|
|
89
|
+
// Should contain the hash if applicable
|
|
90
|
+
if (hash.length > 0) {
|
|
91
|
+
let fileContents = fs.readFileSync(relativePath, 'utf-8');
|
|
92
|
+
expect(fileContents.includes(`id="${hash}"`), `[${suite}] File does not contain id="${hash}": ${relativePath}`).toBe(true);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// Fetch the URL to ensure it exists remotely
|
|
97
|
+
let url = item.url;
|
|
98
|
+
fetch(url).then(response => {
|
|
99
|
+
expect(response.status, `[${suite}] Failed to fetch ${url}`).toBe(200);
|
|
100
|
+
}).catch(err => {
|
|
101
|
+
throw new Error(`Failed to fetch ${url}: ${err}`);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
107
|
//# sourceMappingURL=item.test.js.map
|
package/test/json.test.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=json.test.d.ts.map
|
package/test/json.test.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { test, expect } from 'vitest';
|
|
2
|
-
import { DocumentationSource } from '../src/json';
|
|
3
|
-
test('can get modification time', () => {
|
|
4
|
-
const source = new DocumentationSource('test/test_crate');
|
|
5
|
-
const modTime = source.lastModified();
|
|
6
|
-
expect(modTime).toBeInstanceOf(Date);
|
|
7
|
-
expect(modTime.getTime()).toBeGreaterThan(0);
|
|
8
|
-
});
|
|
9
|
-
test('can determine if generation is needed', () => {
|
|
10
|
-
const source = new DocumentationSource('test/test_crate');
|
|
11
|
-
const needsGen = source.shouldGenerate();
|
|
12
|
-
expect(typeof needsGen).toBe('boolean');
|
|
13
|
-
});
|
|
14
|
-
test('can generate JSON', () => {
|
|
15
|
-
const source = new DocumentationSource('test/test_crate');
|
|
16
|
-
source.generateJson();
|
|
17
|
-
let json = source.getJson();
|
|
18
|
-
expect(json).toBeDefined();
|
|
19
|
-
expect(json.index).toBeDefined();
|
|
20
|
-
// Should not be stale
|
|
21
|
-
const needsGenAfter = source.shouldGenerate();
|
|
22
|
-
expect(needsGenAfter).toBe(false);
|
|
23
|
-
}, 10000); // Allow up to 10 seconds for generation
|
|
1
|
+
import { test, expect } from 'vitest';
|
|
2
|
+
import { DocumentationSource } from '../src/json';
|
|
3
|
+
test('can get modification time', () => {
|
|
4
|
+
const source = new DocumentationSource('test/test_crate');
|
|
5
|
+
const modTime = source.lastModified();
|
|
6
|
+
expect(modTime).toBeInstanceOf(Date);
|
|
7
|
+
expect(modTime.getTime()).toBeGreaterThan(0);
|
|
8
|
+
});
|
|
9
|
+
test('can determine if generation is needed', () => {
|
|
10
|
+
const source = new DocumentationSource('test/test_crate');
|
|
11
|
+
const needsGen = source.shouldGenerate();
|
|
12
|
+
expect(typeof needsGen).toBe('boolean');
|
|
13
|
+
});
|
|
14
|
+
test('can generate JSON', () => {
|
|
15
|
+
const source = new DocumentationSource('test/test_crate');
|
|
16
|
+
source.generateJson();
|
|
17
|
+
let json = source.getJson();
|
|
18
|
+
expect(json).toBeDefined();
|
|
19
|
+
expect(json.index).toBeDefined();
|
|
20
|
+
// Should not be stale
|
|
21
|
+
const needsGenAfter = source.shouldGenerate();
|
|
22
|
+
expect(needsGenAfter).toBe(false);
|
|
23
|
+
}, 10000); // Allow up to 10 seconds for generation
|
|
24
24
|
//# sourceMappingURL=json.test.js.map
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
# This file is automatically @generated by Cargo.
|
|
2
|
-
# It is not intended for manual editing.
|
|
3
|
-
version = 4
|
|
4
|
-
|
|
5
|
-
[[package]]
|
|
6
|
-
name = "proc-macro2"
|
|
7
|
-
version = "1.0.105"
|
|
8
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
-
checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7"
|
|
10
|
-
dependencies = [
|
|
11
|
-
"unicode-ident",
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
[[package]]
|
|
15
|
-
name = "quote"
|
|
16
|
-
version = "1.0.43"
|
|
17
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
18
|
-
checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a"
|
|
19
|
-
dependencies = [
|
|
20
|
-
"proc-macro2",
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
[[package]]
|
|
24
|
-
name = "serde"
|
|
25
|
-
version = "1.0.228"
|
|
26
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
-
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
|
28
|
-
dependencies = [
|
|
29
|
-
"serde_core",
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
[[package]]
|
|
33
|
-
name = "serde_core"
|
|
34
|
-
version = "1.0.228"
|
|
35
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
36
|
-
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
|
37
|
-
dependencies = [
|
|
38
|
-
"serde_derive",
|
|
39
|
-
]
|
|
40
|
-
|
|
41
|
-
[[package]]
|
|
42
|
-
name = "serde_derive"
|
|
43
|
-
version = "1.0.228"
|
|
44
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
45
|
-
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|
46
|
-
dependencies = [
|
|
47
|
-
"proc-macro2",
|
|
48
|
-
"quote",
|
|
49
|
-
"syn",
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
[[package]]
|
|
53
|
-
name = "syn"
|
|
54
|
-
version = "2.0.114"
|
|
55
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
56
|
-
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
|
|
57
|
-
dependencies = [
|
|
58
|
-
"proc-macro2",
|
|
59
|
-
"quote",
|
|
60
|
-
"unicode-ident",
|
|
61
|
-
]
|
|
62
|
-
|
|
63
|
-
[[package]]
|
|
64
|
-
name = "test_crate"
|
|
65
|
-
version = "0.1.0"
|
|
66
|
-
dependencies = [
|
|
67
|
-
"serde",
|
|
68
|
-
]
|
|
69
|
-
|
|
70
|
-
[[package]]
|
|
71
|
-
name = "unicode-ident"
|
|
72
|
-
version = "1.0.22"
|
|
73
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
74
|
-
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "proc-macro2"
|
|
7
|
+
version = "1.0.105"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"unicode-ident",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[[package]]
|
|
15
|
+
name = "quote"
|
|
16
|
+
version = "1.0.43"
|
|
17
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
18
|
+
checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a"
|
|
19
|
+
dependencies = [
|
|
20
|
+
"proc-macro2",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "serde"
|
|
25
|
+
version = "1.0.228"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
|
28
|
+
dependencies = [
|
|
29
|
+
"serde_core",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[[package]]
|
|
33
|
+
name = "serde_core"
|
|
34
|
+
version = "1.0.228"
|
|
35
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
36
|
+
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
|
37
|
+
dependencies = [
|
|
38
|
+
"serde_derive",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[[package]]
|
|
42
|
+
name = "serde_derive"
|
|
43
|
+
version = "1.0.228"
|
|
44
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
45
|
+
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|
46
|
+
dependencies = [
|
|
47
|
+
"proc-macro2",
|
|
48
|
+
"quote",
|
|
49
|
+
"syn",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[[package]]
|
|
53
|
+
name = "syn"
|
|
54
|
+
version = "2.0.114"
|
|
55
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
56
|
+
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
|
|
57
|
+
dependencies = [
|
|
58
|
+
"proc-macro2",
|
|
59
|
+
"quote",
|
|
60
|
+
"unicode-ident",
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
[[package]]
|
|
64
|
+
name = "test_crate"
|
|
65
|
+
version = "0.1.0"
|
|
66
|
+
dependencies = [
|
|
67
|
+
"serde",
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
[[package]]
|
|
71
|
+
name = "unicode-ident"
|
|
72
|
+
version = "1.0.22"
|
|
73
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
74
|
+
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "test_crate"
|
|
3
|
-
version = "0.1.0"
|
|
4
|
-
edition = "2024"
|
|
5
|
-
|
|
6
|
-
[dependencies]
|
|
1
|
+
[package]
|
|
2
|
+
name = "test_crate"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
|
|
6
|
+
[dependencies]
|
|
7
7
|
serde = { version = "1.0" }
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
// function
|
|
2
|
-
pub fn add(left: u64, right: u64) -> u64 {
|
|
3
|
-
left + right
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
// re-export
|
|
7
|
-
pub use serde::{Serialize, Deserialize};
|
|
8
|
-
|
|
9
|
-
pub mod nested_module {
|
|
10
|
-
pub use serde::ser::*;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
pub struct TestStructPlain {
|
|
14
|
-
pub field1: u32,
|
|
15
|
-
pub field2: String,
|
|
16
|
-
}
|
|
17
|
-
impl TestStructPlain {
|
|
18
|
-
pub fn new(field1: u32, field2: String) -> Self {
|
|
19
|
-
Self { field1, field2 }
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
impl TestStructPlain {
|
|
23
|
-
pub fn method_plain(&self) -> String {
|
|
24
|
-
format!("field1: {}, field2: {}", self.field1, self.field2)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
pub struct TestStructTuple(pub u32, pub String);
|
|
29
|
-
impl TestStructTuple {
|
|
30
|
-
pub fn new(field1: u32, field2: String) -> Self {
|
|
31
|
-
Self(field1, field2)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
pub const TEST_CONST: u32 = 42;
|
|
36
|
-
pub type TestTypeAlias = u64;
|
|
37
|
-
|
|
38
|
-
mod module_a;
|
|
39
|
-
pub use module_a::TestEnum;
|
|
40
|
-
|
|
41
|
-
pub mod module_b;
|
|
42
|
-
|
|
43
|
-
#[macro_export]
|
|
44
|
-
macro_rules! test_macro {
|
|
45
|
-
($name:ident) => {
|
|
46
|
-
pub fn $name() -> String {
|
|
47
|
-
stringify!($name).to_string()
|
|
48
|
-
}
|
|
49
|
-
};
|
|
1
|
+
// function
|
|
2
|
+
pub fn add(left: u64, right: u64) -> u64 {
|
|
3
|
+
left + right
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// re-export
|
|
7
|
+
pub use serde::{Serialize, Deserialize};
|
|
8
|
+
|
|
9
|
+
pub mod nested_module {
|
|
10
|
+
pub use serde::ser::*;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
pub struct TestStructPlain {
|
|
14
|
+
pub field1: u32,
|
|
15
|
+
pub field2: String,
|
|
16
|
+
}
|
|
17
|
+
impl TestStructPlain {
|
|
18
|
+
pub fn new(field1: u32, field2: String) -> Self {
|
|
19
|
+
Self { field1, field2 }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
impl TestStructPlain {
|
|
23
|
+
pub fn method_plain(&self) -> String {
|
|
24
|
+
format!("field1: {}, field2: {}", self.field1, self.field2)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
pub struct TestStructTuple(pub u32, pub String);
|
|
29
|
+
impl TestStructTuple {
|
|
30
|
+
pub fn new(field1: u32, field2: String) -> Self {
|
|
31
|
+
Self(field1, field2)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
pub const TEST_CONST: u32 = 42;
|
|
36
|
+
pub type TestTypeAlias = u64;
|
|
37
|
+
|
|
38
|
+
mod module_a;
|
|
39
|
+
pub use module_a::TestEnum;
|
|
40
|
+
|
|
41
|
+
pub mod module_b;
|
|
42
|
+
|
|
43
|
+
#[macro_export]
|
|
44
|
+
macro_rules! test_macro {
|
|
45
|
+
($name:ident) => {
|
|
46
|
+
pub fn $name() -> String {
|
|
47
|
+
stringify!($name).to_string()
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
50
|
}
|