@@ -52,6 +52,7 @@ describe('AST', () => {
5252 } ,
5353 libraryName : 'Lib' ,
5454 functions : [ ] ,
55+ operators : [ ] ,
5556 } )
5657
5758 ast = parseNode ( 'using Lib for *;' )
@@ -61,6 +62,7 @@ describe('AST', () => {
6162 typeName : null ,
6263 libraryName : 'Lib' ,
6364 functions : [ ] ,
65+ operators : [ ] ,
6466 } )
6567
6668 ast = parseNode ( 'using Lib for S;' )
@@ -73,6 +75,7 @@ describe('AST', () => {
7375 } ,
7476 libraryName : 'Lib' ,
7577 functions : [ ] ,
78+ operators : [ ] ,
7679 } )
7780
7881 ast = parseNode ( 'using L.Lib for S;' )
@@ -85,6 +88,7 @@ describe('AST', () => {
8588 } ,
8689 libraryName : 'L.Lib' ,
8790 functions : [ ] ,
91+ operators : [ ] ,
8892 } )
8993 } )
9094
@@ -100,6 +104,7 @@ describe('AST', () => {
100104 } ,
101105 libraryName : 'Lib' ,
102106 functions : [ ] ,
107+ operators : [ ] ,
103108 } )
104109
105110 ast = parseNode ( 'using Lib for * global;' )
@@ -109,6 +114,7 @@ describe('AST', () => {
109114 typeName : null ,
110115 libraryName : 'Lib' ,
111116 functions : [ ] ,
117+ operators : [ ] ,
112118 } )
113119
114120 ast = parseNode ( 'using Lib for S global;' )
@@ -121,6 +127,7 @@ describe('AST', () => {
121127 } ,
122128 libraryName : 'Lib' ,
123129 functions : [ ] ,
130+ operators : [ ] ,
124131 } )
125132
126133 ast = parseNode ( 'using L.Lib for S global;' )
@@ -133,6 +140,7 @@ describe('AST', () => {
133140 } ,
134141 libraryName : 'L.Lib' ,
135142 functions : [ ] ,
143+ operators : [ ] ,
136144 } )
137145 } )
138146
@@ -148,6 +156,7 @@ describe('AST', () => {
148156 } ,
149157 libraryName : null ,
150158 functions : [ 'f' ] ,
159+ operators : [ null ] ,
151160 } )
152161
153162 ast = parseNode ( 'using { f, g } for uint;' )
@@ -161,6 +170,7 @@ describe('AST', () => {
161170 } ,
162171 libraryName : null ,
163172 functions : [ 'f' , 'g' ] ,
173+ operators : [ null , null ] ,
164174 } )
165175
166176 ast = parseNode ( 'using { f } for *;' )
@@ -170,6 +180,7 @@ describe('AST', () => {
170180 typeName : null ,
171181 libraryName : null ,
172182 functions : [ 'f' ] ,
183+ operators : [ null ] ,
173184 } )
174185
175186 ast = parseNode ( 'using { f } for S;' )
@@ -182,6 +193,7 @@ describe('AST', () => {
182193 } ,
183194 libraryName : null ,
184195 functions : [ 'f' ] ,
196+ operators : [ null ] ,
185197 } )
186198 } )
187199
@@ -197,6 +209,7 @@ describe('AST', () => {
197209 } ,
198210 libraryName : null ,
199211 functions : [ 'f' ] ,
212+ operators : [ null ] ,
200213 } )
201214
202215 ast = parseNode ( 'using { f, g } for uint global;' )
@@ -210,6 +223,7 @@ describe('AST', () => {
210223 } ,
211224 libraryName : null ,
212225 functions : [ 'f' , 'g' ] ,
226+ operators : [ null , null ] ,
213227 } )
214228
215229 ast = parseNode ( 'using { f } for * global;' )
@@ -219,6 +233,7 @@ describe('AST', () => {
219233 typeName : null ,
220234 libraryName : null ,
221235 functions : [ 'f' ] ,
236+ operators : [ null ] ,
222237 } )
223238
224239 ast = parseNode ( 'using { f } for S global;' )
@@ -231,6 +246,67 @@ describe('AST', () => {
231246 } ,
232247 libraryName : null ,
233248 functions : [ 'f' ] ,
249+ operators : [ null ] ,
250+ } )
251+ } )
252+
253+ describe ( 'user-defined operators' , function ( ) {
254+ it ( 'defining a single operator' , function ( ) {
255+ const ast = parseNode ( 'using { add as + } for Fixed18 global;' )
256+ assert . deepEqual ( ast , {
257+ type : 'UsingForDeclaration' ,
258+ isGlobal : true ,
259+ typeName : {
260+ type : 'UserDefinedTypeName' ,
261+ namePath : 'Fixed18' ,
262+ } ,
263+ libraryName : null ,
264+ functions : [ 'add' ] ,
265+ operators : [ '+' ] ,
266+ } )
267+ } )
268+
269+ it ( 'defining two operators' , function ( ) {
270+ const ast = parseNode ( 'using { add as +, sub as - } for Fixed18 global;' )
271+ assert . deepEqual ( ast , {
272+ type : 'UsingForDeclaration' ,
273+ isGlobal : true ,
274+ typeName : {
275+ type : 'UserDefinedTypeName' ,
276+ namePath : 'Fixed18' ,
277+ } ,
278+ libraryName : null ,
279+ functions : [ 'add' , 'sub' ] ,
280+ operators : [ '+' , '-' ] ,
281+ } )
282+ } )
283+
284+ it ( 'mixing attached functions and user-defined operators' , function ( ) {
285+ let ast = parseNode ( 'using { add, sub as - } for Fixed18 global;' )
286+ assert . deepEqual ( ast , {
287+ type : 'UsingForDeclaration' ,
288+ isGlobal : true ,
289+ typeName : {
290+ type : 'UserDefinedTypeName' ,
291+ namePath : 'Fixed18' ,
292+ } ,
293+ libraryName : null ,
294+ functions : [ 'add' , 'sub' ] ,
295+ operators : [ null , '-' ] ,
296+ } )
297+
298+ ast = parseNode ( 'using { add as +, sub } for Fixed18 global;' )
299+ assert . deepEqual ( ast , {
300+ type : 'UsingForDeclaration' ,
301+ isGlobal : true ,
302+ typeName : {
303+ type : 'UserDefinedTypeName' ,
304+ namePath : 'Fixed18' ,
305+ } ,
306+ libraryName : null ,
307+ functions : [ 'add' , 'sub' ] ,
308+ operators : [ '+' , null ] ,
309+ } )
234310 } )
235311 } )
236312 } )
0 commit comments