Repository navigation
Expand file tree
/
Copy pathHtmlOutput.fs
More file actions
114 lines (94 loc) · 4.69 KB
/
Copy pathHtmlOutput.fs
File metadata and controls
114 lines (94 loc) · 4.69 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
module AngouriMath.Interactive.Tests.HtmlOutput
open Xunit
open Microsoft.DotNet.Interactive.Formatting
open AngouriMath.FSharp.Core
open Microsoft.DotNet.Interactive.FSharp
open Microsoft.DotNet.Interactive.Commands
open Microsoft.DotNet.Interactive.Events
open Microsoft.DotNet.Interactive
open System.Linq
open System.IO
open AngouriMath
open AngouriMath.FSharp.Functions
[<Fact>]
let ``Latex with magic ILatexizeable html`` () =
AngouriMath.InteractiveExtension.KernelExtension.applyMagic()
let entity = parsed "x / 2"
let html = entity.ToDisplayString("text/html")
Assert.Equal(@"
<script id='MathJax-script' async src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'></script>
\[\frac{x}{2}\]", html)
[<Fact>]
let ``Latex with magic ERational for html`` () =
AngouriMath.InteractiveExtension.KernelExtension.applyMagic()
let entity = (("2 / 3" |> asNumber) :?> Entity.Number.Rational).ERational
let html = entity.ToDisplayString("text/html")
Assert.Equal(@"
<script id='MathJax-script' async src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'></script>
\[\frac{2}{3}\]", html)
[<Fact>]
let ``Latex with magic ERational multi-char for html`` () =
AngouriMath.InteractiveExtension.KernelExtension.applyMagic()
let entity = (("23 / 36" |> asNumber) :?> Entity.Number.Rational).ERational
let html = entity.ToDisplayString("text/html")
Assert.Equal(@"
<script id='MathJax-script' async src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'></script>
\[\frac{23}{36}\]", html)
[<Fact>]
let ``Latex with magic ILatexizeable latex`` () =
AngouriMath.InteractiveExtension.KernelExtension.applyMagic()
let entity = parsed "x / 2"
let latex = entity.ToDisplayString("text/latex")
Assert.Equal(@"$$\frac{x}{2}$$", latex)
[<Fact>]
let ``Latex with magic ERational for latex`` () =
AngouriMath.InteractiveExtension.KernelExtension.applyMagic()
let entity = (("2 / 3" |> asNumber) :?> Entity.Number.Rational).ERational
let latex = entity.ToDisplayString("text/latex")
Assert.Equal(@"$$\frac{2}{3}$$", latex)
[<Fact>]
let ``Latex with magic ERational multi-char for latex`` () =
AngouriMath.InteractiveExtension.KernelExtension.applyMagic()
let entity = (("23 / 36" |> asNumber) :?> Entity.Number.Rational).ERational
let latex = entity.ToDisplayString("text/latex")
Assert.Equal(@"$$\frac{23}{36}$$", latex)
[<Fact>]
let ``Latex with magic EDecimal`` () =
AngouriMath.InteractiveExtension.KernelExtension.applyMagic()
let entity = (("1 / 2" |> asNumber) :?> Entity.Number.Real).EDecimal
let output = entity.ToDisplayString("text/plain")
Assert.Equal("0.5", output)
[<Fact>]
let ``Latex with magic EInteger`` () =
AngouriMath.InteractiveExtension.KernelExtension.applyMagic()
let entity = (("2" |> asNumber) :?> Entity.Number.Integer).EInteger
let output = entity.ToDisplayString("text/plain")
Assert.Equal("2", output)
[<Fact(Skip = "Not working in the embedded kernel")>]
let ``Latex formatter automatically applied in Interactive`` () =
// Set up the right path
let path = Path.GetFullPath(Path.Join(Directory.GetCurrentDirectory(), "../../../../../Wrappers/AngouriMath.Interactive/bin/Release/netstandard2.1"))
Assert.True(Directory.Exists(path), $"Directory not found: {path}. We are at {Directory.GetCurrentDirectory()}")
// The code we will send
let i = $"#i \"nuget:{path}\""
let r = "#r \"nuget:AngouriMath.Interactive, *-*\""
let code = "open Core\nparsed \"x / 2\""
task {
use kernel = (new FSharpKernel()).UseKernelHelpers()
// Execute #i magic command and look for no errors
let! after_i = kernel.SendAsync(SubmitCode(i), System.Threading.CancellationToken.None)
Assert.All(after_i.Events, fun ev -> Assert.False(ev :? CommandFailed, "After i: " + ev.ToDisplayString())) |> ignore
// Execute #r magic command and look for no errors
let! after_r = kernel.SendAsync(SubmitCode(r), System.Threading.CancellationToken.None)
Assert.All(after_r.Events, fun ev -> Assert.False(ev :? CommandFailed, "After r: " + ev.ToDisplayString())) |> ignore
// Execute our code and find the right LaTeX code
let! res = kernel.SendAsync(SubmitCode(code), System.Threading.CancellationToken.None)
let mutable displayValueReceived = false
Assert.All(res.Events, fun ev ->
match ev with
| :? DisplayEvent as dp ->
Assert.Contains("<script id='MathJax-script'", dp.FormattedValues.First().ToDisplayString())
displayValueReceived <- true
| _ -> ()) |> ignore
Assert.True(displayValueReceived, "No display value was received")
}