# Path: snaked/plugins/snippets/parser.py
# def parse_snippets_from(filename):
#     pl = ''
#     csnippet = None
#     snippets = {}
#     for l in open(filename).read().decode('utf-8').splitlines():
#         if l.startswith('snippet'):
#             tag_and_variant = l.split(None, 2)[1:]
#             if len(tag_and_variant) == 2:
#                 tag, variant = tag_and_variant
#             else:
#                 tag, variant = tag_and_variant[0], None
#             csnippet = Snippet(tag, variant)
#             snippets[csnippet.label] = csnippet
#             if pl.startswith('#'):
#                 csnippet.comment = pl[1:].strip()
#         elif l.startswith('\t') and csnippet:
#             csnippet.body.append(l[1:])
# 
#         pl = l
# 
#     return snippets


import os.path
from snaked.plugins.snippets.parser import parse_snippets_from

def get_slice(body, start, end):
    return body[start:end]

def test_parse_snippets_from():
    result = parse_snippets_from(python_snippets)

    assert 'imp' in result
    assert result['imp'].comment == 'Module import'
    assert result['imp'].snippet == 'imp'
    assert result['imp'].body == ['import ${1:module}']

    assert 'try Try/Except' in result
    assert result['try Try/Except'].snippet == 'try'

    assert 'try Try/Except/Else' in result
    assert result['try Try/Except/Else'].snippet == 'try'

def test_snippet_body_and_offsets():
    result = parse_snippets_from(python_snippets)
    body, stop_offsets, insert_offsets = result['cl'].get_body_and_offsets()

    assert get_slice(body, *stop_offsets[1]) == 'ClassName'
    assert get_slice(body, *stop_offsets[2]) == 'object'
    assert get_slice(body, *stop_offsets[3]) == ''
    assert get_slice(body, *stop_offsets[4]) == 'super(ClassName, self).__init__()'

    assert get_slice(body, *stop_offsets[1]) == 'ClassName'

def test_snippet_body_and_offsets2():

# Path: snaked/plugins/snippets/parser.py
# def parse_snippets_from(filename):
#     pl = ''
#     csnippet = None
#     snippets = {}
#     for l in open(filename).read().decode('utf-8').splitlines():
#         if l.startswith('snippet'):
#             tag_and_variant = l.split(None, 2)[1:]
#             if len(tag_and_variant) == 2:
#                 tag, variant = tag_and_variant
#             else:
#                 tag, variant = tag_and_variant[0], None
#             csnippet = Snippet(tag, variant)
#             snippets[csnippet.label] = csnippet
#             if pl.startswith('#'):
#                 csnippet.comment = pl[1:].strip()
#         elif l.startswith('\t') and csnippet:
#             csnippet.body.append(l[1:])
# 
#         pl = l
# 
#     return snippets


# Path: tests/test_snippets.py
import os.path
from snaked.plugins.snippets.parser import parse_snippets_from


def get_slice(body, start, end):
    return body[start:end]

def test_parse_snippets_from():
    result = parse_snippets_from(python_snippets)

    assert 'imp' in result
    assert result['imp'].comment == 'Module import'
    assert result['imp'].snippet == 'imp'
    assert result['imp'].body == ['import ${1:module}']

    assert 'try Try/Except' in result
    assert result['try Try/Except'].snippet == 'try'

    assert 'try Try/Except/Else' in result
    assert result['try Try/Except/Else'].snippet == 'try'

def test_snippet_body_and_offsets():
    result = parse_snippets_from(python_snippets)
    body, stop_offsets, insert_offsets = result['cl'].get_body_and_offsets()

    assert get_slice(body, *stop_offsets[1]) == 'ClassName'
    assert get_slice(body, *stop_offsets[2]) == 'object'
    assert get_slice(body, *stop_offsets[3]) == ''
    assert get_slice(body, *stop_offsets[4]) == 'super(ClassName, self).__init__()'

    assert get_slice(body, *stop_offsets[1]) == 'ClassName'

def test_snippet_body_and_offsets2():

    result = parse_snippets_from(python_snippets)