compiler/tests/extras/PPCSmalltalkParserTests.st
changeset 510 869853decf31
child 524 f6f68d32de73
equal deleted inserted replaced
509:fd22630c7e62 510:869853decf31
       
     1 "{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 PPSmalltalkParserTests subclass:#PPCSmalltalkParserTests
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'PetitCompiler-Extras-Tests-Smalltalk'
       
    10 !
       
    11 
       
    12 !PPCSmalltalkParserTests class methodsFor:'resources'!
       
    13 
       
    14 resources
       
    15     ^ Array with: (PPCSetUpBeforeTearDownAfterResource for: self)
       
    16 ! !
       
    17 
       
    18 !PPCSmalltalkParserTests class methodsFor:'testing'!
       
    19 
       
    20 isAbstract
       
    21     ^ self == PPCSmalltalkParserTests
       
    22 ! !
       
    23 
       
    24 !PPCSmalltalkParserTests methodsFor:'accessing'!
       
    25 
       
    26 compiledParser
       
    27     ^ self compiledParserClass new
       
    28 
       
    29     "Created: / 29-07-2015 / 17:00:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    30 !
       
    31 
       
    32 compiledParserClass
       
    33     ^ Smalltalk at: self compiledParserClassName
       
    34 
       
    35     "Created: / 29-07-2015 / 16:54:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    36 !
       
    37 
       
    38 compiledParserClassName
       
    39     "Return the name of the compiled parser"
       
    40 
       
    41     ^ (self petitParserClass name , 'C_' , 
       
    42             "This is bit hacky!!"
       
    43             ((self compilerConfiguration isKindOf: PPCTokenizingConfiguration) ifTrue:[ 'Tokenizing' ] ifFalse:[ 'Universal' ])) asSymbol
       
    44 
       
    45     "Created: / 29-07-2015 / 16:54:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    46 !
       
    47 
       
    48 compilerConfiguration
       
    49     "Return configuration to use when compiling parser (as instance of PPCConfiguration)"
       
    50 
       
    51     ^ self subclassResponsibility
       
    52 
       
    53     "Created: / 29-07-2015 / 16:53:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    54 !
       
    55 
       
    56 parserClass
       
    57     ^ self compiledParserClass
       
    58 
       
    59     "Modified: / 29-07-2015 / 18:43:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    60 !
       
    61 
       
    62 parserInstanceFor: aSymbol
       
    63     ^ self parserClass new startSymbol: aSymbol
       
    64 
       
    65     "Modified: / 29-07-2015 / 18:43:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    66 !
       
    67 
       
    68 petitParser
       
    69     ^ self petitParserClass new
       
    70 
       
    71     "Created: / 29-07-2015 / 17:01:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    72 !
       
    73 
       
    74 petitParserClass
       
    75     ^ PPSmalltalkParser
       
    76 ! !
       
    77 
       
    78 !PPCSmalltalkParserTests methodsFor:'context'!
       
    79 
       
    80 context
       
    81 
       
    82     ^ PPCContext new 
       
    83 ! !
       
    84 
       
    85 !PPCSmalltalkParserTests methodsFor:'setup & teardown'!
       
    86 
       
    87 setUpBefore
       
    88     "Called before any of my tests is run (when resources are set up)"
       
    89     | time configuration |
       
    90 
       
    91     configuration := self compilerConfiguration.
       
    92     configuration arguments parserName: self compiledParserClassName.
       
    93     time := Time millisecondsToRun: [
       
    94         self petitParser compileWithConfiguration: configuration.
       
    95     ].
       
    96     Transcript show: self petitParserClass name ; show:' compiled in: '; show: time asString; show: 'ms'; cr.
       
    97 
       
    98     "Created: / 29-07-2015 / 16:29:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    99     "Modified: / 29-07-2015 / 18:40:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   100 !
       
   101 
       
   102 tearDownAfter
       
   103     "Called after all my tests are ryn(when resources are torn down)"
       
   104 
       
   105     "Created: / 29-07-2015 / 16:33:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   106 ! !
       
   107