import pytest
from PyTeX import json, lexer, bib

@pytest.fixture
def simple():
    with open('data/simple.bib') as f:
        return lexer.FileIn(f, bib.SUB_DICT)

def test_FileIn(f=simple):
    assert f().read() == """@article{test,   author = {Dillon Niederhut},   title={Structured data with PyTeX},   year=2016 }"""

def test_Parser(f=simple):
    token_list = []
    for token in f().tokenize(bib.REGEX_LIST):
        token_list.append(token.name)
    assert token_list == [
    'Item',
    'Start',
    'Text',
    'Next',
    'Text',
    'Assign',
    'Start',
    'Text',
    'End',
    'Next',
    'Text',
    'Assign',
    'Start',
    'Text',
    'End',
    'Next',
    'Text',
    'Assign',
    'Number'
    'End',
    'EOF'
    ]

def test_compiler(f=simple):
    parser = bib.Parser(f().tokenize(bib.REGEX_LIST))
    assert parser.parse() == [
        {
        'article' : {
            'author' : 'Dillon Niederhut',
            'title' : 'Structured data with PyTeX',
            'year' : 2016
            }
        }
    ]

@@ -854,46 +854,25 @@
  == 
-%5B%0A        %7B%0A        'article
+%7B%0A    'test
 ' : %7B%0A
-    
     
@@ -906,24 +906,44 @@
 erhut',%0A    
+    'name' : 'test'%0A
         'tit
@@ -982,24 +982,47 @@
 X',%0A        
+'type' : 'article'%0A    
     'year' :
@@ -1030,22 +1030,8 @@
 2016
-%0A            %7D
 %0A   
@@ -1037,14 +1037,14 @@
       %7D%0A    
-%5D
+%7D
 %0A

test for bib output modified