@@ -234,12 +234,129 @@ End Namespace
234234 expect ( block . type ) . toBe ( "fallback_chunk" )
235235 } )
236236 } )
237+
238+ it ( "should use fallback chunking for MQL files" , async ( ) => {
239+ // Test with MQL4 file
240+ const mql4Content = `//+------------------------------------------------------------------+
241+ //| ExpertAdvisor.mq4|
242+ //+------------------------------------------------------------------+
243+ #property copyright "Copyright 2024"
244+ #property version "1.00"
245+ #property strict
246+
247+ // Input parameters
248+ input double LotSize = 0.01;
249+ input int StopLoss = 50;
250+ input int TakeProfit = 100;
251+ input int MagicNumber = 12345;
252+
253+ // Global variables
254+ int ticket = 0;
255+ double lastPrice = 0;
256+
257+ //+------------------------------------------------------------------+
258+ //| Expert initialization function |
259+ //+------------------------------------------------------------------+
260+ int OnInit()
261+ {
262+ Print("Expert Advisor initialized");
263+ lastPrice = Ask;
264+ return(INIT_SUCCEEDED);
265+ }
266+
267+ //+------------------------------------------------------------------+
268+ //| Expert deinitialization function |
269+ //+------------------------------------------------------------------+
270+ void OnDeinit(const int reason)
271+ {
272+ Print("Expert Advisor deinitialized");
273+ }
274+
275+ //+------------------------------------------------------------------+
276+ //| Expert tick function |
277+ //+------------------------------------------------------------------+
278+ void OnTick()
279+ {
280+ double currentPrice = Ask;
281+
282+ if(OrdersTotal() == 0)
283+ {
284+ // Open a buy order
285+ ticket = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 3,
286+ Ask - StopLoss * Point,
287+ Ask + TakeProfit * Point,
288+ "EA Trade", MagicNumber, 0, clrGreen);
289+
290+ if(ticket < 0)
291+ {
292+ Print("Error opening order: ", GetLastError());
293+ }
294+ }
295+
296+ lastPrice = currentPrice;
297+ }`
298+
299+ // Test .mq4 extension
300+ const mq4Result = await parser . parseFile ( "expert.mq4" , {
301+ content : mql4Content ,
302+ fileHash : "test-hash-mq4" ,
303+ } )
304+
305+ expect ( mq4Result . length ) . toBeGreaterThan ( 0 )
306+ mq4Result . forEach ( ( block ) => {
307+ expect ( block . type ) . toBe ( "fallback_chunk" )
308+ } )
309+
310+ // Test .mq5 extension
311+ const mq5Result = await parser . parseFile ( "expert.mq5" , {
312+ content : mql4Content ,
313+ fileHash : "test-hash-mq5" ,
314+ } )
315+
316+ expect ( mq5Result . length ) . toBeGreaterThan ( 0 )
317+ mq5Result . forEach ( ( block ) => {
318+ expect ( block . type ) . toBe ( "fallback_chunk" )
319+ } )
320+
321+ // Test .mqh extension (header file)
322+ const mqhContent = `//+------------------------------------------------------------------+
323+ //| Common.mqh |
324+ //+------------------------------------------------------------------+
325+ #property copyright "Copyright 2024"
326+ #property version "1.00"
327+
328+ // Common functions and definitions
329+ #define MAX_ORDERS 10
330+ #define MIN_LOT_SIZE 0.01
331+
332+ double CalculateLotSize(double riskPercent, double stopLoss)
333+ {
334+ double accountBalance = AccountBalance();
335+ double riskAmount = accountBalance * riskPercent / 100;
336+ double lotSize = riskAmount / (stopLoss * MarketInfo(Symbol(), MODE_TICKVALUE));
337+
338+ return NormalizeDouble(lotSize, 2);
339+ }`
340+
341+ const mqhResult = await parser . parseFile ( "common.mqh" , {
342+ content : mqhContent ,
343+ fileHash : "test-hash-mqh" ,
344+ } )
345+
346+ expect ( mqhResult . length ) . toBeGreaterThan ( 0 )
347+ mqhResult . forEach ( ( block ) => {
348+ expect ( block . type ) . toBe ( "fallback_chunk" )
349+ } )
350+ } )
237351} )
238352
239353describe ( "Fallback Extensions Configuration" , ( ) => {
240354 it ( "should correctly identify extensions that need fallback chunking" , ( ) => {
241355 // Extensions that should use fallback
242356 expect ( shouldUseFallbackChunking ( ".vb" ) ) . toBe ( true )
357+ expect ( shouldUseFallbackChunking ( ".mq4" ) ) . toBe ( true )
358+ expect ( shouldUseFallbackChunking ( ".mq5" ) ) . toBe ( true )
359+ expect ( shouldUseFallbackChunking ( ".mqh" ) ) . toBe ( true )
243360 expect ( shouldUseFallbackChunking ( ".scala" ) ) . toBe ( true )
244361 expect ( shouldUseFallbackChunking ( ".swift" ) ) . toBe ( true )
245362
@@ -256,6 +373,9 @@ describe("Fallback Extensions Configuration", () => {
256373 it ( "should be case-insensitive" , ( ) => {
257374 expect ( shouldUseFallbackChunking ( ".VB" ) ) . toBe ( true )
258375 expect ( shouldUseFallbackChunking ( ".Vb" ) ) . toBe ( true )
376+ expect ( shouldUseFallbackChunking ( ".MQ4" ) ) . toBe ( true )
377+ expect ( shouldUseFallbackChunking ( ".mQ5" ) ) . toBe ( true )
378+ expect ( shouldUseFallbackChunking ( ".MQH" ) ) . toBe ( true )
259379 expect ( shouldUseFallbackChunking ( ".SCALA" ) ) . toBe ( true )
260380 expect ( shouldUseFallbackChunking ( ".Scala" ) ) . toBe ( true )
261381 } )
0 commit comments