# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import, division, print_function

#from decimal import Decimal
from datetime import datetime
import pytz
import pytest
from poker.card import Card
from poker.hand import Combo
from poker.constants import Currency, GameType, Game, Limit, Action, MoneyType
from poker.handhistory import _Player, _PlayerAction
from poker.room.pokerstars import PokerStarsHandHistory, _Street
from . import stars_hands


ET = pytz.timezone('US/Eastern')


@pytest.fixture
def hand(request):
    """Parse handhistory defined in hand_text class attribute
    and returns a PokerStarsHandHistory instance.
    """
    hh = PokerStarsHandHistory(request.instance.hand_text)
    hh.parse()
    return hh


@pytest.fixture
def hand_header(request):
    """Parse hand history header only defined in hand_text
    and returns a PokerStarsHandHistory instance.
    """
    hh = PokerStarsHandHistory(request.instance.hand_text)
    hh.parse_header()
    return hh


@pytest.fixture(scope='module')
def flop():
    return _Street([
        '[2s 6d 6h]',
        'W2lkm2n: bets 80',
        'MISTRPerfect: folds',
        'Uncalled bet (80) returned to W2lkm2n',
        'W2lkm2n collected 150 from pot',
        "W2lkm2n: doesn't show hand"
        ], 'FLOP')


def test_open_from_file(testdir):
    bbb_path = str(testdir.joinpath('handhistory/bbb.txt'))
    hh = PokerStarsHandHistory.from_file(bbb_path)
    hh.parse()
    assert hh.ident == 138364355489
    assert type(hh.raw) is str


class TestHandHeaderNoLimitHoldemTourFreeroll:
    hand_text = """
PokerStars Hand #152455023342: Tournament #1545783901, Freeroll  Hold'em No Limit - Level I (10/20) - 2016/04/25 23:22:00 BRT [2016/04/25 22:22:00 ET]
    """  # noqa

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('ident', 152455023342),
        ('game_type', GameType.TOUR),
        ('tournament_ident', '1545783901'),
        ('tournament_level', 'I'),
        ('currency', Currency('USD')),
        ('buyin', 0),
        ('rake', 0),
        ('game', Game.HOLDEM),
        ('limit', Limit.NL),
        ('sb', 10),
        ('bb', 20),
        ('date', ET.localize(datetime(2016, 4, 25, 22, 22, 0))),
        ('extra', {'money_type': MoneyType.REAL}),
        ])
    def test_values_after_header_parsed(self, hand_header, attribute, expected_value):
        assert getattr(hand_header, attribute) == expected_value


class TestHandHeaderNoLimitHoldemTourPlayMoney:
    hand_text = """
PokerStars Hand #152504147861: Tournament #1545751329, 870+130 Hold'em No Limit - Level I (10/20) - 2016/04/27 1:17:16 BRT [2016/04/27 0:17:16 ET]
    """  # noqa

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('ident', 152504147861),
        ('game_type', GameType.TOUR),
        ('tournament_ident', '1545751329'),
        ('tournament_level', 'I'),
        ('currency', None),
        ('buyin', 870),
        ('rake', 130),
        ('game', Game.HOLDEM),
        ('limit', Limit.NL),
        ('sb', 10),
        ('bb', 20),
        ('date', ET.localize(datetime(2016, 4, 27, 00, 17, 16))),
        ('extra', {'money_type': MoneyType.PLAY}),
        ])
    def test_values_after_header_parsed(self, hand_header, attribute, expected_value):
        assert getattr(hand_header, attribute) == expected_value


class TestHandHeaderLimitHoldemCashPlayMoney:
    hand_text = """
PokerStars Hand #153769972916:  Hold'em Limit (10/20) - 2016/05/24 8:52:39 BRT [2016/05/24 7:52:39 ET]
    """  # noqa

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('ident', 153769972916),
        ('game_type', GameType.CASH),
        ('tournament_ident', None),
        ('tournament_level', None),
        ('currency', None),
        ('buyin', None),
        ('rake', None),
        ('game', Game.HOLDEM),
        ('limit', Limit.FL),
        ('sb', 10),
        ('bb', 20),
        ('date', ET.localize(datetime(2016, 5, 24, 7, 52, 39))),
        ('extra', {'money_type': MoneyType.PLAY}),
        ])
    def test_values_after_header_parsed(self, hand_header, attribute, expected_value):
        assert getattr(hand_header, attribute) == expected_value


class TestHandHeaderNoLimitHoldemTourStarcoin:
    hand_text = """
PokerStars Hand #153719873192: Tournament #1573768726, 184 SC Hold'em No Limit - Level I (25/50) - 2016/05/23 6:48:22 BRT [2016/05/23 5:48:22 ET]
    """  # noqa

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('ident', 153719873192),
        ('game_type', GameType.TOUR),
        ('tournament_ident', '1573768726'),
        ('tournament_level', 'I'),
        ('currency', Currency.STARS_COIN),
        ('buyin', 184),
        ('rake', 0),
        ('game', Game.HOLDEM),
        ('limit', Limit.NL),
        ('sb', 25),
        ('bb', 50),
        ('date', ET.localize(datetime(2016, 5, 23, 5, 48, 22))),
        ('extra', {'money_type': MoneyType.REAL}),
        ])
    def test_values_after_header_parsed(self, hand_header, attribute, expected_value):
        assert getattr(hand_header, attribute) == expected_value


class TestHandHeaderPotLimitOmahaCash:
    hand_text = """
PokerStars Hand #107030112846: Omaha Pot Limit ($0.01/$0.02 USD) - 2013/11/15 9:03:10 AWST [2013/11/14 20:03:10 ET]
    """  # noqa

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('ident', 107030112846),
        ('game_type', GameType.CASH),
        ('tournament_ident', None),
        ('tournament_level', None),
        ('currency', Currency.USD),
        ('buyin', None),
        ('rake', None),
        ('game', Game.OMAHA),
        ('limit', Limit.PL),
        ('sb', 0.01),
        ('bb', 0.02),
        ('date', ET.localize(datetime(2013, 11, 14, 20, 3, 10))),
        ('extra', {'money_type': MoneyType.REAL}),
        ])
    def test_values_after_header_parsed(self, hand_header, attribute, expected_value):
        assert getattr(hand_header, attribute) == expected_value


class TestHandWithFlopOnly:
    hand_text = stars_hands.HAND1

    # in py.test 2.4 it is recommended to use string like "attribute,expected",
    # but with tuple, it works in both 2.3.5 and 2.4
    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('ident', 105024000105),
        ('game_type', GameType.TOUR),
        ('tournament_ident', '797469411'),
        ('tournament_level', 'I'),
        ('currency', Currency.USD),
        ('buyin', 3.19),
        ('rake', 0.31),
        ('game', Game.HOLDEM),
        ('limit', Limit.NL),
        ('sb', 10),
        ('bb', 20),
        ('date', ET.localize(datetime(2013, 10, 4, 13, 53, 27))),
        ])
    def test_values_after_header_parsed(self, hand_header, attribute, expected_value):
        assert getattr(hand_header, attribute) == expected_value

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('table_name', '797469411 15'),
        ('max_players', 9),
        ('button', _Player(name='flettl2', stack=1500, seat=1, combo=None)),
        ('hero', _Player(name='W2lkm2n', stack=3000, seat=5, combo=Combo('AcJh'))),
        ('players', [
            _Player(name='flettl2', stack=1500, seat=1, combo=None),
            _Player(name='santy312', stack=3000, seat=2, combo=None),
            _Player(name='flavio766', stack=3000, seat=3, combo=None),
            _Player(name='strongi82', stack=3000, seat=4, combo=None),
            _Player(name='W2lkm2n', stack=3000, seat=5, combo=Combo('AcJh')),
            _Player(name='MISTRPerfect', stack=3000, seat=6, combo=None),
            _Player(name='blak_douglas', stack=3000, seat=7, combo=None),
            _Player(name='sinus91', stack=1500, seat=8, combo=None),
            _Player(name='STBIJUJA', stack=1500, seat=9, combo=None),
        ]),
        ('turn', None),
        ('river', None),
        ('board', (Card('2s'), Card('6d'), Card('6h'))),
        # ('preflop_actions', (
        #     "strongi82: folds",
        #     "W2lkm2n: raises 40 to 60",
        #     "MISTRPerfect: calls 60",
        #     "blak_douglas: folds",
        #     "sinus91: folds",
        #     "STBIJUJA: folds",
        #     "flettl2: folds",
        #     "santy312: folds",
        #     "flavio766: folds"
        # )),
        ('total_pot', 150),
        ('show_down', False),
        ('winners', ('W2lkm2n',)),
        ])
    def test_body(self, hand, attribute, expected_value):
        assert getattr(hand, attribute) == expected_value

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('actions', (
            _PlayerAction('strongi82', Action.FOLD, 0, 4),
            _PlayerAction('W2lkm2n', Action.RAISE, 60, 5),
            _PlayerAction('MISTRPerfect', Action.CALL, 60, 6),
            _PlayerAction('blak_douglas', Action.FOLD, 0, 7),
            _PlayerAction('sinus91', Action.FOLD, 0, 8),
            _PlayerAction('STBIJUJA', Action.FOLD, 0, 9),
            _PlayerAction('flettl2', Action.FOLD, 0, 1),
            _PlayerAction('santy312', Action.FOLD, 0, 2),
            _PlayerAction('flavio766', Action.FOLD, 0, 3),
        )),
        ('cards', ()),
        #('players', ('W2lkm2n', 'MISTRPerfect')),
        #('pot', Decimal(150))
    ])
    def test_preflop_attributes(self, hand, attribute, expected_value):
        assert getattr(hand.preflop, attribute) == expected_value

    def test_preflop(self, hand):
        assert isinstance(hand.preflop, _Street)

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('actions', (
            _PlayerAction('W2lkm2n', Action.BET, 80, 5),
            _PlayerAction('MISTRPerfect', Action.FOLD, 0, 6),
            _PlayerAction('W2lkm2n', Action.RETURN, 80, 5),
            _PlayerAction('W2lkm2n', Action.WIN, 150, 5),
            _PlayerAction('W2lkm2n', Action.MUCK, 0, 5),
        )),
        ('cards', (Card('2s'), Card('6d'), Card('6h'))),
        ('is_rainbow', True),
        ('is_monotone', False),
        ('is_triplet', False),
        # TODO: http://www.pokerology.com/lessons/flop-texture/
        # assert flop.is_dry
        ('has_pair', True),
        ('has_straightdraw', False),
        ('has_gutshot', True),
        ('has_flushdraw', False),
        ('players', ('W2lkm2n', 'MISTRPerfect')),
        ('pot', 150)
    ])
    def test_flop_attributes(self, hand, attribute, expected_value):
        assert getattr(hand.flop, attribute) == expected_value

    def test_flop(self, hand):
        assert isinstance(hand.flop, _Street)


class TestAllinPreflopHand:
    hand_text = stars_hands.HAND2

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('ident', 105034215446),
        ('game_type', GameType.TOUR),
        ('tournament_ident', '797536898'),
        ('tournament_level', 'XI'),
        ('currency', Currency.USD),
        ('buyin', 3.19),
        ('rake', 0.31),
        ('game', Game.HOLDEM),
        ('limit', Limit.NL),
        ('sb', 400),
        ('bb', 800),
        ('date', ET.localize(datetime(2013, 10, 4, 17, 22, 20))),
    ])
    def test_values_after_header_parsed(self, hand_header, attribute, expected_value):
        assert getattr(hand_header, attribute) == expected_value

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('table_name', '797536898 9'),
        ('max_players', 9),
        ('button', _Player(name='W2lkm2n', stack=11815, seat=2, combo=Combo('JdJs'))),
        ('hero', _Player(name='W2lkm2n', stack=11815, seat=2, combo=Combo('JdJs'))),
        ('players', [
            _Player(name='RichFatWhale', stack=12910, seat=1, combo=None),
            _Player(name='W2lkm2n', stack=11815, seat=2, combo=Combo('JdJs')),
            _Player(name='Labahra', stack=7395, seat=3, combo=None),
            _Player(name='Lean Abadia', stack=7765, seat=4, combo=None),
            _Player(name='lkenny44', stack=10080, seat=5, combo=None),
            _Player(name='Newfie_187', stack=1030, seat=6, combo=None),
            _Player(name='Hokolix', stack=13175, seat=7, combo=None),
            _Player(name='pmmr', stack=2415, seat=8, combo=None),
            _Player(name='costamar', stack=13070, seat=9, combo=None),
        ]),
        ('board', (Card('3c'), Card('6s'), Card('9d'), Card('8d'), Card('Ks'))),
        # ('preflop_actions', (
        #     "lkenny44: folds",
        #     "Newfie_187: raises 155 to 955 and is all-in",
        #     "Hokolix: folds",
        #     "pmmr: folds",
        #     "costamar: raises 12040 to 12995 and is all-in",
        #     "RichFatWhale: folds",
        #     "W2lkm2n: calls 11740 and is all-in",
        #     "Labahra: folds",
        #     "Lean Abadia: folds",
        #     "Uncalled bet (1255) returned to costamar")),
        ('total_pot', 26310),
        ('show_down', True),
        ('winners', ('costamar',)),
        ])
    def test_body(self, hand, attribute, expected_value):
        assert getattr(hand, attribute) == expected_value

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('actions', None),
        ('cards', (Card('3c'), Card('6s'), Card('9d'))),
        ('is_rainbow', True),
        ('is_monotone', False),
        ('is_triplet', False),
        # TODO: http://www.pokerology.com/lessons/flop-texture/
        # assert flop.is_dry
        ('has_pair', False),
        ('has_straightdraw', True),
        ('has_gutshot', True),
        ('has_flushdraw', False),
        ('players', None),
    ])
    def test_flop_attributes(self, hand, attribute, expected_value):
        assert getattr(hand.flop, attribute) == expected_value

    def test_flop(self, hand):
        assert isinstance(hand.flop, _Street)

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('actions', None),
        ('cards', (Card('8d'),)),
        ('players', None)
    ])
    def test_turn_attributes(self, hand, attribute, expected_value):
        assert getattr(hand.turn, attribute) == expected_value

    def test_turn(self, hand):
        assert isinstance(hand.turn, _Street)

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('actions', None),
        ('cards', (Card('Ks'),)),
        ('players', None)
    ])
    def test_river_attributes(self, hand, attribute, expected_value):
        assert getattr(hand.river, attribute) == expected_value

    def test_river(self, hand):
        assert isinstance(hand.river, _Street)

    @pytest.mark.xfail
    def test_flop_pot(self, hand):
        assert hand.flop.pot == 26310


class TestBodyMissingPlayerNoBoard:
    hand_text = stars_hands.HAND3

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
         ('ident', 105026771696),
         ('game_type', GameType.TOUR),
         ('tournament_ident', '797469411'),
         ('tournament_level', 'X'),
         ('currency', Currency.USD),
         ('buyin', 3.19),
         ('rake', 0.31),
         ('game', Game.HOLDEM),
         ('limit', Limit.NL),
         ('sb', 300),
         ('bb', 600),
         ('date', ET.localize(datetime(2013, 10, 4, 14, 50, 56)))
        ])
    def test_values_after_header_parsed(self, hand_header, attribute, expected_value):
        assert getattr(hand_header, attribute) == expected_value

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('table_name', '797469411 11'),
        ('max_players', 9),
        ('button', _Player(name='W2lkm2n', stack=10714, seat=8, combo=Combo('6d8d'))),
        ('hero', _Player(name='W2lkm2n', stack=10714, seat=8, combo=Combo('6d8d'))),
        ('players', [
            _Player(name='Empty Seat 1', stack=-1, seat=1, combo=None),
            _Player(name='snelle_jel', stack=4295, seat=2, combo=None),
            _Player(name='EuSh0wTelm0', stack=11501, seat=3, combo=None),
            _Player(name='panost3', stack=7014, seat=4, combo=None),
            _Player(name='Samovlyblen', stack=7620, seat=5, combo=None),
            _Player(name='Theralion', stack=4378, seat=6, combo=None),
            _Player(name='wrsport1015', stack=9880, seat=7, combo=None),
            _Player(name='W2lkm2n', stack=10714, seat=8, combo=Combo('6d8d')),
            _Player(name='fischero68', stack=8724, seat=9, combo=None),
        ]),
        ('turn', None),
        ('river', None),
        ('board', None),
        # ('preflop_actions', (
        #     'EuSh0wTelm0: folds',
        #     'panost3: folds',
        #     'Samovlyblen: folds',
        #     'Theralion: raises 600 to 1200',
        #     'wrsport1015: folds',
        #     'W2lkm2n: folds',
        #     'fischero68: folds',
        #     'snelle_jel: folds',
        #     'Uncalled bet (600) returned to Theralion',
        #     'Theralion collected 1900 from pot',
        #     "Theralion: doesn't show hand"
        # )),
        ('total_pot', 1900),
        ('show_down', False),
        ('winners', ('Theralion',)),
    ])
    def test_body(self, hand, attribute, expected_value):
        assert getattr(hand, attribute) == expected_value

    def test_flop(self, hand):
        assert hand.flop is None


class TestBodyEveryStreet:
    hand_text = stars_hands.HAND4

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('ident', 105025168298),
        ('game_type', GameType.TOUR),
        ('tournament_ident', '797469411'),
        ('tournament_level', 'IV'),
        ('currency', Currency.USD),
        ('buyin', 3.19),
        ('rake', 0.31),
        ('game', Game.HOLDEM),
        ('limit', Limit.NL),
        ('sb', 50),
        ('bb', 100),
        ('date', ET.localize(datetime(2013, 10, 4, 14, 19, 17)))
    ])
    def test_values_after_header_parsed(self, hand_header, attribute, expected_value):
        assert getattr(hand_header, attribute) == expected_value

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('table_name', '797469411 15'),
        ('max_players', 9),
        ('button', _Player(name='W2lkm2n', stack=5145, seat=5, combo=Combo('Jc5c'))),
        ('hero', _Player(name='W2lkm2n', stack=5145, seat=5, combo=Combo('Jc5c'))),
        ('players', [
            _Player(name='flettl2', stack=3000, seat=1, combo=None),
            _Player(name='santy312', stack=5890, seat=2, combo=None),
            _Player(name='flavio766', stack=11010, seat=3, combo=None),
            _Player(name='strongi82', stack=2855, seat=4, combo=None),
            _Player(name='W2lkm2n', stack=5145, seat=5, combo=Combo('Jc5c')),
            _Player(name='MISTRPerfect', stack=2395, seat=6, combo=None),
            _Player(name='blak_douglas', stack=3000, seat=7, combo=None),
            _Player(name='sinus91', stack=3000, seat=8, combo=None),
            _Player(name='STBIJUJA', stack=1205, seat=9, combo=None),
        ]),
        ('board', (Card('6s'), Card('4d'), Card('3s'), Card('8c'), Card('Kd'))),
        # ('preflop_actions', (
        #     'sinus91: folds',
        #     'STBIJUJA: folds',
        #     'flettl2: raises 125 to 225',
        #     'santy312: folds',
        #     'flavio766: folds',
        #     'strongi82: folds',
        #     'W2lkm2n: folds',
        #     'MISTRPerfect: folds',
        #     'blak_douglas: calls 125')),
        ('total_pot', 1300),
        ('show_down', False),
        ('winners', ('flettl2',)),
    ])
    def test_body(self, hand, attribute, expected_value):
        assert getattr(hand, attribute) == expected_value

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('actions', (
            _PlayerAction('blak_douglas', Action.CHECK, 0, 7),
            _PlayerAction('flettl2', Action.BET, 150, 1),
            _PlayerAction('blak_douglas', Action.CALL, 150, 7),
        )),
        ('cards', (Card('6s'), Card('4d'), Card('3s'))),
        ('is_rainbow', False),
        ('is_monotone', False),
        ('is_triplet', False),
        # TODO: http://www.pokerology.com/lessons/flop-texture/
        # assert flop.is_dry
        ('has_pair', False),
        ('has_straightdraw', True),
        ('has_gutshot', True),
        ('has_flushdraw', True),
        ('players', ('blak_douglas', 'flettl2')),
    ])
    def test_flop_attributes(self, hand, attribute, expected_value):
        assert getattr(hand.flop, attribute) == expected_value

    def test_flop(self, hand):
        assert isinstance(hand.flop, _Street)

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('actions', (
            _PlayerAction('blak_douglas', Action.CHECK, 0, 7),
            _PlayerAction('flettl2', Action.BET, 250, 1),
            _PlayerAction('blak_douglas', Action.CALL, 250, 7),
        )),
        ('cards', (Card('8c'),)),
        ('players', ('blak_douglas', 'flettl2')),
    ])
    def test_turn_attributes(self, hand, attribute, expected_value):
        assert getattr(hand.turn, attribute) == expected_value

    def test_turn(self, hand):
        assert isinstance(hand.turn, _Street)

    @pytest.mark.parametrize(('attribute', 'expected_value'), [
        ('actions', (
            _PlayerAction('blak_douglas', Action.CHECK, 0, 7),
            _PlayerAction('flettl2', Action.BET, 1300, 1),
            _PlayerAction('blak_douglas', Action.FOLD, 0, 7),
            _PlayerAction('flettl2', Action.RETURN, 1300, 1),
            _PlayerAction('flettl2', Action.WIN, 1300, 1),
            _PlayerAction('flettl2', Action.MUCK, 0, 1),
        )),
        ('cards', (Card('Kd'),)),
        ('players', ('blak_douglas', 'flettl2')),
    ])
    def test_river_attributes(self, hand, attribute, expected_value):
        assert getattr(hand.river, attribute) == expected_value

    def test_river(self, hand):
        assert isinstance(hand.river, _Street)

    @pytest.mark.xfail
    def test_flop_pot(self, hand):
        assert hand.flop.pot == 800


class TestClassRepresentation:
    hand_text = stars_hands.HAND1

    # def test_unicode(self, hand_header):
    #     assert str(hand_header) == u'<PokerStarsHandHistory: #105024000105>'

    def test_str(self, hand_header):
        assert str(hand_header) == '<PokerStarsHandHistory: #105024000105>'


class TestPlayerNameWithDot:
    hand_text = stars_hands.HAND5

    def test_player_is_in_player_list(self, hand):
        assert '.prestige.U$' in [p.name for p in hand.players]

    def test_player_stack(self, hand):
        player_names = [p.name for p in hand.players]
        player_index = player_names.index('.prestige.U$')
        assert hand.players[player_index].stack == 3000

def test_no_hero():
    hh = PokerStarsHandHistory(stars_hands.HAND6)
    hh.parse()

def test_parse_all_hands():
    for idx, hand in enumerate({k: v for k, v in stars_hands.__dict__.items() if 'HAND' in k}.values()):
        print('HAND%s' % (idx + 1))
        hh = PokerStarsHandHistory(hand)
        hh.parse()

def test_file_and_string_same(testdir):
    file_path = str(testdir.joinpath('handhistory/hand8.txt'))
    hh_file = PokerStarsHandHistory.from_file(file_path)
    hh_str = PokerStarsHandHistory(stars_hands.HAND8)
    print(bytes(hh_file.raw, encoding='utf-8'),'\n', bytes(hh_str.raw, encoding='utf-8'))
    #assert len(hh_file.raw) == len(hh_str.raw)
    #assert hh_file.raw == hh_str.raw
    hh_file._split_raw()
    hh_str._split_raw()
    print(hh_file._splitted,'\n', hh_str._splitted)
    assert hh_file._splitted == hh_str._splitted