Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Unified Diff: compiler/javatests/com/google/dart/compiler/backend/js/analysis/TreeShakerTest.java

Issue 8676041: JS tree shaking for incremental builds. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: compiler/javatests/com/google/dart/compiler/backend/js/analysis/TreeShakerTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/backend/js/analysis/TreeShakerTest.java b/compiler/javatests/com/google/dart/compiler/backend/js/analysis/TreeShakerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..d0cbb0ca4e09c1e5c09a55c680fd3d4c0121699a
--- /dev/null
+++ b/compiler/javatests/com/google/dart/compiler/backend/js/analysis/TreeShakerTest.java
@@ -0,0 +1,52 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+
+package com.google.dart.compiler.backend.js.analysis;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+/**
+ * Tests the JS based tree shaker used in incremental compilation.
+ */
+public class TreeShakerTest extends TestCase {
+ /**
+ * Tests {@link TreeShaker#reduce(java.io.Reader, java.io.Writer, long)} can
+ * remove unused methods.
+ */
+ public void testReduce() throws IOException {
+ StringBuffer inputSrc = new StringBuffer();
+ inputSrc.append("function A() {}\n");
+ inputSrc.append("A.prototype.foo = function(){}\n");
+ inputSrc.append("function B() {}\n");
+ inputSrc.append("B.prototype.foo = function(){}\n");
+ inputSrc.append("function C() { A(); }\n");
+ inputSrc.append("RunEntry(C);\n");
+
+ StringReader inputCode = new StringReader(inputSrc.toString());
+ StringWriter outputCode = new StringWriter();
+
+ TreeShaker.reduce(inputCode, outputCode, inputSrc.toString().length());
+
+ StringBuffer outputSrc = new StringBuffer();
+ outputSrc.append("function A() {}\n");
+ outputSrc.append("function C() { A(); }\n");
+ outputSrc.append("RunEntry(C);\n");
+
+ assertEquals(outputSrc.toString(), outputCode.toString());
+ }
+
+ /**
+ * Tests {@link TreeShaker#reduce(java.io.Reader, java.io.Writer, long)} can
+ * handle empty code.
+ */
+ public void testReduceEmpty() throws IOException {
+ StringReader inputSrc = new StringReader("");
+ StringWriter outputSrc = new StringWriter();
+ TreeShaker.reduce(inputSrc, outputSrc, 0);
+
+ assertEquals("", outputSrc.toString());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698