-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
80 lines (69 loc) · 2.07 KB
/
main_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
75
76
77
78
79
80
package main
import (
"fmt"
"testing"
"github.com/gowasm/gox/parser"
"github.com/gowasm/gox/scanner"
"github.com/gowasm/gox/token"
)
// should test for all of these
// case token.ASSIGN, token.EQL, token.NEQ, token.DEFINE,
//token.LPAREN, token.LBRACE, token.COMMA, token.COLON,
//token.RETURN, token.IF, token.SWITCH, token.CASE:
func TestOtagParse(t *testing.T) {
t.Log(doParseAst("return <a>hello world</a>"))
t.Log(doParseAst("lol := <a>hahaha</a>"))
t.Log(doParseAst("if <abc></abc> == <abc></abc> {}"))
t.Log(doParseAst(`return <a attr="value">hello world</a>`))
t.Log(doParseAst(`return <a attr="value" attr2={"bang"}>hello world</a>`))
t.Log(doParseAst(`
return <a attr="value" go={func () string { return "go" }} func="yes">
hello world
</a>`))
t.Log(doParseAst(`
return <a attr="value" go={func () string { return "go" }} func="yes">
hello world<div></div>
<p class="class isn't a reserved keyword">
yeah that's right
let's have another line
and another one
{<back at it="again"></back>}
{func () vecty.Component {
return <wow></wow>
}()}
</p>
</a>`))
// check to see if newlines in OTAGs okay
t.Log(doParseAst(`
return <a attr="value"
go={func () string { return "go" }}
func="yes">
hello world
</a>`))
t.Skip()
}
func doTestExpr(strExpr string) {
expr, err := parser.ParseExpr(strExpr)
fmt.Printf("err: %v value: %v\n", err, expr)
}
func doParseAst(strExpr string) (result string) {
// src is the input that we want to tokenize.
src := []byte(strExpr)
func () string {
return ""
}()
// Initialize the scanner.
var s scanner.Scanner
fset := token.NewFileSet() // positions are relative to fset
file := fset.AddFile("", fset.Base(), len(src)) // register input "file"
s.Init(file, src, nil /* no error handler */, scanner.ScanComments)
// Repeated calls to Scan yield the token sequence found in the input.
for {
pos, tok, lit := s.Scan()
if tok == token.EOF {
break
}
result += fmt.Sprintf("%s\t%s\t%q\n", fset.Position(pos), tok, lit)
}
return result
}