示例#1
0
 def test_simple(self):
     code = 'private _unit = 2;'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 1)
示例#2
0
 def test_while_no_errors(self):
     code = 'while {count x > 0} do {}'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
示例#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)
示例#4
0
 def test_custom_function(self):
     code = 'a = createMarker ["a", [0,0,0]];'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
示例#5
0
 def test_lowercase(self):
     code = 'mapa = "MapBoard_altis_F" createvehicle [0,0,0];'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
示例#6
0
 def test_evaluate(self):
     code = 'x = 2;'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
     self.assertEqual(Number(), analyzer['x'])
示例#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)
示例#8
0
 def test_isNil_function(self):
     code = 'x = isNil format []\n'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
示例#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)
示例#10
0
 def test_isNil_undefined(self):
     code = 'x = isNil "_var";'
     analyzer = analyze(parse(code))
     self.assertEqual(len(analyzer.exceptions), 1)
示例#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)
示例#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)
示例#13
0
 def test_with_globals(self):
     code = 'private _x = ""; AF(_x)'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
示例#14
0
 def test_nested(self):
     code = 'private _x = {}; private _y = {call _x}; call _y'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
示例#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)
示例#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)
示例#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)
示例#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)
示例#19
0
 def test_foreach_no_error(self):
     code = "{sleep 1} forEach lamps;"
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
示例#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)
示例#21
0
 def test_getConfig(self):
     code = 'configFile >> "CfgWeapons" >> x >> "WeaponSlotsInfo" >> "mass"'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
示例#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)
示例#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, [])
示例#24
0
 def test_while(self):
     code = 'while {true} do {_x = 2}'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 1)
示例#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)
示例#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)
示例#27
0
 def test_foreach_no_errors(self):
     code = '{} foreach [];'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])
示例#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)
示例#29
0
 def test_wrong_if(self):
     code = 'if ;'
     analyzer = analyze(parse(code))
     errors = analyzer.exceptions
     self.assertEqual(len(errors), 1)
示例#30
0
 def test_with_space(self):
     code = '//USES_VARIABLES ["_x", "_y"];'
     analyzer = analyze(parse(code))
     self.assertEqual(analyzer.exceptions, [])