import * as assert from "assert" ; import { FunctionCountVisitor , Histogram , TLE } from "../extension.bundle" ; suite ( "FunctionCountVisitor" , ( ) => { function testFunctionCountsVisitor ( expressionWithoutQuotes , expectedFunctionCounts ) { const tleParseResult = TLE . Parser . parse ( `"${ expressionWithoutQuotes }"` ) ; const visitor = FunctionCountVisitor . visit ( tleParseResult . expression ) ; const expected = new Histogram ( ) ; for ( let propName of Object . getOwnPropertyNames ( expectedFunctionCounts ) ) { expected . add ( propName , expectedFunctionCounts [ propName ] ) ; } assert . deepStrictEqual ( visitor . functionCounts , expected ) ; } test ( "no args" , ( ) => { testFunctionCountsVisitor ( "[func1()]" , { "func1" : 1 , "func1(0)" : 1 } ) ; } ) ; test ( "one arg" , ( ) => { testFunctionCountsVisitor ( "[func1('a')]" , { "func1" : 1 , "func1(1)" : 1 } ) ; } ) ; test ( "one arg called 2x" , ( ) => { testFunctionCountsVisitor ( "[add(func1('a'),func1(1))]" , { "add" : 1 , "add(2)" : 1 , "func1" : 2 , "func1(1)" : 2 } ) ; } ) ; test ( "one arg once, two args once" , ( ) => { testFunctionCountsVisitor ( "[add(func1('a', 2),func1(1))]" , { "add" : 1 , "add(2)" : 1 , "func1" : 2 , "func1(1)" : 1 , "func1(2)" : 1 } ) ; } ) ; test ( "user function" , ( ) => { testFunctionCountsVisitor ( "[udf.func1([])]" , { "udf.func1" : 1 , "udf.func1(1)" : 1 } ) ; } ) ; } ) ;