def test_2(self): text = ''' int[] _my_favoRite_ints_ = {0x12, 0x1fE, 441, -81, -0xfFf}; ''' expected_result = [ NewLine(), SplitContainer.from_single_token('int'), '[', ']', SplitContainer([ Underscore(), Word.from_('my'), Underscore(), NonEng(Word.from_('favo')), Word.from_('Rite'), Underscore(), Word.from_('ints'), Underscore() ]), '=', '{', Number([HexStart(), '1', '2']), ',', Number([HexStart(), '1', 'f', 'E']), ',', Number(['4', '4', '1']), ',', Number(['-', '8', '1']), ',', Number(['-', HexStart(), 'f', 'F', 'f']), '}', ';', NewLine(), NewLine() ] self.__test_apply_preprocessors(text, expected_result)
def process_number_literal(possible_number): if is_number(possible_number) and possible_number not in tabs: parts_of_number = [] if possible_number.startswith('-'): parts_of_number.append('-') possible_number = possible_number[1:] if possible_number.startswith("0x"): parts_of_number.append(HexStart()) possible_number = possible_number[2:] hex = True else: hex = False for ch in possible_number: if ch == '.': parts_of_number.append(DecimalPoint()) elif ch == 'l' or ch == 'L': parts_of_number.append(L()) elif (ch == 'f' or ch == 'F') and not hex: parts_of_number.append(F()) elif (ch == 'd' or ch == 'D') and not hex: parts_of_number.append(D()) elif (ch == 'e' or ch == 'E') and not hex: parts_of_number.append(E()) else: parts_of_number.append(ch) return Number(parts_of_number) else: return ParseableToken(possible_number)
def test_simple_log(self): input = [NewLine(), SplitContainer.from_single_token('log'), '.', SplitContainer.from_single_token('info'), '(', StringLiteral([SplitContainer.from_single_token("Hi")]), ')', ';', Number([HexStart(), '3', '4', 'a', '3', '5', 'E', L()])] actual = logs.mark(input, None) expected = [NewLine(), LogStatement(SplitContainer.from_single_token('log'), SplitContainer.from_single_token('info'), INFO, [StringLiteral([SplitContainer.from_single_token("Hi")])]), Number([HexStart(), '3', '4', 'a', '3', '5', 'E', L()])] self.assertEqual(expected, actual)
def test_tabs_and_newlines_before_semicolon(self): input = [NewLine(), SplitContainer.from_single_token('log'), '.', SplitContainer.from_single_token('d'), '(', StringLiteral([SplitContainer.from_single_token("Hi")]), ')', NewLine(), NewLine(), Tab(), Tab(), ';', Number([HexStart(), '3', '4', 'a', '3', '5', 'E', L()])] actual = logs.mark(input, None) expected = [NewLine(), LogStatement(SplitContainer.from_single_token('log'), SplitContainer.from_single_token('d'), DEBUG, [StringLiteral([SplitContainer.from_single_token("Hi")])], [NewLine(), NewLine(), Tab(), Tab()]), Number([HexStart(), '3', '4', 'a', '3', '5', 'E', L()])] self.assertEqual(expected, actual)
def test_no_dot(self): input = [NewLine(), SplitContainer.from_single_token('log'), SplitContainer.from_single_token('infooooo'), '(', StringLiteral([SplitContainer.from_single_token("Hi")]), ')', ';', Number([HexStart(), '3', '4', 'a', '3', '5', 'E', L()])] actual = logs.mark(input, None) self.assertEqual(input, actual)
def test_no_logs(self): input = [NewLine(), SplitContainer.from_single_token('long'), '[', ']', SplitContainer([Word.from_('lovely'), Underscore(), Word.from_('longs')]), '=', '{', Number([HexStart(), '3', '4', 'a', '3', '5', 'E', L ()])] actual = logs.mark(input, None) self.assertEqual(input, actual)
def test_1(self): text = ''' long[] lovely_longs = {0x34a35EL, 0x88bc96fl , -0x34L}; ''' expected_result = [ NewLine(), SplitContainer.from_single_token('long'), '[', ']', SplitContainer( [Word.from_('lovely'), Underscore(), Word.from_('longs')]), '=', '{', Number([HexStart(), '3', '4', 'a', '3', '5', 'E', L()]), ',', Tab(), Number([HexStart(), '8', '8', 'b', 'c', '9', '6', 'f', L()]), Tab(), Tab(), ',', Number(['-', HexStart(), '3', '4', L()]), '}', ';', NewLine(), NewLine() ] self.__test_apply_preprocessors(text, expected_result)
def test_content_length_over_limit(self): input = [NewLine(), SplitContainer.from_single_token('log'), '.', SplitContainer.from_single_token('info'), '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '(', '1', '*', '3', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')', ')' ')', ')', ')', ')', ')', ')', ')', ')' ')', ')', ')', ')', ')', ')', ')', ')' ';', Number([HexStart(), '3', '4', 'a', '3', '5', 'E', L()])] actual = logs.mark(input, None) self.assertEqual(input, actual)
def test_6(self): text = ''' 9a abc1 ~-0xFFFFFL= .0E+5 |= ? == != ** ++ -- += -= /= *= %= $ <= >= @ ^= &= # >> << && || +*!/><\t\n {}[],.-:();&|\\'~%^ ''' expected_result = [ NewLine(), SplitContainer([Word.from_('9'), Word.from_('a')]), SplitContainer([Word.from_('abc'), Word.from_('1')]), NewLine(), '~', Number(['-', HexStart(), 'F', 'F', 'F', 'F', 'F', L()]), '=', NewLine(), Number([DecimalPoint(), '0', E(), '+', '5']), NewLine(), '|=', NewLine(), '?', NewLine(), '==', NewLine(), '!=', NewLine(), '**', NewLine(), '++', NewLine(), '--', NewLine(), '+=', NewLine(), '-=', NewLine(), '/=', NewLine(), '*=', NewLine(), '%=', NewLine(), '$', NewLine(), '<=', NewLine(), '>=', NewLine(), '@', NewLine(), Tab(), '^=', NewLine(), Tab(), '&=', NewLine(), Tab(), '#', NewLine(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), Tab(), '>>', NewLine(), '<<', NewLine(), '&&', NewLine(), '||', NewLine(), '+', '*', '!', '/', '>', '<', Tab(), NewLine(), NewLine(), '{', '}', '[', ']', ',', '.', '-', ':', '(', ')', ';', '&', '|', Backslash(), "'", '~', '%', '^', NewLine(), NewLine() ] self.__test_apply_preprocessors(text, expected_result)