Debian Codegraph @

rhino/testsrc/org/mozilla/javascript/tests/harmony/ToSourceTest.java

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package org.mozilla.javascript.tests.harmony;
6
7 import org.junit.Assert;
8 import org.junit.Test;
9 import org.mozilla.javascript.CompilerEnvirons;
10 import org.mozilla.javascript.Context;
11 import org.mozilla.javascript.Parser;
12 import org.mozilla.javascript.ast.AstRoot;
13
14
15 public class ToSourceTest {
16
17 private void assertSource(String source, String expectedOutput) {
18 CompilerEnvirons env = new CompilerEnvirons();
19 env.setLanguageVersion(Context.VERSION_ES6);
20 Parser parser = new Parser(env);
21 AstRoot root = parser.parse(source, null, 0);
22 Assert.assertEquals(expectedOutput, root.toSource());
23 }
24
25
26 /**
27 * Tests that var declaration AST nodes is properly decompiled.
28 */
29 @Test
30 public void testArrowFunctionToSource() {
31 assertSource("var a3 = a.map(s => s.length);", "var a3 = a.map(s => s.length);\n");
32 }
33
34 }