# Path: nesasm/compiler.py
# def look_ahead(tokens, index, _type, value=None):
# def t_endline(tokens, index):
# def t_modifier(tokens, index):
# def t_directive(tokens, index):
# def t_directive_argument(tokens, index):
# def t_decimal_argument(tokens, index):
# def t_relative(tokens, index):
# def t_instruction(tokens, index):
# def t_zeropage(tokens, index):
# def t_label(tokens, index):
# def t_marker(tokens, index):
# def t_address(tokens, index):
# def t_string(tokens, index):
# def t_address_or_t_marker(tokens, index):
# def t_address_or_t_binary_number(tokens, index):
# def t_address_or_t_number(tokens, index):
# def t_hex_number(tokens, index):
# def t_binary_number(tokens, index):
# def t_decimal_number(tokens, index):
# def t_number(tokens, index):
# def t_equal(tokens, index):
# def t_separator(tokens, index):
# def t_accumulator(tokens, index):
# def t_register_x(tokens, index):
# def t_register_y(tokens, index):
# def t_open(tokens, index):
# def t_close(tokens, index):
# def t_open_square_brackets(tokens, index):
# def t_close_square_brackets(tokens, index):
# def t_nesasm_compatible_open(tokens, index):
# def t_nesasm_compatible_close(tokens, index):
# def t_list(tokens, index):
# def OR(args, tokens, index):
# def lexical(code):
# def get_value(token, labels=None, constants=None):
# def syntax(tokens):
# def get_labels(ast, cart=None):
# def get_constants(ast, cart):
# def semantic(ast, iNES=False, cart=None):
# def compile_file(asmfile, output=None, path=None):
# def write_bin_code(code, file):
# def compile(code, path):


from unittest import TestCase
from unittest import skip
from nesasm.compiler import lexical, get_labels, syntax, Cartridge


class LabelTest(TestCase):

    def get_labels(self, source, start_addr=0):
        cart = Cartridge()
        if start_addr != 0:
            cart.set_org(start_addr)
        return get_labels(syntax(lexical(source)), cart)

    def test_waitvblank_label(self):
        code = '''
            WAITVBLANK:
              BIT $2002
              BPL WAITVBLANK
              RTS
        '''

        labels = self.get_labels(code)
        self.assertEquals(labels['WAITVBLANK'], 0)

    def test_waitvblank_label_org_at_0x0100(self):
        code = '''
            .org 0100
            WAITVBLANK:
              BIT $2002
              BPL WAITVBLANK
              RTS
        '''


# Path: nesasm/compiler.py
# def look_ahead(tokens, index, _type, value=None):
# def t_endline(tokens, index):
# def t_modifier(tokens, index):
# def t_directive(tokens, index):
# def t_directive_argument(tokens, index):
# def t_decimal_argument(tokens, index):
# def t_relative(tokens, index):
# def t_instruction(tokens, index):
# def t_zeropage(tokens, index):
# def t_label(tokens, index):
# def t_marker(tokens, index):
# def t_address(tokens, index):
# def t_string(tokens, index):
# def t_address_or_t_marker(tokens, index):
# def t_address_or_t_binary_number(tokens, index):
# def t_address_or_t_number(tokens, index):
# def t_hex_number(tokens, index):
# def t_binary_number(tokens, index):
# def t_decimal_number(tokens, index):
# def t_number(tokens, index):
# def t_equal(tokens, index):
# def t_separator(tokens, index):
# def t_accumulator(tokens, index):
# def t_register_x(tokens, index):
# def t_register_y(tokens, index):
# def t_open(tokens, index):
# def t_close(tokens, index):
# def t_open_square_brackets(tokens, index):
# def t_close_square_brackets(tokens, index):
# def t_nesasm_compatible_open(tokens, index):
# def t_nesasm_compatible_close(tokens, index):
# def t_list(tokens, index):
# def OR(args, tokens, index):
# def lexical(code):
# def get_value(token, labels=None, constants=None):
# def syntax(tokens):
# def get_labels(ast, cart=None):
# def get_constants(ast, cart):
# def semantic(ast, iNES=False, cart=None):
# def compile_file(asmfile, output=None, path=None):
# def write_bin_code(code, file):
# def compile(code, path):


# Path: nesasm/tests/label_test.py
from unittest import TestCase
from unittest import skip
from nesasm.compiler import lexical, get_labels, syntax, Cartridge



class LabelTest(TestCase):

    def get_labels(self, source, start_addr=0):
        cart = Cartridge()
        if start_addr != 0:
            cart.set_org(start_addr)
        return get_labels(syntax(lexical(source)), cart)

    def test_waitvblank_label(self):
        code = '''
            WAITVBLANK:
              BIT $2002
              BPL WAITVBLANK
              RTS
        '''

        labels = self.get_labels(code)
        self.assertEquals(labels['WAITVBLANK'], 0)

    def test_waitvblank_label_org_at_0x0100(self):
        code = '''
            .org 0100
            WAITVBLANK:
              BIT $2002
              BPL WAITVBLANK
              RTS
        '''


        labels = self.get_labels(code)