forked from mozilla/rhino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
testsrc/org/mozilla/javascript/tests/es5/GeneratorToStringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.mozilla.javascript.tests.es5; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.ScriptableObject; | ||
import org.mozilla.javascript.TopLevel; | ||
import org.mozilla.javascript.tests.Utils; | ||
|
||
public class GeneratorToStringTest { | ||
private Context cx; | ||
|
||
@Before | ||
public void setUp() { | ||
cx = Context.enter(); | ||
cx.setLanguageVersion(Context.VERSION_ES6); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
Context.exit(); | ||
} | ||
|
||
@Test | ||
public void generatorsTest() { | ||
String code = " function* f() {\n" + " yield 1;\n" + " }; f.toString();"; | ||
test("\n" + "function* f() {\n" + " yield 1;\n" + "}\n", code); | ||
} | ||
|
||
private static void test(Object expected, String js) { | ||
Utils.runWithAllOptimizationLevels( | ||
cx -> { | ||
cx.setLanguageVersion(Context.VERSION_ES6); | ||
ScriptableObject scope = new TopLevel(); | ||
cx.initStandardObjects(scope); | ||
|
||
Object result = cx.evaluateString(scope, js, "test", 1, null); | ||
assertEquals(expected, result); | ||
|
||
return null; | ||
}); | ||
} | ||
} |