11" Syntax highlighting tests for vim-solidity
22
3- " Helper function is defined in test/vimrc
4-
53Before:
64 set rtp+=.
75 filetype plugin indent on
@@ -20,148 +18,18 @@ Given solidity (transient keyword):
2018 }
2119
2220Execute (transient should be highlighted as keyword):
23- normal! /transient
24- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
25- AssertEqual 'solKeyword', l:group
26-
27- Given solidity (unchecked block):
28- function test() public {
29- unchecked {
30- x++;
31- }
32- }
33-
34- Execute (unchecked should be highlighted as keyword):
35- normal! /unchecked
36- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
37- AssertEqual 'solKeyword', l:group
38-
39- Given solidity (custom error):
40- error InsufficientBalance(uint256 available, uint256 required);
41-
42- Execute (error should be highlighted as keyword):
43- normal! /error
44- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
45- AssertEqual 'solKeyword', l:group
46-
47- Given solidity (fallback function):
48- fallback() external payable {}
49-
50- Execute (fallback should be highlighted as keyword):
51- normal! /fallback
52- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
53- AssertEqual 'solKeyword', l:group
54-
55- Given solidity (receive function):
56- receive() external payable {}
57-
58- Execute (receive should be highlighted as keyword):
59- normal! /receive
60- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
61- AssertEqual 'solKeyword', l:group
62-
63- # ==============================================================================
64- # Issue #15: String Literal Bug
65- # ==============================================================================
66-
67- Given solidity (string with function signature):
68- bytes32 hash = keccak256(bytes("submitSomething(bytes)"));
69- uint256 value = 42;
70-
71- Execute (string should close properly and value should highlight correctly):
72- " Check that string is highlighted
73- normal! /"submitSomething
74- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
75- AssertEqual 'solString', l:group
76-
77- " Check that content after string is highlighted correctly
78- normal! /value
79- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
80- " Should be highlighted as identifier (no specific group) or Number group
81- " The important thing is it's NOT solString
82- AssertNotEqual 'solString', l:group
83-
84- Given solidity (multiple strings with parens):
85- string memory a = "func(uint256)";
86- string memory b = "other(bytes)";
87-
88- Execute (both strings should be highlighted independently):
89- normal! /"func
90- let l:group1 = synIDattr(synID(line('.'), col('.'), 1), 'name')
91- AssertEqual 'solString', l:group1
92-
93- normal! /"other
94- let l:group2 = synIDattr(synID(line('.'), col('.'), 1), 'name')
95- AssertEqual 'solString', l:group2
96-
97- # ==============================================================================
98- # Basic Syntax Elements
99- # ==============================================================================
100-
101- Given solidity (contract declaration):
102- contract MyContract {
103- }
104-
105- Execute (contract should be highlighted as Type):
106- normal! /contract
107- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
108- AssertEqual 'solContract', l:group
109-
110- normal! /MyContract
111- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
112- AssertEqual 'solContractName', l:group
113-
114- Given solidity (function declaration):
115- function test() public pure returns (uint256) {
116- return 42;
117- }
118-
119- Execute (function elements should be highlighted correctly):
120- normal! /function
121- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
122- AssertEqual 'solFunction', l:group
123-
124- normal! /test
125- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
126- AssertEqual 'solFuncName', l:group
127-
128- normal! /public
129- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
130- AssertEqual 'solKeyword', l:group
131-
132- normal! /uint256
133- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
134- AssertEqual 'solBuiltinType', l:group
135-
136- Given solidity (comments and natspec):
137- /// @notice This is a natspec comment
138- // Regular comment
139- /* Block comment */
140-
141- Execute (comments should be highlighted):
142- normal! gg
143- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
144- AssertEqual 'solLineComment', l:group
145-
146- # ==============================================================================
147- # Assembly / Yul
148- # ==============================================================================
149-
150- Given solidity (assembly block):
151- assembly {
152- let x := add(1, 2)
153- sstore(0, x)
154- }
155-
156- Execute (assembly keywords should be highlighted):
157- normal! /assembly
158- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
159- AssertEqual 'yul', l:group
160-
161- normal! /add
162- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
163- AssertEqual 'yulAssemblyOp', l:group
164-
165- normal! /sstore
166- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
167- AssertEqual 'yulAssemblyOp', l:group
21+ set filetype=solidity
22+ runtime! syntax/solidity.vim
23+ call search('transient', 'w')
24+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
25+ AssertEqual 'solKeyword', g:syn
26+
27+ Given solidity (uint256 type):
28+ uint256 value;
29+
30+ Execute (uint256 should be highlighted as builtin type):
31+ set filetype=solidity
32+ runtime! syntax/solidity.vim
33+ call search('uint256', 'w')
34+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
35+ AssertEqual 'solBuiltinType', g:syn
0 commit comments