Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigIntLiteral.toSource includes suffix #1432

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
}