compiler/tests/Dart__ParserTests.st
changeset 8 c2de4aaa2670
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/tests/Dart__ParserTests.st	Tue Nov 04 00:17:12 2014 +0000
@@ -0,0 +1,165 @@
+"{ Package: 'ctu:dart/compiler/tests' }"
+
+"{ NameSpace: Dart }"
+
+PPCompositeParserTest subclass:#ParserTests
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Languages-Dart-Parser-Tests'
+!
+
+
+!ParserTests methodsFor:'accessing'!
+
+parserClass
+        ^ Dart::Parser
+
+    "Modified: / 11-01-2013 / 13:14:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ParserTests methodsFor:'parsing'!
+
+fail: aString rule: aSymbol 
+
+    ^super fail: (Dart::Scanner for: aString) rule: aSymbol
+
+    "Created: / 14-03-2012 / 22:51:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-01-2013 / 13:28:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+parse: aString rule: aSymbol
+        | production |
+        production := self parserInstance.
+        aSymbol = #start ifFalse: [ 
+                production := production productionAt: aSymbol.
+                production := production , (Dart::Parser::TokenParser for: #EOF).
+        ].
+
+        result := production parse: (Dart::Scanner for: aString).
+        self 
+            assert: result isPetitFailure not
+            description: 'Unable to parse ' , aString printString.
+
+        ^ result
+
+    "Created: / 14-03-2012 / 22:51:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-01-2013 / 15:35:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ParserTests methodsFor:'tests - expressions'!
+
+test_expression_01
+
+    self parse:'1 + 1' rule: #expression
+
+    "Created: / 11-01-2013 / 15:12:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_expression_02
+
+    self parse:'a.foo()' rule: #expression
+
+    "Created: / 11-01-2013 / 15:19:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_expression_04
+
+    self parse:'new Foo()' rule: #expression
+
+    "Created: / 11-01-2013 / 15:38:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ParserTests methodsFor:'tests - literals'!
+
+test_literal_01
+
+    self parse: '1' rule: #literal.
+    self parse: '1.0' rule: #literal.
+    self parse: 'true' rule: #literal.
+    self parse: 'false' rule: #literal.
+    self parse: 'null' rule: #literal.
+
+    "Created: / 11-01-2013 / 15:13:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ParserTests methodsFor:'tests - misc'!
+
+test_misc_01
+
+    self parse:'=' rule: #assignmentOperator
+
+    "Created: / 11-01-2013 / 15:49:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ParserTests methodsFor:'tests - smoke'!
+
+test_smoke_01
+    self parse: 'import ''dart:html'';
+
+void main() {
+
+}'
+
+    "Created: / 11-01-2013 / 13:15:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_smoke_01a
+    self parse: 'void main() { }'
+
+    "Created: / 11-01-2013 / 13:37:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_smoke_02
+    self parse: '
+
+void main() {
+    var a = 1 + 1;
+
+}'
+
+    "Created: / 11-01-2013 / 13:30:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-01-2013 / 15:07:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_smoke_03
+    self parse: '
+
+class Test {
+  void foo() {
+    print("Foo");
+  }
+}
+
+void main() {1
+  1 = 1 + 1;
+  Test foo = new Test();
+  foo.foo();  
+}'
+
+    "Created: / 11-01-2013 / 13:34:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ParserTests methodsFor:'tests - statements'!
+
+test_statement_01
+
+    self parse:'a = 1;' rule: #statement
+
+    "Created: / 11-01-2013 / 15:40:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_statement_02
+
+    self parse:'return 1;' rule: #statement
+
+    "Created: / 11-01-2013 / 15:44:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ParserTests class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+