|
| 1 | +component extends="org.lucee.cfml.test.LuceeTestCase" { |
| 2 | + |
| 3 | + function run( testResults, testBox ) { |
| 4 | + describe( "LDEV-6428 Reduce member function runtime execution overhead", function() { |
| 5 | + |
| 6 | + // These tests pin the behaviour of `Casting.getValue` on the queryColumn |
| 7 | + // special-case branch -- only reached via the CFML expression interpreter |
| 8 | + // path (evaluate, dynamic dispatch), NOT compiled bytecode. Compiled paths |
| 9 | + // for valueList/valueArray/quotedValueList go through CastOther, a |
| 10 | + // different code path. The interpreter path through Casting.java:68 was |
| 11 | + // previously untested. |
| 12 | + |
| 13 | + describe( "queryColumn cast via interpreted expression (Casting.getValue)", function() { |
| 14 | + |
| 15 | + it( "evaluate( 'valueList(q.col)' ) resolves to delimited column values", function() { |
| 16 | + var q = queryNew( "a", "varchar", [ [ "x" ], [ "y" ], [ "z" ] ] ); |
| 17 | + expect( evaluate( "valueList(q.a)" ) ).toBe( "x,y,z" ); |
| 18 | + }); |
| 19 | + |
| 20 | + it( "evaluate( 'valueList(q.col, delim)' ) honours custom delimiter", function() { |
| 21 | + var q = queryNew( "a", "varchar", [ [ "1" ], [ "2" ], [ "3" ] ] ); |
| 22 | + expect( evaluate( "valueList(q.a, ';')" ) ).toBe( "1;2;3" ); |
| 23 | + }); |
| 24 | + |
| 25 | + it( "evaluate( 'valueArray(q.col)' ) returns array of column values", function() { |
| 26 | + var q = queryNew( "a", "integer", [ [ 1 ], [ 2 ], [ 3 ] ] ); |
| 27 | + var result = evaluate( "valueArray(q.a)" ); |
| 28 | + expect( arrayLen( result ) ).toBe( 3 ); |
| 29 | + expect( result[ 1 ] ).toBe( 1 ); |
| 30 | + expect( result[ 2 ] ).toBe( 2 ); |
| 31 | + expect( result[ 3 ] ).toBe( 3 ); |
| 32 | + }); |
| 33 | + |
| 34 | + it( "evaluate( 'quotedValueList(q.col)' ) returns quoted delimited values", function() { |
| 35 | + var q = queryNew( "a", "varchar", [ [ "foo" ], [ "bar" ] ] ); |
| 36 | + expect( evaluate( "quotedValueList(q.a)" ) ).toBe( "'foo','bar'" ); |
| 37 | + }); |
| 38 | + |
| 39 | + it( "queryColumn cast handles single-row query", function() { |
| 40 | + var q = queryNew( "a", "varchar", [ [ "only" ] ] ); |
| 41 | + expect( evaluate( "valueList(q.a)" ) ).toBe( "only" ); |
| 42 | + }); |
| 43 | + |
| 44 | + it( "queryColumn cast handles empty query", function() { |
| 45 | + var q = queryNew( "a", "varchar" ); |
| 46 | + expect( evaluate( "valueList(q.a)" ) ).toBe( "" ); |
| 47 | + expect( arrayLen( evaluate( "valueArray(q.a)" ) ) ).toBe( 0 ); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + describe( "queryColumn cast via compiled bytecode (CastOther) -- regression guard", function() { |
| 52 | + |
| 53 | + it( "valueList(q.col) inline resolves correctly", function() { |
| 54 | + var q = queryNew( "a", "varchar", [ [ "x" ], [ "y" ], [ "z" ] ] ); |
| 55 | + expect( valueList( q.a ) ).toBe( "x,y,z" ); |
| 56 | + }); |
| 57 | + |
| 58 | + it( "valueArray(q.col) inline resolves correctly", function() { |
| 59 | + var q = queryNew( "a", "integer", [ [ 1 ], [ 2 ], [ 3 ] ] ); |
| 60 | + var result = valueArray( q.a ); |
| 61 | + expect( arrayLen( result ) ).toBe( 3 ); |
| 62 | + }); |
| 63 | + |
| 64 | + it( "quotedValueList(q.col) inline resolves correctly", function() { |
| 65 | + var q = queryNew( "a", "varchar", [ [ "foo" ], [ "bar" ] ] ); |
| 66 | + expect( quotedValueList( q.a ) ).toBe( "'foo','bar'" ); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + describe( "member-method dispatch -- MemberUtil.call -> BIFCall -> Casting.getValue", function() { |
| 71 | + |
| 72 | + it( "qry.valueList(column) member call resolves", function() { |
| 73 | + var q = queryNew( "a", "varchar", [ [ "x" ], [ "y" ], [ "z" ] ] ); |
| 74 | + expect( q.valueList( "a" ) ).toBe( "x,y,z" ); |
| 75 | + }); |
| 76 | + |
| 77 | + it( "struct member call (struct.keyArray) dispatches through MemberUtil", function() { |
| 78 | + var s = { foo=1, bar=2 }; |
| 79 | + var keys = s.keyArray(); |
| 80 | + expect( arrayLen( keys ) ).toBe( 2 ); |
| 81 | + }); |
| 82 | + |
| 83 | + it( "array member call (array.len) dispatches through MemberUtil", function() { |
| 84 | + var a = [ 10, 20, 30 ]; |
| 85 | + expect( a.len() ).toBe( 3 ); |
| 86 | + }); |
| 87 | + |
| 88 | + it( "member call with named args dispatches through BIFCall named-arg path (line 113)", function() { |
| 89 | + var s = { foo=1, bar=2 }; |
| 90 | + // structKeyExists named-arg via member |
| 91 | + expect( s.keyExists( key="foo" ) ).toBeTrue(); |
| 92 | + expect( s.keyExists( key="missing" ) ).toBeFalse(); |
| 93 | + }); |
| 94 | + }); |
| 95 | + |
| 96 | + describe( "evaluate() named-arg dispatch -- BIFCall.getValue:113 path", function() { |
| 97 | + |
| 98 | + it( "evaluate with named args resolves through Casting wrapper in BIFCall", function() { |
| 99 | + expect( evaluate( "structKeyExists(struct={a:1,b:2}, key='a')" ) ).toBeTrue(); |
| 100 | + expect( evaluate( "structKeyExists(struct={a:1,b:2}, key='zz')" ) ).toBeFalse(); |
| 101 | + }); |
| 102 | + }); |
| 103 | + |
| 104 | + describe( "exception messages must match pre-LDEV-6428 .143 baseline", function() { |
| 105 | + |
| 106 | + // These tests lock in the exact exception messages produced on .143 (the |
| 107 | + // pre-LDEV-6428 baseline). Captured from D:/tmp/ldev6428-throws/run-143.log |
| 108 | + // on 2026-06-25. Any deviation indicates a behavioural change in error |
| 109 | + // reporting that downstream users may grep against. |
| 110 | + |
| 111 | + it( "wrong arg type (replace with struct) keeps the 'second Argument [sub1] is invalid' message", function() { |
| 112 | + try { |
| 113 | + "zac,claude,joshi".replace( { x = 1 }, "+" ); |
| 114 | + fail( "expected exception" ); |
| 115 | + } |
| 116 | + catch ( any e ) { |
| 117 | + expect( e.type ).toBe( "expression" ); |
| 118 | + expect( e.message ).toBe( "Invalid call of the function [replace], second Argument [sub1] is invalid, When passing three parameters or more, the second parameter must be a simple value." ); |
| 119 | + } |
| 120 | + }); |
| 121 | + |
| 122 | + it( "missing required arg (arr.append()) keeps the 'too few arguments for function [ArrayAppend] call' message", function() { |
| 123 | + try { |
| 124 | + var arr = [ 1, 2, 3 ]; |
| 125 | + arr.append(); |
| 126 | + fail( "expected exception" ); |
| 127 | + } |
| 128 | + catch ( any e ) { |
| 129 | + expect( e.type ).toBe( "expression" ); |
| 130 | + expect( e.message ).toBe( "too few arguments for function [ArrayAppend] call" ); |
| 131 | + } |
| 132 | + }); |
| 133 | + |
| 134 | + it( "too many args (arr.len(...extras...)) keeps the 'too many arguments for function [arraylen] call' message", function() { |
| 135 | + try { |
| 136 | + var arr = [ 1, 2, 3 ]; |
| 137 | + arr.len( "extra1", "extra2", "extra3", "extra4" ); |
| 138 | + fail( "expected exception" ); |
| 139 | + } |
| 140 | + catch ( any e ) { |
| 141 | + expect( e.type ).toBe( "expression" ); |
| 142 | + expect( e.message ).toBe( "too many arguments for function [arraylen] call" ); |
| 143 | + } |
| 144 | + }); |
| 145 | + |
| 146 | + it( "receiver type mismatch (numeric.keyArray) keeps the 'function [keyArray] does not exist in the Numeric' message shape", function() { |
| 147 | + // The "Available functions are [...]" list is runtime-derived from the |
| 148 | + // FLD member-function registry plus any-typed BIFs. Installed extensions |
| 149 | + // can add or remove entries from this list, so we lock the message shape |
| 150 | + // (prefix + bracketed list + ending) rather than the exact contents. |
| 151 | + try { |
| 152 | + var n = 123; |
| 153 | + n.keyArray(); |
| 154 | + fail( "expected exception" ); |
| 155 | + } |
| 156 | + catch ( any e ) { |
| 157 | + expect( e.type ).toBe( "expression" ); |
| 158 | + expect( e.message ).toMatch( "^The function \[keyArray\] does not exist in the Numeric\. Available functions are \[.+\]\.$" ); |
| 159 | + } |
| 160 | + }); |
| 161 | + |
| 162 | + it( "invalid sort type keeps the 'invalid sort type [...]' message", function() { |
| 163 | + try { |
| 164 | + var arr = [ 3, 1, 2 ]; |
| 165 | + arr.sort( "not_a_valid_sort_type" ); |
| 166 | + fail( "expected exception" ); |
| 167 | + } |
| 168 | + catch ( any e ) { |
| 169 | + expect( e.type ).toBe( "expression" ); |
| 170 | + expect( e.message ).toBe( "invalid sort type [not_a_valid_sort_type], sort types are [text, textNoCase, numeric]" ); |
| 171 | + } |
| 172 | + }); |
| 173 | + |
| 174 | + it( "wrong arg type to struct.keyExists keeps the 'Can't cast Complex Object Type [Array] to String' message", function() { |
| 175 | + try { |
| 176 | + var s = { foo = 1, bar = 2 }; |
| 177 | + s.keyExists( [ 1, 2, 3 ] ); |
| 178 | + fail( "expected exception" ); |
| 179 | + } |
| 180 | + catch ( any e ) { |
| 181 | + expect( e.type ).toBe( "expression" ); |
| 182 | + expect( e.message ).toBe( "Can't cast Complex Object Type [Array] to String" ); |
| 183 | + } |
| 184 | + }); |
| 185 | + |
| 186 | + it( "evaluate(valueList(q.missing_col)) keeps the 'Column [MISSING_COL] not found' message", function() { |
| 187 | + try { |
| 188 | + var q = queryNew( "name", "varchar", [ [ "alice" ], [ "bob" ] ] ); |
| 189 | + evaluate( "valueList(q.missing_col)" ); |
| 190 | + fail( "expected exception" ); |
| 191 | + } |
| 192 | + catch ( any e ) { |
| 193 | + expect( e.type ).toBe( "database" ); |
| 194 | + expect( e.message ).toBe( "Column [MISSING_COL] not found in query, Columns are [NAME]" ); |
| 195 | + } |
| 196 | + }); |
| 197 | + |
| 198 | + it( "member call on null receiver keeps the 'variable [NULLVAR] doesn't exist' message", function() { |
| 199 | + try { |
| 200 | + var nullVar = javacast( "null", "" ); |
| 201 | + nullVar.len(); |
| 202 | + fail( "expected exception" ); |
| 203 | + } |
| 204 | + catch ( any e ) { |
| 205 | + expect( e.type ).toBe( "expression" ); |
| 206 | + expect( e.message ).toBe( "variable [NULLVAR] doesn't exist" ); |
| 207 | + } |
| 208 | + }); |
| 209 | + }); |
| 210 | + }); |
| 211 | + } |
| 212 | +} |
0 commit comments