'use strict';

// This test loads all of the timelines from raidboss and makes
// sure that timeline.js can parse them without errors.

let fs = require('fs');
let path = require('path');

let Timeline = require('../ui/raidboss/timeline.js');
let ignoreFiles = ['README.txt'];

let testFolder =
    path.join(__dirname, '..', 'ui', 'raidboss', 'data', 'timelines');

let exitCode = 0;

fs.readdirSync(testFolder).forEach((file) => {
  if (ignoreFiles.indexOf(file) >= 0)
    return;
  let contents = fs.readFileSync(path.join(testFolder, file)) + '';
  let t = new Timeline(contents);
  for (let i = 0; i < t.errors.length; ++i) {
    let e = t.errors[i];
    console.error(file + ':' + e.lineNumber + ': ' + e.error + ': ' + e.line);
    exitCode = 1;
  }
});

process.exit(exitCode);

@@ -177,25 +177,24 @@
 re('path');%0A
-%0A
 let Timeline
@@ -238,60 +238,26 @@
 s');
-%0Alet ignoreFiles = %5B'README.txt'%5D;
 %0A%0Alet 
-test
+base
 Folder =
 %0A   
@@ -252,20 +252,16 @@
 Folder =
-%0A   
  path.jo
@@ -308,128 +308,247 @@
 ata'
-, 'timelines');%0A%0Alet exitCode = 0;%0A%0Afs.readdirSync(testFolder).forEach((file) =%3E %7B%0A  if (ignoreFiles.indexOf(file) %3E= 0)
+);%0A%0Alet testedAny = false;%0Alet exitCode = 0;%0A%0Alet testTimelineFile = function(fullPath, context) %7B%0A  testedAny = true;%0A  if (!fs.existsSync(fullPath)) %7B%0A    console.error(fullPath + ' doesn%5C't exist.  (' + context + ')');%0A    exitCode = 1;
 %0A   
@@ -556,16 +556,21 @@
 return;%0A
+  %7D%0A%0A
   let co
@@ -598,35 +598,16 @@
 ync(
-path.join(testFolder, file)
+fullPath
 ) + 
@@ -817,18 +817,705 @@
 1;%0A  %7D%0A%7D
-)
 ;
+%0A%0Alet testDirectory = function(dir) %7B%0A  fs.readdirSync(dir).forEach((file) =%3E %7B%0A    let fullPath = path.join(dir, file);%0A    let stat = fs.statSync(fullPath);%0A    if (stat.isDirectory()) %7B%0A      testDirectory(fullPath);%0A      return;%0A    %7D%0A    if (file.substr(file.length - 3) != '.js')%0A      return;%0A%0A    let contents = fs.readFileSync(fullPath) + '';%0A    let m = contents.match(/%5E%5Cs*timelineFile: '(%5B%5E'%5D*)',%5Cs$/m);%0A    if (!m)%0A      return;%0A    // TODO: could count line numbers here%0A    let context = fullPath;%0A%0A    testTimelineFile(path.join(dir, m%5B1%5D), context);%0A  %7D);%0A%7D;%0A%0AtestDirectory(baseFolder);%0A%0Aif (!testedAny) %7B%0A  console.error('Did not find any timelines');%0A  exitCode = 1;%0A%7D
 %0A%0Aproces

verify timelines from triggers exist (#548)