compiler/Dart__ParserTests.st
changeset 8 c2de4aaa2670
parent 7 cccc239c8833
child 9 ae0dabfd3321
equal deleted inserted replaced
7:cccc239c8833 8:c2de4aaa2670
     1 "{ Package: 'jv:dart/compiler' }"
       
     2 
       
     3 "{ NameSpace: Dart }"
       
     4 
       
     5 PPCompositeParserTest subclass:#ParserTests
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'Languages-Dart-Parser-Tests'
       
    10 !
       
    11 
       
    12 
       
    13 !ParserTests methodsFor:'accessing'!
       
    14 
       
    15 parserClass
       
    16         ^ Dart::Parser
       
    17 
       
    18     "Modified: / 11-01-2013 / 13:14:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    19 ! !
       
    20 
       
    21 !ParserTests methodsFor:'parsing'!
       
    22 
       
    23 fail: aString rule: aSymbol 
       
    24 
       
    25     ^super fail: (Dart::Scanner for: aString) rule: aSymbol
       
    26 
       
    27     "Created: / 14-03-2012 / 22:51:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    28     "Modified: / 11-01-2013 / 13:28:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    29 !
       
    30 
       
    31 parse: aString rule: aSymbol
       
    32         | production |
       
    33         production := self parserInstance.
       
    34         aSymbol = #start ifFalse: [ 
       
    35                 production := production productionAt: aSymbol.
       
    36                 production := production , (Dart::Parser::TokenParser for: #EOF).
       
    37         ].
       
    38 
       
    39         result := production parse: (Dart::Scanner for: aString).
       
    40         self 
       
    41             assert: result isPetitFailure not
       
    42             description: 'Unable to parse ' , aString printString.
       
    43 
       
    44         ^ result
       
    45 
       
    46     "Created: / 14-03-2012 / 22:51:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    47     "Modified: / 11-01-2013 / 15:35:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    48 ! !
       
    49 
       
    50 !ParserTests methodsFor:'tests - expressions'!
       
    51 
       
    52 test_expression_01
       
    53 
       
    54     self parse:'1 + 1' rule: #expression
       
    55 
       
    56     "Created: / 11-01-2013 / 15:12:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    57 !
       
    58 
       
    59 test_expression_02
       
    60 
       
    61     self parse:'a.foo()' rule: #expression
       
    62 
       
    63     "Created: / 11-01-2013 / 15:19:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    64 !
       
    65 
       
    66 test_expression_04
       
    67 
       
    68     self parse:'new Foo()' rule: #expression
       
    69 
       
    70     "Created: / 11-01-2013 / 15:38:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    71 ! !
       
    72 
       
    73 !ParserTests methodsFor:'tests - literals'!
       
    74 
       
    75 test_literal_01
       
    76 
       
    77     self parse: '1' rule: #literal.
       
    78     self parse: '1.0' rule: #literal.
       
    79     self parse: 'true' rule: #literal.
       
    80     self parse: 'false' rule: #literal.
       
    81     self parse: 'null' rule: #literal.
       
    82 
       
    83     "Created: / 11-01-2013 / 15:13:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    84 ! !
       
    85 
       
    86 !ParserTests methodsFor:'tests - misc'!
       
    87 
       
    88 test_misc_01
       
    89 
       
    90     self parse:'=' rule: #assignmentOperator
       
    91 
       
    92     "Created: / 11-01-2013 / 15:49:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    93 ! !
       
    94 
       
    95 !ParserTests methodsFor:'tests - smoke'!
       
    96 
       
    97 test_smoke_01
       
    98     self parse: 'import ''dart:html'';
       
    99 
       
   100 void main() {
       
   101 
       
   102 }'
       
   103 
       
   104     "Created: / 11-01-2013 / 13:15:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   105 !
       
   106 
       
   107 test_smoke_01a
       
   108     self parse: 'void main() { }'
       
   109 
       
   110     "Created: / 11-01-2013 / 13:37:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   111 !
       
   112 
       
   113 test_smoke_02
       
   114     self parse: '
       
   115 
       
   116 void main() {
       
   117     var a = 1 + 1;
       
   118 
       
   119 }'
       
   120 
       
   121     "Created: / 11-01-2013 / 13:30:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   122     "Modified: / 11-01-2013 / 15:07:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   123 !
       
   124 
       
   125 test_smoke_03
       
   126     self parse: '
       
   127 
       
   128 class Test {
       
   129   void foo() {
       
   130     print("Foo");
       
   131   }
       
   132 }
       
   133 
       
   134 void main() {1
       
   135   1 = 1 + 1;
       
   136   Test foo = new Test();
       
   137   foo.foo();  
       
   138 }'
       
   139 
       
   140     "Created: / 11-01-2013 / 13:34:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   141 ! !
       
   142 
       
   143 !ParserTests methodsFor:'tests - statements'!
       
   144 
       
   145 test_statement_01
       
   146 
       
   147     self parse:'a = 1;' rule: #statement
       
   148 
       
   149     "Created: / 11-01-2013 / 15:40:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   150 !
       
   151 
       
   152 test_statement_02
       
   153 
       
   154     self parse:'return 1;' rule: #statement
       
   155 
       
   156     "Created: / 11-01-2013 / 15:44:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   157 ! !
       
   158 
       
   159 !ParserTests class methodsFor:'documentation'!
       
   160 
       
   161 version_HG
       
   162 
       
   163     ^ '$Changeset: <not expanded> $'
       
   164 ! !