aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLoris Cro <kappaloris@gmail.com>2022-09-04 22:45:57 +0200
committerLoris Cro <kappaloris@gmail.com>2022-09-04 22:45:57 +0200
commitdbd60e3d296f1c195c4b4d56ca55ecb30444d407 (patch)
treebd35bec73ca68e38ed18eea3f57c1c2fdc5974d3 /lib
parent9ce841a0f04be0aed70d69abad7e4aacca754e3c (diff)
downloadzig-dbd60e3d296f1c195c4b4d56ca55ecb30444d407.tar.gz
zig-dbd60e3d296f1c195c4b4d56ca55ecb30444d407.zip
autodoc: add support for doc tests
Diffstat (limited to 'lib')
-rw-r--r--lib/docs/index.html6
-rw-r--r--lib/docs/main.js15
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/docs/index.html b/lib/docs/index.html
index ddc0ecbfb2..83c09894aa 100644
--- a/lib/docs/index.html
+++ b/lib/docs/index.html
@@ -711,7 +711,11 @@
<h2>Examples</h2>
<ul id="listFnExamples" class="examples"></ul>
</div>
- <div id="sectTests" class="hidden">
+ <div id="sectDocTests" class="hidden">
+ <h2>DocTests</h2>
+ <pre id="docTestsCode"></pre>
+ </div>
+ <div id="sectTests" class="hidden">
<h2>Tests</h2>
<div class="table-container">
<table>
diff --git a/lib/docs/main.js b/lib/docs/main.js
index 28e8b32472..3da9466d8f 100644
--- a/lib/docs/main.js
+++ b/lib/docs/main.js
@@ -13,6 +13,8 @@ var zigAnalysis;
const domListTypes = document.getElementById("listTypes");
const domSectTests = document.getElementById("sectTests");
const domListTests = document.getElementById("listTests");
+ const domSectDocTests = document.getElementById("sectDocTests");
+ const domDocTestsCode = document.getElementById("docTestsCode");
const domSectNamespaces = document.getElementById("sectNamespaces");
const domListNamespaces = document.getElementById("listNamespaces");
const domSectErrSets = document.getElementById("sectErrSets");
@@ -384,6 +386,7 @@ var zigAnalysis;
domSectPkgs.classList.add("hidden");
domSectTypes.classList.add("hidden");
domSectTests.classList.add("hidden");
+ domSectDocTests.classList.add("hidden");
domSectNamespaces.classList.add("hidden");
domSectErrSets.classList.add("hidden");
domSectFns.classList.add("hidden");
@@ -452,6 +455,10 @@ var zigAnalysis;
let lastIsDecl = isDecl(last);
let lastIsType = isType(last);
let lastIsContainerType = isContainerType(last);
+
+ if (lastIsDecl){
+ renderDocTest(last);
+ }
if (lastIsContainerType) {
return renderContainer(last);
@@ -477,6 +484,14 @@ var zigAnalysis;
return renderValue(last);
}
+
+ }
+
+ function renderDocTest(decl) {
+ if (!("decltest" in decl)) return;
+ const astNode = zigAnalysis.astNodes[decl.decltest];
+ domSectDocTests.classList.remove("hidden");
+ domDocTestsCode.innerHTML = astNode.code;
}
function renderUnknownDecl(decl) {