-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
145 lines (125 loc) · 3.78 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { strict as assert } from 'assert';
// /////////////////////////////////////////////////////////////////////////////
// graph-to-dot
// /////////////////////////////////////////////////////////////////////////////
import { graphToDot, props } from './graph-to-dot.js';
assert.equal('a="1" b="true" c="str"', props({ a: 1, b: true, c: 'str' }));
assert.equal('', props(undefined));
/** @type {Call<void>} */
const call = (_mac, [to], _evt) => to;
/** @type {Graph} */
const g2 = {
noLib: {
libLoaded: { to: ['noDom'], call },
},
noDom: {
domContentLoaded: { to: ['formReady'], call },
},
formReady: {
ENTER: call,
change: { to: ['formValid', 'formInvalid'], call },
},
formValid: {
ENTER: call,
change: { to: ['formValid', 'formInvalid'], call },
submit: { to: ['submitting'], call },
},
formInvalid: {
ENTER: call,
change: { to: ['formValid', 'formInvalid'], call },
},
submitting: {
ENTER: call,
LEAVE: call,
progress: { to: ['submitting'], call },
netError: { to: ['formValid'], call },
'5XX': { to: ['formValid'], call },
'4XX': { to: ['formInvalid'], call },
200: { to: ['thankYou'], call },
},
thankYou: {
ENTER: call,
},
};
const expectedDot = `digraph {
graph [rankdir=LR]
node [fontname="Trebuchet MS" fontsize=14
color="/accent3/3" shape=box style="rounded,filled"]
edge [fontname="Trebuchet MS" fontsize=10 arrowsize=0.7]
noLib [color="/accent3/1"]
noLib -> noDom [label="libLoaded"]
noDom -> formReady [label="domContentLoaded"]
formReady -> formValid [label="change"]
formReady -> formInvalid [label="change"]
formValid -> formValid [label="change" tailport="s"]
formValid -> formInvalid [label="change"]
formValid -> submitting [label="submit"]
formInvalid -> formValid [label="change"]
formInvalid -> formInvalid [label="change"]
submitting -> thankYou [label="200"]
submitting -> submitting [label="progress"]
submitting -> formValid [label="netError"]
submitting -> formValid [label="5XX"]
submitting -> formInvalid [label="4XX"]
thankYou [color="/accent3/2"]
{ rank=same noLib noDom formReady }
{ rank=same formValid formInvalid }
}`;
const opts = {
edges: {
formValid: {
change: {
formValid: { tailport: 's' },
},
},
},
post: `
{ rank=same noLib noDom formReady }
{ rank=same formValid formInvalid }`,
};
assert.equal(graphToDot(g2, 'noLib', opts), expectedDot);
// /////////////////////////////////////////////////////////////////////////////
// compile-md
// /////////////////////////////////////////////////////////////////////////////
import { compileMd } from './compile-md.js';
const src = `
# Title
para
## Sub
\`\`\`javascript
const msg = 'Hello Documentation';
console.log(msg);
\`\`\`
\`\`\`javascript code
const msg = '## Hello Compilation';
console.log(msg);
\`\`\`
\`\`\`javascript both
const msg2 = '## Hello Text **and** code';
console.log(msg2);
\`\`\`
`;
const expectedMd =
"console.log('');\n" +
"console.log('# Title');\n" +
"console.log('');\n" +
"console.log('para');\n" +
"console.log('');\n" +
"console.log('## Sub');\n" +
"console.log('');\n" +
"console.log('```javascript');\n" +
"console.log('const msg = \\'Hello Documentation\\';');\n" +
"console.log('console.log(msg);');\n" +
"console.log('```');\n" +
"console.log('');\n" +
"const msg = '## Hello Compilation';\n" +
'console.log(msg);\n' +
"console.log('');\n" +
"console.log('```javascript');\n" +
"console.log('const msg2 = \\'## Hello Text **and** code\\';');\n" +
"console.log('console.log(msg2);');\n" +
"console.log('```');\n" +
"const msg2 = '## Hello Text **and** code';\n" +
'console.log(msg2);\n' +
"console.log('');";
assert.equal(compileMd(src), expectedMd);