11import { describe , assert } from 'poku' ;
22import { describeOptions } from '../../../common.test.cjs' ;
33import getBinaryParser from '../../../../lib/parsers/binary_parser.js' ;
4- import { srcEscape } from '../../../../lib/helpers.js' ;
54import { privateObjectProps } from '../../../../lib/helpers.js' ;
65
76describe ( 'Binary Parser: Block Native Object Props' , describeOptions ) ;
87
98const blockedFields = Array . from ( privateObjectProps ) . map ( ( prop ) => [
10- { name : prop } ,
9+ { name : prop , table : '' } ,
1110] ) ;
1211
1312blockedFields . forEach ( ( fields ) => {
@@ -17,8 +16,42 @@ blockedFields.forEach((fields) => {
1716 } catch ( error ) {
1817 assert . strictEqual (
1918 error . message ,
20- `The field name (${ srcEscape ( fields [ 0 ] . name ) } ) can't be the same as an object's private property.` ,
19+ `The field name (${ fields [ 0 ] . name } ) can't be the same as an object's private property.` ,
2120 `Ensure safe ${ fields [ 0 ] . name } ` ,
2221 ) ;
2322 }
2423} ) ;
24+
25+ blockedFields
26+ . map ( ( fields ) =>
27+ fields . map ( ( field ) => ( { ...field , name : field . name . slice ( 1 ) } ) ) ,
28+ )
29+ . forEach ( ( fields ) => {
30+ try {
31+ getBinaryParser ( fields , { nestTables : '_' } , { } ) ;
32+ assert . fail ( 'An error was expected' ) ;
33+ } catch ( error ) {
34+ assert . strictEqual (
35+ error . message ,
36+ `The field name (_${ fields [ 0 ] . name } ) can't be the same as an object's private property.` ,
37+ `Ensure safe _${ fields [ 0 ] . name } for nestTables as string` ,
38+ ) ;
39+ }
40+ } ) ;
41+
42+ blockedFields
43+ . map ( ( fields ) =>
44+ fields . map ( ( field ) => ( { ...field , name : '' , table : field . name } ) ) ,
45+ )
46+ . forEach ( ( fields ) => {
47+ try {
48+ getBinaryParser ( fields , { nestTables : true } , { } ) ;
49+ assert . fail ( 'An error was expected' ) ;
50+ } catch ( error ) {
51+ assert . strictEqual (
52+ error . message ,
53+ `The field name (${ fields [ 0 ] . table } ) can't be the same as an object's private property.` ,
54+ `Ensure safe ${ fields [ 0 ] . table } for nestTables as true` ,
55+ ) ;
56+ }
57+ } ) ;
0 commit comments