forked from dotnet/interactive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotebookTestScript.dib
206 lines (144 loc) · 3.84 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
#!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
Comamnd cancelled
```
#!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
const x = await interactive.csharp.getVariable("x");
document.getElementById("output").innerText = `The value is ${x}.`;
console.log(`The value is ${x}.`);
#!markdown
# Execute the next cell, the output should be displayed as JSON like so:
``` json
{"Name":"Developer","Salary":42}
```
#!csharp
display(new { Name = "Developer", Salary = 42 }, "application/json");
#!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
This cell should prompt the user for input
#!csharp
var input = await GetInputAsync("give me data");
input
#!fsharp
let input = GetInputAsync "give me data" false |> Async.RunSynchronously
input
#!markdown
Test adding cell to notebook (VSCode only)
#!csharp
using Microsoft.DotNet.Interactive;
using Microsoft.DotNet.Interactive.Commands;
var _ = Kernel.Root.SendAsync(new SendEditableCode("markdown","# this is a markdown cell."));
#!markdown
# Check this manual scenario:
1. `Ctrl+Shift+P` => ".NET Interactive: 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# (Interactive)".
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
{
"metadata": {
"kernelspec": {
"display_name": ".NET (F#)",
"language": "F#",
"name": ".net-fsharp"
},
"language_info": {
"name": "F#"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": null,
"source": [
"1+1"
],
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"<div class=\"dni-plaintext\">2</div>"
]
},
"metadata": {}
}
],
"metadata": {
"dotnet_interactive": {
"language": "fsharp"
}
}
}
],
"nbformat": 4,
"nbformat_minor": 2
}
```
#!markdown
# Open the two previously saved notebooks via the following:
1. `Ctrl+Shift+P` => ".NET Interactive: 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.