-
Notifications
You must be signed in to change notification settings - Fork 8
/
Tests.fs
124 lines (102 loc) · 5.38 KB
/
Tests.fs
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
namespace SharpVG.Tests
open SharpVG
open Xunit
open FsCheck
open FsCheck.Xunit
open BasicChecks
open System
module Tests =
[<SvgProperty>]
let ``create rect with style`` (r, g, b) =
let style = Style.createWithStroke <| Values(r, g, b)
let element =
Rect.create Point.origin Area.full
|> Element.createWithStyle style
|> Element.toString
let result = sprintf "<rect stroke=\"rgb(%d,%d,%d)\" x=\"0\" y=\"0\" width=\"100%%\" height=\"100%%\"/>" r g b
Assert.Equal(result, element);
[<SvgProperty>]
let ``draw lines`` (x1, y1, x2, y2, c, r, g, b, p, o, fo) =
let point1, point2 = Point.ofFloats (x1, y1), Point.ofFloats (x2, y2)
let fill, stroke, strokeWidth, opacity, fillOpacity = Hex c, Values(r, g, b), Length.ofFloat p, o, fo
let style = Style.create fill stroke strokeWidth opacity fillOpacity
let line = Line.create point1 point2
let tag = line |> Element.createWithStyle style |> Element.toString
checkBodylessTag "line" tag
[<SvgProperty>]
let ``draw rectangles`` (x, y, h, w, c, r, g, b, p, o, fo) =
let point = Point.ofFloats (x, y)
let area = Area.ofFloats (h, w)
let fill, stroke, strokeWidth, opacity, fillOpacity = Hex c, Values(r, g, b), Length.ofFloat p, o, fo
let style = Style.create fill stroke strokeWidth opacity fillOpacity
let rect = Rect.create point area
let tag = rect |> Element.createWithStyle style |> Element.toString
checkBodylessTag "rect" tag
[<SvgProperty>]
let ``draw circles`` (x, y, radius, c, r, g, b, p, o, fo) =
let point = Point.ofFloats (x, y)
let fill, stroke, strokeWidth, opacity, fillOpacity = Hex c, Values(r, g, b), Length.ofFloat p, o, fo
let style = Style.create fill stroke strokeWidth opacity fillOpacity
let circle = Circle.create point (Length.ofFloat radius)
let tag = circle |> Element.createWithStyle style |> Element.toString
checkBodylessTag "circle" tag
[<SvgProperty>]
let ``draw ellipses`` (x1, y1, x2, y2, c, r, g, b, p, o, fo) =
let point1, point2 = Point.ofFloats (x1, y1), Point.ofFloats (x2, y2)
let fill, stroke, strokeWidth, opacity, fillOpacity = Hex c, Values(r, g, b), Length.ofFloat p, o, fo
let style = Style.create fill stroke strokeWidth opacity fillOpacity
let ellipse = Ellipse.create point1 point2
let tag = ellipse |> Element.createWithStyle style |> Element.toString
checkBodylessTag "ellipse" tag
[<Property>]
let ``draw images`` (x, y, h, w) =
let point = Point.ofFloats (x, y)
let area = Area.ofFloats (h, w)
let image = Image.create point area "test.jpg"
let tag = image |> Element.create |> Element.toString
checkBodylessTag "image" tag
[<SvgProperty>]
let ``draw texts`` (x, y, c, r, g, b, p, o, fo) =
let point = Point.ofFloats (x, y)
let fill, stroke, strokeWidth, opacity, fillOpacity = Hex c, Values(r, g, b), Length.ofFloat p, o, fo
let style = Style.create fill stroke strokeWidth opacity fillOpacity
let text = Text.create point "test"
let tag = text |> Element.createWithStyle style |> Element.toString
checkTag "text" tag
[<SvgProperty>]
let ``animate circles`` (x, y, radius, c, r, g, b, p, o, fo) =
let p1 = Point.ofInts (100, 100)
let p2 = Point.ofInts (500, 500)
let p3 = Point.ofInts (200, 200)
let point = Point.ofFloats (x, y)
let path = Path.empty |> (Path.addSmoothQuadraticBezierCurveTo Absolute p1) |> (Path.addLineTo Absolute p2) |> (Path.addSmoothQuadraticBezierCurveTo Absolute p3)
let timing = Timing.create <| TimeSpan.FromSeconds(0.0)
let fill, stroke, strokeWidth, opacity, fillOpacity = Hex c, Values(r, g, b), Length.ofFloat p, o, fo
let style = Style.create fill stroke strokeWidth opacity fillOpacity
let circle = Circle.create point (Length.ofFloat radius)
let animation = Animation.createMotion timing path None
let tag = circle |> Element.createWithStyle style |> Element.withAnimation animation |> Element.toString
checkTag "circle" tag
[<Fact>]
let ``do lots and don't fail`` () =
let points = seq {
yield Point.ofInts (1, 1)
yield Point.ofInts (4, 4)
yield Point.ofInts (8, 8)
}
let point = Point.ofInts (24, 15)
let style1 = Style.create (Name Colors.Red) (Hex 0xff0000) (Length.ofFloat 3.0) 1.0 1.0
let style2 = Style.create (Name Colors.Blue) (SmallHex 0xf00s) (Length.ofFloat 6.0) 1.0 1.0
let length = Length.ofPixels 1
let area = Area.create length length
let graphics = seq {
yield Image.create point area "myimage1.jpg" |> Element.create
yield Image.create point area "myimage2.jpg" |> Element.createWithStyle style1
yield Text.create point "Hello World!" |> Element.createWithStyle style2
yield Line.create point point |> Element.createWithStyle style1
yield Rect.create point area |> Element.createWithStyle style2
yield Circle.create point length |> Element.create
yield Ellipse.create point point |> Element.createWithStyle style1
}
let html = graphics |> Svg.ofSeq |> Svg.toHtml "SVG Demo"
checkTag "SVG Demo" html