compiler/tests/PPCASTUtilitiesTests.st
changeset 515 b5316ef15274
child 518 a6d8b93441b0
equal deleted inserted replaced
502:1e45d3c96ec5 515:b5316ef15274
       
     1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 TestCase subclass:#PPCASTUtilitiesTests
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:'SomeClassVariable'
       
     8 	poolDictionaries:''
       
     9 	category:'PetitCompiler-Tests-Support'
       
    10 !
       
    11 
       
    12 !PPCASTUtilitiesTests methodsFor:'methods under test'!
       
    13 
       
    14 methodSimple1
       
    15     ^ 1
       
    16 
       
    17     "Created: / 27-07-2015 / 13:27:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    18 !
       
    19 
       
    20 methodWithArguments: arg1
       
    21     (arg1 + 4) yourself isOdd ifTrue:[ 
       
    22         ^ true
       
    23     ].
       
    24     ^ false not.
       
    25 
       
    26     "Created: / 27-07-2015 / 13:35:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    27 !
       
    28 
       
    29 methodWithClassReference
       
    30     ^ PPCASTUtilities new
       
    31 
       
    32     "Created: / 27-07-2015 / 13:28:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    33 !
       
    34 
       
    35 methodWithClassVariableReference
       
    36     ^ SomeClassVariable
       
    37 
       
    38     "Created: / 27-07-2015 / 14:02:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    39 !
       
    40 
       
    41 methodWithInstanceVariableReference
       
    42     ^ testSelector
       
    43 
       
    44     "Created: / 27-07-2015 / 13:29:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    45 !
       
    46 
       
    47 methodWithSelfSend1
       
    48     ^ self methodSimple1
       
    49 
       
    50     "Created: / 27-07-2015 / 13:28:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    51 !
       
    52 
       
    53 methodWithSelfSend2
       
    54     ^ self methodWithSelfSend1
       
    55 
       
    56     "Created: / 27-07-2015 / 13:34:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    57 !
       
    58 
       
    59 methodWithSelfSend3
       
    60     ^ self methodWithInstanceVariableReference
       
    61 
       
    62     "Created: / 27-07-2015 / 14:01:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    63 !
       
    64 
       
    65 methodWithSuperSend
       
    66     ^ super yourself
       
    67 
       
    68     "Created: / 27-07-2015 / 14:02:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    69 !
       
    70 
       
    71 methodWithTemporaries
       
    72     | tmp1 |
       
    73 
       
    74     tmp1 := 3.
       
    75     (tmp1 + 4) yourself isOdd ifTrue:[ 
       
    76         | tmp2 |
       
    77 
       
    78         tmp2 := tmp1 + 1.
       
    79         ^ tmp1 + tmp2.
       
    80     ].
       
    81     ^ tmp1
       
    82 
       
    83     "Created: / 27-07-2015 / 13:33:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    84 ! !
       
    85 
       
    86 !PPCASTUtilitiesTests methodsFor:'tests'!
       
    87 
       
    88 test_checkNodeIsFunctional_1
       
    89     self shouldnt: [ PPCASTUtilities new checkNodeIsFunctional: (self class >> #methodSimple1) parseTree inClass: self class ]
       
    90             raise: PPCCompilationError.
       
    91     self shouldnt: [ PPCASTUtilities new checkNodeIsFunctional: (self class >> #methodWithSelfSend1) parseTree inClass: self class ]
       
    92             raise: PPCCompilationError.
       
    93     self shouldnt: [ PPCASTUtilities new checkNodeIsFunctional: (self class >> #methodWithSelfSend2) parseTree inClass: self class ]
       
    94             raise: PPCCompilationError.
       
    95     self shouldnt: [ PPCASTUtilities new checkNodeIsFunctional: (self class >> #methodWithClassReference) parseTree inClass: self class ]
       
    96             raise: PPCCompilationError.
       
    97     self shouldnt: [ PPCASTUtilities new checkNodeIsFunctional: (self class >> #methodWithTemporaries) parseTree inClass: self class ]
       
    98             raise: PPCCompilationError.
       
    99     self shouldnt: [ PPCASTUtilities new checkNodeIsFunctional: (self class >> #methodWithArguments:) parseTree inClass: self class ]
       
   100             raise: PPCCompilationError.
       
   101 
       
   102     "Created: / 27-07-2015 / 14:00:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   103 !
       
   104 
       
   105 test_checkNodeIsFunctional_2
       
   106     self should: [ PPCASTUtilities new checkNodeIsFunctional: (self class >> #methodWithInstanceVariableReference) parseTree inClass: self class ]
       
   107          raise: PPCCompilationError.
       
   108     self should: [ PPCASTUtilities new checkNodeIsFunctional: (self class >> #methodWithClassVariableReference) parseTree inClass: self class ]
       
   109          raise: PPCCompilationError.
       
   110     self should: [ PPCASTUtilities new checkNodeIsFunctional: (self class >> #methodWithSelfSend3) parseTree inClass: self class ]
       
   111          raise: PPCCompilationError.
       
   112     self should: [ PPCASTUtilities new checkNodeIsFunctional: (self class >> #methodWithSuperSend) parseTree inClass: self class ]
       
   113          raise: PPCCompilationError.
       
   114 
       
   115     "Created: / 27-07-2015 / 14:00:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   116 ! !
       
   117