linter: more tests
diff --git a/linter/src/main/java/org/apache/royale/linter/rules/StrictEqualityRule.java b/linter/src/main/java/org/apache/royale/linter/rules/StrictEqualityRule.java
index 4ba214e..89645c0 100644
--- a/linter/src/main/java/org/apache/royale/linter/rules/StrictEqualityRule.java
+++ b/linter/src/main/java/org/apache/royale/linter/rules/StrictEqualityRule.java
@@ -29,7 +29,6 @@
import org.apache.royale.linter.LinterRule;
import org.apache.royale.linter.TokenVisitor;
import org.apache.royale.linter.problems.ILinterProblem;
-import org.apache.royale.linter.rules.StrictEqualityRule.StrictEqualityLinterProblem;
/**
* Checks for uses of the '==' and '!='' operators instead of the stricter '==='
diff --git a/linter/src/test/java/org/apache/royale/linter/rules/TestStaticConstantsRule.java b/linter/src/test/java/org/apache/royale/linter/rules/TestStaticConstantsRule.java
new file mode 100644
index 0000000..ad44763
--- /dev/null
+++ b/linter/src/test/java/org/apache/royale/linter/rules/TestStaticConstantsRule.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.royale.linter.rules;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.linter.ASLinter;
+import org.apache.royale.linter.LinterRule;
+import org.apache.royale.linter.LinterSettings;
+import org.junit.Test;
+
+public class TestStaticConstantsRule {
+ @Test
+ public void testStaticConstant() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new StaticConstantsRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "class MyClass{static const HELLO:String = \"hello\";}", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testFieldConstant() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new StaticConstantsRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "class MyClass{const HELLO:String = \"hello\";}", problems);
+ assertEquals(1, problems.size());
+ assertTrue(problems.get(0) instanceof StaticConstantsRule.StaticConstantsLinterProblem);
+ }
+
+ @Test
+ public void testLocalConstant() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new StaticConstantsRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ // this rule tests only class members, and not locals
+ linter.lint("file.as", "class MyClass{function myMethod():void{const HELLO:String = \"hello\";}}", problems);
+ assertEquals(0, problems.size());
+ }
+}
\ No newline at end of file
diff --git a/linter/src/test/java/org/apache/royale/linter/rules/TestStrictEqualityRule.java b/linter/src/test/java/org/apache/royale/linter/rules/TestStrictEqualityRule.java
new file mode 100644
index 0000000..04aacde
--- /dev/null
+++ b/linter/src/test/java/org/apache/royale/linter/rules/TestStrictEqualityRule.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.royale.linter.rules;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.linter.ASLinter;
+import org.apache.royale.linter.LinterRule;
+import org.apache.royale.linter.LinterSettings;
+import org.junit.Test;
+
+public class TestStrictEqualityRule {
+ @Test
+ public void testStrictEquality() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new StrictEqualityRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "a === b", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testStrictInquality() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new StrictEqualityRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "a !== b", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testLooseEquality() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new StrictEqualityRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "a == b", problems);
+ assertEquals(1, problems.size());
+ assertTrue(problems.get(0) instanceof StrictEqualityRule.StrictEqualityLinterProblem);
+ }
+
+ @Test
+ public void testLooseInquality() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new StrictEqualityRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "a != b", problems);
+ assertEquals(1, problems.size());
+ assertTrue(problems.get(0) instanceof StrictEqualityRule.StrictEqualityLinterProblem);
+ }
+}
\ No newline at end of file
diff --git a/linter/src/test/java/org/apache/royale/linter/rules/TestSwitchWithoutDefaultRule.java b/linter/src/test/java/org/apache/royale/linter/rules/TestSwitchWithoutDefaultRule.java
new file mode 100644
index 0000000..f23cf9f
--- /dev/null
+++ b/linter/src/test/java/org/apache/royale/linter/rules/TestSwitchWithoutDefaultRule.java
@@ -0,0 +1,59 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.linter.rules;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.linter.ASLinter;
+import org.apache.royale.linter.LinterRule;
+import org.apache.royale.linter.LinterSettings;
+import org.junit.Test;
+
+public class TestSwitchWithoutDefaultRule {
+ @Test
+ public void testSwitchWithoutDefault() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new SwitchWithoutDefaultRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "switch(a) {case 1:break;}", problems);
+ assertEquals(1, problems.size());
+ assertTrue(problems.get(0) instanceof SwitchWithoutDefaultRule.SwitchWithoutDefaultLinterProblem);
+ }
+
+ @Test
+ public void testSwitchWithDefault() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new SwitchWithoutDefaultRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "switch(a) {case 1:break;default:}", problems);
+ assertEquals(0, problems.size());
+ }
+}
\ No newline at end of file
diff --git a/linter/src/test/java/org/apache/royale/linter/rules/TestUnsafeNegationRule.java b/linter/src/test/java/org/apache/royale/linter/rules/TestUnsafeNegationRule.java
new file mode 100644
index 0000000..960b792
--- /dev/null
+++ b/linter/src/test/java/org/apache/royale/linter/rules/TestUnsafeNegationRule.java
@@ -0,0 +1,109 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.linter.rules;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.linter.ASLinter;
+import org.apache.royale.linter.LinterRule;
+import org.apache.royale.linter.LinterSettings;
+import org.junit.Test;
+
+public class TestUnsafeNegationRule {
+ @Test
+ public void testUnsafeNegationIn() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new UnsafeNegationRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "!a in b", problems);
+ assertEquals(1, problems.size());
+ assertTrue(problems.get(0) instanceof UnsafeNegationRule.UnsafeNegationLinterProblem);
+ }
+
+ @Test
+ public void testUnsafeNegationIs() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new UnsafeNegationRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "!a is b", problems);
+ assertEquals(1, problems.size());
+ assertTrue(problems.get(0) instanceof UnsafeNegationRule.UnsafeNegationLinterProblem);
+ }
+
+ @Test
+ public void testUnsafeNegationInstanceOf() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new UnsafeNegationRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "!a instanceof b", problems);
+ assertEquals(1, problems.size());
+ assertTrue(problems.get(0) instanceof UnsafeNegationRule.UnsafeNegationLinterProblem);
+ }
+
+ @Test
+ public void testSafeNegationIn() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new StrictEqualityRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "!(a in b)", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testSafeNegationIs() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new StrictEqualityRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "!(a is b)", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testSafeNegationInstanceOf() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new StrictEqualityRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "!(a instanceof b)", problems);
+ assertEquals(0, problems.size());
+ }
+}
\ No newline at end of file
diff --git a/linter/src/test/java/org/apache/royale/linter/rules/TestValidTypeofRule.java b/linter/src/test/java/org/apache/royale/linter/rules/TestValidTypeofRule.java
new file mode 100644
index 0000000..c95c452
--- /dev/null
+++ b/linter/src/test/java/org/apache/royale/linter/rules/TestValidTypeofRule.java
@@ -0,0 +1,131 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.linter.rules;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.linter.ASLinter;
+import org.apache.royale.linter.LinterRule;
+import org.apache.royale.linter.LinterSettings;
+import org.junit.Test;
+
+public class TestValidTypeofRule {
+ @Test
+ public void testInvalidTypeof() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new ValidTypeofRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "typeof a == \"other\"", problems);
+ assertEquals(1, problems.size());
+ assertTrue(problems.get(0) instanceof ValidTypeofRule.ValidTypeofLinterProblem);
+ }
+
+ @Test
+ public void testValidTypeofBoolean() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new ValidTypeofRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "typeof a == \"boolean\"", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testValidTypeofFunction() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new ValidTypeofRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "typeof a == \"function\"", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testValidTypeofNumber() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new ValidTypeofRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "typeof a == \"number\"", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testValidTypeofObject() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new ValidTypeofRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "typeof a == \"object\"", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testValidTypeofString() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new ValidTypeofRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "typeof a == \"string\"", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testValidTypeofXml() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new ValidTypeofRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "typeof a == \"xml\"", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testValidTypeofUndefined() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new ValidTypeofRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "typeof a == \"undefined\"", problems);
+ assertEquals(0, problems.size());
+ }
+}
\ No newline at end of file
diff --git a/linter/src/test/java/org/apache/royale/linter/rules/TestVariablesOnTopRule.java b/linter/src/test/java/org/apache/royale/linter/rules/TestVariablesOnTopRule.java
new file mode 100644
index 0000000..2227d3b
--- /dev/null
+++ b/linter/src/test/java/org/apache/royale/linter/rules/TestVariablesOnTopRule.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.royale.linter.rules;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.linter.ASLinter;
+import org.apache.royale.linter.LinterRule;
+import org.apache.royale.linter.LinterSettings;
+import org.junit.Test;
+
+public class TestVariablesOnTopRule {
+ @Test
+ public void testOneVariableOnTop() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new VariablesOnTopRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "function myFunction():void{var a:String = null;while(true){}}", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testMultipleVariablesOnTop() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new VariablesOnTopRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "function myFunction():void{var a:String = null;var b:Number = 123.4;while(true){}}", problems);
+ assertEquals(0, problems.size());
+ }
+
+ @Test
+ public void testVariableNotOnTop() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new VariablesOnTopRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "function myFunction():void{while(true){}var a:String = null;}", problems);
+ assertEquals(1, problems.size());
+ assertTrue(problems.get(0) instanceof VariablesOnTopRule.VariablesOnTopLinterProblem);
+ }
+
+ @Test
+ public void testVariableOnTopAndVariableNotOnTop() {
+ List<LinterRule> rules = new ArrayList<LinterRule>();
+ rules.add(new VariablesOnTopRule());
+ LinterSettings settings = new LinterSettings();
+ settings.rules = rules;
+ ASLinter linter = new ASLinter(settings);
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+ linter.lint("file.as", "function myFunction():void{var a:String = null;while(true){}var b:Number = 123.4;}", problems);
+ assertEquals(1, problems.size());
+ assertTrue(problems.get(0) instanceof VariablesOnTopRule.VariablesOnTopLinterProblem);
+ }
+}
\ No newline at end of file