diff options
| author | Mel <einebeere@gmail.com> | 2022-05-09 00:01:02 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-05-09 00:01:02 +0200 |
| commit | b09a14147d397904722ee7c25e4defc56135b96f (patch) | |
| tree | 694dc725528310f3a65d04785b8eea33908ce69f /pkg/lang/parser/parser_test.go | |
| parent | b5a9660b6ac42bce27c746e76013c3ce5992743a (diff) | |
| download | jinx-b09a14147d397904722ee7c25e4defc56135b96f.tar.zst jinx-b09a14147d397904722ee7c25e4defc56135b96f.zip | |
Extract source walk part of scanner
Diffstat (limited to 'pkg/lang/parser/parser_test.go')
| -rw-r--r-- | pkg/lang/parser/parser_test.go | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/pkg/lang/parser/parser_test.go b/pkg/lang/parser/parser_test.go index 969e878..c3794e9 100644 --- a/pkg/lang/parser/parser_test.go +++ b/pkg/lang/parser/parser_test.go @@ -4,7 +4,7 @@ import ( "jinx/pkg/lang/ast" "jinx/pkg/lang/parser" "jinx/pkg/lang/scanner" - "jinx/pkg/lang/scanner/token" + "jinx/pkg/libs/source" "strings" "testing" @@ -12,8 +12,8 @@ import ( ) func TestIntLit(t *testing.T) { - source := `123` - p := cheatWithScanner(t, source) + src := `123` + p := cheatWithScanner(t, src) program, err := p.Parse() require.NoError(t, err) @@ -30,8 +30,8 @@ func TestIntLit(t *testing.T) { } func TestSimpleBinaryExpr(t *testing.T) { - source := `1 + 2` - p := cheatWithScanner(t, source) + src := `1 + 2` + p := cheatWithScanner(t, src) program, err := p.Parse() require.NoError(t, err) @@ -48,7 +48,7 @@ func TestSimpleBinaryExpr(t *testing.T) { }, Op: ast.BinOpPlus, Right: ast.Expr{ - At: token.NewLoc(0, 4), + At: source.NewLoc(0, 4), Kind: ast.ExprKindIntLit, Value: ast.ExprIntLit{Value: 2}, }, @@ -59,8 +59,8 @@ func TestSimpleBinaryExpr(t *testing.T) { } func TestLeftAssocBinaryExpr(t *testing.T) { - source := `1 + 2 + 3` - p := cheatWithScanner(t, source) + src := `1 + 2 + 3` + p := cheatWithScanner(t, src) program, err := p.Parse() require.NoError(t, err) @@ -80,7 +80,7 @@ func TestLeftAssocBinaryExpr(t *testing.T) { }, Op: ast.BinOpPlus, Right: ast.Expr{ - At: token.NewLoc(0, 4), + At: source.NewLoc(0, 4), Kind: ast.ExprKindIntLit, Value: ast.ExprIntLit{Value: 2}, }, @@ -88,7 +88,7 @@ func TestLeftAssocBinaryExpr(t *testing.T) { }, Op: ast.BinOpPlus, Right: ast.Expr{ - At: token.NewLoc(0, 8), + At: source.NewLoc(0, 8), Kind: ast.ExprKindIntLit, Value: ast.ExprIntLit{Value: 3}, }, @@ -99,8 +99,8 @@ func TestLeftAssocBinaryExpr(t *testing.T) { } func TestRightAssocBinaryExpr(t *testing.T) { - source := `x = y = z` - p := cheatWithScanner(t, source) + src := `x = y = z` + p := cheatWithScanner(t, src) program, err := p.Parse() require.NoError(t, err) @@ -117,19 +117,19 @@ func TestRightAssocBinaryExpr(t *testing.T) { }, Op: ast.BinOpAssign, Right: ast.Expr{ - At: token.NewLoc(0, 4), + At: source.NewLoc(0, 4), Kind: ast.ExprKindBinary, Value: ast.ExprBinary{ Left: ast.Expr{ - At: token.NewLoc(0, 4), + At: source.NewLoc(0, 4), Kind: ast.ExprKindIdent, - Value: ast.ExprIdent{Value: ast.IdentNode{At: token.NewLoc(0, 4), Value: "y"}}, + Value: ast.ExprIdent{Value: ast.IdentNode{At: source.NewLoc(0, 4), Value: "y"}}, }, Op: ast.BinOpAssign, Right: ast.Expr{ - At: token.NewLoc(0, 8), + At: source.NewLoc(0, 8), Kind: ast.ExprKindIdent, - Value: ast.ExprIdent{Value: ast.IdentNode{At: token.NewLoc(0, 8), Value: "z"}}, + Value: ast.ExprIdent{Value: ast.IdentNode{At: source.NewLoc(0, 8), Value: "z"}}, }, }, }, @@ -140,8 +140,8 @@ func TestRightAssocBinaryExpr(t *testing.T) { } func TestVarDecl(t *testing.T) { - source := `var x = 123` - p := cheatWithScanner(t, source) + src := `var x = 123` + p := cheatWithScanner(t, src) program, err := p.Parse() require.NoError(t, err) @@ -149,9 +149,9 @@ func TestVarDecl(t *testing.T) { require.Equal(t, ast.Stmt{ Kind: ast.StmtKindVarDecl, Value: ast.StmtVarDecl{ - Name: ast.IdentNode{At: token.NewLoc(0, 4), Value: "x"}, + Name: ast.IdentNode{At: source.NewLoc(0, 4), Value: "x"}, Value: ast.Expr{ - At: token.NewLoc(0, 8), + At: source.NewLoc(0, 8), Kind: ast.ExprKindIntLit, Value: ast.ExprIntLit{Value: 123}, }, @@ -160,14 +160,14 @@ func TestVarDecl(t *testing.T) { } func TestEmptyStmt(t *testing.T) { - source := ` + src := ` ; ` - p := cheatWithScanner(t, source) + p := cheatWithScanner(t, src) program, err := p.Parse() require.NoError(t, err) @@ -179,17 +179,17 @@ func TestEmptyStmt(t *testing.T) { Value: ast.StmtEmpty{}, }, { - At: token.NewLoc(3, 1), + At: source.NewLoc(3, 1), Kind: ast.StmtKindEmpty, Value: ast.StmtEmpty{}, }, { - At: token.NewLoc(3, 2), + At: source.NewLoc(3, 2), Kind: ast.StmtKindEmpty, Value: ast.StmtEmpty{}, }, { - At: token.NewLoc(6, 1), + At: source.NewLoc(6, 1), Kind: ast.StmtKindEmpty, Value: ast.StmtEmpty{}, }, @@ -199,13 +199,13 @@ func TestEmptyStmt(t *testing.T) { } func TestMultipleStmts(t *testing.T) { - source := sourceify( + src := sourceify( `var x = 1`, `var y = 2`, `z = 3`, ) - p := cheatWithScanner(t, source) + p := cheatWithScanner(t, src) program, err := p.Parse() require.NoError(t, err) @@ -215,42 +215,42 @@ func TestMultipleStmts(t *testing.T) { { Kind: ast.StmtKindVarDecl, Value: ast.StmtVarDecl{ - Name: ast.IdentNode{At: token.NewLoc(0, 4), Value: "x"}, + Name: ast.IdentNode{At: source.NewLoc(0, 4), Value: "x"}, Value: ast.Expr{ - At: token.NewLoc(0, 8), + At: source.NewLoc(0, 8), Kind: ast.ExprKindIntLit, Value: ast.ExprIntLit{Value: 1}, }, }, }, { - At: token.NewLoc(1, 0), + At: source.NewLoc(1, 0), Kind: ast.StmtKindVarDecl, Value: ast.StmtVarDecl{ - Name: ast.IdentNode{At: token.NewLoc(1, 4), Value: "y"}, + Name: ast.IdentNode{At: source.NewLoc(1, 4), Value: "y"}, Value: ast.Expr{ - At: token.NewLoc(1, 8), + At: source.NewLoc(1, 8), Kind: ast.ExprKindIntLit, Value: ast.ExprIntLit{Value: 2}, }, }, }, { - At: token.NewLoc(2, 0), + At: source.NewLoc(2, 0), Kind: ast.StmtKindExpr, Value: ast.StmtExpr{ Value: ast.Expr{ - At: token.NewLoc(2, 0), + At: source.NewLoc(2, 0), Kind: ast.ExprKindBinary, Value: ast.ExprBinary{ Left: ast.Expr{ - At: token.NewLoc(2, 0), + At: source.NewLoc(2, 0), Kind: ast.ExprKindIdent, - Value: ast.ExprIdent{Value: ast.IdentNode{At: token.NewLoc(2, 0), Value: "z"}}, + Value: ast.ExprIdent{Value: ast.IdentNode{At: source.NewLoc(2, 0), Value: "z"}}, }, Op: ast.BinOpAssign, Right: ast.Expr{ - At: token.NewLoc(2, 4), + At: source.NewLoc(2, 4), Kind: ast.ExprKindIntLit, Value: ast.ExprIntLit{Value: 3}, }, @@ -263,12 +263,12 @@ func TestMultipleStmts(t *testing.T) { } func TestIfStmt(t *testing.T) { - source := sourceify( + src := sourceify( `if false {`, ` var x = 2`, `}`, ) - p := cheatWithScanner(t, source) + p := cheatWithScanner(t, src) program, err := p.Parse() require.NoError(t, err) @@ -277,25 +277,25 @@ func TestIfStmt(t *testing.T) { Kind: ast.StmtKindIf, Value: ast.StmtIf{ Cond: ast.Expr{ - At: token.NewLoc(0, 3), + At: source.NewLoc(0, 3), Kind: ast.ExprKindBoolLit, Value: ast.ExprBoolLit{Value: false}, }, Then: ast.BlockNode{ - At: token.NewLoc(0, 9), + At: source.NewLoc(0, 9), Stmts: []ast.Stmt{ { - At: token.NewLoc(0, 10), + At: source.NewLoc(0, 10), Kind: ast.StmtKindEmpty, Value: ast.StmtEmpty{}, }, { - At: token.NewLoc(1, 1), + At: source.NewLoc(1, 1), Kind: ast.StmtKindVarDecl, Value: ast.StmtVarDecl{ - Name: ast.IdentNode{At: token.NewLoc(1, 5), Value: "x"}, + Name: ast.IdentNode{At: source.NewLoc(1, 5), Value: "x"}, Value: ast.Expr{ - At: token.NewLoc(1, 9), + At: source.NewLoc(1, 9), Kind: ast.ExprKindIntLit, Value: ast.ExprIntLit{Value: 2}, }, |
