Beispiel #1
0
 def test_simple(self):
     code = 'private _unit = 2;'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 1)
Beispiel #2
0
 def test_while_no_errors(self):
     code = 'while {count x > 0} do {}'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
Beispiel #3
0
 def test_assign_wrong(self):
     analyzer = analyze(parse('1 = 2;'))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 1)
     self.assertEqual((1, 1), errors[0].position)
Beispiel #4
0
 def test_custom_function(self):
     code = 'a = createMarker ["a", [0,0,0]];'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
Beispiel #5
0
 def test_lowercase(self):
     code = 'mapa = "MapBoard_altis_F" createvehicle [0,0,0];'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
Beispiel #6
0
 def test_evaluate(self):
     code = 'x = 2;'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
     self.assertEqual(Number(), analyzer['x'])
Beispiel #7
0
 def test_foreach(self):
     code = 'y = {if (_x == 1) exitWith{1};} forEach x;'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
     self.assertEqual(type(analyzer['y']), Anything)
Beispiel #8
0
 def test_isNil_function(self):
     code = 'x = isNil format []\n'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
Beispiel #9
0
 def test_configClass(self):
     code = 'private _defaultCrew = getText (configFile >> "cfgVehicles" >> "All" >> "crew");' \
            '"isClass _x && {getNumber (_x >> \'scope\') == 2} && {getText (_x >> \'crew\') != _defaultCrew}" configClasses (configFile >> "cfgVehicles")'
     analyzer = analyze(parse(code))
     self.assertEqual(len(analyzer.exceptions), 0)
Beispiel #10
0
 def test_isNil_undefined(self):
     code = 'x = isNil "_var";'
     analyzer = analyze(parse(code))
     self.assertEqual(len(analyzer.exceptions), 1)
Beispiel #11
0
 def test_isNil_error(self):
     code = 'x = isNil "(_var";'
     analyzer = analyze(parse(code))
     self.assertEqual(len(analyzer.exceptions), 1)
     self.assertTrue(
         'Parenthesis "(" not closed' in analyzer.exceptions[0].message)
Beispiel #12
0
 def test_isNil(self):
     code = 'private _var = A getVariable "x"; x = isNil "_var";'
     analyzer = analyze(parse(code))
     self.assertEqual(len(analyzer.exceptions), 0)
Beispiel #13
0
 def test_with_globals(self):
     code = 'private _x = ""; AF(_x)'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
Beispiel #14
0
 def test_nested(self):
     code = 'private _x = {}; private _y = {call _x}; call _y'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
Beispiel #15
0
 def test_foreach_error(self):
     code = '{hint str _y} forEach [1,2]'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 1)
Beispiel #16
0
 def test_if_then(self):
     code = 'if (false) then {_damage = 0.95;};'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 1)
Beispiel #17
0
 def test_foreach_variable(self):
     code = '{hint str _y} forEach _d;'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 2)
Beispiel #18
0
 def test_if_then_else(self):
     code = 'if (false) then\n {_damage = 0.95}\n\telse\n\t{_damage = 1};'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 2)
Beispiel #19
0
 def test_foreach_no_error(self):
     code = "{sleep 1} forEach lamps;"
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
Beispiel #20
0
 def test_if_then_specs(self):
     code = 'if (false) then [{_damage = 0.95},{_damage = 1}]'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 2)
Beispiel #21
0
 def test_getConfig(self):
     code = 'configFile >> "CfgWeapons" >> x >> "WeaponSlotsInfo" >> "mass"'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
Beispiel #22
0
 def test_if(self):
     code = 'if (not _onoff) then {_damage = 0.95;};'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 2)
Beispiel #23
0
 def test_get_variable_unknown_first_element(self):
     code = 'missionNamespace getVariable[format["x_%1",x],[]];'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
Beispiel #24
0
 def test_while(self):
     code = 'while {true} do {_x = 2}'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 1)
Beispiel #25
0
 def test_for_missing_do(self):
     code = 'for "_i" from 1 to 10 {y pushBack _i;};'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 3)
     self.assertEqual((1, 23), errors[0].position)
Beispiel #26
0
 def test_for_specs(self):
     code = 'for [{_x = 1},{_x <= 10},{_x = _x + 1}] do {_y = _y + 2}'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 6)
Beispiel #27
0
 def test_foreach_no_errors(self):
     code = '{} foreach [];'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
Beispiel #28
0
 def test_for_code(self):
     code = 'private _x = {hint str _y}; for "_i" from 0 to 10 do _x'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 1)
Beispiel #29
0
 def test_wrong_if(self):
     code = 'if ;'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 1)
Beispiel #30
0
 def test_with_space(self):
     code = '//USES_VARIABLES ["_x", "_y"];'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])