• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yyle88 / syntaxgo / 13515929993

25 Feb 2025 07:31AM UTC coverage: 48.257% (-0.3%) from 48.518%
13515929993

push

github

yangyile
添加两个小的函数用来调整代码块的范围

0 of 6 new or added lines in 1 file covered. (0.0%)

540 of 1119 relevant lines covered (48.26%)

5.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/syntaxgo_astnode/node.go
1
package syntaxgo_astnode
2

3
import (
4
        "go/ast"
5
        "go/token"
6
)
7

8
// Node represents a syntax node with position information.
9
// Node 表示一个带有位置信息的语法节点。
10
type Node struct {
11
        pos token.Pos // position of first character belonging to the node // 节点第一个字符的位置
12
        end token.Pos // position of first character immediately after the node // 节点结束后第一个字符的位置
13
}
14

15
// NewNode creates a new Node with the specified start and end positions.
16
// NewNode 创建一个带有指定起始和结束位置的 Node。
17
func NewNode(pos, end token.Pos) *Node {
34✔
18
        return &Node{pos: pos, end: end}
34✔
19
}
34✔
20

21
// NewNodeV1 creates a new Node from an existing ast.Node.
22
// NewNodeV1 从一个现有的 ast.Node 创建一个新的 Node。
23
func NewNodeV1(node ast.Node) *Node {
2✔
24
        return NewNode(node.Pos(), node.End())
2✔
25
}
2✔
26

27
// NewNodeV2 creates a new Node with the specified start and end positions as integers.
28
// NewNodeV2 创建一个带有指定起始和结束位置(整数)的 Node。
29
func NewNodeV2(pos, end int) *Node {
×
30
        return NewNode(token.Pos(pos), token.Pos(end))
×
31
}
×
32

33
// Pos returns the start position of the Node.
34
// Pos 返回 Node 的起始位置。
35
func (x *Node) Pos() token.Pos {
30✔
36
        return x.pos
30✔
37
}
30✔
38

39
// End returns the end position of the Node.
40
// End 返回 Node 的结束位置。
41
func (x *Node) End() token.Pos {
30✔
42
        return x.end
30✔
43
}
30✔
44

45
// SetPos sets the start position of the Node.
46
// SetPos 设置 Node 的起始位置。
NEW
47
func (x *Node) SetPos(pos token.Pos) {
×
NEW
48
        x.pos = pos
×
NEW
49
}
×
50

51
// SetEnd sets the end position of the Node.
52
// SetEnd 设置 Node 的结束位置。
NEW
53
func (x *Node) SetEnd(end token.Pos) {
×
NEW
54
        x.end = end
×
NEW
55
}
×
56

57
// GetCode returns the code corresponding to the Node from the source.
58
// GetCode 从源代码中返回与 Node 对应的代码。
59
func (x *Node) GetCode(source []byte) []byte {
2✔
60
        return source[x.Pos()-1 : x.End()-1]
2✔
61
}
2✔
62

63
// GetText returns the text corresponding to the Node from the source.
64
// GetText 从源代码中返回与 Node 对应的文本。
65
func (x *Node) GetText(source []byte) string {
2✔
66
        return string(source[x.Pos()-1 : x.End()-1])
2✔
67
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc