-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathparseSourceCodeDefinitions.solidity.spec.ts
More file actions
74 lines (63 loc) · 2.88 KB
/
Copy pathparseSourceCodeDefinitions.solidity.spec.ts
File metadata and controls
74 lines (63 loc) · 2.88 KB
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
import { testParseSourceCodeDefinitions } from "./helpers"
import { solidityQuery } from "../queries"
import { sampleSolidity } from "./fixtures/sample-solidity"
describe("Solidity Source Code Definition Tests", () => {
let parseResult: string
beforeAll(async () => {
const result = await testParseSourceCodeDefinitions("test.sol", sampleSolidity, {
language: "solidity",
wasmFile: "tree-sitter-solidity.wasm",
queryString: solidityQuery,
extKey: "sol",
})
expect(result).toBeDefined()
expect(typeof result).toBe("string")
parseResult = result as string
})
it("should parse contract declarations", () => {
expect(parseResult).toMatch(/22--102 \| contract TestContract is ITestInterface/)
expect(parseResult).toMatch(/5--9 \| interface ITestInterface/)
expect(parseResult).toMatch(/11--20 \| library MathLib/)
})
it("should parse using directives", () => {
expect(parseResult).toMatch(/23--23 \| {5}using MathLib for uint256;/)
})
it("should parse type declarations", () => {
expect(parseResult).toMatch(/25--30 \| {5}struct UserInfo {/)
expect(parseResult).toMatch(/32--37 \| {5}enum UserRole {/)
})
it("should parse state variable declarations", () => {
expect(parseResult).toMatch(/39--39 \| {5}uint256 private immutable totalSupply;/)
expect(parseResult).toMatch(/40--40 \| {5}mapping\(address => UserInfo\) private users;/)
expect(parseResult).toMatch(/41--41 \| {5}UserRole\[\] private roles;/)
})
it("should parse function declarations", () => {
expect(parseResult).toMatch(/70--87 \| {5}function transfer\(/)
expect(parseResult).toMatch(/89--93 \| {5}function interfaceFunction\(/)
expect(parseResult).toMatch(/6--6 \| {5}function interfaceFunction\(uint256 value\) external returns \(bool\);/)
expect(parseResult).toMatch(
/12--14 \| {5}function add\(uint256 a, uint256 b\) internal pure returns \(uint256\) {/,
)
expect(parseResult).toMatch(
/16--19 \| {5}function subtract\(uint256 a, uint256 b\) internal pure returns \(uint256\) {/,
)
})
it("should parse constructor declarations", () => {
expect(parseResult).toMatch(/63--68 \| {5}constructor\(uint256 _initialSupply\) {/)
})
it("should parse special function declarations", () => {
expect(parseResult).toMatch(/95--97 \| {5}fallback\(\) external payable {/)
expect(parseResult).toMatch(/99--101 \| {5}receive\(\) external payable {/)
})
it("should parse event declarations", () => {
expect(parseResult).toMatch(/43--47 \| {5}event Transfer\(/)
expect(parseResult).toMatch(/7--7 \| {5}event InterfaceEvent\(address indexed sender, uint256 value\);/)
})
it("should parse error declarations", () => {
expect(parseResult).toMatch(/49--53 \| {5}error InsufficientBalance\(/)
expect(parseResult).toMatch(/8--8 \| {5}error InterfaceError\(string message\);/)
})
it("should parse modifier declarations", () => {
expect(parseResult).toMatch(/55--61 \| {5}modifier onlyAdmin\(\) {/)
})
})