@@ -705,5 +705,107 @@ if (inav.flight.gpsValid === 1) {
705705 } ) ;
706706} ) ;
707707
708+ describe ( 'OPERAND_TYPE.LC in handleNot' , ( ) => {
709+ let decompiler ;
710+
711+ beforeEach ( ( ) => {
712+ decompiler = new Decompiler ( ) ;
713+ } ) ;
714+
715+ test ( 'should decompile NOT(EQUAL) as !== using LC reference' , ( ) => {
716+ // This tests that OPERAND_TYPE.LC (value 4) is correctly used in handleNot
717+ // to recognize when operandA references another Logic Condition
718+ const conditions = [
719+ // LC 0: flight.vbat === 100
720+ {
721+ index : 0 ,
722+ enabled : 1 ,
723+ activatorId : - 1 ,
724+ operation : 1 , // EQUAL
725+ operandAType : 2 , // FLIGHT
726+ operandAValue : 4 , // VBAT
727+ operandBType : 0 , // VALUE
728+ operandBValue : 100
729+ } ,
730+ // LC 1: NOT(LC 0) - should become flight.vbat !== 100
731+ {
732+ index : 1 ,
733+ enabled : 1 ,
734+ activatorId : - 1 ,
735+ operation : 12 , // NOT
736+ operandAType : 4 , // OPERAND_TYPE.LC - this is what we're testing
737+ operandAValue : 0 , // Reference to LC 0
738+ operandBType : 0 ,
739+ operandBValue : 0
740+ } ,
741+ // LC 2: Action activated by the NOT condition
742+ {
743+ index : 2 ,
744+ enabled : 1 ,
745+ activatorId : 1 ,
746+ operation : 18 , // GVAR_SET
747+ operandAType : 0 ,
748+ operandAValue : 0 ,
749+ operandBType : 0 ,
750+ operandBValue : 1
751+ }
752+ ] ;
753+
754+ const result = decompiler . decompile ( conditions ) ;
755+
756+ expect ( result . success ) . toBe ( true ) ;
757+ // handleNot should recognize LC reference and optimize NOT(EQUAL) to !==
758+ expect ( result . code ) . toContain ( '!==' ) ;
759+ expect ( result . code ) . toContain ( 'flight.vbat' ) ;
760+ expect ( result . code ) . toContain ( '100' ) ;
761+ } ) ;
762+ } ) ;
763+
764+ describe ( 'whenChanged (DELTA operation)' , ( ) => {
765+ let decompiler ;
766+
767+ beforeEach ( ( ) => {
768+ decompiler = new Decompiler ( ) ;
769+ } ) ;
770+
771+ test ( 'should decompile DELTA operation as whenChanged()' , ( ) => {
772+ // DELTA operation monitors a value and triggers when it changes by threshold
773+ // whenChanged(flight.vbat, 100, () => { gvar[0] = 1; })
774+ const conditions = [
775+ // LC 0: DELTA operation - monitors vbat changes > 100
776+ {
777+ index : 0 ,
778+ enabled : 1 ,
779+ activatorId : - 1 ,
780+ operation : 50 , // DELTA
781+ operandAType : 2 , // FLIGHT
782+ operandAValue : 4 , // FLIGHT_PARAM.VBAT
783+ operandBType : 0 , // VALUE
784+ operandBValue : 100 // threshold
785+ } ,
786+ // LC 1: Action - set gvar[0] = 1 when delta triggers
787+ {
788+ index : 1 ,
789+ enabled : 1 ,
790+ activatorId : 0 ,
791+ operation : 18 , // GVAR_SET
792+ operandAType : 0 , // VALUE
793+ operandAValue : 0 , // gvar index
794+ operandBType : 0 , // VALUE
795+ operandBValue : 1
796+ }
797+ ] ;
798+
799+ const result = decompiler . decompile ( conditions ) ;
800+
801+ expect ( result . success ) . toBe ( true ) ;
802+ // Should output whenChanged(), not delta()
803+ expect ( result . code ) . toContain ( 'whenChanged(' ) ;
804+ expect ( result . code ) . not . toContain ( 'delta(' ) ;
805+ expect ( result . code ) . toContain ( 'flight.vbat' ) ;
806+ expect ( result . code ) . toContain ( '100' ) ;
807+ } ) ;
808+ } ) ;
809+
708810// Export the load function for the runner
709811module . exports = { loadDecompiler } ;
0 commit comments