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 ABEEA100F2 for ; Sat, 7 Mar 2015 12:06:57 +0000 (UTC) Received: (qmail 59926 invoked by uid 500); 7 Mar 2015 12:06:55 -0000 Delivered-To: apmail-flex-commits-archive@flex.apache.org Received: (qmail 59869 invoked by uid 500); 7 Mar 2015 12:06:55 -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 58984 invoked by uid 99); 7 Mar 2015 12:06:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Mar 2015 12:06:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9FCF5E0ACF; Sat, 7 Mar 2015 12:06:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cdutz@apache.org To: commits@flex.apache.org Date: Sat, 07 Mar 2015 12:07:14 -0000 Message-Id: In-Reply-To: <0179febeb78b4335a3d6fbf7ffdb3d31@git.apache.org> References: <0179febeb78b4335a3d6fbf7ffdb3d31@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [21/24] git commit: [flex-utilities] [refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD language module for Apache Flex http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestCompilationUnit.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestCompilationUnit.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestCompilationUnit.java new file mode 100644 index 0000000..a59d9c3 --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestCompilationUnit.java @@ -0,0 +1,84 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import static org.testng.Assert.*; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestCompilationUnit extends AbstractAs3ParserTestBase { + + @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(expected, result, message); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestConstStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestConstStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestConstStatement.java new file mode 100644 index 0000000..5743275 --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestConstStatement.java @@ -0,0 +1,62 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestConstStatement extends AbstractStatementTestBase { + + @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/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestDoStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestDoStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestDoStatement.java new file mode 100644 index 0000000..d650f0a --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestDoStatement.java @@ -0,0 +1,57 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestDoStatement extends AbstractStatementTestBase { + + @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/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestE4xExpression.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestE4xExpression.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestE4xExpression.java new file mode 100644 index 0000000..3ad142a --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestE4xExpression.java @@ -0,0 +1,44 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestE4xExpression extends AbstractStatementTestBase { + + @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/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestEmptyStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestEmptyStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestEmptyStatement.java new file mode 100644 index 0000000..454744a --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestEmptyStatement.java @@ -0,0 +1,39 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestEmptyStatement extends AbstractStatementTestBase { + + @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/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestExpression.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestExpression.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestExpression.java new file mode 100644 index 0000000..bda05e8 --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestExpression.java @@ -0,0 +1,186 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestExpression extends AbstractStatementTestBase { + + @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/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestForStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestForStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestForStatement.java new file mode 100644 index 0000000..8560c13 --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestForStatement.java @@ -0,0 +1,97 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestForStatement extends AbstractStatementTestBase { + + @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/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestIfStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestIfStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestIfStatement.java new file mode 100644 index 0000000..06c2f7f --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestIfStatement.java @@ -0,0 +1,128 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestIfStatement extends AbstractStatementTestBase { + + @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/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterface.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterface.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterface.java new file mode 100644 index 0000000..cf27b05 --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterface.java @@ -0,0 +1,72 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import static org.testng.Assert.*; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestInterface extends AbstractAs3ParserTestBase { + + @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(expected, result, message); + } + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterfaceContent.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterfaceContent.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterfaceContent.java new file mode 100644 index 0000000..ea99d9b --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterfaceContent.java @@ -0,0 +1,88 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import static org.testng.Assert.*; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestInterfaceContent extends AbstractAs3ParserTestBase { + + @Test + 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("" + expected + "", result, message); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPackageContent.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPackageContent.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPackageContent.java new file mode 100644 index 0000000..224a0dd --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPackageContent.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 org.apache.flex.pmd.parser.impl; + +import static org.testng.Assert.*; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestPackageContent extends AbstractAs3ParserTestBase { + + @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(expected, result, message); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPrimaryExpression.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPrimaryExpression.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPrimaryExpression.java new file mode 100644 index 0000000..81a8730 --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPrimaryExpression.java @@ -0,0 +1,102 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import static org.testng.Assert.*; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestPrimaryExpression extends AbstractAs3ParserTestBase { + + @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("" + expected + "", result, "unexpected"); + } + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestReturnStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestReturnStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestReturnStatement.java new file mode 100644 index 0000000..8110a05 --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestReturnStatement.java @@ -0,0 +1,65 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestReturnStatement extends AbstractStatementTestBase { + + @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/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestSwitchStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestSwitchStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestSwitchStatement.java new file mode 100644 index 0000000..284cc6b --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestSwitchStatement.java @@ -0,0 +1,50 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestSwitchStatement extends AbstractStatementTestBase { + + @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/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestTryCatchFinallyStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestTryCatchFinallyStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestTryCatchFinallyStatement.java new file mode 100644 index 0000000..190f129 --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestTryCatchFinallyStatement.java @@ -0,0 +1,54 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestTryCatchFinallyStatement extends AbstractStatementTestBase { + + @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/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestUnaryExpression.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestUnaryExpression.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestUnaryExpression.java new file mode 100644 index 0000000..5cc2b01 --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestUnaryExpression.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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestUnaryExpression extends AbstractStatementTestBase { + + @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/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestVarStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestVarStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestVarStatement.java new file mode 100644 index 0000000..325ed06 --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestVarStatement.java @@ -0,0 +1,119 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestVarStatement extends AbstractStatementTestBase { + + @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"); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestWhileStatement.java ---------------------------------------------------------------------- diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestWhileStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestWhileStatement.java new file mode 100644 index 0000000..6cd12dc --- /dev/null +++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestWhileStatement.java @@ -0,0 +1,63 @@ +/* + * 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 org.apache.flex.pmd.parser.impl; + +import org.apache.flex.pmd.parser.exceptions.TokenException; +import org.testng.annotations.Test; + +public class TestWhileStatement extends AbstractStatementTestBase { + + @Test + public void testWhile() throws TokenException { + assertStatement("1", + "while( i++ ){ trace( i ); }", + "" + + "" + + "" + + "i" + + "" + + "" + + "" + + "trace" + + "i" + + "" + "" + ""); + } + + @Test + public void testWhileWithEmptyStatement() throws TokenException { + assertStatement("1", + "while( i++ ); ", + "" + + "" + + "" + + "i" + + ";"); + } + + @Test + public void testWhileWithoutBlock() throws TokenException { + assertStatement("1", + "while( i++ ) trace( i ); ", + "" + + "" + + "" + + "i" + + "" + + "trace" + + "i"); + } +}