# Path: filepaths.py
# TEST_CONFIG_FILE_PATH = os.path.join(TESTS_CONFIG_PATH, 'test-config.json')
# 
# Path: filepaths.py
# TESTS_CONFIG_PATH = os.path.join(TESTS_RESOURCES_PATH, 'config')
# 
# Path: filepaths.py
# LEXING_TEST_FILES_PATH = os.path.join(TESTS_RESOURCES_PATH, 'lexing_test_files')
# 
# Path: filepaths.py
# TRAILING_WHITE_SPACE_TEST_FILES_PATH = os.path.join(TESTS_RESOURCES_PATH, 'trailing_white_space_test_files')
# 
# Path: tests/resources/common/test_methods.py
# class CommonMethods(unittest.TestCase):
# 
#     def status_error(self, str_to_parse):
#         parser = Parser()
#         result = parser.parse(str_to_parse)
#         self.assertEqual(const.ERROR, result["Status"])
# 
#     def match_statement(self, expected, characters):
#         parser = Parser()
#         parser.parse(characters)
#         self.assertEqual(expected, parser.all_statements[-1][0])
#         self.assertEqual(len(parser.all_statements[-1]), 1)
# 
#     def match_program(self, expected, characters):
#         parser = Parser()
#         result = parser.parse(characters)
#         self.assertEqual(const.SUCCESS, result["Status"])
#         self.assertEqual(expected, parser.line_reductions[-1][0])
# 
#     def lex_warnings_match(self, expected, characters):
#         result = Lexer().lex(characters)
#         self.assertEqual(expected, result[const.WARNINGS])
# 
#     def match_regex(self, identifier, match_group, lexer_type, parser_type):
#         result = regex_handler.find_match(identifier)
#         if match_group is None:
#             self.assertEqual(identifier, result[const.MATCH].group())
#         else:
#             self.assertEqual(identifier, result[const.MATCH].group(match_group))
#         self.assertEqual(lexer_type, result[const.TOKEN_LEXER_TYPE])
#         self.assertEqual(parser_type, result[const.TOKEN_PARSER_TYPE])
# 
#     def directory_lexing(self, expected, brs_file_path):
#         bslint.load_config_file(default_filepath=TEST_CONFIG_FILE_PATH)
#         result = bslint.bslint.runner(brs_file_path).files
#         expected.sort()
#         result.sort()
#         self.assertEqual(expected, result)
# 
#     def method_dec_spacing(self, expected, string):
#         result = commands.check_method_dec_spacing(string)
#         self.assertEqual(expected, result)
# 
#     def spaces_around_operators(self, expected, string, chars_index, operator):
#         result = commands.check_spaces_around_operators(string, chars_index, operator)
#         self.assertEqual(expected, result)
# 
#     def spell_check(self, expected, string):
#         result = commands.check_spelling(string, const.ID)
#         self.assertEqual(expected, result)
# 
#     def lex_file(self, expected, file):
#         file = open(file, "r+").read()
#         result = Lexer().lex(file)
#         self.assertEqual(expected, result[const.WARNINGS])
#         self.assertEqual(const.SUCCESS, result[const.STATUS])
# 
#     def lex_string(self, expected, string):
#         result = Lexer().lex(string)
#         self.assertEqual(expected, result[const.WARNINGS])
#         self.assertEqual(const.SUCCESS, result[const.STATUS])
# 
#     def lex_identifier(self, expected, identifier):
#         lexer = Lexer()
#         lexer.lex(identifier)
#         self.assertEqual(expected, lexer.statements_counter)
# 
#     def match(self, identifier, match_group):
#         result = regex_handler.find_match(identifier)
#         self.assertEqual(identifier, result[const.MATCH].group(match_group))
#         self.assertEqual(const.ID, result[const.TOKEN_LEXER_TYPE])
#         self.assertEqual(const.ID, result[const.TOKEN_PARSER_TYPE])


import os
import unittest
import bslint
import bslint.messages.handler as error
import bslint.messages.error_constants as err_const
from filepaths import TEST_CONFIG_FILE_PATH
from filepaths import TESTS_CONFIG_PATH
from filepaths import LEXING_TEST_FILES_PATH
from filepaths import TRAILING_WHITE_SPACE_TEST_FILES_PATH
from tests.resources.common.test_methods import CommonMethods as Common



class TestTrailingWhiteSpace(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        trailing_white_space_config_path = os.path.join(TESTS_CONFIG_PATH,
                                                        'trailing_white_space/trailing-white-space-config.json')
        bslint.load_config_file(user_filepath=trailing_white_space_config_path, default_filepath=TEST_CONFIG_FILE_PATH)
        cls.common = Common()

    def test_no_trailing_white_space(self):
        file_name = os.path.join(LEXING_TEST_FILES_PATH, 'skeleton-main.brs')
        self.common.lex_file([], file_name)

    def test_trailing_white_space_first_line(self):
        file_name = os.path.join(TRAILING_WHITE_SPACE_TEST_FILES_PATH, 'trailing-white-space-first-line.brs')
        expected = [error.get_error_msg(err_const.TRAILING_WHITE_SPACE, [1])]
        self.common.lex_file(expected, file_name)

    def test_trailing_white_space_multi_lines(self):
        file_name = os.path.join(TRAILING_WHITE_SPACE_TEST_FILES_PATH, 'trailing-white-space-multi-lines.brs')
        expected = [error.get_error_msg(err_const.TRAILING_WHITE_SPACE, [2]),
                    error.get_error_msg(err_const.TRAILING_WHITE_SPACE, [3]),

# Path: filepaths.py
# TEST_CONFIG_FILE_PATH = os.path.join(TESTS_CONFIG_PATH, 'test-config.json')
# 
# Path: filepaths.py
# TESTS_CONFIG_PATH = os.path.join(TESTS_RESOURCES_PATH, 'config')
# 
# Path: filepaths.py
# LEXING_TEST_FILES_PATH = os.path.join(TESTS_RESOURCES_PATH, 'lexing_test_files')
# 
# Path: filepaths.py
# TRAILING_WHITE_SPACE_TEST_FILES_PATH = os.path.join(TESTS_RESOURCES_PATH, 'trailing_white_space_test_files')
# 
# Path: tests/resources/common/test_methods.py
# class CommonMethods(unittest.TestCase):
# 
#     def status_error(self, str_to_parse):
#         parser = Parser()
#         result = parser.parse(str_to_parse)
#         self.assertEqual(const.ERROR, result["Status"])
# 
#     def match_statement(self, expected, characters):
#         parser = Parser()
#         parser.parse(characters)
#         self.assertEqual(expected, parser.all_statements[-1][0])
#         self.assertEqual(len(parser.all_statements[-1]), 1)
# 
#     def match_program(self, expected, characters):
#         parser = Parser()
#         result = parser.parse(characters)
#         self.assertEqual(const.SUCCESS, result["Status"])
#         self.assertEqual(expected, parser.line_reductions[-1][0])
# 
#     def lex_warnings_match(self, expected, characters):
#         result = Lexer().lex(characters)
#         self.assertEqual(expected, result[const.WARNINGS])
# 
#     def match_regex(self, identifier, match_group, lexer_type, parser_type):
#         result = regex_handler.find_match(identifier)
#         if match_group is None:
#             self.assertEqual(identifier, result[const.MATCH].group())
#         else:
#             self.assertEqual(identifier, result[const.MATCH].group(match_group))
#         self.assertEqual(lexer_type, result[const.TOKEN_LEXER_TYPE])
#         self.assertEqual(parser_type, result[const.TOKEN_PARSER_TYPE])
# 
#     def directory_lexing(self, expected, brs_file_path):
#         bslint.load_config_file(default_filepath=TEST_CONFIG_FILE_PATH)
#         result = bslint.bslint.runner(brs_file_path).files
#         expected.sort()
#         result.sort()
#         self.assertEqual(expected, result)
# 
#     def method_dec_spacing(self, expected, string):
#         result = commands.check_method_dec_spacing(string)
#         self.assertEqual(expected, result)
# 
#     def spaces_around_operators(self, expected, string, chars_index, operator):
#         result = commands.check_spaces_around_operators(string, chars_index, operator)
#         self.assertEqual(expected, result)
# 
#     def spell_check(self, expected, string):
#         result = commands.check_spelling(string, const.ID)
#         self.assertEqual(expected, result)
# 
#     def lex_file(self, expected, file):
#         file = open(file, "r+").read()
#         result = Lexer().lex(file)
#         self.assertEqual(expected, result[const.WARNINGS])
#         self.assertEqual(const.SUCCESS, result[const.STATUS])
# 
#     def lex_string(self, expected, string):
#         result = Lexer().lex(string)
#         self.assertEqual(expected, result[const.WARNINGS])
#         self.assertEqual(const.SUCCESS, result[const.STATUS])
# 
#     def lex_identifier(self, expected, identifier):
#         lexer = Lexer()
#         lexer.lex(identifier)
#         self.assertEqual(expected, lexer.statements_counter)
# 
#     def match(self, identifier, match_group):
#         result = regex_handler.find_match(identifier)
#         self.assertEqual(identifier, result[const.MATCH].group(match_group))
#         self.assertEqual(const.ID, result[const.TOKEN_LEXER_TYPE])
#         self.assertEqual(const.ID, result[const.TOKEN_PARSER_TYPE])


# Path: tests/styling_tests/trailing_white_space_test.py
import os
import unittest
import bslint
import bslint.messages.handler as error
import bslint.messages.error_constants as err_const
from filepaths import TEST_CONFIG_FILE_PATH
from filepaths import TESTS_CONFIG_PATH
from filepaths import LEXING_TEST_FILES_PATH
from filepaths import TRAILING_WHITE_SPACE_TEST_FILES_PATH
from tests.resources.common.test_methods import CommonMethods as Common




class TestTrailingWhiteSpace(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        trailing_white_space_config_path = os.path.join(TESTS_CONFIG_PATH,
                                                        'trailing_white_space/trailing-white-space-config.json')
        bslint.load_config_file(user_filepath=trailing_white_space_config_path, default_filepath=TEST_CONFIG_FILE_PATH)
        cls.common = Common()

    def test_no_trailing_white_space(self):
        file_name = os.path.join(LEXING_TEST_FILES_PATH, 'skeleton-main.brs')
        self.common.lex_file([], file_name)

    def test_trailing_white_space_first_line(self):
        file_name = os.path.join(TRAILING_WHITE_SPACE_TEST_FILES_PATH, 'trailing-white-space-first-line.brs')
        expected = [error.get_error_msg(err_const.TRAILING_WHITE_SPACE, [1])]
        self.common.lex_file(expected, file_name)

    def test_trailing_white_space_multi_lines(self):
        file_name = os.path.join(TRAILING_WHITE_SPACE_TEST_FILES_PATH, 'trailing-white-space-multi-lines.brs')
        expected = [error.get_error_msg(err_const.TRAILING_WHITE_SPACE, [2]),
                    error.get_error_msg(err_const.TRAILING_WHITE_SPACE, [3]),

                    error.get_error_msg(err_const.TRAILING_WHITE_SPACE, [7])]