-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoparser_spec.js
115 lines (108 loc) · 4.11 KB
/
goparser_spec.js
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
require(['./goparser', 'fs'], function(goparser, fs) {
describe("goparser.Parser.parseOperandNode", function() {
it("(17) parsed as int_lit", function() {
var parser = new goparser.Parser("(17)", {trackLocations: true});
expect(parser.parseOperandNode()).toEqual(
{
loc: {start: {line: 1, column: 0}, end: {line: 1, column:4}},
type: "ParenExpr",
argument: {
loc: {start: {line: 1, column: 1}, end: {line: 1, column:3}},
type: "int_lit",
value: 17
}
});
expect(parser._curToken.type).toEqual(";");
});
});
describe("goparser.Parser.parseBasicLitNode", function() {
it("42 parsed as int_lit", function() {
var parser = new goparser.Parser("42", {trackLocations: true});
expect(parser.parseBasicLitNode())
.toEqual({loc: {start: {line: 1, column: 0}, end: {line: 1, column:2}},
type: "int_lit", value: 42});
expect(parser._curToken.type).toEqual(";");
});
});
describe("goparser.Parser.parseIdentifierOrQualifiedIdentNode", function() {
it("Println parsed as Identifier", function() {
var parser = new goparser.Parser("Println", {trackLocations: true});
expect(parser.parseIdentifierOrQualifiedIdentNode())
.toEqual({loc: {start: {line: 1, column: 0}, end: {line: 1, column:7}},
type: "Identifier", name: "Println"});
expect(parser._curToken.type).toEqual(";");
});
it("fmt.Println parsed as QualifiedIdent", function() {
var parser = new goparser.Parser("fmt.Println", {trackLocations: true});
expect(parser.parseIdentifierOrQualifiedIdentNode())
.toEqual({loc: {start: {line: 1, column: 0}, end: {line: 1, column:11}},
type: "QualifiedIdent", package: "fmt", name: "Println"});
expect(parser._curToken.type).toEqual(";");
});
});
describe("goparser.Parser.parseUnaryExprNode", function() {
it("+17 parsed as UnaryExpr", function() {
var parser = new goparser.Parser("+17", {trackLocations: true});
expect(parser.parseUnaryExprNode()).toEqual(
{loc: {start: {line: 1, column: 0}, end: {line: 1, column:3}},
type: "UnaryExpr",
operator: "+",
argument: {
loc: {start: {line: 1, column: 1}, end: {line: 1, column:3}},
type: "int_lit",
value: 17,
},
prefix: true
});
expect(parser._curToken.type).toEqual(";");
});
it("*&sheeps parsed as UnaryExpr", function() {
var parser = new goparser.Parser("*&sheeps", {trackLocations: true});
expect(parser.parseUnaryExprNode()).toEqual(
{loc: {start: {line: 1, column: 0}, end: {line: 1, column:8}},
type: "UnaryExpr",
operator: "*",
argument: {
loc: {start: {line: 1, column: 1}, end: {line: 1, column:8}},
type: "UnaryExpr",
operator: "&",
argument: {
loc: {start: {line: 1, column: 2}, end: {line: 1, column:8}},
type: "Identifier",
name: "sheeps"
},
prefix: true,
},
prefix: true,
});
expect(parser._curToken.type).toEqual(";");
});
});
describe("goparser.Parser.parseExpressionNode", function() {
xit("true || !false parsed as Expression", function() {
var parser = new goparser.Parser("true || !false", {trackLocations: true});
expect(parser.parseExpressionNode()).toEqual(
{loc: {start: {line: 1, column: 0}, end: {line: 1, column:14}},
type: "Expression",
operator: "||",
left: {
loc: {start: {line: 1, column: 0}, end: {line: 1, column:4}},
type: "Identifier",
name: "true",
},
right: {
loc: {start: {line: 1, column: 8}, end: {line: 1, column:14}},
type: "UnaryExpr",
operator: "!",
argument: {
loc: {start: {line: 1, column: 9}, end: {line: 1, column:14}},
type: "Indentifier",
name: "false",
},
prefix: true
},
});
expect(parser._curToken.type).toEqual(";");
});
});
});