Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for preprocessor plugins #266

Open
3 of 11 tasks
JackWilliams-FractureSounds opened this issue Dec 21, 2022 · 0 comments
Open
3 of 11 tasks

Add tests for preprocessor plugins #266

JackWilliams-FractureSounds opened this issue Dec 21, 2022 · 0 comments

Comments

@JackWilliams-FractureSounds
Copy link
Collaborator

JackWilliams-FractureSounds commented Dec 21, 2022

SublimeKSP uses unittest for testing.
The documentation can be found here with instructions on how to run tests

We need tests to check if code if compiled correctly
We need tests to check if errors are identified correctly
Look at other tests for examples.

This is a good first issue if you are looking to contribute!
If you need any more guidance, feel free to contact me :))

Tests needed:

  • Additional Macro Tests
  • Const Blocks
  • Structs
  • UI Arrays
  • Multidimensional Arrays
  • Lists
  • Open Size Arrays
  • Persistence Handling
  • UI Functions (set_button_properties etc.)
  • String Array Initialisation
  • Array Concat

If you find any tests that are needed then please add!


Examples

Example for comparing outputs

class ForLoop(unittest.TestCase):
    def testForLoopBasic(self):
        code = '''
            on init
                declare i
                for i := 0 to 10
                  message(i)
                end for
            end on'''
        expected_output = '''
            on init
                declare $i
                $i := 0
                while ($i<=10)
                    message($i)
                    inc($i)
                end while
            end on'''
        output = do_compile(code, remove_preprocessor_vars=True)
        output = [l.strip() for l in output.split('\n') if l]
        expected_output = [l.strip() for l in expected_output.split('\n') if l]
        self.assertEqual(output, expected_output)

Example to check if a line is in the output

class PropertyTests(unittest.TestCase):
    def testAlias1(self):
        code = '''
        on init
          declare a
          property b -> a
          message(b)
        end on
        '''
        output = do_compile(code)
        self.assertTrue('message($a)' in output)

Example to check if an error raised

class TypeChecks(unittest.TestCase):
    def testAssignStringToIntVar1(self):
        code = '''
            on init
                declare x := 'test'
            end on'''
        self.assertRaises(ParseException, do_compile, code, extra_syntax_checks=True)
@mkruselj mkruselj changed the title Add tests for preprocesser plugins Add tests for preprocessor plugins Dec 21, 2022
@JackWilliams-FractureSounds JackWilliams-FractureSounds changed the title Add tests for preprocessor plugins Add tests for preprocessor plugins (Good First Issue) Dec 25, 2022
@mkruselj mkruselj changed the title Add tests for preprocessor plugins (Good First Issue) Add tests for preprocessor plugins Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants