import evaluate from '../src/lib/evaluate'
import loadArea from './lib/load-area'

import {readFileSync, readdirSync} from 'graceful-fs'

import path from 'path'

import {describe, it} from 'mocha'
import {expect} from 'chai'

const studentDir = './test/example-students/'

function loadStudent(filename) {
	return JSON.parse(readFileSync(filename, {encoding: 'utf-8'}))
}

function getStudentNames() {
	return readdirSync(studentDir)
		.filter(filename => path.extname(filename) === '.json')
		.map(filename => path.resolve(studentDir + filename))
}

export function cli() {
	getStudentNames()
		.map(filename => {
			const s = loadStudent(filename)
			s.areas = s.areas.map(loadArea)
			return {...s, filename}
		})
		.forEach(({courses, overrides, areas, filename, expectation=true, pending=false}) => {
			const func = pending ? describe.skip : describe
			func(path.basename(filename), () => {
				areas.forEach(data => {
					it(`${expectation ? 'should' : 'should not'} pass ${data.name}`, () => {
						const result = evaluate({courses, overrides}, data)
						expect(result).to.have.property('computed', expectation)
					})
				})
			})
		})
}

@@ -218,16 +218,43 @@
 m 'chai'
+%0Aimport yaml from 'js-yaml'
 %0A%0Aconst 
@@ -332,25 +332,34 @@
  %7B%0A%09
-return JSON.parse
+const data = yaml.safeLoad
 (rea
@@ -400,16 +400,94 @@
 f-8'%7D))%0A
+%09data.areas = data.areas.map(loadArea)%0A%09data.filename = filename%0A%09return data%0A
 %7D%0A%0Afunct
@@ -679,170 +679,46 @@
 ion 
-cli() %7B%0A%09getStudentNames()%0A%09%09.map(filename =%3E %7B%0A%09%09%09const s = loadS
+testStudent(s
 tudent
-(filen
+FileN
 ame)
-%0A%09%09%09s.areas = s.areas.map(loadArea)%0A%09%09%09return %7B...s, filename%7D%0A%09%09%7D)%0A%09%09.forEach((
+ %7B%0A%09const 
 %7Bcou
@@ -783,25 +783,49 @@
 g=false%7D
-)
  =
-%3E %7B%0A%09%09
+ loadStudent(studentFileName)%0A%0A
 %09const f
@@ -865,18 +865,17 @@
 escribe%0A
-%09%09
+%0A
 %09func(pa
@@ -905,18 +905,16 @@
 () =%3E %7B%0A
-%09%09
 %09%09areas.
@@ -931,18 +931,16 @@
 ta =%3E %7B%0A
-%09%09
 %09%09%09it(%60$
@@ -1011,18 +1011,16 @@
 %3E %7B%0A%09%09%09%09
-%09%09
 const re
@@ -1063,18 +1063,16 @@
 , data)%0A
-%09%09
 %09%09%09%09expe
@@ -1131,29 +1131,85 @@
 %0A%09%09%09
-%09%09
 %7D)%0A
-%09%09
 %09%09%7D)%0A
-%09%09
 %09%7D)%0A
-%09%09%7D
+%7D%0A%0Aexport function cli() %7B%0A%09getStudentNames().forEach(testStudent
 )%0A%7D%0A

prepare to be able to test a single student at a time