Skip to content

Commit

Permalink
fix(gd): Wrap node name in \tikz@pp@name #1119
Browse files Browse the repository at this point in the history
* fix(gd): Wrap node name in `\tikz@pp@name`

when tikz calls `\pgfgdedge`.

Signed-off-by: muzimuzhi <[email protected]>

* fix(gd): Add `\tikz@pp@name` for edge kind `-!-`

Signed-off-by: muzimuzhi <[email protected]>

* test(gd)!: New test set and its first test

The gd test set only runs on LuaTeX.

`pgfgd-debug.lua` adds debugging code to `InterfaceToDisplay` functions
which helps in checking tests based on states of display layer (Lua),
rather than box content.

Signed-off-by: muzimuzhi <[email protected]>

* chore: Add changelog entries

Signed-off-by: muzimuzhi <[email protected]>

* test(gd): optimize Lua code

Signed-off-by: Henri Menke <[email protected]>

* fixup! test(gd): optimize Lua code

Signed-off-by: Henri Menke <[email protected]>

* fixup! fixup! test(gd): optimize Lua code

Signed-off-by: Henri Menke <[email protected]>

* feat(ci): Archive failed test output for all test sets

This extends #1114, commit
  2bff7c6

Signed-off-by: muzimuzhi <[email protected]>

* fixup! fixup! fixup! test(gd): optimize Lua code

- Load `pgfgd-test.lua` after gd lib.
- Update test file (no prefix, no ending period).

Signed-off-by: muzimuzhi <[email protected]>

Co-authored-by: Henri Menke <[email protected]>
  • Loading branch information
muzimuzhi and hmenke authored Jan 11, 2022
1 parent 1a1880a commit 307703b
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: test-diff-files
path: build/test/*.diff
path: build/test*/*.diff
3 changes: 3 additions & 0 deletions build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ specialformats["latex"] = specialformats["latex"] or
}
checkengines = {"pdftex", "latexdvips", "latexdvisvgm", "luatex", "xetex"}

-- Use multiple sets of tests
checkconfigs = { "build", "config-gd" }

--- Keep all \special data (may one day be the l3build default)
maxprintline = 9999

Expand Down
5 changes: 5 additions & 0 deletions config-gd.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Tests for graph drawing (gd) library

stdengine = "luatex"
checkengines = {"luatex"}
testfiledir = "testfiles-gd"
2 changes: 2 additions & 0 deletions doc/generic/pgf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lot of contributed changes. Thanks to everyone who volunteered their time!
- Add Matrix chat to README
- Add rhombic polihedra #1022
- Add Developer Certificate of Origin (DCO) to Pull Request template and enforce
- Add test set for `graphdrawing` (gd)

### Fixed

Expand Down Expand Up @@ -58,6 +59,7 @@ lot of contributed changes. Thanks to everyone who volunteered their time!
- Suppress white space at line end when `datavisualization` reads from a file
#1112
- Form-only patterns have no specified color #1122
- Make `graphdrawing` work with `name prefix` and `name suffix` options #1087

### Changed

Expand Down
32 changes: 32 additions & 0 deletions testfiles-gd/support/pgfgd-debug.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local InterfaceToDisplay = assert(pgf.gd.interface.InterfaceToDisplay)

-- helper
local function typeout(...)
texio.write_nl(17, "Gd Lua layer Info: " .. string.format(...))
end

local createVertex = assert(InterfaceToDisplay.createVertex)
function InterfaceToDisplay.createVertex(name, ...)
typeout("Create vertex '%s'", name)
createVertex(name, ...)
end

local createEdge = assert(InterfaceToDisplay.createEdge)
function InterfaceToDisplay.createEdge(tail, head, direction, ...)
typeout("Create edge '%s' from '%s' to '%s'", direction, tail, head)
createEdge(tail, head, direction, ...)
end

--[[ this generates too many debugging lines
local createEvent = assert(InterfaceToDisplay.createEvent)
function InterfaceToDisplay.createEvent(kind, ...)
typeout("Create event '%s'", kind)
return createEvent(kind, ...)
end
--]]

local addToVertexOptions = assert(InterfaceToDisplay.addToVertexOptions)
function InterfaceToDisplay.addToVertexOptions(name, ...)
typeout("Add options to vertex '%s'", name)
addToVertexOptions(name, ...)
end
5 changes: 5 additions & 0 deletions testfiles-gd/support/pgfgd-regression-test.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\input regression-test.tex

\ifdefined\directlua
\AtBeginDocument{\directlua{dofile('pgfgd-debug.lua')}}
\fi
66 changes: 66 additions & 0 deletions testfiles-gd/tikz-gd-gh1087.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
\documentclass{minimal}
\input{pgfgd-regression-test}

\RequirePackage{tikz}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{layered}

\makeatletter
\def\pgfutil@packageerror#1#2#3{\immediate\write17{Package #1 Error: #2.}}
\makeatother
\begin{document}

\START

% use all five edge kinds
% make node names variable, to prevent false negative results
\def\testgraph#1{ a#1 -> {b#1, c#1 <-> d#1} -- e#1 <- f#1; a#1 -!- f#1; }
\SEPARATOR
\TYPE{Base graph: \testgraph{}}
\SEPARATOR

\BEGINTEST{Empty `name prefix`}
\tikzpicture
\graph[layered layout] { [parse/.expand once=\testgraph{1}] };
\path (b1);
\path[name prefix=z-] (b1);
\endtikzpicture
\ENDTEST

\BEGINTEST{Non-empty `name prefix`}
\tikzpicture[name prefix=x-]
\graph[layered layout] { [parse/.expand once=\testgraph{2}] };

% works
\path (b2) (x-b2);
\path[name prefix=] (x-b2);
\path[name prefix=y-] (x-b2);

% should throw errors
\path[name prefix=] (b2);
\endtikzpicture
\ENDTEST

\BEGINTEST{Simple non-gd graph + Empty `name suffix`}
\tikzpicture
\graph { [parse/.expand once=\testgraph{3}] };
\path (b3);
\path[name suffix=-z] (b3);
\endtikzpicture
\ENDTEST

\BEGINTEST{Simple non-gd graph + Non-empty `name suffix`}
\tikzpicture[name suffix=-x]
\graph { [parse/.expand once=\testgraph{4}] };

% works
\path (b4) (b4-x);
\path[name suffix=] (b4-x);
\path[name suffix=-y] (b4-x);

% throws errors
\path[name suffix=] (b4);
\endtikzpicture
\ENDTEST

\END
57 changes: 57 additions & 0 deletions testfiles-gd/tikz-gd-gh1087.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
============================================================
Base graph: a -> {b, c <-> d} -- e <- f; a -!- f;
============================================================
============================================================
TEST 1: Empty `name prefix`
============================================================
Gd Lua layer Info: Create vertex 'a1'
Gd Lua layer Info: Create vertex 'b1'
Gd Lua layer Info: Create vertex 'c1'
Gd Lua layer Info: Create vertex 'd1'
Gd Lua layer Info: Create edge '<->' from 'c1' to 'd1'
Gd Lua layer Info: Create edge '->' from 'a1' to 'b1'
Gd Lua layer Info: Create edge '->' from 'a1' to 'c1'
Gd Lua layer Info: Create vertex 'e1'
Gd Lua layer Info: Create edge '--' from 'b1' to 'e1'
Gd Lua layer Info: Create edge '--' from 'd1' to 'e1'
Gd Lua layer Info: Create vertex 'f1'
Gd Lua layer Info: Create edge '<-' from 'e1' to 'f1'
Gd Lua layer Info: Add options to vertex 'a1'
Gd Lua layer Info: Add options to vertex 'a1'
Gd Lua layer Info: Add options to vertex 'f1'
Gd Lua layer Info: Add options to vertex 'f1'
Gd Lua layer Info: Create edge '-!-' from 'a1' to 'f1'
============================================================
============================================================
TEST 2: Non-empty `name prefix`
============================================================
Gd Lua layer Info: Create vertex 'x-a2'
Gd Lua layer Info: Create vertex 'x-b2'
Gd Lua layer Info: Create vertex 'x-c2'
Gd Lua layer Info: Create vertex 'x-d2'
Gd Lua layer Info: Create edge '<->' from 'x-c2' to 'x-d2'
Gd Lua layer Info: Create edge '->' from 'x-a2' to 'x-b2'
Gd Lua layer Info: Create edge '->' from 'x-a2' to 'x-c2'
Gd Lua layer Info: Create vertex 'x-e2'
Gd Lua layer Info: Create edge '--' from 'x-b2' to 'x-e2'
Gd Lua layer Info: Create edge '--' from 'x-d2' to 'x-e2'
Gd Lua layer Info: Create vertex 'x-f2'
Gd Lua layer Info: Create edge '<-' from 'x-e2' to 'x-f2'
Gd Lua layer Info: Add options to vertex 'x-a2'
Gd Lua layer Info: Add options to vertex 'x-a2'
Gd Lua layer Info: Add options to vertex 'x-f2'
Gd Lua layer Info: Add options to vertex 'x-f2'
Gd Lua layer Info: Create edge '-!-' from 'x-a2' to 'x-f2'
Package pgf Error: No shape named `b2' is known.
============================================================
============================================================
TEST 3: Simple non-gd graph + Empty `name suffix`
============================================================
============================================================
============================================================
TEST 4: Simple non-gd graph + Non-empty `name suffix`
============================================================
Package pgf Error: No shape named `b4' is known.
============================================================
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@
%
% Handle late options and operators
\tikzgraphsset{source,target,.unknown/.code=,#1}%
\tikzgdlatenodeoptionacallback{\tikz@lib@graph@name}%
\tikzgdlatenodeoptionacallback{\tikz@pp@name\tikz@lib@graph@name}%
\node also[graphs/redirect unknown to tikz,/tikz/graphs/.cd,#1](\tikz@lib@graph@name);%
\pgfkeysvalueof{/tikz/graphs/@operators}%
}%
Expand Down
19 changes: 12 additions & 7 deletions tex/generic/pgf/graphdrawing/tex/tikzlibrarygraphdrawing.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,20 @@
%
% Setup for the graphs syntax
%
/tikz/graphs/new ->/.code n args={4}{\pgfgdedge{##1}{##2}{->}{/tikz,##3}{##4}},
/tikz/graphs/new <-/.code n args={4}{\pgfgdedge{##1}{##2}{<-}{/tikz,##3}{##4}},
/tikz/graphs/new --/.code n args={4}{\pgfgdedge{##1}{##2}{--}{/tikz,##3}{##4}},
/tikz/graphs/new <->/.code n args={4}{\pgfgdedge{##1}{##2}{<->}{/tikz,##3}{##4}},
/tikz/graphs/new -!-/.code n args={4}{\pgfgdedge{##1}{##2}{-!-}{/tikz,##3}{##4}},
/tikz/graphs/new ->/.code n args={4}{\tikz@lib@gd@edge{##1}{##2}{->}{/tikz,##3}{##4}},
/tikz/graphs/new <-/.code n args={4}{\tikz@lib@gd@edge{##1}{##2}{<-}{/tikz,##3}{##4}},
/tikz/graphs/new --/.code n args={4}{\tikz@lib@gd@edge{##1}{##2}{--}{/tikz,##3}{##4}},
/tikz/graphs/new <->/.code n args={4}{\tikz@lib@gd@edge{##1}{##2}{<->}{/tikz,##3}{##4}},
/tikz/graphs/new -!-/.code n args={4}{\tikz@lib@gd@edge{##1}{##2}{-!-}{/tikz,##3}{##4}},
/tikz/graphs/placement/compute position/.code=,%
}
}%

% wrapper for \pgfgdedge
\def\tikz@lib@gd@edge#1#2{%
\pgfgdedge{\tikz@pp@name{#1}}{\tikz@pp@name{#2}}%
}

\pgfgdaddprepareedgehook{
\tikz@enable@edge@quotes%
\let\tikz@transform=\pgfutil@empty%
Expand Down Expand Up @@ -130,11 +135,11 @@
}%

\def\tikz@gd@edge@from@parent@macro#1#2{
[/utils/exec=\pgfgdedge{\tikzparentnode}{\tikzchildnode}{--}{/tikz,#1}{#2}]
[/utils/exec=\tikz@lib@gd@edge{\tikzparentnode}{\tikzchildnode}{--}{/tikz,#1}{#2}]
}%

\def\tikz@gd@plain@edge@macro#1#2{
\pgfgdedge{\tikztostart}{\tikztotarget}{--}{/tikz,#1}{#2}
\tikz@lib@gd@edge{\tikztostart}{\tikztotarget}{--}{/tikz,#1}{#2}
}%


Expand Down

0 comments on commit 307703b

Please sign in to comment.