Esempio n. 1
0
 def test_ignore_symbols(self):
     testString = ("class Moo {\n"
                   "\tfoo = xxx;\n"
                   "\tclass xxx {};\n"
                   "};")
     with self.assertRaises(RuntimeError):
         parse(testString)
Esempio n. 2
0
def test_eof_in_translation_key():
    translations = {
        'STR_CLASS_TITLE': 'Translated title',
        'STR_CLASS_TEXT': 'Translated text'
    }
    with pytest.raises(ParseError, match=r'Syntax error'):
        parse('''
            class testClass {
                title = $STR_CLASS_TITLE;
                texts[] = {$STR_CLA''',
              translations=translations)
Esempio n. 3
0
 def test_integer_property(self):
     expected = {
         'Moo': {
             'value': 1
         }
     }
     result = parse('class Moo {\r\nvalue=1; };')
     self.assertEqual(result, expected)
Esempio n. 4
0
 def test_array_of_scalars(self):
     expected = {
         'Moo': {
             'foo': ['bar', 'baz', 1.5e2]
         }
     }
     result = parse('class Moo {\r\nfoo[]={"bar", "baz",1.5e2}; };')
     self.assertEqual(result, expected)
Esempio n. 5
0
 def test_more_than_one_value_in_file(self):
     expected = {
         'version': 12,
         'Moo': {
             'value': 1
         }
     }
     result = parse('version=12;\n\nclass Moo  {\r\n value = 1; };')
     self.assertEqual(result, expected)
Esempio n. 6
0
def test_nested_arrays_generation():
    items = {
        'kickTimeout': [
            [0, -1], [1, 180], [2, 180], [3, 180],
        ]
    }

    output = armaclass.generate(items)
    items_reparsed = armaclass.parse(output)

    assert items == items_reparsed
 def parse_functions_hpp(self):
     self.functions = []
     for _file in self.function_hpps:
         with open(_file, 'r') as hppfile:
             _content = hppfile.read()
         _parsed_content = armaclass.parse(_content)
         for prefix, value in _parsed_content.items():
             for category, bvalue in value.items():
                 for function_name in bvalue:
                     if function_name != 'file':
                         self.functions.append(
                             ASFunction(function_name, prefix, category))
Esempio n. 8
0
def do_it_really(config_file, csv_1):
    with open(config_file, 'r') as f:
        content = f.read()
    Output_parse = armaclass.parse(content)
    for key, value in Output_parse.items():

        for a_key, a_value in value.items():

            if isinstance(a_value, dict):
                for b_key, b_value in a_value.items():
                    if b_key == 'displayName':
                        with open(csv_1, 'a') as file_csv:
                            file_csv.write('"{}","{}"\n'.format(
                                a_key, b_value))
Esempio n. 9
0
def test_whitespace_after_translation_key():
    expected = {
        'testClass': {
            'title': 'Translated title',
            'texts': ['Translated text'],
        }
    }
    translations = {
        'STR_CLASS_TITLE': 'Translated title',
        'STR_CLASS_TEXT': 'Translated text'
    }
    result = parse('''
        class testClass {
            title = $STR_CLASS_TITLE ;
            texts[] = {$STR_CLASS_TEXT };};
    ''',
                   translations=translations)
    assert result == expected
Esempio n. 10
0
    def test_multiline_init(self):
        source = textwrap.dedent(r'''
            class Item0 {
                position[]={1954.6425,5.9796591,5538.1045};
                id=0;
                init="[this, ""Platoon""] call FP_fnc_setVehicleName;" \n "if (isServer) then {" \n "  [this] call FP_fnc_clearVehicle; this addWeaponCargoGlobal [""CUP_launch_M136"", 1];" \n "  this addMagazineCargoGlobal [""1Rnd_HE_Grenade_shell"", 10];" \n "  this addMagazineCargoGlobal [""ATMine_Range_Mag"", 6];" \n "};";
            };
        ''')

        result = parse(source)
        expected = {
            'Item0': {
                'position': [1954.6425, 5.9796591, 5538.1045],
                'id': 0,
                'init': '[this, "Platoon"] call FP_fnc_setVehicleName;\nif (isServer) then {\n  [this] call FP_fnc_clearVehicle; this addWeaponCargoGlobal ["CUP_launch_M136", 1];\n  this addMagazineCargoGlobal ["1Rnd_HE_Grenade_shell", 10];\n  this addMagazineCargoGlobal ["ATMine_Range_Mag", 6];\n};'
            }
        }
        self.assertEqual(result, expected)
Esempio n. 11
0
def test_class_with_translation_strings():
    expected = {
        'testClass': {
            'title': "Test Class",
            'values': [0, 1],
            'texts': ["STR_UNTRANSLATED", "Translated text"],
            'default': 1
        }
    }
    translations = {
        'STR_CLASS_TITLE': 'Test Class',
        'STR_TRANSLATED': 'Translated text'
    }
    result = parse('''
        class testClass {
            title = $STR_CLASS_TITLE;
            values[] = {0,1};
            texts[] = {$STR_UNTRANSLATED, $STR_TRANSLATED};
            default = 1;
        };
    ''',
                   translations=translations)
    assert result == expected
Esempio n. 12
0
 def test_integer_property(self):
     expected = {"Moo": {"value": 1}}
     result = parse("class Moo {\r\nvalue=1; };")
     self.assertEqual(result, expected)
Esempio n. 13
0
def test_array():
    expected = {'var': [1, 2, 3]}
    result = parse('var[]={1, 2, 3};')
    assert result == expected
    assert type(result['var']) == list
Esempio n. 14
0
def test_empty_array():
    expected = {'var': []}
    result = parse('var[]={};')
    assert result == expected
    assert type(result['var']) == list
Esempio n. 15
0
def _common_test_(python, sqf):
    output = armaclass.generate(python)
    assert output.strip() == sqf

    item_reparsed = armaclass.parse(output)
    assert item_reparsed == python
Esempio n. 16
0
 def test_empty(self):
     expected = {'Moo': {}}
     result = parse('class Moo {};')
     self.assertEqual(result, expected)
Esempio n. 17
0
 def test_multiline_comments(self):
     self.assertEqual(parse("/* foo comment*/"), {});
     self.assertEqual(parse("/* foo comment\nsomething */x=2;"), {'x': 2});
     self.assertEqual(parse("x=2;/* foo comment*/"), {'x': 2});
     self.assertEqual(parse("x/*asd*/=/**/2;/* foo comment*/"), {'x': 2});
     self.assertEqual(parse("class Moo { /* foo comment*/};"), {'Moo': {}});
Esempio n. 18
0
 def test_macros(self):
     self.assertEqual(parse('#include "cfgSurfaces.h"'), {"#include": ['"cfgSurfaces.h"']})
     self.assertEqual(parse('#define TESTING firstline = 1;\\\nsecondline = 2;'), {"#define": ['TESTING firstline = 1;\\\nsecondline = 2;']})
Esempio n. 19
0
 def test_scientific_notation(self):
     self.assertEqual(parse('x=-1.5e2;'), {'x': -1.5e2})
Esempio n. 20
0
 def test_empty(self):
     expected = {"Moo": {}}
     result = parse("class Moo {};")
     self.assertEqual(result, expected)
Esempio n. 21
0
 def test_more_than_one_value_in_file(self):
     expected = {"version": 12, "Moo": {"value": 1}}
     result = parse("version=12;\n\nclass Moo  {\r\n value = 1; };")
     self.assertEqual(result, expected)
Esempio n. 22
0
 def test_array_of_scalars(self):
     expected = {"Moo": {"foo": ["bar", "baz", 1.5e2]}}
     result = parse('class Moo {\r\nfoo[]={"bar", "baz",1.5e2}; };')
     self.assertEqual(result, expected)
Esempio n. 23
0
 def test_ignore_inheritance(self):
     testString = 'class Moo : foo {};'
     self.assertEqual(parse(testString), {'Moo': {}})
Esempio n. 24
0
 def test_scientific_notation(self):
     self.assertEqual(parse("x=-1.5e2;"), {"x": -1.5e2})
Esempio n. 25
0
 def test_line_comments(self):
     self.assertEqual(parse('// foo comment'), {})
     self.assertEqual(parse('// foo comment\nx=2;'), {'x': 2})
     self.assertEqual(parse('x=2;// foo comment'), {'x': 2})
     self.assertEqual(parse('class Moo { // foo comment\n};'), {'Moo': {}})
Esempio n. 26
0
 def test_ignore_inheritance(self):
     testString = "class Moo : foo {};"
     self.assertEqual(parse(testString), {"Moo": {}})
Esempio n. 27
0
 def test_quote_escaping_by_double_quote(self):
     self.assertEqual(parse('foo="bar ""haha"";";\n'), {'foo': 'bar "haha";'})
Esempio n. 28
0
 def test_line_comments(self):
     self.assertEqual(parse("// foo comment"), {})
     self.assertEqual(parse("// foo comment\nx=2;"), {"x": 2})
     self.assertEqual(parse("x=2;// foo comment"), {"x": 2})
     self.assertEqual(parse("class Moo { // foo comment\n};"), {"Moo": {}})
Esempio n. 29
0
 def test_sample(self):
     expected = {
         "Session": {
             "Player1": {
                 "customScore": 0,
                 "killed": 0,
                 "killsAir": 0,
                 "killsArmor": 0,
                 "killsInfantry": 4,
                 "killsPlayers": 0,
                 "killsSoft": 0,
                 "killsTotal": 4,
                 "name": "Lord DK"
             },
             "Player2": {
                 "customScore": 0,
                 "killed": 0,
                 "killsAir": 0,
                 "killsArmor": 0,
                 "killsInfantry": 3,
                 "killsPlayers": 0,
                 "killsSoft": 0,
                 "killsTotal": 3,
                 "name": "XiviD"
             },
             "Player3": {
                 "customScore": 0,
                 "killed": 0,
                 "killsAir": 0,
                 "killsArmor": 0,
                 "killsInfantry": 2,
                 "killsPlayers": 0,
                 "killsSoft": 0,
                 "killsTotal": 2,
                 "name": "40mm2Die"
             },
             "Player4": {
                 "customScore": 0,
                 "killed": 0,
                 "killsAir": 0,
                 "killsArmor": 0,
                 "killsInfantry": 4,
                 "killsPlayers": 0,
                 "killsSoft": 0,
                 "killsTotal": 4,
                 "name": "WickerMan"
             },
             "Player5": {
                 "customScore": 0,
                 "killed": 1,
                 "killsAir": 0,
                 "killsArmor": 0,
                 "killsInfantry": 3,
                 "killsPlayers": 0,
                 "killsSoft": -1,
                 "killsTotal": 1,
                 "name": "Fusselwurm"
             },
             "Player6": {
                 "customScore": 0,
                 "killed": 0,
                 "killsAir": 0,
                 "killsArmor": 0,
                 "killsInfantry": 0,
                 "killsPlayers": 0,
                 "killsSoft": 0,
                 "killsTotal": 0,
                 "name": "Simmax"
             },
             "Player7": {
                 "customScore": 0,
                 "killed": 2,
                 "killsAir": 0,
                 "killsArmor": 0,
                 "killsInfantry": 0,
                 "killsPlayers": 0,
                 "killsSoft": 0,
                 "killsTotal": 0,
                 "name": "Andre"
             },
             "duration": 5821.1724,
             "gameType": "Coop",
             "island": "Altis",
             "mission": "W-CO@10 StealBoot v03"
         }
     }
     result = parse("\n\tclass Session\n\t{\n\tmission=\"W-CO@10 StealBoot v03\";\n\tisland=\"Altis\";\n\t" +
         "gameType=\"Coop\";\n\tduration=5821.1724;\n\tclass Player1\n\t{\n\tname=\"Lord DK\";\n\tkillsInfantry=4;\n\t" +
         "killsSoft=0;\n\tkillsArmor=0;\n\tkillsAir=0;\n\tkillsPlayers=0;\n\tcustomScore=0;\n\tkillsTotal=4;\n\tkilled=0;" +
         "\n\t};\n\tclass Player2\n\t{\n\tname=\"XiviD\";\n\tkillsInfantry=3;\n\tkillsSoft=0;\n\tkillsArmor=0;\n\tkillsAir=0;" +
         "\n\tkillsPlayers=0;\n\tcustomScore=0;\n\tkillsTotal=3;\n\tkilled=0;\n\t};\n\t" +
         "class Player3\n\t{\n\tname=\"40mm2Die\";\n\tkillsInfantry=2;\n\tkillsSoft=0;\n\tkillsArmor=0;\n\tkillsAir=0;" +
         "\n\tkillsPlayers=0;\n\tcustomScore=0;\n\tkillsTotal=2;\n\tkilled=0;\n\t};\n\t" +
         "class Player4\n\t{\n\tname=\"WickerMan\";\n\tkillsInfantry=4;\n\tkillsSoft=0;\n\tkillsArmor=0;\n\tkillsAir=0;" +
         "\n\tkillsPlayers=0;\n\tcustomScore=0;\n\tkillsTotal=4;\n\tkilled=0;\n\t};\n\t" +
         "class Player5\n\t{\n\tname=\"Fusselwurm\";\n\tkillsInfantry=3;\n\tkillsSoft=-1;\n\tkillsArmor=0;\n\tkillsAir=0;" +
         "\n\tkillsPlayers=0;\n\tcustomScore=0;\n\tkillsTotal=1;\n\tkilled=1;\n\t};\n\t" +
         "class Player6\n\t{\n\tname=\"Simmax\";\n\tkillsInfantry=0;\n\tkillsSoft=0;\n\tkillsArmor=0;\n\tkillsAir=0;" +
         "\n\tkillsPlayers=0;\n\tcustomScore=0;\n\tkillsTotal=0;\n\tkilled=0;\n\t};\n\t" +
         "class Player7\n\t{\n\tname=\"Andre\";\n\tkillsInfantry=0;\n\tkillsSoft=0;\n\tkillsArmor=0;\n\tkillsAir=0;" +
         "\n\tkillsPlayers=0;\n\tcustomScore=0;\n\tkillsTotal=0;\n\tkilled=2;\n\t};\n\t};\n\n\t")
     self.assertEqual(result, expected)
Esempio n. 30
0
def test_class():
    expected = {'var': {}}
    result = parse('class var {};')
    assert result == expected
    assert type(result['var']) == dict