forked from dotnet/interactive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotebookTestScript.dib
324 lines (213 loc) · 6.78 KB
/
NotebookTestScript.dib
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!meta
{"kernelInfo":{"defaultKernelName":null,"items":[{"name":"csharp","languageName":"C#","aliases":["c#","cs"]},{"name":"fsharp","languageName":"F#","aliases":["f#","fs"]},{"name":"pwsh","languageName":"PowerShell","aliases":["powershell"]},{"name":"javascript","languageName":"JavaScript","aliases":["js"]},{"name":"html","languageName":"HTML"},{"name":"sql","languageName":"SQL"},{"name":"kql","languageName":"KQL"},{"name":"mermaid","languageName":"Mermaid"},{"name":"http","languageName":"HTTP"},{"name":"value"}]}}
#!markdown
# Verify execution count.
The next code cell should have empty square brackets on the left, e.g., "`[ ]`". Execute the cell and upon completion there should be a number there; probably "`[1]`". Execute the cell again and verify that the number in the brackets increments by one, e.g., "`[2]`".
#!csharp
1+1
#!markdown
# Execute the following cell.
You'll notice a counter that appears and starts incrementing. After a second or two, stop the cell. Your output should look similar to:
```
5
Command cancelled
```
N.b., the old values (e.g., `1`, `2`, `3`, `4`, etc.) should no longer be displayed, but overwritten.
#!csharp
using System.Threading.Tasks;
using Microsoft.DotNet.Interactive;
var output = string.Empty.Display("text/plain");
var counter = 1;
while (!KernelInvocationContext.Current.CancellationToken.IsCancellationRequested)
{
await Task.Delay(500, KernelInvocationContext.Current.CancellationToken);
output.Update($"{counter++}");
}
#!markdown
# Execute the next two cells.
#!csharp
var x = 123;
#!html
<div id="output">The value is not yet set.</div>
#!markdown
# Execute the next cell. After execution, the output immediately above this should read:
```
The value is 123.
```
And the output below the next cell should display the same value.
#!javascript
#!share --from csharp x
document.getElementById("output").innerText = `The value is ${x}.`;
console.log(`The value is ${x}.`);
#!markdown
# Execude the next cell. After execution, the output immediately below should be:
```
javascript
```
#!javascript
const jsKernel = kernel.root.findKernelByName('javascript');
console.log(jsKernel.name);
#!markdown
# Execude the next cell. After execution, the output immediately below should be:
```
[".NET","csharp","fsharp","html","javascript","kql","mermaid","pwsh","sql","value","vscode","webview"]
```
#!javascript
kernels = Array.from(kernel.root.findKernels(s => true).map(k => k.name)).sort();
return kernels;
#!markdown
# Execude the next cell. After execution, the output immediately below should be:
```
1234
```
And the `POLYGLOT NOTEBOOK: VARIABLES` window should contain a variable with name `asdf`, value `1234` and kernel Name `csharp`
#!javascript
await kernel.root.send({ commandType: 'SubmitCode', command: { code: 'var asdf = 1234; Console.WriteLine(asdf);', targetKernelName: 'csharp' } });
#!markdown
# Execute the next cell, the output should be displayed as HTML like so:
| Name | Salary |
:---|---: |
| Developer | 42 |
change the renderer using the `...` element, choose the json and the output should look like so:
``` json
{"Name":"Developer","Salary":42}
```
#!csharp
var value = new { Name = "Developer", Salary = 42 };
value.Display("application/json", "text/html");
#!markdown
# Execute the next cell, the output should be displayed like so:
31.1
#!csharp
10m + 21.1m
#!markdown
# Execute the next cell. It should fail with the message:
```
Error: Value 'undefinedVariableName' not found in kernel pwsh
2
```
#!csharp
#!share --from pwsh undefinedVariableName
1+1
#!markdown
# Execute the next cell and verify the following error appears:
```
input.fsx (1,11)-(1,12) parse error Unexpected token '+' or incomplete expression
```
#!fsharp
let x = 1 +
#!markdown
# Complex console output
#!markdown
The output should look like:
<span style="color:#00FF00">this is green</span>
this is white
<span style="color:#FF0000">this is red</span>
#!csharp
Console.Write("\x1b[38;2;0;255;0m");
Console.WriteLine("this is green");
Console.Write("\x1b[0m");
"this is white".Display();
Console.Error.Write("\x1b[38;2;255;0;0m");
Console.Error.WriteLine("this is red");
Console.Error.Write("\x1b[0m");
#!markdown
# vscode kernel and user input prompts
This cell should prompt the user for input
#!csharp
var input = await Microsoft.DotNet.Interactive.Kernel.GetInputAsync("give me data");
input
#!fsharp
let input = task {
return! Microsoft.DotNet.Interactive.Kernel.GetInputAsync ("give me data")
}
input.Result
#!markdown
This should prompt you for input.
#!value
#!value --from-value @input:wat --name value_from_input
#!markdown
This should output the thing you typed into the prompt.
#!fsharp
#!share --from value value_from_input
value_from_input
#!markdown
Now check the variable explorer. Is the value there in the `#!value` kernel?
#!markdown
# Check this manual scenario:
1. `Ctrl+Shift+P` => "Polyglot Notebook: Create new blank notebook"
2. Select "Create as .dib"
3. Select "F#"
4. You should have a new empty notebook named something like "Untitled-1.dib" with a single cell of type "F# (Polyglot Notebook)".
5. Set the cell contents to `1+1` and execute.
6. Verify output of `2`.
7. Save to disk.
8. Open that file in notepad.
9. The contents should look like this:
```
#!fsharp
1+1
```
#!markdown
# Execute the above scenario again with the following changes:
2. Select "Create as .ipynb"
4. File should be named something like "Untitled-1.ipynb".
(new steps)
9. The contents should look like this:
``` json
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"polyglot_notebook": {
"language": "fsharp"
},
"vscode": {
"languageId": "dotnet-interactive.fsharp"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\r\n"
]
}
],
"source": [
"1+1"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".NET (F#)",
"language": "F#",
"name": ".net-fsharp"
},
"language_info": {
"name": "F#"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
```
#!markdown
# Open the two previously saved notebooks via the following:
1. `Ctrl+Shift+P` => "Polyglot Notebook: Open notebook"
2. Select the "Untitled-1.dib"/"Untitled-1.ipynb" from before.
3. Verify that it contains a single F# cell with the contents "1+1" and that it can execute.
#!markdown
# Test adding cell to notebook (VSCode only)
#!csharp
using Microsoft.DotNet.Interactive;
using Microsoft.DotNet.Interactive.Commands;
var _ = Kernel.Root.SendAsync(new SendEditableCode("fsharp","#!share --from csharp x\nx"));
#!csharp
using Microsoft.DotNet.Interactive;
using Microsoft.DotNet.Interactive.Commands;
var _ = Kernel.Root.SendAsync(new SendEditableCode("markdown","# markdown cell"));