@@ -44,41 +44,41 @@ describe('Expression Core - Detection', function() {
4444 }
4545 } ) ;
4646
47- describe ( '$ Factory Function' , function ( ) {
47+ describe ( 'expr Factory Function' , function ( ) {
4848
4949 it ( 'should create expression object' , function ( ) {
50- const { $ } = MonSQLize ;
51- const expr = $ ( "amount > 100" ) ;
50+ const { expr } = MonSQLize ;
51+ const expression = expr ( "amount > 100" ) ;
5252
53- assert ( expr !== null && typeof expr === 'object' , 'Expression should be an object' ) ;
54- assert . strictEqual ( expr . __expr__ , 'amount > 100' , 'Expression string should match' ) ;
55- assert . strictEqual ( expr . __compiled__ , false , 'Should not be compiled yet' ) ;
53+ assert ( expression !== null && typeof expression === 'object' , 'Expression should be an object' ) ;
54+ assert . strictEqual ( expression . __expr__ , 'amount > 100' , 'Expression string should match' ) ;
55+ assert . strictEqual ( expression . __compiled__ , false , 'Should not be compiled yet' ) ;
5656 } ) ;
5757
5858 it ( 'should throw error for non-string input' , function ( ) {
59- const { $ } = MonSQLize ;
59+ const { expr } = MonSQLize ;
6060
6161 assert . throws ( ( ) => {
62- $ ( 123 ) ;
62+ expr ( 123 ) ;
6363 } , TypeError , 'Should throw TypeError for number' ) ;
6464 } ) ;
6565
6666 it ( 'should throw error for empty string' , function ( ) {
67- const { $ } = MonSQLize ;
67+ const { expr } = MonSQLize ;
6868
6969 assert . throws ( ( ) => {
70- $ ( '' ) ;
70+ expr ( '' ) ;
7171 } , Error , 'Should throw Error for empty string' ) ;
7272 } ) ;
7373 } ) ;
7474
7575 describe ( 'Expression Detection' , function ( ) {
7676
7777 it ( 'should detect expression in $match stage' , async function ( ) {
78- const { $ } = MonSQLize ;
78+ const { expr } = MonSQLize ;
7979
8080 const result = await collection ( 'test_orders' ) . aggregate ( [
81- { $match : $ ( "amount > 100" ) }
81+ { $match : expr ( "amount > 100" ) }
8282 ] ) ;
8383
8484 assert ( Array . isArray ( result ) , 'Result should be an array' ) ;
@@ -98,10 +98,10 @@ describe('Expression Core - Detection', function() {
9898 } ) ;
9999
100100 it ( 'should allow mixing old and new syntax' , async function ( ) {
101- const { $ } = MonSQLize ;
101+ const { expr } = MonSQLize ;
102102
103103 const result = await collection ( 'test_orders' ) . aggregate ( [
104- { $match : $ ( "amount > 100" ) } ,
104+ { $match : expr ( "amount > 100" ) } ,
105105 { $match : { status : 'paid' } } // 旧语法
106106 ] ) ;
107107
@@ -116,20 +116,20 @@ describe('Expression Core - Detection', function() {
116116 describe ( 'Basic Comparison Operators' , function ( ) {
117117
118118 it ( 'should compile > operator' , async function ( ) {
119- const { $ } = MonSQLize ;
119+ const { expr } = MonSQLize ;
120120
121121 const result = await collection ( 'test_orders' ) . aggregate ( [
122- { $match : $ ( "amount > 100" ) }
122+ { $match : expr ( "amount > 100" ) }
123123 ] ) ;
124124
125125 assert . strictEqual ( result . length , 2 ) ;
126126 } ) ;
127127
128128 it ( 'should compile >= operator' , async function ( ) {
129- const { $ } = MonSQLize ;
129+ const { expr } = MonSQLize ;
130130
131131 const result = await collection ( 'test_orders' ) . aggregate ( [
132- { $match : $ ( "amount >= 150" ) }
132+ { $match : expr ( "amount >= 150" ) }
133133 ] ) ;
134134
135135 // amount >= 150: 150, 200 共2个
@@ -138,10 +138,10 @@ describe('Expression Core - Detection', function() {
138138 } ) ;
139139
140140 it ( 'should compile <= operator' , async function ( ) {
141- const { $ } = MonSQLize ;
141+ const { expr } = MonSQLize ;
142142
143143 const result = await collection ( 'test_orders' ) . aggregate ( [
144- { $match : $ ( "amount <= 75" ) }
144+ { $match : expr ( "amount <= 75" ) }
145145 ] ) ;
146146
147147 // amount <= 75: 50, 75 共2个
@@ -150,31 +150,31 @@ describe('Expression Core - Detection', function() {
150150 } ) ;
151151
152152 it ( 'should compile < operator' , async function ( ) {
153- const { $ } = MonSQLize ;
153+ const { expr } = MonSQLize ;
154154
155155 const result = await collection ( 'test_orders' ) . aggregate ( [
156- { $match : $ ( "amount < 100" ) }
156+ { $match : expr ( "amount < 100" ) }
157157 ] ) ;
158158
159159 assert . strictEqual ( result . length , 2 ) ;
160160 } ) ;
161161
162162 it ( 'should compile === operator' , async function ( ) {
163- const { $ } = MonSQLize ;
163+ const { expr } = MonSQLize ;
164164
165165 const result = await collection ( 'test_orders' ) . aggregate ( [
166- { $match : $ ( "status === 'paid'" ) }
166+ { $match : expr ( "status === 'paid'" ) }
167167 ] ) ;
168168
169169 assert . strictEqual ( result . length , 2 ) ;
170170 assert ( result . every ( r => r . status === 'paid' ) ) ;
171171 } ) ;
172172
173173 it ( 'should compile !== operator' , async function ( ) {
174- const { $ } = MonSQLize ;
174+ const { expr } = MonSQLize ;
175175
176176 const result = await collection ( 'test_orders' ) . aggregate ( [
177- { $match : $ ( "status !== 'paid'" ) }
177+ { $match : expr ( "status !== 'paid'" ) }
178178 ] ) ;
179179
180180 assert . strictEqual ( result . length , 2 ) ;
@@ -185,10 +185,10 @@ describe('Expression Core - Detection', function() {
185185 describe ( 'Logical Operators' , function ( ) {
186186
187187 it ( 'should compile && (AND) operator' , async function ( ) {
188- const { $ } = MonSQLize ;
188+ const { expr } = MonSQLize ;
189189
190190 const result = await collection ( 'test_orders' ) . aggregate ( [
191- { $match : $ ( "amount > 100 && status === 'paid'" ) }
191+ { $match : expr ( "amount > 100 && status === 'paid'" ) }
192192 ] ) ;
193193
194194 // amount > 100 且 status === 'paid': id=2(150,paid), id=3(200,paid)
@@ -197,10 +197,10 @@ describe('Expression Core - Detection', function() {
197197 } ) ;
198198
199199 it ( 'should compile || (OR) operator' , async function ( ) {
200- const { $ } = MonSQLize ;
200+ const { expr } = MonSQLize ;
201201
202202 const result = await collection ( 'test_orders' ) . aggregate ( [
203- { $match : $ ( "amount > 150 || status === 'pending'" ) }
203+ { $match : expr ( "amount > 150 || status === 'pending'" ) }
204204 ] ) ;
205205
206206 // amount > 150(id=3:200) 或 status === 'pending'(id=1:50, id=4:75)
0 commit comments