@@ -4,6 +4,112 @@ using Test
4
4
import MathLink: WExpr, WSymbol
5
5
6
6
7
+
8
+ @testset " interpolation" begin
9
+ set_GreedyEval (false )
10
+ x = exp (1 )
11
+ @test W ` Sin[$x ]` == W " Sin" (x)
12
+ @test W ` Cos[$(log (2 )) ]` == W " Cos" (log (2 ))
13
+
14
+ @test W ` Sin[$(1.2e19 ) ]` == W ` Sin[1.2*^19]`
15
+ @test string (W ` Sin[$(1.2e19 ) ]` ) == " W`Sin[1.2*^19]`"
16
+ end
17
+
18
+
19
+ function TestMeta (x)
20
+ # println("M '",x,"'")
21
+ return Meta. parse (x)
22
+ end
23
+
24
+ function TestEscape (x)
25
+ # println("E '",x,"'")
26
+ return escape_string (x)
27
+ end
28
+
29
+ function EscapeDollar (str:: AbstractString )
30
+ # println("R '",str,"'")
31
+ return replace (str,' \$ ' => " \\\$ " )
32
+ end
33
+
34
+ @testset " Conversion of strange characters" begin
35
+ a= " !"
36
+ println (" Test with variable after" )
37
+ # ##Test with variable after
38
+ @test TestMeta (" \" $a \" " ) == " !"
39
+ @test TestMeta (" \"\$ a\" " ) == :(" $(a) " )
40
+ # ##Invalid escape sequence
41
+ @test_throws Base. Meta. ParseError (" invalid escape sequence" ) TestMeta (" \"\\ $a \" " )
42
+ @test TestMeta (" \"\\\$ a\" " ) == " \$ a"
43
+ @test TestMeta (" \"\\\\ $a \" " ) == " \\ !"
44
+ @test TestMeta (" \"\\\\\$ a\" " ) == :(" \\ $(a) " )
45
+ @test_throws Base. Meta. ParseError (" invalid escape sequence" ) TestMeta (" \"\\\\\\ $a \" " )
46
+
47
+ println (" Test with no variable after" )
48
+ # ##Test with no variable after
49
+ # ## TestMeta("\"$\"") ###Invalid syntax
50
+ @test_throws Base. Meta. ParseError TestMeta (" \"\$\" " )
51
+ # ## TestMeta("\"\\$\"") ###Invalid syntax
52
+ @test TestMeta (" \"\\\$\" " ) == " \$ "
53
+ # ## TestMeta("\"\\\\$\"") ###Invalid syntax
54
+ @test_throws Base. Meta. ParseError TestMeta (" \"\\\\\$\" " )
55
+ # ## TestMeta("\"\\\\\\$\"") ###Invalid syntax
56
+ @test TestMeta (" \"\\\\\\\$\" " ) == " \\\$ "
57
+
58
+ println (" Test escaped strings" )
59
+ # ## Test escaped strings
60
+ @test TestEscape (" \$ " ) == " \$ "
61
+ @test TestEscape (" \\\$ " ) == " \\\\\$ "
62
+ @test TestEscape (" \\\\\$ " ) == " \\\\\\\\\$ "
63
+ @test TestEscape (" \$\$ " ) == " \$\$ "
64
+ @test TestEscape (" \\\$\$ " ) == " \\\\\$\$ "
65
+ @test TestEscape (" \\\\\$\$ " ) == " \\\\\\\\\$\$ "
66
+
67
+ println (" Test escaped strings" )
68
+ @test EscapeDollar (" \$ " ) == " \\\$ "
69
+ @test EscapeDollar (" \\\$ " ) == " \\\\\$ "
70
+ @test EscapeDollar (" \\\\\$ " ) == " \\\\\\\$ "
71
+ @test EscapeDollar (" \$\$ " ) == " \\\$\\\$ "
72
+ @test EscapeDollar (" \\\$\$ " ) == " \\\\\$\\\$ "
73
+ @test EscapeDollar (" \\\\\$\$ " ) == " \\\\\\\$\\\$ "
74
+
75
+ set_GreedyEval (false )
76
+ println (" Test math on the symbols" )
77
+ @test weval (WSymbol (" a" )+ WSymbol (" a" )) == weval (2 * WSymbol (" a" ))
78
+ @test weval (WSymbol (" \$ " )+ WSymbol (" \$ " )) == weval (2 * WSymbol (" \$ " ))
79
+ println (" Test creating the symbol" )
80
+ # ##Test creating the symbol
81
+ @test W ` a` == WSymbol (" a" )
82
+ @test W ` a` == W " a"
83
+ @test W `\$ ` == WSymbol (" \$ " )
84
+
85
+
86
+ println (" Test creating the symbol string" )
87
+ # ##Test creating the symbol string
88
+ @test W ` "a"` == " a"
89
+ @test W ` "\$ "` == " \$ "
90
+
91
+
92
+ println (" Other tests" )
93
+ @test W ` "\$ "` == " \$ "
94
+ @test W ` "a"` == " a"
95
+ @test W ` {a -> b}` == W " List" (W " Rule" (W " a" ,W " b" ))
96
+ @test W ` {"a" -> "b"}` == W " List" (W " Rule" (" a" ," b" ))
97
+ @test W ` "a" -> "b"` == W " Rule" (" a" ," b" )
98
+ @test W ` a -> b` == W " Rule" (W " a" ,W " b" )
99
+ @test W ` "b(\$ )a"` == " b(\$ )a"
100
+ @test W ` "b\\\$ "` == " b\\\$ "
101
+ @test W ` "b\$ "` == " b\$ "
102
+ @test W ` "$a "` == " \$ a"
103
+ @test W ` "$"` == " \$ "
104
+ @test W ` "$"` == " \$ "
105
+ @test W ` "$" -> "b"` == W " Rule" (" \$ " ," b" )
106
+ @test W ` {"$" -> "b"}` == W " List" (W " Rule" (" \$ " ," b" ))
107
+ @test W ` {"a" -> "$"}` == W " List" (W " Rule" (" a" ," \$ " ))
108
+ @test W ` {a -> "$"}` == W " List" (W " Rule" (W " a" ," \$ " ))
109
+
110
+ end
111
+
112
+
7
113
@testset " W2JuliaExpr" begin
8
114
# ##Test of a simple MathLink to Julia converter. It converts MathLink expressions to the correcsponding Julia constructions
9
115
@testset " Variables" begin
196
302
@test weval (W " Dot" (A,x)) == WExpr (W " List" ,A* x)
197
303
end
198
304
199
- @testset " interpolation" begin
200
- x = exp (1 )
201
- @test W ` Sin[$x ]` == W " Sin" (x)
202
- @test W ` Cos[$(log (2 )) ]` == W " Cos" (log (2 ))
203
-
204
- @test W ` Sin[$(1.2e19 ) ]` == W ` Sin[1.2*^19]`
205
- @test string (W ` Sin[$(1.2e19 ) ]` ) == " W`Sin[1.2*^19]`"
206
- end
207
-
208
305
209
306
210
307
@testset " README" begin
358
455
@test ! showable (" text/latex" ,W " a" + W " b" )
359
456
end
360
457
458
+
459
+
460
+
461
+ @testset " String conversions floats" begin
462
+ # ##A few special tests to solve issue 94
463
+ # ##https://github.com/JuliaInterop/MathLink.jl/issues/94
464
+
465
+
466
+ # ###
467
+ # ## weval(W"ToExpression"("17.0000000000000000000000000", W"StandardForm", W"Hold"))
468
+
469
+ s= " 17.000000000"
470
+ @test MathLink. parseexpr (s) == s
471
+ s= " 17.0000000000"
472
+ @test MathLink. parseexpr (s) == s
473
+ s= " 17.00000000000"
474
+ @test MathLink. parseexpr (s) == s
475
+ s= " 17.000000000000"
476
+ @test MathLink. parseexpr (s) == s
477
+ s= " 17.0000000000000"
478
+ @test MathLink. parseexpr (s) == s
479
+ s= " 17.00000000000000"
480
+ @test MathLink. parseexpr (s) == s
481
+
482
+ @test W ` 17.000000000` == 17.0
483
+ @test W ` 17.000000000000` == 17.0
484
+ @test W ` 17.00000000000000000` == 17.0
485
+ @test W ` 17.000000000000000000000` == 17.0
486
+
487
+ end
488
+
0 commit comments