flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gordonsm...@apache.org
Subject [1/2] git commit: [flex-falcon] - Falcon: Added unit tests for MXMLTextData.
Date Wed, 17 Apr 2013 02:57:58 GMT
Updated Branches:
  refs/heads/develop a5c10c63d -> f0d8b739a


Falcon: Added unit tests for MXMLTextData.

The tests cover MXMLTextData of type TEXT, WHITESPACE, COMMENT, ASDOC,
and CDATA. It looks like types ENTITY, DATABINDING, and OTHER may be
historical cruft that can be removed. I need to investigate this.

Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/a90c2e3b
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/a90c2e3b
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/a90c2e3b

Branch: refs/heads/develop
Commit: a90c2e3bad34a8e7bf7cc9922b4a21fc7a509e84
Parents: c4b2cd2
Author: Gordon Smith <gordonsmith@apache.org>
Authored: Tue Apr 16 19:57:13 2013 -0700
Committer: Gordon Smith <gordonsmith@apache.org>
Committed: Tue Apr 16 19:57:13 2013 -0700

----------------------------------------------------------------------
 .../flex/compiler/internal/mxml/MXMLDataTests.java |   28 ++-
 .../internal/mxml/MXMLInstructionDataTests.java    |    3 +-
 .../compiler/internal/mxml/MXMLTextDataTests.java  |  228 +++++++++++++++
 .../compiler/internal/mxml/MXMLUnitDataTests.java  |   12 +-
 4 files changed, 267 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a90c2e3b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLDataTests.java
----------------------------------------------------------------------
diff --git a/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLDataTests.java
b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLDataTests.java
index e13de93..da89b5a 100644
--- a/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLDataTests.java
+++ b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLDataTests.java
@@ -19,6 +19,11 @@
 
 package org.apache.flex.compiler.internal.mxml;
 
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileWriter;
@@ -31,9 +36,8 @@ import org.apache.flex.compiler.mxml.IMXMLData;
 import org.apache.flex.compiler.mxml.IMXMLDataManager;
 import org.apache.flex.utils.FilenameNormalization;
 import org.apache.flex.utils.StringUtils;
-import org.junit.Ignore;
+import org.junit.Test;
 
-@Ignore
 public class MXMLDataTests
 {
 	protected String getMXML(String[] code)
@@ -67,4 +71,24 @@ public class MXMLDataTests
 		IMXMLData mxmlData = mxmlDataManager.get(fileSpec);
 		return mxmlData;
 	}
+	
+	/**
+	 * Tests that an empty MXML file produces a non-null MXMLData with 0 units.
+	 */
+	@Test
+	public void MXMLData_empty()
+	{
+		String[] code = new String[]
+		{
+			""
+		};
+		IMXMLData mxmlData = getMXMLData(getMXML(code));
+		assertThat("mxmlData", mxmlData, is(notNullValue()));
+		assertThat("getFileSpecification, getPath", mxmlData.getFileSpecification().getPath(),
is(mxmlData.getPath()));
+		assertThat("getNumUnits", mxmlData.getNumUnits(), is(0));
+		assertThat("getEnd", mxmlData.getEnd(), is(0));
+		assertThat("getRootTag", mxmlData.getRootTag(), is(nullValue()));
+		assertThat("getMXMLDialect", mxmlData.getMXMLDialect(), is(MXMLDialect.DEFAULT));
+		assertThat("getProblems", mxmlData.getProblems().size(), is(0));
+	}
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a90c2e3b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLInstructionDataTests.java
----------------------------------------------------------------------
diff --git a/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLInstructionDataTests.java
b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLInstructionDataTests.java
index 69f394f..34ee37c 100644
--- a/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLInstructionDataTests.java
+++ b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLInstructionDataTests.java
@@ -20,6 +20,7 @@
 package org.apache.flex.compiler.internal.mxml;
 
 import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
 import static org.junit.Assert.assertThat;
 
 import org.apache.flex.compiler.mxml.IMXMLInstructionData;
@@ -36,7 +37,7 @@ public class MXMLInstructionDataTests extends MXMLUnitDataTests
 	private IMXMLInstructionData getMXMLInstructionData(String[] code)
 	{
 		IMXMLUnitData unitData = getMXMLUnitData(code);
-		assertThat("instanceof", unitData instanceof IMXMLInstructionData, is(true));
+		assertThat("instanceOf", unitData, is(instanceOf(IMXMLInstructionData.class)));
 		return (IMXMLInstructionData)unitData;
 	}
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a90c2e3b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLTextDataTests.java
----------------------------------------------------------------------
diff --git a/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLTextDataTests.java
b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLTextDataTests.java
new file mode 100644
index 0000000..26c75a6
--- /dev/null
+++ b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLTextDataTests.java
@@ -0,0 +1,228 @@
+/*
+ *
+ *  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.compiler.internal.mxml;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.junit.Assert.assertThat;
+
+import org.apache.flex.compiler.mxml.IMXMLTextData;
+import org.apache.flex.compiler.mxml.IMXMLUnitData;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link MXMLTextData}.
+ * 
+ * @author Gordon Smith
+ */
+public class MXMLTextDataTests extends MXMLUnitDataTests
+{
+	private IMXMLTextData getMXMLTextData(String[] code)
+	{
+		IMXMLUnitData unitData = getMXMLUnitData(code);
+		assertThat("instanceOf", unitData, is(instanceOf(IMXMLTextData.class)));
+		return (IMXMLTextData)unitData;
+	}
+
+	@Test
+	public void MXMLTextData_text()
+	{
+		String[] code = new String[]
+		{
+			"abc"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.TEXT));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is(code[0]));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+
+	@Test
+	public void MXMLTextData_textWithWhitespace()
+	{
+		String[] code = new String[]
+		{
+			" a b c "
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.TEXT));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is(code[0]));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+
+	@Test
+	public void MXMLTextData_whitespace()
+	{
+		String[] code = new String[]
+		{
+			" \t\r\n"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.WHITESPACE));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is(code[0]));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+
+	@Test
+	public void MXMLTextData_comment_empty()
+	{
+		String[] code = new String[]
+		{
+			"<!-- -->"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.COMMENT));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is(""));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+	
+	@Test
+	public void MXMLTextData_comment()
+	{
+		String[] code = new String[]
+		{
+			"<!--abc-->"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.COMMENT));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is(""));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+	
+	@Test
+	public void MXMLTextData_ASDoc_empty()
+	{
+		String[] code = new String[]
+		{
+			"<!--- -->"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.ASDOC));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is(""));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+	
+	@Test
+	public void MXMLTextData_ASDoc()
+	{
+		String[] code = new String[]
+		{
+			"<!---abc-->"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.ASDOC));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is(""));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+	
+	@Test
+	public void MXMLTextData_CDATA_empty()
+	{
+		String[] code = new String[]
+		{
+			"<![CDATA[]]>"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.CDATA));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is(""));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+	
+	@Test
+	public void MXMLTextData_CDATA_whitespace()
+	{
+		String[] code = new String[]
+		{
+			"<![CDATA[ \t\r\n]]>"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.CDATA));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is(" \t\r\n"));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+	
+	@Test
+	public void MXMLTextData_CDATA_abc()
+	{
+		String[] code = new String[]
+		{
+			"<![CDATA[abc]]>"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.CDATA));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is("abc"));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+	
+	@Test
+	public void MXMLTextData_CDATA_metacharacters()
+	{
+		String[] code = new String[]
+		{
+			"<![CDATA[<&>]]>"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.CDATA));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is("<&>"));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+	
+	@Ignore
+	@Test
+	public void MXMLTextData_entity()
+	{
+		String[] code = new String[]
+		{
+			"&lt;"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.ENTITY));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is("<&>"));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+	
+	@Ignore
+	@Test
+	public void MXMLTextData_databinding()
+	{
+		String[] code = new String[]
+		{
+			"{abc}"
+		};
+		IMXMLTextData textData = getMXMLTextData(code);
+		assertThat("getTextType", textData.getTextType(), is(IMXMLTextData.TextType.DATABINDING));
+		assertThat("getContent", textData.getContent(), is(code[0]));
+		assertThat("getCompilableText", textData.getCompilableText(), is("<&>"));
+		//assertThat("getCompilableTextStart", textData.getCompilableTextStart(), is(0));
+	}
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a90c2e3b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLUnitDataTests.java
----------------------------------------------------------------------
diff --git a/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLUnitDataTests.java
b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLUnitDataTests.java
index ec9a152..4209df3 100644
--- a/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLUnitDataTests.java
+++ b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLUnitDataTests.java
@@ -20,6 +20,8 @@
 package org.apache.flex.compiler.internal.mxml;
 
 import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
 import static org.junit.Assert.assertThat;
 
 import org.apache.flex.compiler.mxml.IMXMLData;
@@ -27,7 +29,9 @@ import org.apache.flex.compiler.mxml.IMXMLUnitData;
 import org.junit.Ignore;
 
 /**
- * JUnit tests for {@link MXMLUnitData}.
+ * Base class for JUnit tests of {@link MXMLUnitData} subclasses.
+ * <p>
+ * Each test tests a tiny portion of MXML that contains only a single unit.
  * 
  * @author Gordon Smith
  */
@@ -38,7 +42,13 @@ public class MXMLUnitDataTests extends MXMLDataTests
     {
     	String mxml = getMXML(code);
     	IMXMLData mxmlData = getMXMLData(mxml);
+    	assertThat("mxmlData", mxmlData, is(notNullValue()));
+		assertThat("getFileSpecification, getPath", mxmlData.getFileSpecification().getPath(),
is(mxmlData.getPath()));
 		assertThat("getNumUnits", mxmlData.getNumUnits(), is(1));
+		assertThat("getEnd", mxmlData.getEnd(), is(mxml.length()));
+		assertThat("getRootTag", mxmlData.getRootTag(), is(nullValue()));
+		assertThat("getMXMLDialect", mxmlData.getMXMLDialect(), is(MXMLDialect.DEFAULT));
+		assertThat("getProblems", mxmlData.getProblems().size(), is(0));
 		return mxmlData.getUnit(0);
     }
 }


Mime
View raw message