<s> import unittest <EOL> import ufora . native . FORA as ForaNative <EOL> emptyCodeDefinitionPoint = ForaNative . CodeDefinitionPoint . ExternalFromStringList ( [ ] ) <EOL> class ExpressionVariableBindingTest ( unittest . TestCase ) : <EOL> def parse ( self , exprStr ) : <EOL> e = ForaNative . parseStringToExpression ( exprStr , emptyCodeDefinitionPoint , "<STR_LIT>" ) <EOL> self . assertIsInstance ( e , ForaNative . Expression , '<STR_LIT>' + str ( e ) ) <EOL> return e <EOL> def testVars0 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ ] ) <EOL> def testVars1 ( self ) : <EOL> e = self . parse ( '<STR_LIT:x>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:x>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVars2 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:x>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ '<STR_LIT:x>' ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVars3 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:x>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVars4 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:x>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ '<STR_LIT:x>' ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVars5 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVars6 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVars7 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVars8 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVars9 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVars10 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:y>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> def testVarsPull1 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:i>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ '<STR_LIT:i>' ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:i>' ] ) <EOL> def testVarsPull2 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:i>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ '<STR_LIT:i>' ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:i>' ] ) <EOL> def testVarsPull3 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:i>' ] ) <EOL> def testVarsClass1 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:x>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVarsClass2 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVarsClass3 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:x>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVarsClass4 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def testVarsClass5 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def testPatterns1 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:x>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> def testVarsObjectMixin ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:x>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVarsClassMixin ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ '<STR_LIT:x>' ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVarsClassMixin2 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> self . assertEqual ( e . freeVariables , [ ] ) <EOL> self . assertEqual ( e . assignedVariables , [ ] ) <EOL> self . assertEqual ( e . mentionedVariables , [ '<STR_LIT:x>' ] ) <EOL> def testVarsClassRebind ( self ) : <EOL> self . verifyRebind ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> '<STR_LIT>' <EOL> ) <EOL> def testVarsClassRebind_2 ( self ) : <EOL> self . verifyRebind ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> '<STR_LIT>' <EOL> ) <EOL> def testVarsClassRebind_3 ( self ) : <EOL> self . verifyRebind ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> '<STR_LIT>' <EOL> ) <EOL> def testVarsClassRebind_4 ( self ) : <EOL> self . verifyRebind ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> '<STR_LIT>' <EOL> ) <EOL> def testVarsClassRebind_5 ( self ) : <EOL> self . verifyRebind ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def testVarsClassRebind_6 ( self ) : <EOL> self . verifyRebind ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> '<STR_LIT>' <EOL> ) <EOL> def verifyRebind ( self , src , rebindDict , dest ) : <EOL> e = self . parse ( src ) <EOL> eRebound = e . rebindFreeVariables ( rebindDict ) <EOL> e2 = self . parse ( dest ) <EOL> self . assertEqual ( str ( eRebound ) , str ( e2 ) , <EOL> "<STR_LIT>" % ( <EOL> rebindDict , src , str ( eRebound ) , str ( e2 ) <EOL> ) <EOL> ) <EOL> def verifyRebindFreeVariableMemberAccess ( self , src , rebindDict , dest ) : <EOL> e = self . parse ( src ) <EOL> eRebound = e <EOL> for k , v in rebindDict . iteritems ( ) : <EOL> eRebound = eRebound . rebindFreeVariableMemberAccess ( k [ <NUM_LIT:0> ] , k [ <NUM_LIT:1> ] , v ) <EOL> e2 = self . parse ( dest ) <EOL> self . assertEqual ( <EOL> str ( eRebound ) , str ( e2 ) , <EOL> "<STR_LIT>" % ( <EOL> rebindDict , src , str ( eRebound ) , str ( e2 ) <EOL> ) <EOL> ) <EOL> def testVariableAccessChains ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> def toList ( l ) : <EOL> return [ [ str ( y ) for y in x ] for x in l ] <EOL> self . assertEqual ( toList ( e . freeVariableMemberAccessChains ) , [ [ '<STR_LIT:x>' , '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ] ) <EOL> def testVariableAccessChains2 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> def toList ( l ) : <EOL> return [ [ str ( y ) for y in x ] for x in l ] <EOL> self . assertEqual ( toList ( e . freeVariableMemberAccessChains ) , [ [ '<STR_LIT:x>' , '<STR_LIT:a>' ] , [ '<STR_LIT:x>' , '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ] ) <EOL> def testRebindingFreeVariableMemberAccesses ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> e2 = e . rebindFreeVariableMemberAccess ( '<STR_LIT:x>' , '<STR_LIT:a>' , '<STR_LIT>' ) <EOL> e2 = e2 . rebindFreeVariableMemberAccess ( '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT>' ) <EOL> self . verifyRebindFreeVariableMemberAccess ( <EOL> '<STR_LIT>' , <EOL> { ( '<STR_LIT:x>' , '<STR_LIT:a>' ) : '<STR_LIT>' , ( '<STR_LIT:x>' , '<STR_LIT:y>' ) : '<STR_LIT>' } , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_rebindFreeVariableMemberAccessChains_1 ( self ) : <EOL> e = self . parse ( '<STR_LIT>' ) <EOL> e2 = e . rebindFreeVariableMemberAccessChain ( [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT:z>' ] , '<STR_LIT>' ) <EOL> e2 = e2 . rebindFreeVariableMemberAccessChain ( [ '<STR_LIT:x>' , '<STR_LIT:a>' ] , '<STR_LIT>' ) <EOL> e2 = e2 . rebindFreeVariableMemberAccessChain ( [ '<STR_LIT:f>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> str ( e2 ) , <EOL> str ( self . parse ( '<STR_LIT>' ) ) <EOL> ) <EOL> def test_rebindFreeVariableMemberAccessChains_2 ( self ) : <EOL> e = self . parse ( "<STR_LIT>" ) <EOL> e2 = e . rebindFreeVariableMemberAccessChain ( [ '<STR_LIT:x>' , '<STR_LIT:y>' ] , '<STR_LIT>' ) <EOL> e2 = e2 . rebindFreeVariableMemberAccessChain ( [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> str ( e2 ) , <EOL> str ( self . parse ( "<STR_LIT>" ) ) <EOL> ) </s>
