|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Tests that an identifier reference in a switch expression declared in an outer function scope |
| 10 | + * is correctly resolved when a binding with the same name is declared in the switch block scope. |
| 11 | + */ |
| 12 | + |
| 13 | +load("assert.js"); |
| 14 | + |
| 15 | +const Type = { |
| 16 | + FLOAT: {}, |
| 17 | + INTEGER: {}, |
| 18 | + LONG: {}, |
| 19 | + BIGDECIMAL: {}, |
| 20 | + DATE: {}, |
| 21 | + TIME: {}, |
| 22 | + DATETIME: {}, |
| 23 | + DURATION: {}, |
| 24 | +}; |
| 25 | + |
| 26 | +function createFormatter(type, options) { |
| 27 | + return {type, options}; |
| 28 | +} |
| 29 | + |
| 30 | +var y = Type.BIGDECIMAL; |
| 31 | +var O = {decimalSeparator: "."}; |
| 32 | + |
| 33 | +var F1 = (function getFormatterForType(t) { |
| 34 | + return (function () { |
| 35 | + switch (t) { |
| 36 | + case Type.FLOAT: |
| 37 | + case Type.INTEGER: |
| 38 | + return createFormatter("Number"); |
| 39 | + case Type.LONG: |
| 40 | + return createFormatter("BigInt"); |
| 41 | + case Type.BIGDECIMAL: |
| 42 | + const t = { |
| 43 | + digits: 34, |
| 44 | + }; |
| 45 | + return createFormatter("Decimal", t); |
| 46 | + case Type.DATE: |
| 47 | + return createFormatter("PlainDate"); |
| 48 | + case Type.TIME: |
| 49 | + return createFormatter("PlainTime"); |
| 50 | + case Type.DATETIME: |
| 51 | + return createFormatter("Instant"); |
| 52 | + case Type.DURATION: |
| 53 | + return createFormatter("Duration"); |
| 54 | + default: |
| 55 | + return null; |
| 56 | + } |
| 57 | + }); |
| 58 | +})(y, O); |
| 59 | + |
| 60 | +var F2 = (function getFormatterForType(t, y) { |
| 61 | + return (function () { |
| 62 | + switch (t) { |
| 63 | + case Type.FLOAT: |
| 64 | + case Type.INTEGER: |
| 65 | + return createFormatter("Number", y); |
| 66 | + case Type.LONG: |
| 67 | + return createFormatter("BigInt", y); |
| 68 | + case Type.BIGDECIMAL: |
| 69 | + const t = Object.assign({}, y, { |
| 70 | + digits: 34, |
| 71 | + }); |
| 72 | + return createFormatter("Decimal", t); |
| 73 | + case Type.DATE: |
| 74 | + return createFormatter("PlainDate", y); |
| 75 | + case Type.TIME: |
| 76 | + return createFormatter("PlainTime", y); |
| 77 | + case Type.DATETIME: |
| 78 | + return createFormatter("Instant", y); |
| 79 | + case Type.DURATION: |
| 80 | + return createFormatter("Duration", y); |
| 81 | + default: |
| 82 | + return null; |
| 83 | + } |
| 84 | + }); |
| 85 | +})(y, O); |
| 86 | + |
| 87 | +var F3 = (function getFormatterForType(r, y) { |
| 88 | + let s = r; |
| 89 | + { |
| 90 | + let t = s; |
| 91 | + return (function () { |
| 92 | + switch (t) { |
| 93 | + case Type.FLOAT: |
| 94 | + case Type.INTEGER: |
| 95 | + return createFormatter("Number", y); |
| 96 | + case Type.LONG: |
| 97 | + return createFormatter("BigInt", y); |
| 98 | + case Type.BIGDECIMAL: |
| 99 | + const t = Object.assign({}, y, { |
| 100 | + digits: 34, |
| 101 | + }); |
| 102 | + return createFormatter("Decimal", t); |
| 103 | + case Type.DATE: |
| 104 | + return createFormatter("PlainDate", y); |
| 105 | + case Type.TIME: |
| 106 | + return createFormatter("PlainTime", y); |
| 107 | + case Type.DATETIME: |
| 108 | + return createFormatter("Instant", y); |
| 109 | + case Type.DURATION: |
| 110 | + return createFormatter("Duration", y); |
| 111 | + default: |
| 112 | + return null; |
| 113 | + } |
| 114 | + }); |
| 115 | + } |
| 116 | +})(y, O); |
| 117 | + |
| 118 | +assertSame('{"type":"Decimal","options":{"digits":34}}', JSON.stringify(F1())); |
| 119 | +assertSame('{"type":"Decimal","options":{"decimalSeparator":".","digits":34}}', JSON.stringify(F2())); |
| 120 | +assertSame('{"type":"Decimal","options":{"decimalSeparator":".","digits":34}}', JSON.stringify(F3())); |
0 commit comments