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
@@ -21,8 +19,9 @@ Given solidity (transient keyword):
2119
2220Execute (transient should be highlighted as keyword):
2321 normal! /transient
24- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
25- AssertEqual 'solKeyword', l:group
22+ normal! w
23+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
24+ AssertEqual 'solKeyword', g:syn
2625
2726Given solidity (unchecked block):
2827 function test() public {
@@ -33,32 +32,36 @@ Given solidity (unchecked block):
3332
3433Execute (unchecked should be highlighted as keyword):
3534 normal! /unchecked
36- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
37- AssertEqual 'solKeyword', l:group
35+ normal! w
36+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
37+ AssertEqual 'solKeyword', g:syn
3838
3939Given solidity (custom error):
4040 error InsufficientBalance(uint256 available, uint256 required);
4141
4242Execute (error should be highlighted as keyword):
4343 normal! /error
44- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
45- AssertEqual 'solKeyword', l:group
44+ normal! w
45+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
46+ AssertEqual 'solKeyword', g:syn
4647
4748Given solidity (fallback function):
4849 fallback() external payable {}
4950
5051Execute (fallback should be highlighted as keyword):
5152 normal! /fallback
52- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
53- AssertEqual 'solKeyword', l:group
53+ normal! w
54+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
55+ AssertEqual 'solKeyword', g:syn
5456
5557Given solidity (receive function):
5658 receive() external payable {}
5759
5860Execute (receive should be highlighted as keyword):
5961 normal! /receive
60- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
61- AssertEqual 'solKeyword', l:group
62+ normal! w
63+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
64+ AssertEqual 'solKeyword', g:syn
6265
6366# ==============================================================================
6467# Issue #15: String Literal Bug
@@ -68,31 +71,20 @@ Given solidity (string with function signature):
6871 bytes32 hash = keccak256(bytes("submitSomething(bytes)"));
6972 uint256 value = 42;
7073
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
74+ Execute (string should close properly):
75+ " Move to the string
76+ normal! /"submit
77+ normal! w
78+ let g:syn1 = synIDattr(synID(line('.'), col('.'), 1), 'name')
79+ " String should be highlighted
80+ Assert g:syn1 ==# 'solString', 'Expected solString, got ' . g:syn1
7681
77- " Check that content after string is highlighted correctly
82+ " Move to value after the string
7883 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
84+ normal! w
85+ let g:syn2 = synIDattr(synID(line('.'), col('.'), 1), 'name')
86+ " Should NOT be in a string
87+ Assert g:syn2 !=# 'solString', 'value should not be in solString'
9688
9789# ==============================================================================
9890# Basic Syntax Elements
@@ -102,46 +94,28 @@ Given solidity (contract declaration):
10294 contract MyContract {
10395 }
10496
105- Execute (contract should be highlighted as Type ):
97+ Execute (contract keyword should be highlighted):
10698 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
99+ normal! w
100+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
101+ AssertEqual 'solContract', g:syn
113102
114103Given solidity (function declaration):
115104 function test() public pure returns (uint256) {
116105 return 42;
117106 }
118107
119- Execute (function elements should be highlighted correctly ):
108+ Execute (function keyword should be highlighted):
120109 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
110+ normal! w
111+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
112+ AssertEqual 'solFunction', g:syn
131113
114+ Execute (uint256 should be highlighted as type):
132115 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
116+ normal! w
117+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
118+ AssertEqual 'solBuiltinType', g:syn
145119
146120# ==============================================================================
147121# Assembly / Yul
@@ -153,15 +127,14 @@ Given solidity (assembly block):
153127 sstore(0, x)
154128 }
155129
156- Execute (assembly keywords should be highlighted):
130+ Execute (assembly keyword should be highlighted):
157131 normal! /assembly
158- let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
159- AssertEqual 'yul', l:group
132+ normal! w
133+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
134+ AssertEqual 'yul', g:syn
160135
136+ Execute (add opcode should be highlighted):
161137 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
138+ normal! w
139+ let g:syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
140+ AssertEqual 'yulAssemblyOp', g:syn
0 commit comments