Return-Path: X-Original-To: apmail-flex-commits-archive@www.apache.org Delivered-To: apmail-flex-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 00A1411E24 for ; Fri, 25 Apr 2014 06:18:59 +0000 (UTC) Received: (qmail 35684 invoked by uid 500); 25 Apr 2014 06:18:37 -0000 Delivered-To: apmail-flex-commits-archive@flex.apache.org Received: (qmail 35568 invoked by uid 500); 25 Apr 2014 06:18:34 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 33862 invoked by uid 99); 25 Apr 2014 06:18:03 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Apr 2014 06:18:03 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5AC4F992D3C; Fri, 25 Apr 2014 06:18:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aharui@apache.org To: commits@flex.apache.org Date: Fri, 25 Apr 2014 06:18:42 -0000 Message-Id: In-Reply-To: <80676bc40a944eefb0afcbcd724091ba@git.apache.org> References: <80676bc40a944eefb0afcbcd724091ba@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [43/46] FlexPMD Donation from Adobe Systems Inc http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestCompilationUnit.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestCompilationUnit.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestCompilationUnit.java new file mode 100644 index 0000000..820dfc7 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestCompilationUnit.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestCompilationUnit extends AbstractAs3ParserTest +{ + @Test + public void testEmptyPackage() throws TokenException + { + assertCompilationUnit( "1", + "package a { } ", + "" + + "" + "a" + + "" + + "" + + "" ); + } + + @Test + public void testEmptyPackagePlusLocalClass() throws TokenException + { + assertCompilationUnit( "1", + "package a { } class Local { }", + "" + + "a" + + "Local" + + "" + + "" ); + } + + @Test + public void testPackageWithClass() throws TokenException + { + assertCompilationUnit( "1", + "package a { public class B { } } ", + "" + + "a" + + "B" + + "public" + + "" + + "" + + "" ); + } + + @Test + public void testPackageWithInterface() throws TokenException + { + assertCompilationUnit( "1", + "package a { public interface B { } } ", + "" + + "a" + + "B" + + "public" + + "" + + "" + + "" ); + } + + private void assertCompilationUnit( final String message, + final String input, + final String expected ) throws TokenException + { + scn.setLines( new String[] + { input, + "__END__" } ); + final String result = new ASTToXMLConverter().convert( asp.parseCompilationUnit() ); + assertEquals( message, + expected, + result ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestConstStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestConstStatement.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestConstStatement.java new file mode 100644 index 0000000..ccfb640 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestConstStatement.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestConstStatement extends AbstractStatementTest +{ + @Test + public void testFullFeaturedConst() throws TokenException + { + assertStatement( "1", + "const a : int = 4", + "" + + "" + + "aint" + + "4" + + "" ); + } + + @Test + public void testInitializedConst() throws TokenException + { + assertStatement( "1", + "const a = 4", + "" + + "a" + + "4" + + "" ); + } + + @Test + public void testSimpleConst() throws TokenException + { + assertStatement( "1", + "const a", + "" + + "a" + + "" ); + } + + @Test + public void testTypedConst() throws TokenException + { + assertStatement( "1", + "const a : Object", + "" + + "aObject" + + "" ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestDoStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestDoStatement.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestDoStatement.java new file mode 100644 index 0000000..a66d2dd --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestDoStatement.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestDoStatement extends AbstractStatementTest +{ + @Test + public void testDo() throws TokenException + { + assertStatement( "1", + "do{ trace( i ); } while( i++ );", + "" + + "" + + "trace" + + "i" + + "" + + "" + + "i" ); + } + + @Test + public void testDoWithEmptyStatement() throws TokenException + { + assertStatement( "1", + "do ; while( i++ ); ", + ";" + + "" + + "i" ); + } + + @Test + public void testDoWithoutBlock() throws TokenException + { + assertStatement( "1", + "do trace( i ); while( i++ ); ", + "" + + "tracei" + + "" + + "i" ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestE4xExpression.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestE4xExpression.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestE4xExpression.java new file mode 100644 index 0000000..7d6f874 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestE4xExpression.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestE4xExpression extends AbstractStatementTest +{ + @Test + public void testE4xFilter() throws TokenException + { + assertStatement( "", + "myXml.(lala=\"lala\")", + "myXml" + + "" + + "lala=" + + "\"lala\"" ); + + assertStatement( "", + "doc.*.worm[1]", + "doc*." ); + + assertStatement( "", + "doc.@worm", + "doc@worm" ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestEmptyStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestEmptyStatement.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestEmptyStatement.java new file mode 100644 index 0000000..6133b33 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestEmptyStatement.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestEmptyStatement extends AbstractStatementTest +{ + @Test + public void testComplex() throws TokenException + { + assertStatement( "1", + "{;1;;}", + ";" + + "1" + + ";" ); + } + + @Test + public void testSimple() throws TokenException + { + assertStatement( "1", + ";", + ";" ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestExpression.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestExpression.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestExpression.java new file mode 100644 index 0000000..16308c9 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestExpression.java @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestExpression extends AbstractStatementTest +{ + @Test + public void testAddExpression() throws TokenException + { + assertStatement( "1", + "5+6", + "5+" + "6" ); + } + + @Test + public void testAndExpression() throws TokenException + { + assertStatement( "1", + "5&&6", + "5" + + "&&" + "6" ); + } + + @Test + public void testAssignmentExpression() throws TokenException + { + assertStatement( "1", + "x+=6", + "x" + + "+=6" ); + } + + @Test + public void testBitwiseAndExpression() throws TokenException + { + assertStatement( "1", + "5&6", + "5" + + "&6" ); + } + + @Test + public void testBitwiseOrExpression() throws TokenException + { + assertStatement( "1", + "5|6", + "5" + + "|6" ); + } + + @Test + public void testBitwiseXorExpression() throws TokenException + { + assertStatement( "1", + "5^6", + "5" + + "^6" ); + } + + @Test + public void testConditionalExpression() throws TokenException + { + assertStatement( "1", + "true?5:6", + "" + + "true5" + "6" + + "" ); + } + + @Test + public void testDivision() throws TokenException + { + assertStatement( "", + "offset = ( this[ axis.unscaled ] / 2 - ( rightPos ) / 2 );", + "offset=" + + "" + + "thisaxisunscaled" + + "/2-" + + "" + + "rightPos/" + + "2" ); + } + + @Test + public void testEncapsulated() throws TokenException + { + assertStatement( "", + "(dataProvider as ArrayCollection) = null", + "" + + "" + + "dataProvider" + + "as" + + "ArrayCollection" + + "=" + "null" ); + } + + @Test + public void testEqualityExpression() throws TokenException + { + assertStatement( "1", + "5!==6", + "5" + + "!==6" ); + } + + @Test + public void testExpressionList() throws TokenException + { + assertStatement( "1", + "5&&6,5&&9", + "" + + "5" + + "&&65&&9" ); + } + + @Test + public void testInstanceOf() throws TokenException + { + assertStatement( "bug237", + "if (a instanceof b){}", + "ainstanceof" + + "b" ); + } + + @Test + public void testMulExpression() throws TokenException + { + assertStatement( "1", + "5/6", + "5" + + "/6" ); + } + + @Test + public void testNewExpression() throws TokenException + { + assertStatement( "", + "new Event()", + "" + + "Event" + + "" ); + + assertStatement( "", + "new Event(\"lala\")", + "" + + "Event" + + "" + + "\"lala\"" ); + + } + + @Test + public void testOrExpression() throws TokenException + { + assertStatement( "1", + "5||6", + "5" + + "||6" ); + } + + @Test + public void testRelationalExpression() throws TokenException + { + assertStatement( "1", + "5<=6", + "5" + + "<=6" ); + } + + @Test + public void testShiftExpression() throws TokenException + { + assertStatement( "1", + "5<<6", + "5" + + "<<6" ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestForStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestForStatement.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestForStatement.java new file mode 100644 index 0000000..afafbf2 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestForStatement.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestForStatement extends AbstractStatementTest +{ + @Test + public void testSimpleFor() throws TokenException + { + assertStatement( "1", + "for( var i : int = 0; i < length; i++ ){ trace( i ); }", + "" + + "iint" + + "0" + + "" + + "" + + "i<length" + + "" + + "i" + + "trace" + + "i" + + "" ); + + assertStatement( "", + " for (i = 0; i < n; i++)", + "" + + "i=" + + "0" + + "i" + + "<n" + + "" + + "i" + + "__END__" ); + } + + @Test + public void testSimpleForEach() throws TokenException + { + assertStatement( "1", + "for each( var obj : Object in list ){ obj.print( i ); }", + "" + + "objObject" + + "" + + "list" + + "" + + "objprint" + + "" + + "i" ); + + assertStatement( "1", + "for each( obj in list ){}", + "obj" + + "list" + + "" ); + + // assertStatement( + // "", "for each (var a:XML in classInfo..accessor) {}", "" ); + } + + @Test + public void testSimpleForIn() throws TokenException + { + assertStatement( "1", + "for( var s : String in obj ){ trace( s, obj[ s ]); }", + "" + + "s" + + "String" + + "obj" ); + + assertStatement( "for in", + " for (p in events);", + "" + + "pevents" ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestIfStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestIfStatement.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestIfStatement.java new file mode 100644 index 0000000..aecc7c2 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestIfStatement.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestIfStatement extends AbstractStatementTest +{ + @Test + public void testBug232() throws TokenException + { + assertStatement( "", + "if (true || /* comment */!false) ) )", + "" + + "true||false)" ); + } + + @Test + public void testIf() throws TokenException + { + assertStatement( "1", + "if( true ){ trace( true ); }", + "" + + "" + "true" + + "" + "trace" + + "" + "true" + + "" ); + + assertStatement( "1", + "if( \"i\" in oaderContext ){ }", + "" + + "" + + "\"i\"in" + + "oaderContext" + + "" ); + + assertStatement( "internal", + "if (col.mx_internal::contentSize) {col.mx_internal::_width = NaN;}", + "" + + "col" + + "" + + "mx_internalcontentSize" + + "" + + "col" + + "" + + "mx_internal" + + "_width" + + "=" + + "NaN" ); + } + + @Test + public void testIfElse() throws TokenException + { + assertStatement( "1", + "if( true ){ trace( true ); } else { trace( false )}", + "" + + "true" + "" + + "trace" + + "" + + "true" + + "" + "" + + "trace" + "" + + "false" + "" ); + } + + @Test + public void testIfWithArrayAccessor() throws TokenException + { + assertStatement( "", + "if ( chart.getItemAt( 0 )[ xField ] > targetXFieldValue ){}", + "chartgetItemAt0xField>targetXFieldValue" + + "" ); + } + + @Test + public void testIfWithEmptyStatement() throws TokenException + { + assertStatement( "1", + "if( i++ ); ", + "" + + "" + + "i;" + + "" ); + } + + @Test + public void testIfWithoutBlock() throws TokenException + { + assertStatement( "1", + "if( i++ ) trace( i ); ", + "" + + "i" + + "" + + "tracei" + "" ); + } + + @Test + public void testIfWithReturn() throws TokenException + { + assertStatement( "", + "if ( true )return;", + "true" ); + + assertStatement( "", + "if ( true )throw new Error();", + "true" + "throw" ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestInterface.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestInterface.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestInterface.java new file mode 100644 index 0000000..6cc46ae --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestInterface.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestInterface extends AbstractAs3ParserTest +{ + @Test + public void testExtends() throws TokenException + { + assertPackageContent( "1", + "public interface A extends B { } ", + "" + + "A" + + "public" + + "B" + + "" ); + + assertPackageContent( "", + " public interface ITimelineEntryRenderer extends IFlexDisplayObject, IDataRenderer{}", + "ITimelineEntryRenderer" + + "publicIFlexDisplayObject" + + "IDataRenderer" + + "" ); + } + + @Test + public void testInclude() throws TokenException + { + assertPackageContent( "1", + "public interface A extends B { include \"ITextFieldInterface.asz\" } ", + "" + + "A" + + "public" + "" + + "B" + + "\"ITextFieldInterface.asz\"" + + "" ); + } + + private void assertPackageContent( final String message, + final String input, + final String expected ) throws TokenException + { + scn.setLines( new String[] + { "{", + input, + "}", + "__END__" } ); + asp.nextToken(); // first call + asp.nextToken(); // skip { + final String result = new ASTToXMLConverter().convert( asp.parsePackageContent() ); + assertEquals( message, + expected, + result ); + } + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestInterfaceContent.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestInterfaceContent.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestInterfaceContent.java new file mode 100644 index 0000000..9c4508e --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestInterfaceContent.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestInterfaceContent extends AbstractAs3ParserTest +{ + @Test(timeout = 2) + public void testConditionalCompilation() throws TokenException + { + assertInterfaceContent( "with conditional compilation", + + "CONFIG::DEBUG { function output():String; } ", + "" + + "output" + + "String" ); + + } + + @Test + public void testImports() throws TokenException + { + assertInterfaceContent( "1", + "import a.b.c;", + "a.b.c" ); + + assertInterfaceContent( "2", + "import a.b.c import x.y.z", + "a.b.c" + + "x.y.z" ); + } + + @Test + public void testMethods() throws TokenException + { + assertInterfaceContent( "1", + "function a()", + "" + + "a" + + "" + + "" + + "" ); + + assertInterfaceContent( "2", + "function set a( value : int ) : void", + "a" + + "" + + "" + + "" + + "value" + + "int" + + "" + + "void" ); + + assertInterfaceContent( "3", + "function get a() : int", + "a" + + "" + + "int" + "" ); + } + + private void assertInterfaceContent( final String message, + final String input, + final String expected ) throws TokenException + { + scn.setLines( new String[] + { "{", + input, + "}", + "__END__" } ); + asp.nextToken(); // first call + asp.nextToken(); // skip { + final String result = new ASTToXMLConverter().convert( asp.parseInterfaceContent() ); + assertEquals( message, + "" + + expected + "", + result ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestPackageContent.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestPackageContent.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestPackageContent.java new file mode 100644 index 0000000..f81df13 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestPackageContent.java @@ -0,0 +1,220 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestPackageContent extends AbstractAs3ParserTest +{ + @Test + public void testClass() throws TokenException + { + assertPackageContent( "1", + "public class A { }", + "" + + "A" + + "public" + "" + + "" ); + } + + @Test + public void testClassWithAsDoc() throws TokenException + { + assertPackageContent( "1", + "/** AsDoc */ public class A { }", + "" + + "/** AsDoc */Apublic" + + "" ); + } + + @Test + public void testClassWithAsDocComplex() throws TokenException + { + assertPackageContent( "1", + "/** AsDoc */ public class A { " + + "/** Member */ " + "public var tmp : Number; " + + "private var tmp2 : int; " + "/** Function */ " + + "protected function foo() : void { } }", + "/** AsDoc */A" + + "public" + + "" + + "public" + + "tmp" + + "Number/** Member */" + + "private" + + "tmp2" + + "int/** Function */" + + "protected" + + "foo" + + "void" ); + } + + @Test + public void testClassWithComment() throws TokenException + { + assertPackageContent( "1", + "/* lala */ /** asDoc */ public class A { }", + "" + + "/** asDoc *//* lala */Apublic" + + "" ); + } + + @Test + public void testClassWithMetadata() throws TokenException + { + assertPackageContent( "1", + "[Bindable(name=\"abc\", value=\"123\")] public class A { }", + "" + + "A" + "Bindable ( name = \"abc\" , value = \"123\" )" + + "" + "public" + + "" ); + } + + @Test + public void testClassWithMetadataAsDoc() throws TokenException + { + assertPackageContent( "1", + "/** Comment */ [Bindable] public class A { }", + "" + + "/** Comment */ABindablepublic" ); + } + + @Test + public void testClassWithMetadataComment() throws TokenException + { + assertPackageContent( "1", + "/* Comment */ [Bindable] public class A { }", + "" + + "/* Comment */" + + "A" + + "" + + "Bindablepublic" ); + } + + @Test + public void testClassWithMetadataWithComment() throws TokenException + { + assertPackageContent( "1", + "/* lala */ /** asDoc */ [Bindable] public class A { }", + "" + + "/** asDoc */" + + "/* lala */A" + + "Bindable" + + "public" + + "" ); + } + + @Test + public void testClassWithSimpleMetadata() throws TokenException + { + assertPackageContent( "1", + "[Bindable] public class A { }", + "ABindable" + + "public" ); + } + + @Test + public void testImports() throws TokenException + { + assertPackageContent( "1", + "import a.b.c;", + "a.b.c" ); + + assertPackageContent( "2", + "import a.b.c import x.y.z", + "a.b.c" + + "x.y.z" ); + } + + @Test + public void testInterface() throws TokenException + { + assertPackageContent( "1", + "public interface A { }", + "" + + "A" + + "public" + "" + + "" ); + } + + @Test + public void testMethodPackages() throws TokenException + { + assertPackageContent( "1", + "public function a() : void { }", + "" + + "public" + + "avoid" + + "" ); + } + + @Test + public void testUse() throws TokenException + { + assertPackageContent( "1", + "use namespace myNamespace", + "myNamespace" ); + } + + @Test + public void testUseNameSpace() throws TokenException + { + assertPackageContent( "FlexPMD-108", + "use namespace mx_internal;", + "mx_internal" ); + } + + private void assertPackageContent( final String message, + final String input, + final String expected ) throws TokenException + { + scn.setLines( new String[] + { "{", + input, + "}", + "__END__" } ); + asp.nextToken(); // first call + asp.nextToken(); // skip { + final String result = new ASTToXMLConverter().convert( asp.parsePackageContent() ); + assertEquals( message, + expected, + result ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestPrimaryExpression.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestPrimaryExpression.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestPrimaryExpression.java new file mode 100644 index 0000000..0670bf6 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestPrimaryExpression.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestPrimaryExpression extends AbstractAs3ParserTest +{ + @Test + public void testArrayLiteral() throws TokenException + { + assertPrimary( "[1,2,3]", + "1" + + "2" + + "3" ); + } + + @Test + public void testBooleans() throws TokenException + { + assertPrimary( "true" ); + assertPrimary( "false" ); + } + + @Test + public void testFunctionLiteral() throws TokenException + { + assertPrimary( "function ( a : Object ) : * { trace('test'); }", + "" + + "" + + "a" + + "Object" + + "*" + + "trace" + + "'test'" + + "" ); + } + + @Test + public void testNull() throws TokenException + { + assertPrimary( "null" ); + } + + @Test + public void testNumbers() throws TokenException + { + assertPrimary( "1" ); + assertPrimary( "0xff" ); + assertPrimary( "0777" ); + assertPrimary( ".12E5" ); + } + + @Test + public void testObjectLiteral() throws TokenException + { + assertPrimary( "{a:1,b:2}", + "" + + "a" + + "1" + + "b" + + "2" ); + } + + @Test + public void testStrings() throws TokenException + { + assertPrimary( "\"string\"" ); + assertPrimary( "'string'" ); + } + + @Test + public void testUndefined() throws TokenException + { + assertPrimary( "undefined" ); + } + + private void assertPrimary( final String input ) throws TokenException + { + assertPrimary( input, + input ); + } + + private void assertPrimary( final String input, + final String expected ) throws TokenException + { + scn.setLines( new String[] + { input, + "__END__" } ); + asp.nextToken(); + final String result = new ASTToXMLConverter().convert( asp.parsePrimaryExpression() ); + assertEquals( "unexpected", + "" + + expected + "", + result ); + } + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestReturnStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestReturnStatement.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestReturnStatement.java new file mode 100644 index 0000000..f1dd833 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestReturnStatement.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestReturnStatement extends AbstractStatementTest +{ + @Test + public void testEmptyReturn() throws TokenException + { + assertStatement( "1", + "return", + "" ); + + assertStatement( "2", + "return;", + "" ); + } + + @Test + public void testFlexPMD181a() throws TokenException + { + assertStatement( "1", + "return (str1 === str2);", + "" + + "str1" + + "===str2" + + "" ); + } + + @Test + public void testFlexPMD181b() throws TokenException + { + assertStatement( "1", + "return testString(str, /^[a-zA-Z\\s]*$/);", + "testString" + + "str" + + "/^[a-zA-Z\\s]*$/" ); + } + + @Test + public void testReturnArrayLiteral() throws TokenException + { + assertStatement( "1", + "return []", + "" + + "" ); + assertStatement( "2", + "return [];", + "" + + "" ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestSwitchStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestSwitchStatement.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestSwitchStatement.java new file mode 100644 index 0000000..89ce628 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestSwitchStatement.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestSwitchStatement extends AbstractStatementTest +{ + @Test + public void testFullFeatured() throws TokenException + { + assertStatement( "1", + "switch( x ){ case 1 : trace('one'); break; default : trace('unknown'); }", + "" + + "x" + "" + + "1" + + "" + + "trace" + + "'one'" + + "break" + + "" + "" + + "default" + + "trace" + "" + + "" + "'unknown'" + + "" ); + assertStatement( "1", + "switch( x ){ case 1 : break; default:}", + "x1break" + + "default" + + "" ); + + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestTryCatchFinallyStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestTryCatchFinallyStatement.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestTryCatchFinallyStatement.java new file mode 100644 index 0000000..45da07e --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestTryCatchFinallyStatement.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestTryCatchFinallyStatement extends AbstractStatementTest +{ + @Test + public void testCatch() throws TokenException + { + assertStatement( "1", + "catch( e : Error ) {trace( true ); }", + "e" + + "Error" + + "trace" + + "true" + + "" ); + } + + @Test + public void testFinally() throws TokenException + { + assertStatement( "1", + "finally {trace( true ); }", + "" + + "" + + "trace" + + "true" ); + } + + @Test + public void testTry() throws TokenException + { + assertStatement( "1", + "try {trace( true ); }", + "" + + "" + + "trace" + + "true" ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestUnaryExpression.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestUnaryExpression.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestUnaryExpression.java new file mode 100644 index 0000000..41ca8d2 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestUnaryExpression.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestUnaryExpression extends AbstractStatementTest +{ + @Test + public void testArrayAccess() throws TokenException + { + assertStatement( "1", + "x[0]", + "x<" + + "/primary>0" ); + } + + @Test + public void testComplex() throws TokenException + { + assertStatement( "1", + "a.b['c'].d.e(1)", + "a" + + "" + + "b" + + "'c'" + + "de" + + "1" + + "" ); + + assertStatement( "2", + "a.b['c']['d'].e(1)", + "a" + + "" + + "b" + + "'c''d'" + + "" + + "e1" + + "" ); + } + + @Test + public void testMethodCall() throws TokenException + { + assertStatement( "1", + "method()", + "" + + "method" ); + + assertStatement( "2", + "method( 1, \"two\" )", + "" + + "method1" + + "\"two\"" ); + } + + @Test + public void testMultipleMethodCall() throws TokenException + { + assertStatement( "1", + "method()()", + "" + + "method" + + "" ); + } + + @Test + public void testParseUnaryExpressions() throws TokenException + { + assertStatement( "1", + "++x", + "x" ); + assertStatement( "2", + "x++", + "x" ); + assertStatement( "3", + "--x", + "x" ); + assertStatement( "4", + "x--", + "x" ); + assertStatement( "5", + "+x", + "x" ); + assertStatement( "6", + "+ x", + "x" ); + assertStatement( "7", + "-x", + "x" ); + assertStatement( "8", + "- x", + "x" ); + assertStatement( "9", + "delete x", + "x" ); + assertStatement( "a", + "void x", + "x" ); + assertStatement( "b", + "typeof x", + "x" ); + assertStatement( "c", + "! x", + "x" ); + assertStatement( "d", + "~ x", + "x" ); + assertStatement( "e", + "x++", + "x" ); + assertStatement( "f", + "x--", + "x" ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestVarStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestVarStatement.java b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestVarStatement.java new file mode 100644 index 0000000..baa9584 --- /dev/null +++ b/FlexPMD/as3-parser/src/test/java/de/bokelberg/flex/parser/TestVarStatement.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.bokelberg.flex.parser; + +import org.junit.Test; + +import com.adobe.ac.pmd.parser.exceptions.TokenException; + +public class TestVarStatement extends AbstractStatementTest +{ + @Test + public void testFlexPMD211() throws TokenException + { + assertStatement( "", + "var a:Vector. = new Vector.();\nvar i:int;", + "a" + + "String" + + "Vector" + + "String" + + "" + + "" ); + } + + @Test + public void testFullFeaturedVar() throws TokenException + { + assertStatement( "1", + "var a : int = 4", + "" + + "" + + "aint" + + "4" + + "" ); + + assertStatement( "1", + "var a : int = 4, b : int = 2;", + "" + + "aint" + + "4" + + "" + + "bint" + + "2" + + "" ); + + assertStatement( "with array", + "var colors:Array = [0x2bc9f6, 0x0086ad];", + "" + + "" + + "colorsArray" + + "" + "" + + "0x2bc9f6" + + "0x0086ad" + + "" ); + } + + @Test + public void testInitializedVar() throws TokenException + { + assertStatement( "1", + "var a = 4", + "" + + "a" + + "4" + + "" ); + } + + @Test + public void testSimpleVar() throws TokenException + { + assertStatement( "1", + "var a", + "" + + "a" + + "" ); + } + + @Test + public void testTypedVar() throws TokenException + { + assertStatement( "1", + "var a : Object", + "" + + "aObject" + + "" ); + } + + @Test + public void testVector() throws TokenException + { + assertStatement( "vector", + "var v:Vector. = new Vector.();", + "vDisplayObjectVectorSprite" ); + + assertStatement( "vector", + "var v:Vector.< Vector.< String > >", + "" + + "" + "vString" ); + + assertStatement( "vector", + "var v:Vector.>;", + "" + + "" + + "vString" ); + + assertStatement( "", + "var HT:Vector. = new Vector.(251, true);", + "HTBitStringVectorBitString251true" ); + } +}