1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-25 13:57:04 +00:00
1. Fix index, including both start and end. So Literal[start:end+1] will
be a valid part.

2. Replace any with string, add file param type

3. Start of making the evaluator, starting with regexp for param types
(these expression can be changed or/and overriden by user later on)


Former-commit-id: ab95265f953dadbf84170b543e1ff8840f9c4a14
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-03-27 22:33:19 +03:00
parent 251eeb6bd0
commit 126c4de29b
8 changed files with 158 additions and 55 deletions

View File

@@ -7,7 +7,6 @@ import (
"testing"
"gopkg.in/kataras/iris.v6/_future/ipel/ast"
"gopkg.in/kataras/iris.v6/_future/ipel/lexer"
)
func TestParseError(t *testing.T) {
@@ -15,8 +14,7 @@ func TestParseError(t *testing.T) {
illegalChar := '$'
input := "{id" + string(illegalChar) + "int range(1,5) else 404}"
l := lexer.New(input)
p := New(l)
p := New(input)
_, err := p.Parse()
@@ -36,10 +34,8 @@ func TestParseError(t *testing.T) {
// success
input2 := "{id:int range(1,5) else 404}"
l2 := lexer.New(input2)
p2 := New(l2)
_, err = p2.Parse()
p.Reset(input2)
_, err = p.Parse()
if err != nil {
t.Fatalf("expecting empty error on input '%s', but got: %s", input2, err.Error())
@@ -89,23 +85,35 @@ func TestParse(t *testing.T) {
},
ErrorCode: 404,
}}, // 2
{"{username:alphabetical", true,
{"{username:alphabetical}", true,
ast.ParamStatement{
Name: "username",
Type: ast.ParamTypeAlphabetical,
ErrorCode: 404,
}}, // 3
{"{username:thisianunexpected", false,
{"{myparam}", true,
ast.ParamStatement{
Name: "username",
Type: ast.ParamTypeUnExpected,
Name: "myparam",
Type: ast.ParamTypeString,
ErrorCode: 404,
}}, // 4
}
{"{myparam_:thisianunexpected}", false,
ast.ParamStatement{
Name: "myparam_",
Type: ast.ParamTypeUnExpected,
ErrorCode: 404,
}}, // 5
{"{myparam2}", false, // false because it will give an error of unexpeced token type with value 2
ast.ParamStatement{
Name: "myparam", // expected "myparam" because we don't allow integers to the parameter names.
Type: ast.ParamTypeString,
ErrorCode: 404,
}}, // 6
}
var p *Parser = new(Parser)
for i, tt := range tests {
l := lexer.New(tt.input)
p := New(l)
p.Reset(tt.input)
resultStmt, err := p.Parse()
if tt.valid && err != nil {