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