# Path: bslint/messages/print_constants.py
# PATH_DOESNT_EXIST = "PATH_DOSNT_EXIST"
# LINTING_COMPLETE = "LINTING_COMPLETE"
# ALL_LINTED_CORRECTLY = "ALL_LINTED_CORRECTLY"
# NO_MANIFEST = "NO_MANIFEST"
# NO_BSLINTRC = "NO_BSLINTRC"
# CANNOT_PARSE_BSLINTRC = "CANNOT_PARSE_BSLINTRC"
# TOTAL_WARNINGS = "TOTAL_WARNINGS"
# TOTAL_ERRORS = "TOTAL_ERRORS"
# WARNINGS_IN_FILE = "WARNINGS_IN_FILE"
# DESCRIPTION = "DESCRIPTION"
# FILE_NAME = "FILE_NAME"
# BSLINTRC_KEY_DOSNT_EXIST = "BSLINTRC_KEY_DOSNT_EXIST"
# WARNING_COLOUR = '\033[93m'
# PASS_COLOUR = '\033[92m'
# END_COLOUR = '\033[0m'
# ERROR_COLOUR = '\033[91m'
# FILE_COLOUR = '\033[34;4m'
# TITLE_COLOUR = '\033[95m'
# HEADER_COLOUR = '\033[34;4m'
# TOTAL_COLOUR = '\033[35m'
# MESSAGE_TABLE = {
#     PATH_DOESNT_EXIST:
#         build.Message(ERROR_COLOUR + "The path you have provided does not exist." + END_COLOUR),
#     LINTING_COMPLETE:
#         build.Message(FILE_COLOUR + "LINTING COMPLETE" + END_COLOUR),
#     ALL_LINTED_CORRECTLY:
#         build.Message(PASS_COLOUR + "All linted correctly" + END_COLOUR),
#     NO_MANIFEST:
#         build.Message(ERROR_COLOUR + "No manifest file found" + END_COLOUR),
#     NO_BSLINTRC:
#         build.Message(ERROR_COLOUR + "Cannot find bslintrc, using default config." + END_COLOUR),
#     CANNOT_PARSE_BSLINTRC:
#         build.Message(ERROR_COLOUR + "Unable to parse JSON in .bslintrc file" + END_COLOUR),
#     TOTAL_WARNINGS:
#         build.Message(TOTAL_COLOUR + "TOTAL WARNINGS: {}" + END_COLOUR),
#     TOTAL_ERRORS:
#         build.Message(TOTAL_COLOUR + "FILES WITH ERRORS: {}" + END_COLOUR),
#     WARNINGS_IN_FILE:
#         build.Message(TOTAL_COLOUR + "WARNINGS IN FILE: {}" + END_COLOUR + "\n"),
#     DESCRIPTION:
#         build.Message(TITLE_COLOUR + "BSLint: A linter for BrightScript." + END_COLOUR),
#     const.WARNINGS: build.Message(WARNING_COLOUR + "{}" + END_COLOUR),
#     const.ERRORS: build.Message(ERROR_COLOUR + "{}" + END_COLOUR),
#     FILE_NAME: build.Message('\r' + FILE_COLOUR + "{}" + END_COLOUR),
#     BSLINTRC_KEY_DOSNT_EXIST: build.Message(ERROR_COLOUR + "Bslintrc key doesn't exist: {}" + END_COLOUR)
# }
# 
# Path: bslint/messages/handler.py
# def get_error_msg(key, params=None):
# def get_print_msg(key, params=None):
# def get_message(key, message_table, params, extra_chars):
# 
# Path: filepaths.py
# TESTS_RESOURCES_PATH = os.path.join(TESTS_PATH, 'resources')
# 
# Path: filepaths.py
# DEFAULT_CONFIG_FILE_PATH = os.path.join(CONFIG_PATH, 'default-config.json')


import unittest
import os
import bslint
from io import StringIO
from bslint.messages import print_constants as print_const
from bslint.messages import handler as msg_handler
from filepaths import TESTS_RESOURCES_PATH
from filepaths import DEFAULT_CONFIG_FILE_PATH



class TestInvalidBSLintJSON(unittest.TestCase):

    def test_invalid_bslintrc(self):
        out = StringIO()
        invalid_json_path = os.path.join(TESTS_RESOURCES_PATH,
                                         'general_test_files/invalid_bslintrc_test_files/.bslintrc')
        bslint.config_loader.load_config_file(invalid_json_path, DEFAULT_CONFIG_FILE_PATH, out)
        result = out.getvalue()
        out.close()
        self.assertEqual(msg_handler.get_print_msg(print_const.CANNOT_PARSE_BSLINTRC), result)

    def test_key_in_bslintrc_not_in_default_config(self):
        out = StringIO()
        invalid_json_path = os.path.join(TESTS_RESOURCES_PATH, 'general_test_files/invalid_key_in_bslintrc/.bslintrc')
        bslint.config_loader.load_config_file(invalid_json_path, DEFAULT_CONFIG_FILE_PATH, out)
        result = out.getvalue()
        out.close()

# Path: bslint/messages/print_constants.py
# PATH_DOESNT_EXIST = "PATH_DOSNT_EXIST"
# LINTING_COMPLETE = "LINTING_COMPLETE"
# ALL_LINTED_CORRECTLY = "ALL_LINTED_CORRECTLY"
# NO_MANIFEST = "NO_MANIFEST"
# NO_BSLINTRC = "NO_BSLINTRC"
# CANNOT_PARSE_BSLINTRC = "CANNOT_PARSE_BSLINTRC"
# TOTAL_WARNINGS = "TOTAL_WARNINGS"
# TOTAL_ERRORS = "TOTAL_ERRORS"
# WARNINGS_IN_FILE = "WARNINGS_IN_FILE"
# DESCRIPTION = "DESCRIPTION"
# FILE_NAME = "FILE_NAME"
# BSLINTRC_KEY_DOSNT_EXIST = "BSLINTRC_KEY_DOSNT_EXIST"
# WARNING_COLOUR = '\033[93m'
# PASS_COLOUR = '\033[92m'
# END_COLOUR = '\033[0m'
# ERROR_COLOUR = '\033[91m'
# FILE_COLOUR = '\033[34;4m'
# TITLE_COLOUR = '\033[95m'
# HEADER_COLOUR = '\033[34;4m'
# TOTAL_COLOUR = '\033[35m'
# MESSAGE_TABLE = {
#     PATH_DOESNT_EXIST:
#         build.Message(ERROR_COLOUR + "The path you have provided does not exist." + END_COLOUR),
#     LINTING_COMPLETE:
#         build.Message(FILE_COLOUR + "LINTING COMPLETE" + END_COLOUR),
#     ALL_LINTED_CORRECTLY:
#         build.Message(PASS_COLOUR + "All linted correctly" + END_COLOUR),
#     NO_MANIFEST:
#         build.Message(ERROR_COLOUR + "No manifest file found" + END_COLOUR),
#     NO_BSLINTRC:
#         build.Message(ERROR_COLOUR + "Cannot find bslintrc, using default config." + END_COLOUR),
#     CANNOT_PARSE_BSLINTRC:
#         build.Message(ERROR_COLOUR + "Unable to parse JSON in .bslintrc file" + END_COLOUR),
#     TOTAL_WARNINGS:
#         build.Message(TOTAL_COLOUR + "TOTAL WARNINGS: {}" + END_COLOUR),
#     TOTAL_ERRORS:
#         build.Message(TOTAL_COLOUR + "FILES WITH ERRORS: {}" + END_COLOUR),
#     WARNINGS_IN_FILE:
#         build.Message(TOTAL_COLOUR + "WARNINGS IN FILE: {}" + END_COLOUR + "\n"),
#     DESCRIPTION:
#         build.Message(TITLE_COLOUR + "BSLint: A linter for BrightScript." + END_COLOUR),
#     const.WARNINGS: build.Message(WARNING_COLOUR + "{}" + END_COLOUR),
#     const.ERRORS: build.Message(ERROR_COLOUR + "{}" + END_COLOUR),
#     FILE_NAME: build.Message('\r' + FILE_COLOUR + "{}" + END_COLOUR),
#     BSLINTRC_KEY_DOSNT_EXIST: build.Message(ERROR_COLOUR + "Bslintrc key doesn't exist: {}" + END_COLOUR)
# }
# 
# Path: bslint/messages/handler.py
# def get_error_msg(key, params=None):
# def get_print_msg(key, params=None):
# def get_message(key, message_table, params, extra_chars):
# 
# Path: filepaths.py
# TESTS_RESOURCES_PATH = os.path.join(TESTS_PATH, 'resources')
# 
# Path: filepaths.py
# DEFAULT_CONFIG_FILE_PATH = os.path.join(CONFIG_PATH, 'default-config.json')


# Path: tests/general_tests/invalid_bslintrc_json_test.py
import unittest
import os
import bslint
from io import StringIO
from bslint.messages import print_constants as print_const
from bslint.messages import handler as msg_handler
from filepaths import TESTS_RESOURCES_PATH
from filepaths import DEFAULT_CONFIG_FILE_PATH




class TestInvalidBSLintJSON(unittest.TestCase):

    def test_invalid_bslintrc(self):
        out = StringIO()
        invalid_json_path = os.path.join(TESTS_RESOURCES_PATH,
                                         'general_test_files/invalid_bslintrc_test_files/.bslintrc')
        bslint.config_loader.load_config_file(invalid_json_path, DEFAULT_CONFIG_FILE_PATH, out)
        result = out.getvalue()
        out.close()
        self.assertEqual(msg_handler.get_print_msg(print_const.CANNOT_PARSE_BSLINTRC), result)

    def test_key_in_bslintrc_not_in_default_config(self):
        out = StringIO()
        invalid_json_path = os.path.join(TESTS_RESOURCES_PATH, 'general_test_files/invalid_key_in_bslintrc/.bslintrc')
        bslint.config_loader.load_config_file(invalid_json_path, DEFAULT_CONFIG_FILE_PATH, out)
        result = out.getvalue()
        out.close()

        self.assertEqual(msg_handler.get_print_msg(print_const.BSLINTRC_KEY_DOSNT_EXIST, ["check_1"]), result)