3
3
4
4
using System ;
5
5
using System . Collections ;
6
+ using System . Collections . Generic ;
6
7
using System . Linq ;
7
8
using Microsoft . PowerFx . Types ;
8
9
using Xunit ;
@@ -53,11 +54,11 @@ public void Number(double val, string expectedStr)
53
54
double ? val2 = val ;
54
55
var formulaValue2 = FormulaValue . New ( ( double ? ) val ) ; // nullable overload
55
56
Assert . Equal ( expectedStr , formulaValue2 . Dump ( ) ) ;
56
-
57
+
57
58
var formulaValue3 = FormulaValue . New ( ( double ? ) null ) ;
58
59
Assert . IsType < NumberType > ( formulaValue3 . Type ) ;
59
60
Assert . IsType < BlankValue > ( formulaValue3 ) ;
60
- }
61
+ }
61
62
62
63
[ Theory ]
63
64
[ InlineData ( "abc" , "\" abc\" " ) ]
@@ -168,7 +169,7 @@ private class TestRow
168
169
[ Fact ]
169
170
public void Table ( )
170
171
{
171
- TableValue val = _cache . NewTable (
172
+ TableValue val = _cache . NewTable (
172
173
new TestRow { a = 10 , str = "alpha" } ,
173
174
new TestRow { a = 15 , str = "beta" } ) ;
174
175
@@ -183,7 +184,7 @@ public void Table()
183
184
184
185
Assert . Equal ( "Table({a:10,str:\" alpha\" },{a:15,str:\" beta\" })" , resultStr ) ;
185
186
}
186
-
187
+
187
188
[ Fact ]
188
189
public void TableFromRecords ( )
189
190
{
@@ -193,7 +194,7 @@ public void TableFromRecords()
193
194
194
195
var result1 = ( ( RecordValue ) val . Index ( 2 ) . Value ) . GetField ( "a" ) . ToObject ( ) ;
195
196
Assert . Equal ( 15.0 , result1 ) ;
196
-
197
+
197
198
dynamic d = val . ToObject ( ) ;
198
199
Assert . Equal ( 10.0 , d [ 0 ] . a ) ;
199
200
@@ -211,7 +212,7 @@ public void TableFromMixedRecords()
211
212
{
212
213
var cache = new TypeMarshallerCache ( ) ;
213
214
RecordValue r1 = _cache . NewRecord ( new { a = 10 , b = 20 , c = 30 } ) ;
214
- RecordValue r2 = _cache . NewRecord ( new { a = 11 , c = 31 } ) ;
215
+ RecordValue r2 = _cache . NewRecord ( new { a = 11 , c = 31 } ) ;
215
216
TableValue val = FormulaValue . NewTable ( r1 . Type , r1 , r2 ) ;
216
217
217
218
// Users first type
@@ -221,7 +222,7 @@ public void TableFromMixedRecords()
221
222
222
223
var result2 = ( ( RecordValue ) val . Index ( 2 ) . Value ) . GetField ( "b" ) ;
223
224
Assert . IsType < BlankValue > ( result2 ) ;
224
- Assert . IsType < NumberType > ( result2 . Type ) ;
225
+ Assert . IsType < NumberType > ( result2 . Type ) ;
225
226
}
226
227
227
228
[ Fact ]
@@ -259,7 +260,7 @@ public void TableFromPrimitive()
259
260
Assert . Equal ( "[10,20]" , resultStr ) ;
260
261
261
262
// Must use NewSingleColumnTable to create a single column table.
262
- Assert . Throws < InvalidOperationException > ( ( ) => NewTableT ( r1 , r2 ) ) ;
263
+ Assert . Throws < InvalidOperationException > ( ( ) => NewTableT ( r1 , r2 ) ) ;
263
264
}
264
265
265
266
[ Fact ]
@@ -309,6 +310,33 @@ public void Blanks()
309
310
Assert . True ( r . GetField ( "missing" ) is BlankValue ) ;
310
311
Assert . Equal ( 15.1 , r . GetField ( "number" ) . ToObject ( ) ) ;
311
312
}
313
+
314
+ [ Fact ]
315
+ public void DeriveFromValidFormulaValue ( )
316
+ {
317
+ // Only Blank and Error can derive from FormulaValue directly.
318
+ // All else should derive from ValidFormulaValue.
319
+ // See ValidFormulaValue for explanation.
320
+ var set = new HashSet < Type >
321
+ {
322
+ typeof ( BlankValue ) ,
323
+ typeof ( ErrorValue ) ,
324
+ typeof ( ValidFormulaValue ) ,
325
+ typeof ( LambdaFormulaValue ) , // Special, can eval to any FormulaValue.
326
+ } ;
327
+
328
+ var asmInterpreter = typeof ( RecalcEngine ) . Assembly ;
329
+ var asmCore = typeof ( Engine ) . Assembly ;
330
+ var allTypes = asmInterpreter . GetTypes ( ) . Concat ( asmCore . GetTypes ( ) ) ;
331
+
332
+ foreach ( var type in allTypes )
333
+ {
334
+ if ( type . BaseType == typeof ( FormulaValue ) )
335
+ {
336
+ Assert . True ( set . Contains ( type ) , $ "Type { type . FullName } should derive from { typeof ( ValidFormulaValue ) . FullName } , not FormulaValue.") ;
337
+ }
338
+ }
339
+ }
312
340
}
313
341
314
342
public static class FormulaValueExtensions
0 commit comments