Skip to content

Commit

Permalink
BigIntLiteral.toSource includes suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCokerC3 authored and gbrail committed Jan 15, 2024
1 parent c5c7fa6 commit a754ea6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/org/mozilla/javascript/ast/BigIntLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void setBigInt(BigInteger value) {

@Override
public String toSource(int depth) {
return makeIndent(depth) + (bigInt == null ? "<null>" : bigInt.toString());
return makeIndent(depth) + (bigInt == null ? "<null>" : bigInt.toString() + "n");
}

/** Visits this node. There are no children to visit. */
Expand Down
47 changes: 47 additions & 0 deletions testsrc/org/mozilla/javascript/tests/BigIntTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.mozilla.javascript.tests;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mozilla.javascript.CompilerEnvirons;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Parser;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ast.AstRoot;
import org.mozilla.javascript.tools.shell.Global;

/** This is a set of tests for parsing and using BigInts. */
public class BigIntTest {

private Context cx;
private Scriptable global;

@Before
public void init() {
cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_ES6);
cx.getWrapFactory().setJavaPrimitiveWrap(false);
global = new Global(cx);
}

@After
public void terminate() {
Context.exit();
}

@Test
public void parse() throws IOException {
String[] INPUTS =
new String[] {"0n", "12n", "-12n", "1234567890987654321n", "-1234567890987654321n"};
CompilerEnvirons env = new CompilerEnvirons();
env.setLanguageVersion(Context.VERSION_ES6);
for (String input : INPUTS) {
String stmt = "x = " + input + ";\n";
AstRoot root = new Parser(env).parse(stmt, "bigint.js", 1);
assertEquals(stmt, root.toSource());
}
}
}

0 comments on commit a754ea6

Please sign in to comment.