Skip to content

Commit 307703b

Browse files
muzimuzhihmenke
andauthored
fix(gd): Wrap node name in \tikz@pp@name #1119
* 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]>
1 parent 1a1880a commit 307703b

File tree

10 files changed

+184
-9
lines changed

10 files changed

+184
-9
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
uses: actions/upload-artifact@v2
3232
with:
3333
name: test-diff-files
34-
path: build/test/*.diff
34+
path: build/test*/*.diff

build.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ specialformats["latex"] = specialformats["latex"] or
4040
}
4141
checkengines = {"pdftex", "latexdvips", "latexdvisvgm", "luatex", "xetex"}
4242

43+
-- Use multiple sets of tests
44+
checkconfigs = { "build", "config-gd" }
45+
4346
--- Keep all \special data (may one day be the l3build default)
4447
maxprintline = 9999
4548

config-gd.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Tests for graph drawing (gd) library
2+
3+
stdengine = "luatex"
4+
checkengines = {"luatex"}
5+
testfiledir = "testfiles-gd"

doc/generic/pgf/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ lot of contributed changes. Thanks to everyone who volunteered their time!
2323
- Add Matrix chat to README
2424
- Add rhombic polihedra #1022
2525
- Add Developer Certificate of Origin (DCO) to Pull Request template and enforce
26+
- Add test set for `graphdrawing` (gd)
2627

2728
### Fixed
2829

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

6264
### Changed
6365

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
local InterfaceToDisplay = assert(pgf.gd.interface.InterfaceToDisplay)
2+
3+
-- helper
4+
local function typeout(...)
5+
texio.write_nl(17, "Gd Lua layer Info: " .. string.format(...))
6+
end
7+
8+
local createVertex = assert(InterfaceToDisplay.createVertex)
9+
function InterfaceToDisplay.createVertex(name, ...)
10+
typeout("Create vertex '%s'", name)
11+
createVertex(name, ...)
12+
end
13+
14+
local createEdge = assert(InterfaceToDisplay.createEdge)
15+
function InterfaceToDisplay.createEdge(tail, head, direction, ...)
16+
typeout("Create edge '%s' from '%s' to '%s'", direction, tail, head)
17+
createEdge(tail, head, direction, ...)
18+
end
19+
20+
--[[ this generates too many debugging lines
21+
local createEvent = assert(InterfaceToDisplay.createEvent)
22+
function InterfaceToDisplay.createEvent(kind, ...)
23+
typeout("Create event '%s'", kind)
24+
return createEvent(kind, ...)
25+
end
26+
--]]
27+
28+
local addToVertexOptions = assert(InterfaceToDisplay.addToVertexOptions)
29+
function InterfaceToDisplay.addToVertexOptions(name, ...)
30+
typeout("Add options to vertex '%s'", name)
31+
addToVertexOptions(name, ...)
32+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
\input regression-test.tex
2+
3+
\ifdefined\directlua
4+
\AtBeginDocument{\directlua{dofile('pgfgd-debug.lua')}}
5+
\fi

testfiles-gd/tikz-gd-gh1087.lvt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
\documentclass{minimal}
2+
\input{pgfgd-regression-test}
3+
4+
\RequirePackage{tikz}
5+
\usetikzlibrary{graphs, graphdrawing}
6+
\usegdlibrary{layered}
7+
8+
\makeatletter
9+
\def\pgfutil@packageerror#1#2#3{\immediate\write17{Package #1 Error: #2.}}
10+
\makeatother
11+
\begin{document}
12+
13+
\START
14+
15+
% use all five edge kinds
16+
% make node names variable, to prevent false negative results
17+
\def\testgraph#1{ a#1 -> {b#1, c#1 <-> d#1} -- e#1 <- f#1; a#1 -!- f#1; }
18+
\SEPARATOR
19+
\TYPE{Base graph: \testgraph{}}
20+
\SEPARATOR
21+
22+
\BEGINTEST{Empty `name prefix`}
23+
\tikzpicture
24+
\graph[layered layout] { [parse/.expand once=\testgraph{1}] };
25+
\path (b1);
26+
\path[name prefix=z-] (b1);
27+
\endtikzpicture
28+
\ENDTEST
29+
30+
\BEGINTEST{Non-empty `name prefix`}
31+
\tikzpicture[name prefix=x-]
32+
\graph[layered layout] { [parse/.expand once=\testgraph{2}] };
33+
34+
% works
35+
\path (b2) (x-b2);
36+
\path[name prefix=] (x-b2);
37+
\path[name prefix=y-] (x-b2);
38+
39+
% should throw errors
40+
\path[name prefix=] (b2);
41+
\endtikzpicture
42+
\ENDTEST
43+
44+
\BEGINTEST{Simple non-gd graph + Empty `name suffix`}
45+
\tikzpicture
46+
\graph { [parse/.expand once=\testgraph{3}] };
47+
\path (b3);
48+
\path[name suffix=-z] (b3);
49+
\endtikzpicture
50+
\ENDTEST
51+
52+
\BEGINTEST{Simple non-gd graph + Non-empty `name suffix`}
53+
\tikzpicture[name suffix=-x]
54+
\graph { [parse/.expand once=\testgraph{4}] };
55+
56+
% works
57+
\path (b4) (b4-x);
58+
\path[name suffix=] (b4-x);
59+
\path[name suffix=-y] (b4-x);
60+
61+
% throws errors
62+
\path[name suffix=] (b4);
63+
\endtikzpicture
64+
\ENDTEST
65+
66+
\END

testfiles-gd/tikz-gd-gh1087.tlg

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
This is a generated file for the l3build validation system.
2+
Don't change this file in any respect.
3+
============================================================
4+
Base graph: a -> {b, c <-> d} -- e <- f; a -!- f;
5+
============================================================
6+
============================================================
7+
TEST 1: Empty `name prefix`
8+
============================================================
9+
Gd Lua layer Info: Create vertex 'a1'
10+
Gd Lua layer Info: Create vertex 'b1'
11+
Gd Lua layer Info: Create vertex 'c1'
12+
Gd Lua layer Info: Create vertex 'd1'
13+
Gd Lua layer Info: Create edge '<->' from 'c1' to 'd1'
14+
Gd Lua layer Info: Create edge '->' from 'a1' to 'b1'
15+
Gd Lua layer Info: Create edge '->' from 'a1' to 'c1'
16+
Gd Lua layer Info: Create vertex 'e1'
17+
Gd Lua layer Info: Create edge '--' from 'b1' to 'e1'
18+
Gd Lua layer Info: Create edge '--' from 'd1' to 'e1'
19+
Gd Lua layer Info: Create vertex 'f1'
20+
Gd Lua layer Info: Create edge '<-' from 'e1' to 'f1'
21+
Gd Lua layer Info: Add options to vertex 'a1'
22+
Gd Lua layer Info: Add options to vertex 'a1'
23+
Gd Lua layer Info: Add options to vertex 'f1'
24+
Gd Lua layer Info: Add options to vertex 'f1'
25+
Gd Lua layer Info: Create edge '-!-' from 'a1' to 'f1'
26+
============================================================
27+
============================================================
28+
TEST 2: Non-empty `name prefix`
29+
============================================================
30+
Gd Lua layer Info: Create vertex 'x-a2'
31+
Gd Lua layer Info: Create vertex 'x-b2'
32+
Gd Lua layer Info: Create vertex 'x-c2'
33+
Gd Lua layer Info: Create vertex 'x-d2'
34+
Gd Lua layer Info: Create edge '<->' from 'x-c2' to 'x-d2'
35+
Gd Lua layer Info: Create edge '->' from 'x-a2' to 'x-b2'
36+
Gd Lua layer Info: Create edge '->' from 'x-a2' to 'x-c2'
37+
Gd Lua layer Info: Create vertex 'x-e2'
38+
Gd Lua layer Info: Create edge '--' from 'x-b2' to 'x-e2'
39+
Gd Lua layer Info: Create edge '--' from 'x-d2' to 'x-e2'
40+
Gd Lua layer Info: Create vertex 'x-f2'
41+
Gd Lua layer Info: Create edge '<-' from 'x-e2' to 'x-f2'
42+
Gd Lua layer Info: Add options to vertex 'x-a2'
43+
Gd Lua layer Info: Add options to vertex 'x-a2'
44+
Gd Lua layer Info: Add options to vertex 'x-f2'
45+
Gd Lua layer Info: Add options to vertex 'x-f2'
46+
Gd Lua layer Info: Create edge '-!-' from 'x-a2' to 'x-f2'
47+
Package pgf Error: No shape named `b2' is known.
48+
============================================================
49+
============================================================
50+
TEST 3: Simple non-gd graph + Empty `name suffix`
51+
============================================================
52+
============================================================
53+
============================================================
54+
TEST 4: Simple non-gd graph + Non-empty `name suffix`
55+
============================================================
56+
Package pgf Error: No shape named `b4' is known.
57+
============================================================

tex/generic/pgf/frontendlayer/tikz/libraries/graphs/tikzlibrarygraphs.code.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@
12081208
%
12091209
% Handle late options and operators
12101210
\tikzgraphsset{source,target,.unknown/.code=,#1}%
1211-
\tikzgdlatenodeoptionacallback{\tikz@lib@graph@name}%
1211+
\tikzgdlatenodeoptionacallback{\tikz@pp@name\tikz@lib@graph@name}%
12121212
\node also[graphs/redirect unknown to tikz,/tikz/graphs/.cd,#1](\tikz@lib@graph@name);%
12131213
\pgfkeysvalueof{/tikz/graphs/@operators}%
12141214
}%

tex/generic/pgf/graphdrawing/tex/tikzlibrarygraphdrawing.code.tex

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,20 @@
8383
%
8484
% Setup for the graphs syntax
8585
%
86-
/tikz/graphs/new ->/.code n args={4}{\pgfgdedge{##1}{##2}{->}{/tikz,##3}{##4}},
87-
/tikz/graphs/new <-/.code n args={4}{\pgfgdedge{##1}{##2}{<-}{/tikz,##3}{##4}},
88-
/tikz/graphs/new --/.code n args={4}{\pgfgdedge{##1}{##2}{--}{/tikz,##3}{##4}},
89-
/tikz/graphs/new <->/.code n args={4}{\pgfgdedge{##1}{##2}{<->}{/tikz,##3}{##4}},
90-
/tikz/graphs/new -!-/.code n args={4}{\pgfgdedge{##1}{##2}{-!-}{/tikz,##3}{##4}},
86+
/tikz/graphs/new ->/.code n args={4}{\tikz@lib@gd@edge{##1}{##2}{->}{/tikz,##3}{##4}},
87+
/tikz/graphs/new <-/.code n args={4}{\tikz@lib@gd@edge{##1}{##2}{<-}{/tikz,##3}{##4}},
88+
/tikz/graphs/new --/.code n args={4}{\tikz@lib@gd@edge{##1}{##2}{--}{/tikz,##3}{##4}},
89+
/tikz/graphs/new <->/.code n args={4}{\tikz@lib@gd@edge{##1}{##2}{<->}{/tikz,##3}{##4}},
90+
/tikz/graphs/new -!-/.code n args={4}{\tikz@lib@gd@edge{##1}{##2}{-!-}{/tikz,##3}{##4}},
9191
/tikz/graphs/placement/compute position/.code=,%
9292
}
9393
}%
9494

95+
% wrapper for \pgfgdedge
96+
\def\tikz@lib@gd@edge#1#2{%
97+
\pgfgdedge{\tikz@pp@name{#1}}{\tikz@pp@name{#2}}%
98+
}
99+
95100
\pgfgdaddprepareedgehook{
96101
\tikz@enable@edge@quotes%
97102
\let\tikz@transform=\pgfutil@empty%
@@ -130,11 +135,11 @@
130135
}%
131136

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

136141
\def\tikz@gd@plain@edge@macro#1#2{
137-
\pgfgdedge{\tikztostart}{\tikztotarget}{--}{/tikz,#1}{#2}
142+
\tikz@lib@gd@edge{\tikztostart}{\tikztotarget}{--}{/tikz,#1}{#2}
138143
}%
139144

140145

0 commit comments

Comments
 (0)