Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions gap/Parser.gi
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles,
od;
return example_node;
end;
read_session_example := function( is_tested_example )
local temp_string_list, temp_curr_line, temp_pos_comment, is_following_line, item_temp, example_node;
read_session_example := function( is_tested_example, pt_mode )
local temp_string_list, temp_curr_line, temp_pos_comment, is_following_line, item_temp, example_node, incorporate_this_line;
example_node := DocumentationExample( tree );
if is_tested_example = false then
example_node!.is_tested_example := false;
Expand All @@ -438,13 +438,19 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles,
or PositionSublist( temp_curr_line, "@EndLogSession" ) <> fail then
break;
fi;
#! @DONT_SCAN_NEXT_LINE
temp_pos_comment := PositionSublist( temp_curr_line, "#!" );
if temp_pos_comment <> fail then
temp_curr_line := temp_curr_line{[ temp_pos_comment + 2 .. Length( temp_curr_line ) ]};
if Length( temp_curr_line ) >= 1 and temp_curr_line[ 1 ] = ' ' then
Remove( temp_curr_line, 1 );
incorporate_this_line := pt_mode;
if not pt_mode then
#! @DONT_SCAN_NEXT_LINE
temp_pos_comment := PositionSublist( temp_curr_line, "#!" );
if temp_pos_comment <> fail then
incorporate_this_line := true;
temp_curr_line := temp_curr_line{[ temp_pos_comment + 2 .. Length( temp_curr_line ) ]};
if Length( temp_curr_line ) >= 1 and temp_curr_line[ 1 ] = ' ' then
Remove( temp_curr_line, 1 );
fi;
fi;
fi;
if incorporate_this_line then
Add( temp_string_list, temp_curr_line );
fi;
od;
Expand Down Expand Up @@ -699,13 +705,13 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles,
end,
@ExampleSession := function()
local example_node;
example_node := read_session_example( true );
example_node := read_session_example( true, plain_text_mode );
Add( current_item, example_node );
end,
@BeginExampleSession := ~.@ExampleSession,
@LogSession := function()
local example_node;
example_node := read_session_example( false );
example_node := read_session_example( false, plain_text_mode );
Add( current_item, example_node );
end,
@BeginLogSession := ~.@LogSession
Expand Down
73 changes: 73 additions & 0 deletions tst/plaintextmode.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#############################################################################
##
## AutoDoc package
##
## Test the behavior of AutoDoc in plain text mode
##
## Copyright 2018
## Contributed by Glen Whitney, studioinfinity.org
##
## Licensed under the GPL 2 or later.
##
#############################################################################

gap> START_TEST( "AutoDoc package: plaintextmode.tst" );
gap> tmpdir := DirectoryTemporary();;
gap> SetInfoLevel( InfoGAPDoc, 0 );
gap> AutoDocWorksheet( "tst/plaintextmode.tst", rec( dir := tmpdir ) );
gap> chap1 := Filename(tmpdir, "chap1.html");;
gap> IsReadableFile(chap1);
true
gap> ReadAll(InputTextFile(chap1));
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<!DOCTYPE html PUBLIC \"-//W3C/\
/DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1\
-strict.dtd\">\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"\
>\n<head>\n<title>GAP (Plain_Text_Mode_Test) - Chapter 1: Test</title>\n<meta \
http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n<meta nam\
e=\"generator\" content=\"GAPDoc2HTML\" />\n<link rel=\"stylesheet\" type=\"te\
xt/css\" href=\"manual.css\" />\n<script src=\"manual.js\" type=\"text/javascr\
ipt\"></script>\n<script type=\"text/javascript\">overwriteStyle();</script>\n\
</head>\n<body class=\"chap1\" onload=\"jscontent()\">\n\n\n<div class=\"chli\
nktop\"><span class=\"chlink1\">Goto Chapter: </span><a href=\"chap0.html\">To\
p</a> <a href=\"chap1.html\">1</a> </div>\n\n<div class=\"chlinkprevnexttop\
\">&nbsp;<a href=\"chap0.html\">[Top of Book]</a>&nbsp; <a href=\"chap0.html#\
contents\">[Contents]</a>&nbsp; &nbsp;<a href=\"chap0.html\">[Previous Chapte\
r]</a>&nbsp; </div>\n\n<p id=\"mathjaxlink\" class=\"pcenter\"><a href=\"chap\
1_mj.html\">[MathJax on]</a></p>\n<p><a id=\"X87712F9D8732193C\" name=\"X87712\
F9D8732193C\"></a></p>\n<div class=\"ChapSects\"><a href=\"chap1.html#X87712F9\
D8732193C\">1 <span class=\"Heading\">Test</span></a>\n</div>\n\n<h3>1 <span c\
lass=\"Heading\">Test</span></h3>\n\n<p>This is dummy text</p>\n\n\n<div class\
=\"example\"><pre>\n<span class=\"GAPprompt\">gap&gt;</span> <span class=\"GAP\
input\">S5 := SymmetricGroup(5);</span>\nSym( [ 1 .. 5 ] )\n<span class=\"GAPp\
rompt\">gap&gt;</span> <span class=\"GAPinput\">Size(S5);</span>\n120\n\n# Thi\
s next command is present to prevent Test() from\n# being misled by the remain\
ing AutoDoc markup.\n<span class=\"GAPprompt\">gap&gt;</span> <span class=\"GA\
Pinput\">STOP_TEST( \"dummy.tst\", 10000 );</span>\n</pre></div>\n\n<p>And we \
wrap up with some dummy text But this should produce more text.</p>\n\n\n<div \
class=\"chlinkprevnextbot\">&nbsp;<a href=\"chap0.html\">[Top of Book]</a>&nbs\
p; <a href=\"chap0.html#contents\">[Contents]</a>&nbsp; &nbsp;<a href=\"chap\
0.html\">[Previous Chapter]</a>&nbsp; </div>\n\n\n<div class=\"chlinkbot\"><s\
pan class=\"chlink1\">Goto Chapter: </span><a href=\"chap0.html\">Top</a> <a \
href=\"chap1.html\">1</a> </div>\n\n<hr />\n<p class=\"foot\">generated by <a\
href=\"http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc\">GAPDoc2HTML</a>\
</p>\n</body>\n</html>\n"
gap> STOP_TEST( "plaintextmode.tst", 10000 );
#! @AutoDocPlainText
@Title Plain Text Mode Test
@Date 2018/08/17
@Chapter Test
This is dummy text
@BeginExampleSession
gap> S5 := SymmetricGroup(5);
Sym( [ 1 .. 5 ] )
gap> Size(S5);
120

# This next command is present to prevent Test() from
# being misled by the remaining AutoDoc markup.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work, sorry.

The correct solution is to put the actual worksheet into a separate file, say tst/plaintextmode.worksheet, and then read that, instead of trying to cram it all into the .tst file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it certainly seemed to work, in that the test succeeded as expected. My motivation to merge both the testing code and the markup being tested in the same file was mostly that plaintextmode "should" work to interpolate plain text commands in any file AutoDoc() is processing, so it seemed perfectly reasonable that the test could process itself. A minor secondary motivation was economizing on the number of files in the test harness. But I am happy to re-do the pull request with separate worksheets and .tst file, and will do so ASAP, probably tonight.

gap> STOP_TEST( "dummy.tst", 10000 );
@EndExampleSession
And we wrap up with some dummy text
@EndAutoDocPlainText
This line in the file should be completely ignored.
#! But this should produce more text.