'use strict' ; import { readFileSync } from 'fs' ; import { Test } from './Test' ; import { Uri , window , workspace } from 'vscode' ; import { PddlExtensionContext } from 'pddl-workspace' ; /**
 * Tests manifest
 */ export class TestsManifest { path : string ; testCases : Test [ ] = [ ] ; constructor ( public readonly defaultDomain , public readonly defaultProblem , public readonly defaultOptions , public readonly uri ) { this . path = uri . fsPath ; } static fromJSON ( path , json , context ) { const defaultDomain = json [ "defaultDomain" ] ; const defaultProblem = json [ "defaultProblem" ] ; const defaultOptions = json [ "defaultOptions" ] ; const uri = Uri . file ( path ) ; const manifest = new TestsManifest ( defaultDomain , defaultProblem , defaultOptions , uri ) ; const tests = json [ "cases" ] ? json [ "cases" ] . map ( ( t ) => Test . fromJSON ( t , context ) ) : [ ] ; tests . forEach ( case1 => manifest . addCase ( case1 ) ) ; return manifest ; } addCase ( testCase ) { testCase . setManifest ( this ) ; this . testCases . push ( testCase ) ; } static load ( path , context ) { const settings = readFileSync ( path ) ; const json = JSON . parse ( settings . toLocaleString ( ) ) ; return TestsManifest . fromJSON ( path , json , context ) ; } async store ( ) { const obj = { } ; if ( this . defaultDomain !== undefined ) { obj [ "defaultDomain" ] = this . defaultDomain ; } if ( this . defaultProblem !== undefined ) { obj [ "defaultProblem" ] = this . defaultProblem ; } if ( this . defaultOptions !== undefined ) { obj [ "defaultOptions" ] = this . defaultOptions ; } const cases = [ ] ; this . testCases . forEach ( test => cases . push ( test . toJSON ( ) ) ) ; if ( cases . length > 0 ) { obj [ "cases" ] = cases ; } const json = JSON . stringify ( obj , null , 2 ) ; try { await workspace . fs . writeFile ( this . uri , Buffer . from ( json , 'utf8' ) ) ; } catch ( err ) { const error = err as Error ; window . showErrorMessage ( `Error saving test case manifest ${ error . name }: ${ error . message }` ) ; } } }