This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
forked from Petix/luacomments
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
6 changed files
with
686 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
local comments = require("comments") | ||
|
||
local expectedTable={ | ||
["--? Can someone explain this?"]={tag="comment",style="custom",type="question",text="Can someone explain this?"}, | ||
["--TODO Fix this!"]={tag="comment",style="custom",type="todo",text="Fix this!"}, | ||
["--bug Crash...."]={tag="comment",style="custom",type="bug",text="Crash...."}, | ||
["--how How does this work?"]={tag="comment",style="custom",type="how",text="How does this work?"}, | ||
["--info Some information..."]={tag="comment",style="custom",type="info",text="Some information..."}, | ||
["--end of `while`"]={tag="comment",style="custom",type="endof",name="while"}, | ||
["--+ Text +--"]={tag="comment",style="custom",type="sep1",text="Text"}, | ||
["--== Text ==--"]={tag="comment",style="custom",type="sep2",text="Text"}, | ||
["--<< Text >>--"]={tag="comment",style="custom",type="sep3",text="Text"}, | ||
["--^ `block name` This sequence does something"]={tag="comment",style="custom",type="startblock",text="This sequence does something",block="block name"}, | ||
["--v `block name` here ends the block"]={tag="comment",style="custom",type="endblock",text="here ends the block",block="block name"}, | ||
["--v here ends the block"]={tag="comment",style="custom",type="endblock",text="here ends the block"}, | ||
["--> other comments"]={tag="comment",style="custom",type="other",text="other comments"} | ||
} | ||
|
||
function testparsecustom(comment,tab) | ||
local t,errno = comments.Parse(comment,"custom") | ||
assert(t,errno) | ||
goDeep(t,tab,comment) | ||
print("Test was successful!") | ||
end | ||
|
||
--recursive | ||
function goDeep(parsed,expected,comment) | ||
for k,v in pairs(expected) do | ||
if(type(v)~="table")then | ||
assert(parsed[k],"Key <".. k .. "> does not exist in parsed table. Text was : "..comment ) | ||
assert(expected[k],"Key <".. k .. "> does not exist in expected table. Text was : "..comment) | ||
assert(parsed[k]==expected[k],"\nNot expected output at key <".. k .."> ! Parsed : '" .. parsed[k] .."' , expected: '" .. expected[k] .."' ! Text was : "..comment ) | ||
else | ||
assert(parsed[k],"No entrie in parsed table with key <".. k ..">! Text was : "..comment) | ||
assert(expected[k],"No entrie in expected table with key <".. k ..">! Text was : "..comment) | ||
goDeep(parsed[k],expected[k],comment) | ||
end | ||
|
||
end | ||
|
||
for k,v in pairs(parsed) do | ||
if(type(v)~="table")then | ||
assert(parsed[k],"Key <".. k .. "> does not exist in parsed table. Text was : "..comment) | ||
assert(expected[k],"Key <".. k .. "> does not exist in expected table. Text was : "..comment) | ||
assert(parsed[k]==expected[k],"\nNot expected output at key <".. k .."> ! Parsed : '" .. parsed[k] .."' , expected: '" .. expected[k] .."' ! Text was : "..comment ) | ||
else | ||
assert(parsed[k],"No entrie in parsed table with key <".. k ..">! Text was : "..comment) | ||
assert(expected[k],"No entrie in expected table with key <".. k ..">! Text was : "..comment) | ||
goDeep(parsed[k],expected[k],comment) | ||
end | ||
|
||
end | ||
end | ||
|
||
function unittest1() | ||
for k,v in pairs(expectedTable) do | ||
testparsecustom(k,v) | ||
end | ||
end | ||
|
||
unittest1() |
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 |
---|---|---|
@@ -0,0 +1,172 @@ | ||
local comments = require("comments") | ||
|
||
|
||
local expectedTables= { | ||
['--| Begins a module/file comment, e.g., "this file does *this*".']={ | ||
type = "module", | ||
style = "explua", | ||
text = 'Begins a module/file comment, e.g., "this file does *this*".', | ||
tag = "comment" | ||
}, | ||
["--by Pedro Miller Rabinovitch <miller@inf.puc-rio.br>"]={ | ||
type = "author", | ||
style = "explua", | ||
text = "Pedro Miller Rabinovitch <miller@inf.puc-rio.br>", | ||
tag = "comment" | ||
}, | ||
["--$Id: myfile.lua,v 1.12 2003/10/17 00:13:56 miller Exp $"]={ | ||
type = "release", | ||
style = "explua", | ||
text = 'myfile.lua,v 1.12 2003/10/17 00:13:56 miller Exp $', | ||
tag = "comment" | ||
}, | ||
["--TODO lots of stuff."]={ | ||
type = "todo", | ||
style = "explua", | ||
text = 'lots of stuff.', | ||
tag = "comment" | ||
}, | ||
["--% This is the purpose of the function, i.e., what it *does*."]={ | ||
type = "descr", | ||
style = "explua", | ||
text = 'This is the purpose of the function, i.e., what it *does*.', | ||
tag = "comment" | ||
}, | ||
["--- And this is the second line, which will concatenated to"]={ | ||
type = "descr", | ||
style = "explua", | ||
text = 'And this is the second line, which will concatenated to', | ||
tag = "comment" | ||
}, | ||
["--- the others."]={ | ||
type = "descr", | ||
style = "explua", | ||
text = 'the others.', | ||
tag = "comment" | ||
}, | ||
["--@ first (string|number|nil) Text of the first parameter"]={ | ||
type = "param", | ||
style = "explua", | ||
var="first", | ||
text = 'Text of the first parameter', | ||
vartype={ | ||
[1]='string', | ||
[2]='number', | ||
[3]='nil', | ||
}, | ||
tag = "comment" | ||
}, | ||
["--@ what (table,number,nil) The second parameter is the table used for an example"]={ | ||
type = "param", | ||
style = "explua", | ||
var="what", | ||
text = 'The second parameter is the table used for an example', | ||
vartype={ | ||
[1]='table', | ||
[2]='number', | ||
[3]='nil', | ||
}, | ||
tag = "comment" | ||
}, | ||
["--@ [...] (any) Optional parameters to the called whatever"]={ | ||
type = "param", | ||
style = "explua", | ||
var="...", | ||
text = 'Optional parameters to the called whatever', | ||
vartype={ | ||
[1]='any' | ||
}, | ||
tag = "comment" | ||
}, | ||
[ "--: (number) Number of whatevers done or nil if an error occured"]={ | ||
type = "return", | ||
style = "explua", | ||
text = 'Number of whatevers done or nil if an error occured', | ||
vartype={ | ||
[1]='number' | ||
}, | ||
tag = "comment" | ||
}, | ||
["--& MyTable It stores some stuff"]={ | ||
type = "table", | ||
style = "explua", | ||
var="MyTable", | ||
text = 'It stores some stuff', | ||
tag = "comment" | ||
}, | ||
["--. MyTable MyKeyInMyTable a important field in my table"]={ | ||
type = "tablefield", | ||
style = "explua", | ||
table="MyTable", | ||
var="MyKeyInMyTable", | ||
text = 'a important field in my table', | ||
tag = "comment" | ||
}, | ||
} | ||
|
||
local expectedTable_withExtendedReturn = { | ||
["--: VARNAME (number) Number of whatevers done or nil if an error occured"]={ | ||
type = "return", | ||
style = "explua", | ||
var = "VARNAME", | ||
text = 'Number of whatevers done or nil if an error occured', | ||
vartype={ | ||
[1]='number' | ||
}, | ||
tag = "comment" | ||
} | ||
} | ||
|
||
|
||
function testparseExpLua(comment,tab,extended) | ||
local t,errno = comments.Parse(comment,"explua",extended) | ||
assert(t,errno) | ||
goDeep(t,tab,comment) | ||
print("Test was successful!") | ||
end | ||
|
||
--recursive | ||
function goDeep(parsed,expected,comment) | ||
for k,v in pairs(expected) do | ||
if(type(v)~="table")then | ||
assert(parsed[k],"Key <".. k .. "> does not exist in parsed table. Text was : "..comment ) | ||
assert(expected[k],"Key <".. k .. "> does not exist in expected table. Text was : "..comment) | ||
assert(parsed[k]==expected[k],"\nNot expected output at key <".. k .."> ! Parsed : '" .. parsed[k] .."' , expected: '" .. expected[k] .."' ! Text was : "..comment ) | ||
|
||
else | ||
assert(parsed[k],"No entrie in parsed table with key <".. k ..">! Text was : "..comment) | ||
assert(expected[k],"No entrie in expected table with key <".. k ..">! Text was : "..comment) | ||
goDeep(parsed[k],expected[k],comment) | ||
end | ||
|
||
end | ||
|
||
for k,v in pairs(parsed) do | ||
if(type(v)~="table")then | ||
assert(parsed[k],"Key <".. k .. "> does not exist in parsed table. Text was : "..comment) | ||
assert(expected[k],"Key <".. k .. "> does not exist in expected table. Text was : "..comment) | ||
assert(parsed[k]==expected[k],"\nNot expected output at key <".. k .."> ! Parsed : '" .. parsed[k] .."' , expected: '" .. expected[k] .."' ! Text was : "..comment ) | ||
|
||
else | ||
assert(parsed[k],"No entrie in parsed table with key <".. k ..">! Text was : "..comment) | ||
assert(expected[k],"No entrie in expected table with key <".. k ..">! Text was : "..comment) | ||
goDeep(parsed[k],expected[k],comment) | ||
end | ||
|
||
end | ||
end | ||
|
||
function unittest1() | ||
for k,v in pairs(expectedTables) do | ||
testparseExpLua(k,v) | ||
end | ||
end | ||
|
||
function unittest2() | ||
for k,v in pairs(expectedTable_withExtendedReturn) do | ||
testparseExpLua(k,v,true) | ||
end | ||
end | ||
|
||
unittest1() | ||
unittest2() |
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
local comments = require("comments") | ||
|
||
|
||
local expectedT = | ||
{ | ||
["--- descr text"]={tag="comment",style="ldoc",text="descr text",type="descr"}, | ||
|
||
["-- @alias M"]={tag="comment",style="ldoc",name="M",type="alias"}, | ||
|
||
["--- @fixme otherwise do what?"]={tag="comment",style="ldoc",text="otherwise do what?",type="fixme"}, | ||
|
||
["--- @todo also handle foo case"]={tag="comment",style="ldoc",text="also handle foo case",type="todo"}, | ||
|
||
["-- @param ... var args!"]={tag="comment",style="ldoc",text="var args!",name="...",type="param"}, | ||
|
||
["-- @usage adsaweass das "]={tag="comment",style="ldoc",text="adsaweass das ",type="usage"}, | ||
|
||
["-- @table stdvars"]={tag="comment",style="ldoc",name="stdvars",type="table"}, | ||
|
||
["-- @section file"]={tag="comment",style="ldoc",name="file",type="section"}, | ||
|
||
["-- @type File"]={tag="comment",style="ldoc",name="File",type="type"}, | ||
|
||
["-- @module mod1"]={tag="comment",style="ldoc",name="mod1",type="module"}, | ||
|
||
["-- @name restable"]={tag="comment",style="ldoc",name="restable",type="name"}, | ||
|
||
["-- @script modtest"]={tag="comment",style="ldoc",name="modtest",type="script"}, | ||
|
||
["-- @tparam string ... var args!"]={tag="comment",style="ldoc",text="var args!",name="...",vartype={"string"},type="tparam"}, | ||
|
||
["-- @tparam string|number ... var args!"]={tag="comment",style="ldoc",text="var args!",name="...",type="tparam",vartype={"string","number"}}, | ||
|
||
["-- @treturn string varname text var args!"]={tag="comment",style="ldoc",text="text var args!",name="varname",vartype={"string"},type="treturn"}, | ||
|
||
["-- @string VAR var args!"]={tag="comment",style="ldoc",text="var args!",name="VAR",vartype={"string"},type="tparam"}, | ||
|
||
["-- string: VAR var args!"]={tag="comment",style="ldoc",text="var args!",name="VAR",vartype={"string"},type="tparam"} | ||
} | ||
|
||
|
||
function testparseLDoc(comment,tab) | ||
local t,errno = comments.Parse(comment,"ldoc") | ||
assert(t,errno) | ||
goDeep(t,tab,comment) | ||
print("Test was successful!") | ||
end | ||
|
||
--recursive | ||
function goDeep(parsed,expected,comment) | ||
for k,v in pairs(expected) do | ||
if(type(v)~="table")then | ||
assert(parsed[k],"Key <".. k .. "> does not exist in parsed table. Text was : "..comment ) | ||
assert(expected[k],"Key <".. k .. "> does not exist in expected table. Text was : "..comment) | ||
assert(parsed[k]==expected[k],"\nNot expected output at key <".. k .."> ! Parsed : '" .. parsed[k] .."' , expected: '" .. expected[k] .."' ! Text was : "..comment ) | ||
-- print(k,expected[k],"********" ,parsed[k],i) | ||
-- print() | ||
else | ||
assert(parsed[k],"No entrie in parsed table with key <".. k ..">! Text was : "..comment) | ||
assert(expected[k],"No entrie in expected table with key <".. k ..">! Text was : "..comment) | ||
goDeep(parsed[k],expected[k],comment) | ||
end | ||
|
||
end | ||
|
||
for k,v in pairs(parsed) do | ||
if(type(v)~="table")then | ||
assert(parsed[k],"Key <".. k .. "> does not exist in parsed table. Text was : "..comment) | ||
assert(expected[k],"Key <".. k .. "> does not exist in expected table. Text was : "..comment) | ||
assert(parsed[k]==expected[k],"\nNot expected output at key <".. k .."> ! Parsed : '" .. parsed[k] .."' , expected: '" .. expected[k] .."' ! Text was : "..comment ) | ||
-- print(k,expected[k],"********" ,parsed[k],i) | ||
-- print() | ||
else | ||
assert(parsed[k],"No entrie in parsed table with key <".. k ..">! Text was : "..comment) | ||
assert(expected[k],"No entrie in expected table with key <".. k ..">! Text was : "..comment) | ||
goDeep(parsed[k],expected[k],comment) | ||
end | ||
|
||
end | ||
end | ||
|
||
function unittest1( ) | ||
for k,v in pairs(expectedT) do | ||
testparseLDoc(k,v) | ||
end | ||
end | ||
|
||
unittest1() |
Oops, something went wrong.