| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package org.mozilla.javascript.tests; |
| 9 |
|
| 10 |
import junit.framework.TestCase; |
| 11 |
|
| 12 |
import org.mozilla.javascript.Context; |
| 13 |
import org.mozilla.javascript.ContextAction; |
| 14 |
import org.mozilla.javascript.Scriptable; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public class GlobalParseXTest extends TestCase { |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public void testParseFloatAndIntWhiteSpaces() { |
| 30 |
testParseFloatWhiteSpaces("\\u00A0 "); |
| 31 |
|
| 32 |
testParseFloatWhiteSpaces("\\t "); |
| 33 |
testParseFloatWhiteSpaces("\\u00A0 "); |
| 34 |
testParseFloatWhiteSpaces("\\u000C "); |
| 35 |
testParseFloatWhiteSpaces("\\u000B "); |
| 36 |
testParseFloatWhiteSpaces("\\u000D "); |
| 37 |
testParseFloatWhiteSpaces("\\u000A "); |
| 38 |
testParseFloatWhiteSpaces("\\u2028 "); |
| 39 |
testParseFloatWhiteSpaces("\\u2029 "); |
| 40 |
} |
| 41 |
|
| 42 |
private void testParseFloatWhiteSpaces(final String prefix) { |
| 43 |
assertEvaluates("789", "String(parseInt('" + prefix + "789 '))"); |
| 44 |
assertEvaluates("7.89", "String(parseFloat('" + prefix + "7.89 '))"); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public void testParseFloatTrailingNoise() { |
| 54 |
testParseFloat("7890", "789e1"); |
| 55 |
testParseFloat("7890", "789E1"); |
| 56 |
testParseFloat("7890", "789E+1"); |
| 57 |
testParseFloat("7890", "789E+1e"); |
| 58 |
testParseFloat("789", "7890E-1"); |
| 59 |
testParseFloat("789", "7890E-1e"); |
| 60 |
|
| 61 |
testParseFloat("789", "789hello"); |
| 62 |
testParseFloat("789", "789e"); |
| 63 |
testParseFloat("789", "789E"); |
| 64 |
testParseFloat("789", "789e+"); |
| 65 |
testParseFloat("789", "789Efgh"); |
| 66 |
testParseFloat("789", "789efgh"); |
| 67 |
testParseFloat("789", "789e-"); |
| 68 |
testParseFloat("789", "789e-hello"); |
| 69 |
testParseFloat("789", "789e+hello"); |
| 70 |
testParseFloat("789", "789+++hello"); |
| 71 |
testParseFloat("789", "789-e-+hello"); |
| 72 |
testParseFloat("789", "789e+e++hello"); |
| 73 |
testParseFloat("789", "789e-e++hello"); |
| 74 |
} |
| 75 |
|
| 76 |
private void testParseFloat(final String expected, final String value) { |
| 77 |
assertEvaluates(expected, "String(parseFloat('" + value + "'))"); |
| 78 |
} |
| 79 |
|
| 80 |
private void assertEvaluates(final Object expected, final String source) { |
| 81 |
final ContextAction action = new ContextAction() { |
| 82 |
public Object run(Context cx) { |
| 83 |
final Scriptable scope = cx.initStandardObjects(); |
| 84 |
final Object rep = cx.evaluateString(scope, source, "test.js", |
| 85 |
0, null); |
| 86 |
assertEquals(expected, rep); |
| 87 |
return null; |
| 88 |
} |
| 89 |
}; |
| 90 |
Utils.runWithAllOptimizationLevels(action); |
| 91 |
} |
| 92 |
} |