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 /**
6  *
7  */
8 package org.mozilla.javascript.tests;
9 
10 import static org.junit.Assert.assertEquals;
11 
12 import org.junit.After;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mozilla.javascript.CompilerEnvirons;
16 import org.mozilla.javascript.Context;
17 import org.mozilla.javascript.ErrorReporter;
18 import org.mozilla.javascript.Parser;
19 import org.mozilla.javascript.ast.AstRoot;
20 
21 /**
22  * @author André Bargull
23  *
24  */
25 public class Bug688018Test {
26     private Context cx;
27 
28     @Before
setUp()29     public void setUp() {
30         cx = Context.enter();
31         cx.setLanguageVersion(Context.VERSION_1_8);
32     }
33 
34     @After
tearDown()35     public void tearDown() {
36         Context.exit();
37     }
38 
parse(CharSequence cs)39     private AstRoot parse(CharSequence cs) {
40         CompilerEnvirons compilerEnv = new CompilerEnvirons();
41         compilerEnv.initFromContext(cx);
42         ErrorReporter compilationErrorReporter = compilerEnv.getErrorReporter();
43         Parser p = new Parser(compilerEnv, compilationErrorReporter);
44         return p.parse(cs.toString(), "<eval>", 1);
45     }
46 
toSource(CharSequence cs)47     private String toSource(CharSequence cs) {
48         return parse(cs).toSource();
49     }
50 
51     @Test
testToSource()52     public void testToSource() {
53         assertEquals("void 0;\n", toSource("void 0;"));
54         assertEquals("void 1;\n", toSource("void 1;"));
55         assertEquals("void 'hello';\n", toSource("void 'hello';"));
56         assertEquals("void fn();\n", toSource("void fn();"));
57     }
58 
59 }
60