import path from 'path';
import fs from 'fs';
import { expect } from 'chai';
import pdf from 'oadf-pdf-converter';
import Lexer from '../../src/Lexer';
import Token, { TYPES as Type } from '../../src/Token';

describe('SELTEC 3 PDF Lexer 25.pdf', () => {
  it('should create the correct tokens', (done) => {
    const filePath = path.join(process.cwd(), 'test/lexer/fixtures/25.pdf');
    const data = new Uint8Array(fs.readFileSync(filePath));
    pdf(data).then((pages) => {
      const tokens = Lexer(pages);
      expect(tokens).to.deep.equal([
        new Token(Type.COMPETITION_NAME, 'offene Kreishallenmeisterschaften 2017'),
        new Token(Type.COMPETITION_CITY, 'Stadtallendorf'),
        new Token(Type.COMPETITION_VENUE, 'Herrenwaldhalle'),
        new Token(Type.COMPETITION_START_DATE, '07.01.2017'),
        new Token(Type.DISCIPLINE_NAME, '60m'),
        new Token(Type.AGE_GROUP_NAME, 'Jugend W14'),
        new Token(Type.EVENT_DATE, '07.01.2017'),
        new Token(Type.EVENT_TIME, '15:00'),
        new Token(Type.ROUND_NAME, 'Finale'),
        new Token(Type.ATHLETE_POSITION, '1'),
        new Token(Type.ATHLETE_BIB, '698'),
        new Token(Type.ATHLETE_FULL_NAME, 'Jalloh Hawa'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'Wiesbadener LV'),
        new Token(Type.PERFORMANCE, '8,22'),
        new Token(Type.GROUP_NUMBER_PLACE, '1./I'),
        new Token(Type.ATHLETE_POSITION, '2'),
        new Token(Type.ATHLETE_BIB, '622'),
        new Token(Type.ATHLETE_FULL_NAME, 'Wilhelm Sayana'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TSV Friedberg-Fauerbach'),
        new Token(Type.PERFORMANCE, '8,46'),
        new Token(Type.GROUP_NUMBER_PLACE, '2./I'),
        new Token(Type.ATHLETE_POSITION, '3'),
        new Token(Type.ATHLETE_BIB, '621'),
        new Token(Type.ATHLETE_FULL_NAME, 'Engel Kyra'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TSV Friedberg-Fauerbach'),
        new Token(Type.PERFORMANCE, '8,52'),
        new Token(Type.GROUP_NUMBER_PLACE, '3./I'),
        new Token(Type.ATHLETE_POSITION, '4'),
        new Token(Type.ATHLETE_BIB, '681'),
        new Token(Type.ATHLETE_FULL_NAME, 'Keutsch Merle'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TV Lauterbach'),
        new Token(Type.PERFORMANCE, '8,70'),
        new Token(Type.GROUP_NUMBER_PLACE, '4./I'),
        new Token(Type.ATHLETE_POSITION, '5'),
        new Token(Type.ATHLETE_BIB, '596'),
        new Token(Type.ATHLETE_FULL_NAME, 'Hegenbart Lina-Sophie'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'SC Steinatal'),
        new Token(Type.PERFORMANCE, '8,74'),
        new Token(Type.GROUP_NUMBER_PLACE, '5./I'),
        new Token(Type.ATHLETE_POSITION, '6'),
        new Token(Type.ATHLETE_BIB, '613'),
        new Token(Type.ATHLETE_FULL_NAME, 'Kotke Lena'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TSV Eintr. Stadtallendorf'),
        new Token(Type.PERFORMANCE, '9,00'),
        new Token(Type.GROUP_NUMBER_PLACE, '6./I'),
        new Token(Type.DISCIPLINE_NAME, '800m'),
        new Token(Type.AGE_GROUP_NAME, 'Jugend W14'),
        new Token(Type.EVENT_DATE, '07.01.2017'),
        new Token(Type.EVENT_TIME, '15:45'),
        new Token(Type.ROUND_NAME, 'Run_TimedHeats'),
        new Token(Type.ATHLETE_POSITION, '1'),
        new Token(Type.ATHLETE_BIB, '681'),
        new Token(Type.ATHLETE_FULL_NAME, 'Keutsch Merle'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TV Lauterbach'),
        new Token(Type.PERFORMANCE, '2:41,13'),
        new Token(Type.GROUP_NUMBER_PLACE, '1./I'),
        new Token(Type.ATHLETE_POSITION, '2'),
        new Token(Type.ATHLETE_BIB, '699'),
        new Token(Type.ATHLETE_FULL_NAME, 'Tikniouine Dunia'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'Wiesbadener LV'),
        new Token(Type.PERFORMANCE, '2:41,91'),
        new Token(Type.GROUP_NUMBER_PLACE, '2./I'),
        new Token(Type.ATHLETE_POSITION, '3'),
        new Token(Type.ATHLETE_BIB, '545'),
        new Token(Type.ATHLETE_FULL_NAME, 'Martin Louisa'),
        new Token(Type.ATHLETE_YOB, '2004'),
        new Token(Type.ATHLETE_CLUB_NAME, 'LG Eder'),
        new Token(Type.PERFORMANCE, '2:45,09'),
        new Token(Type.GROUP_NUMBER_PLACE, '3./I'),
        new Token(Type.ATHLETE_POSITION, '4'),
        new Token(Type.ATHLETE_BIB, '551'),
        new Token(Type.ATHLETE_FULL_NAME, 'Heinbach Lisa'),
        new Token(Type.ATHLETE_YOB, '2004'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'LG Langgöns-Oberkleen'),
        new Token(Type.PERFORMANCE, '2:48,73'),
        new Token(Type.GROUP_NUMBER_PLACE, '4./I'),
        new Token(Type.ATHLETE_POSITION, '5'),
        new Token(Type.ATHLETE_BIB, '594'),
        new Token(Type.ATHLETE_FULL_NAME, 'Auel Junia'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_CLUB_NAME, 'SC Steinatal'),
        new Token(Type.PERFORMANCE, '2:49,41'),
        new Token(Type.GROUP_NUMBER_PLACE, '5./I'),
        new Token(Type.ATHLETE_POSITION, '6'),
        new Token(Type.ATHLETE_BIB, '533'),
        new Token(Type.ATHLETE_FULL_NAME, 'Pasanbegovic Kira'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'LAZ Gießen'),
        new Token(Type.PERFORMANCE, '2:49,53'),
        new Token(Type.GROUP_NUMBER_PLACE, '6./I'),
        new Token(Type.ATHLETE_POSITION, '7'),
        new Token(Type.ATHLETE_BIB, '552'),
        new Token(Type.ATHLETE_FULL_NAME, 'Scharré Lotta'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'LG Langgöns-Oberkleen'),
        new Token(Type.PERFORMANCE, '2:50,67'),
        new Token(Type.GROUP_NUMBER_PLACE, '7./I'),
        new Token(Type.ATHLETE_POSITION, '8'),
        new Token(Type.ATHLETE_BIB, '553'),
        new Token(Type.ATHLETE_FULL_NAME, 'Scharré Mia'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'LG Langgöns-Oberkleen'),
        new Token(Type.PERFORMANCE, '2:52,65'),
        new Token(Type.GROUP_NUMBER_PLACE, '8./I'),
        new Token(Type.ATHLETE_POSITION, '9'),
        new Token(Type.ATHLETE_BIB, '618'),
        new Token(Type.ATHLETE_FULL_NAME, 'Schmidt Lara'),
        new Token(Type.ATHLETE_YOB, '2004'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TSV Eintr. Stadtallendorf'),
        new Token(Type.PERFORMANCE, '3:03,63'),
        new Token(Type.GROUP_NUMBER_PLACE, '9./I'),
        new Token(Type.ATHLETE_BIB, '693'),
        new Token(Type.ATHLETE_FULL_NAME, 'Götzfried Marie'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'Wiesbadener LV'),
        new Token(Type.PERFORMANCE, 'n.a.'),
        new Token(Type.ATHLETE_BIB, '691'),
        new Token(Type.ATHLETE_FULL_NAME, 'van Gool Eline'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'Wiesbadener LV'),
        new Token(Type.PERFORMANCE, 'disq.'),
        new Token(Type.COMMENT, 'Läuferin hat aufgegeben und den Innenraum betreten, anschließend hat die Läuferin den lauf fortgesetzt'),
        new Token(Type.DISCIPLINE_NAME, '60m Hürden'),
        new Token(Type.AGE_GROUP_NAME, 'Jugend W14'),
        new Token(Type.DISCIPLINE_ADDITIONAL_INFO, '762mm'),
        new Token(Type.EVENT_DATE, '07.01.2017'),
        new Token(Type.EVENT_TIME, '10:15'),
        new Token(Type.ROUND_NAME, 'Run_TimedHeats'),
        new Token(Type.ATHLETE_POSITION, '1'),
        new Token(Type.ATHLETE_BIB, '698'),
        new Token(Type.ATHLETE_FULL_NAME, 'Jalloh Hawa'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'Wiesbadener LV'),
        new Token(Type.PERFORMANCE, '10,06'),
        new Token(Type.GROUP_NUMBER_PLACE, '1./III'),
        new Token(Type.ATHLETE_POSITION, '2'),
        new Token(Type.ATHLETE_BIB, '622'),
        new Token(Type.ATHLETE_FULL_NAME, 'Wilhelm Sayana'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TSV Friedberg-Fauerbach'),
        new Token(Type.PERFORMANCE, '10,18'),
        new Token(Type.GROUP_NUMBER_PLACE, '1./II'),
        new Token(Type.ATHLETE_POSITION, '3'),
        new Token(Type.ATHLETE_BIB, '521'),
        new Token(Type.ATHLETE_FULL_NAME, 'Walther Juliane'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'Königsteiner LV'),
        new Token(Type.PERFORMANCE, '10,25'),
        new Token(Type.GROUP_NUMBER_PLACE, '1./I'),
        new Token(Type.ATHLETE_POSITION, '4'),
        new Token(Type.ATHLETE_BIB, '673'),
        new Token(Type.ATHLETE_FULL_NAME, 'Debus Lara-Sophie'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TV Haiger'),
        new Token(Type.PERFORMANCE, '10,27'),
        new Token(Type.GROUP_NUMBER_PLACE, '2./I'),
        new Token(Type.ATHLETE_POSITION, '5'),
        new Token(Type.ATHLETE_BIB, '613'),
        new Token(Type.ATHLETE_FULL_NAME, 'Kotke Lena'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TSV Eintr. Stadtallendorf'),
        new Token(Type.PERFORMANCE, '10,44'),
        new Token(Type.GROUP_NUMBER_PLACE, '2./III'),
        new Token(Type.ATHLETE_POSITION, '6'),
        new Token(Type.ATHLETE_BIB, '691'),
        new Token(Type.ATHLETE_FULL_NAME, 'van Gool Eline'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'Wiesbadener LV'),
        new Token(Type.PERFORMANCE, '10,48'),
        new Token(Type.GROUP_NUMBER_PLACE, '2./II'),
        new Token(Type.ATHLETE_POSITION, '7'),
        new Token(Type.ATHLETE_BIB, '670'),
        new Token(Type.ATHLETE_FULL_NAME, 'Mogk Sarah'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TV Friedrichstein'),
        new Token(Type.PERFORMANCE, '10,52'),
        new Token(Type.GROUP_NUMBER_PLACE, '3./III'),
        new Token(Type.ATHLETE_POSITION, '8'),
        new Token(Type.ATHLETE_BIB, '602'),
        new Token(Type.ATHLETE_FULL_NAME, 'Zalucki Sophia'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TSF Heuchelheim 1888'),
        new Token(Type.PERFORMANCE, '10,61'),
        new Token(Type.GROUP_NUMBER_PLACE, '3./I'),
        new Token(Type.ATHLETE_POSITION, '9'),
        new Token(Type.ATHLETE_BIB, '619'),
        new Token(Type.ATHLETE_FULL_NAME, 'Erdil Nilay'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TSV Eintr. Stadtallendorf'),
        new Token(Type.PERFORMANCE, '11,41'),
        new Token(Type.GROUP_NUMBER_PLACE, '4./I'),
        new Token(Type.ATHLETE_POSITION, '10'),
        new Token(Type.ATHLETE_BIB, '674'),
        new Token(Type.ATHLETE_FULL_NAME, 'Mencke Annika'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'TV Haiger'),
        new Token(Type.PERFORMANCE, '11,54'),
        new Token(Type.GROUP_NUMBER_PLACE, '3./II'),
        new Token(Type.ATHLETE_POSITION, '11'),
        new Token(Type.ATHLETE_BIB, '540'),
        new Token(Type.ATHLETE_FULL_NAME, 'Schindler Johanna'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'LAZ Gießen'),
        new Token(Type.PERFORMANCE, '11,78'),
        new Token(Type.GROUP_NUMBER_PLACE, '4./II'),
        new Token(Type.ATHLETE_BIB, '535'),
        new Token(Type.ATHLETE_FULL_NAME, 'Gans Nikola'),
        new Token(Type.ATHLETE_YOB, '2004'),
        new Token(Type.ATHLETE_CLUB_NAME, 'LAZ Gießen'),
        new Token(Type.PERFORMANCE, 'n.a.'),
        new Token(Type.ATHLETE_BIB, '693'),
        new Token(Type.ATHLETE_FULL_NAME, 'Götzfried Marie'),
        new Token(Type.ATHLETE_YOB, '2003'),
        new Token(Type.ATHLETE_COUNTRY, 'GER'),
        new Token(Type.ATHLETE_CLUB_NAME, 'Wiesbadener LV'),
        new Token(Type.PERFORMANCE, 'n.a.'),
        new Token(Type.ATHLETE_BIB, '534'),
        new Token(Type.ATHLETE_FULL_NAME, 'Wettstein Dana'),
        new Token(Type.ATHLETE_YOB, '2004'),
        new Token(Type.ATHLETE_CLUB_NAME, 'LAZ Gießen'),
        new Token(Type.PERFORMANCE, 'disq.'),
        new Token(Type.END),
      ]);
      done();
    }).catch((e) => {
      done(e);
    });
  });
});
