| 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());
|
| + }
|
| +}
|
|
|