/
wajaf_test.go
74 lines (53 loc) · 1.58 KB
/
wajaf_test.go
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
package wajaf
import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"testing"
)
func readfile(name string, t *testing.T) []byte {
data, err := ioutil.ReadFile(name)
if err != nil {
t.Errorf("Error loading XML File errors into string %s", err)
return nil
}
return data
}
func TestWajaf(t *testing.T) {
app := NewApplication("manual_application")
c1 := NewSeparatorContainer("")
c1.SetAttributes(Attributes{"width": "max", "height": "max", "mode": "vertical", "auto": "yes"})
app.AddChild(c1)
z0 := c1.NewZone("", "z0")
z0.AddChild(NewHTMLElement("", "HTML <h1>ELEMENT</h1> CONTENT"))
z1 := NewSeparatorZone("", "z1")
z1.AddHelp("tooltip on z1", "z1 help", "You can use z1 clicking on it")
z1.AddMessage("messageid", "The message is any string with specific tag name")
c1.AddChild(z1)
z2 := NewSeparatorZone("", "z2")
c1.AddChild(z2)
e1 := NewCodeElement("code1", "function test() { alert('Wajaf test'); }")
app.AddChild(e1)
app.AddEvent("start", "function() { alert('Wajaf working'); }")
data, err := json.Marshal(app)
fmt.Printf("JSON = %s, %v\n", string(data), err)
return
}
func TestWajafLoad(t *testing.T) {
app := NewApplication("loaded_application")
data := readfile("testunit/app.code", t)
xml.Unmarshal(data, app)
// fmt.Printf("XML TO APP: %#v\n", app)
x, err := xml.Marshal(app)
fmt.Println("XML = ", string(x), err)
// s, err := json.Marshal(app)
// fmt.Println("JSON = ", string(s), err)
json, err := json.Marshal(app)
if err != nil {
fmt.Println("error json marshal", err)
return
}
fmt.Println("JSON CODE", string(json))
return
}