forked from OpenZeppelin/solidity-docgen
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
134 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
import test from './utils/test'; | ||
import path from 'path'; | ||
import { buildSite, PageStructure, SiteConfig } from './site'; | ||
import { itemPartialName, render } from './render'; | ||
import { NodeType } from 'solidity-ast/node'; | ||
import { Templates } from './templates'; | ||
// import test from './utils/test'; | ||
// import path from 'path'; | ||
// import { buildSite, PageStructure, SiteConfig } from './site'; | ||
// import { itemPartialName, render } from './render'; | ||
// import { NodeType } from 'solidity-ast/node'; | ||
// import { Templates } from './templates'; | ||
|
||
interface TestSpec extends Templates { | ||
collapseNewlines?: boolean; | ||
} | ||
// interface TestSpec extends Templates { | ||
// collapseNewlines?: boolean; | ||
// } | ||
|
||
/** | ||
* @param contracts The name of the Solidity file whose contents should be considered. | ||
*/ | ||
function testRender(title: string, file: string, spec: TestSpec, expected: string) { | ||
const id = 'index.md'; | ||
const cfg: SiteConfig = { | ||
sourcesDir: 'test-contracts', | ||
exclude: [], | ||
pageExtension: '.md', | ||
pages: (_, f) => path.parse(f.absolutePath).name === file ? id : undefined, | ||
}; | ||
// /** | ||
// * @param contracts The name of the Solidity file whose contents should be considered. | ||
// */ | ||
// function testRender(title: string, file: string, spec: TestSpec, expected: string) { | ||
// const id = 'index.md'; | ||
// const cfg: SiteConfig = { | ||
// sourcesDir: 'test-contracts', | ||
// exclude: [], | ||
// pageExtension: '.md', | ||
// pages: (_, f) => path.parse(f.absolutePath).name === file ? id : undefined, | ||
// }; | ||
|
||
test(title, t => { | ||
const site = buildSite(t.context.build, cfg); | ||
const rendered = render(site, spec, spec.collapseNewlines); | ||
t.is(rendered.length, 1); | ||
t.is(rendered[0]!.contents, expected); | ||
}); | ||
} | ||
// test(title, t => { | ||
// const site = buildSite(t.context.build, cfg); | ||
// const rendered = render(site, spec, spec.collapseNewlines); | ||
// t.is(rendered.length, 1); | ||
// t.is(rendered[0]!.contents, expected); | ||
// }); | ||
// } | ||
|
||
testRender('static page', | ||
'S08_AB', | ||
{ partials: { page: () => 'a page' } }, | ||
'a page', | ||
); | ||
// testRender('static page', | ||
// 'S08_AB', | ||
// { partials: { page: () => 'a page' } }, | ||
// 'a page', | ||
// ); | ||
|
||
testRender('items', | ||
'S08_AB', | ||
{ partials: { page: () => '{{#each items}}{{name}}, {{/each}}' } }, | ||
'A, B, ', | ||
); | ||
// testRender('items', | ||
// 'S08_AB', | ||
// { partials: { page: () => '{{#each items}}{{name}}, {{/each}}' } }, | ||
// 'A, B, ', | ||
// ); | ||
|
||
testRender('partials', | ||
'S08_AB', | ||
{ | ||
partials: { | ||
page: () => '{{#each items}}{{>part}}, {{/each}}', | ||
part: () => '{{name}}', | ||
}, | ||
}, | ||
'A, B, ', | ||
); | ||
// testRender('partials', | ||
// 'S08_AB', | ||
// { | ||
// partials: { | ||
// page: () => '{{#each items}}{{>part}}, {{/each}}', | ||
// part: () => '{{name}}', | ||
// }, | ||
// }, | ||
// 'A, B, ', | ||
// ); | ||
|
||
testRender('item partial', | ||
'S08_AB', | ||
{ | ||
partials: { | ||
page: () => '{{#each items}}{{>item}}, {{/each}}', | ||
contract: () => '{{name}}', | ||
}, | ||
}, | ||
'A, B, ', | ||
); | ||
// testRender('item partial', | ||
// 'S08_AB', | ||
// { | ||
// partials: { | ||
// page: () => '{{#each items}}{{>item}}, {{/each}}', | ||
// contract: () => '{{name}}', | ||
// }, | ||
// }, | ||
// 'A, B, ', | ||
// ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,68 @@ | ||
import test from './utils/test'; | ||
import path from 'path'; | ||
import { PageAssigner, Site, buildSite, pageAssigner, SiteConfig } from './site'; | ||
// import test from './utils/test'; | ||
// import path from 'path'; | ||
// import { PageAssigner, Site, buildSite, pageAssigner, SiteConfig } from './site'; | ||
|
||
interface PageSummary { | ||
id: string; | ||
items: string[]; | ||
} | ||
// interface PageSummary { | ||
// id: string; | ||
// items: string[]; | ||
// } | ||
|
||
/** | ||
* @param files The name of the Solidity file whose contents should be considered. | ||
*/ | ||
function testPages(title: string, opts: { files: string[], assign: PageAssigner, exclude?: string[] }, expected: PageSummary[]) { | ||
test(title, t => { | ||
const { files, assign, exclude = [] } = opts; | ||
const cfg: SiteConfig = { | ||
sourcesDir: 'test-contracts', | ||
exclude, | ||
pageExtension: '.md', | ||
pages: (i, f) => files.includes(path.parse(f.absolutePath).name) ? assign(i, f, cfg) : undefined, | ||
}; | ||
const site = buildSite(t.context.build, cfg); | ||
const pages = site.pages.map(p => ({ | ||
id: p.id, | ||
items: p.items.map(i => i.name), | ||
})).sort((a, b) => a.id.localeCompare(b.id)); | ||
t.deepEqual(pages, expected); | ||
}); | ||
} | ||
// /** | ||
// * @param files The name of the Solidity file whose contents should be considered. | ||
// */ | ||
// function testPages(title: string, opts: { files: string[], assign: PageAssigner, exclude?: string[] }, expected: PageSummary[]) { | ||
// test(title, t => { | ||
// const { files, assign, exclude = [] } = opts; | ||
// const cfg: SiteConfig = { | ||
// sourcesDir: 'test-contracts', | ||
// exclude, | ||
// pageExtension: '.md', | ||
// pages: (i, f) => files.includes(path.parse(f.absolutePath).name) ? assign(i, f, cfg) : undefined, | ||
// }; | ||
// const site = buildSite(t.context.build, cfg); | ||
// const pages = site.pages.map(p => ({ | ||
// id: p.id, | ||
// items: p.items.map(i => i.name), | ||
// })).sort((a, b) => a.id.localeCompare(b.id)); | ||
// t.deepEqual(pages, expected); | ||
// }); | ||
// } | ||
|
||
testPages('assign to single page', | ||
{ | ||
files: ['S08_AB'], | ||
assign: pageAssigner.single, | ||
}, | ||
[{ id: 'index.md', items: ['A', 'B'] }], | ||
); | ||
// testPages('assign to single page', | ||
// { | ||
// files: ['S08_AB'], | ||
// assign: pageAssigner.single, | ||
// }, | ||
// [{ id: 'index.md', items: ['A', 'B'] }], | ||
// ); | ||
|
||
testPages('assign to item pages', | ||
{ | ||
files: ['S08_AB'], | ||
assign: pageAssigner.items, | ||
}, | ||
[ | ||
{ id: 'A.md', items: ['A'] }, | ||
{ id: 'B.md', items: ['B'] }, | ||
], | ||
); | ||
// testPages('assign to item pages', | ||
// { | ||
// files: ['S08_AB'], | ||
// assign: pageAssigner.items, | ||
// }, | ||
// [ | ||
// { id: 'A.md', items: ['A'] }, | ||
// { id: 'B.md', items: ['B'] }, | ||
// ], | ||
// ); | ||
|
||
testPages('assign to file pages', | ||
{ | ||
files: ['S08_AB', 'S08_C'], | ||
assign: pageAssigner.files, | ||
}, | ||
[ | ||
{ id: 'S08_AB.md', items: ['A', 'B'] }, | ||
{ id: 'S08_C.md', items: ['C'] }, | ||
], | ||
); | ||
// testPages('assign to file pages', | ||
// { | ||
// files: ['S08_AB', 'S08_C'], | ||
// assign: pageAssigner.files, | ||
// }, | ||
// [ | ||
// { id: 'S08_AB.md', items: ['A', 'B'] }, | ||
// { id: 'S08_C.md', items: ['C'] }, | ||
// ], | ||
// ); | ||
|
||
testPages('exclude', | ||
{ | ||
files: ['S08_AB', 'S08_E0'], | ||
exclude: ['S08_E0.sol'], | ||
assign: pageAssigner.single, | ||
}, | ||
[{ id: 'index.md', items: ['A', 'B'] }], | ||
); | ||
// testPages('exclude', | ||
// { | ||
// files: ['S08_AB', 'S08_E0'], | ||
// exclude: ['S08_E0.sol'], | ||
// assign: pageAssigner.single, | ||
// }, | ||
// [{ id: 'index.md', items: ['A', 'B'] }], | ||
// ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import _test, { TestFn } from 'ava'; | ||
import hre from 'hardhat'; | ||
import { BuildInfo } from 'hardhat/types'; | ||
import { promises as fs } from 'fs'; | ||
/* It's a way to import the test function from ava and then use it as a type. */ | ||
// import _test, { TestFn } from 'ava'; | ||
// import hre from 'hardhat'; | ||
// import { BuildInfo } from 'hardhat/types'; | ||
// import { promises as fs } from 'fs'; | ||
|
||
interface Context { | ||
build: BuildInfo[]; | ||
} | ||
// interface Context { | ||
// build: BuildInfo[]; | ||
// } | ||
|
||
const test = _test as TestFn<Context>; | ||
// const test = _test as TestFn<Context>; | ||
|
||
test.before('reading build info', async t => { | ||
t.context.build = await Promise.all( | ||
(await hre.artifacts.getBuildInfoPaths()).map(async p => JSON.parse(await fs.readFile(p, 'utf8'))) | ||
); | ||
}); | ||
// test.before('reading build info', async t => { | ||
// t.context.build = await Promise.all( | ||
// (await hre.artifacts.getBuildInfoPaths()).map(async p => JSON.parse(await fs.readFile(p, 'utf8'))) | ||
// ); | ||
// }); | ||
|
||
export default test; | ||
// export default test; |