-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path08-header-parameters.rakutest
More file actions
135 lines (109 loc) · 2.92 KB
/
08-header-parameters.rakutest
File metadata and controls
135 lines (109 loc) · 2.92 KB
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
use Test;
# use lib <. lib>;
use Text::CodeProcessing;
use Text::CodeProcessing::REPLSandbox;
plan 4;
#============================================================
# 1 Header parsing
#============================================================
my $code1 = q:to/INIT/;
----
title: "Replacement example"
author: Anton Antonov
date: 2025-06-19
output: html_notebook
params:
partSize: 0.25
dataDirName: "~/fake-data"
exportQ: FALSE
----
INIT
my %res1 =
:title("Replacement example"),
:author("Anton Antonov"),
:date("2025-06-19"),
:output("html_notebook"),
params => {:dataDirName("~/fake-data"), :!exportQ, :partSize(0.25)};
is-deeply
Text::CodeProcessing::Header.parse($code1, actions => Text::CodeProcessing::HeaderActions.new).made,
%res1,
'YAML header parameters';
#============================================================
# 1 Header parsing
#============================================================
my $code2 = q:to/INIT/;
----
title: "Replacement example"
author: Anton Antonov
date: 2025-06-19
output: html_notebook
params:
partSize: 0.25
dataDirName: "~/fake-data"
exportQ: FALSE
----
## First section
Some text, here is code:
```raku
1 + 1
```
INIT
is-deeply
Text::CodeProcessing::Header.parse($code2, actions => Text::CodeProcessing::HeaderActions.new).made,
%res1,
'YAML header parameters';
#============================================================
# 3 markdown header parameter replacement
#============================================================
my $code3 = q:to/INIT/;
----
title: "Replacement example"
author: Anton Antonov
date: 2025-06-19
output: html_notebook
params:
partSize: 0.25
dataDirName: "~/fake-data"
exportQ: FALSE
----
## First section
Getting data from %params<dataDirName>:
```raku
say %params<partSize>;
say (%params{"exportQ"} ?? '' !! 'do not ') ~ 'export it';
```
INIT
my $resCode3 = q:to/INIT/;
----
title: "Replacement example"
author: Anton Antonov
date: 2025-06-19
output: html_notebook
params:
partSize: 0.25
dataDirName: "~/fake-data"
exportQ: FALSE
----
## First section
Getting data from '~/fake-data':
```raku
say 0.25;
say (False ?? '' !! 'do not ') ~ 'export it';
```
```
#OUT:0.25
#OUT:do not export it
```
INIT
is
StringCodeChunksEvaluation($code3, 'markdown', evalOutputPrompt => '#OUT:', evalErrorPrompt => '#ERR:').trim,
$resCode3.trim,
'replacement of parameters in a Markdown string';
#============================================================
# 4 markdown header parameter override
#============================================================
is
StringCodeChunksEvaluation($code3, 'markdown', params => {dataDirName => './true-data'}, evalOutputPrompt => '#OUT:', evalErrorPrompt => '#ERR:').trim,
$resCode3.subst('from \'~/fake-data\'', 'from \'./true-data\'').trim,
'replacement of parameters in a Markdown string';
done-testing;