-
Notifications
You must be signed in to change notification settings - Fork 850
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Greg Caban <[email protected]>
- Loading branch information
Showing
6 changed files
with
85 additions
and
6 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
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
49 changes: 49 additions & 0 deletions
49
tests/src/test/java/org/mozilla/javascript/tests/NullishCoalescingOpTest.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,49 @@ | ||
package org.mozilla.javascript.tests; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.Scriptable; | ||
|
||
public class NullishCoalescingOpTest { | ||
|
||
@Test | ||
public void testNullishColascingBasic() { | ||
try (Context cx = Context.enter()) { | ||
Scriptable scope = cx.initStandardObjects(); | ||
cx.setLanguageVersion(Context.VERSION_ES6); | ||
|
||
String script = "null ?? 'default string'"; | ||
Assert.assertEquals( | ||
"default string", | ||
cx.evaluateString(scope, script, "nullish coalescing basic", 0, null)); | ||
|
||
String script2 = "undefined ?? 'default string'"; | ||
Assert.assertEquals( | ||
"default string", | ||
cx.evaluateString(scope, script2, "nullish coalescing basic", 0, null)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNullishColascingPrecedence() { | ||
try (Context cx = Context.enter()) { | ||
Scriptable scope = cx.initStandardObjects(); | ||
cx.setLanguageVersion(Context.VERSION_ES6); | ||
cx.setOptimizationLevel(-1); | ||
|
||
String script1 = "3 == 3 ? 'yes' ?? 'default string' : 'no'"; | ||
Assert.assertEquals( | ||
"yes", cx.evaluateString(scope, script1, "nullish coalescing basic", 0, null)); | ||
|
||
String script3 = "3 || null ?? 'default string'"; | ||
Assert.assertEquals( | ||
3.0, cx.evaluateString(scope, script3, "nullish coalescing basic", 0, null)); | ||
|
||
String script2 = "3 && null ?? 'default string'"; | ||
Assert.assertEquals( | ||
"default string", | ||
cx.evaluateString(scope, script2, "nullish coalescing basic", 0, null)); | ||
} | ||
} | ||
} |
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