@@ -22,25 +22,55 @@ import { isWindows } from "../src/core/platform.ts";
2222import { execProcess } from "../src/core/process.ts" ;
2323import { canonicalizeSnapshot , checkSnapshot } from "./verify-snapshot.ts" ;
2424
25- export const withDocxContent = async < T > ( file : string ,
26- k : ( xml : string ) => Promise < T > ) => {
27- const [ _dir , stem ] = dirAndStem ( file ) ;
28- const temp = await Deno . makeTempDir ( ) ;
29- try {
30- // Move the docx to a temp dir and unzip it
31- const zipFile = join ( temp , stem + ".zip" ) ;
32- await Deno . copyFile ( file , zipFile ) ;
33- await unzip ( zipFile ) ;
34-
35- // Open the core xml document and match the matches
36- const docXml = join ( temp , "word" , "document.xml" ) ;
37- const xml = await Deno . readTextFile ( docXml ) ;
38- const result = await k ( xml ) ;
39- return result ;
40- } finally {
41- await Deno . remove ( temp , { recursive : true } ) ;
42- }
43- } ;
25+ export const withDocxContent = async < T > (
26+ file : string ,
27+ k : ( xml : string ) => Promise < T >
28+ ) => {
29+ const [ _dir , stem ] = dirAndStem ( file ) ;
30+ const temp = await Deno . makeTempDir ( ) ;
31+ try {
32+ // Move the docx to a temp dir and unzip it
33+ const zipFile = join ( temp , stem + ".zip" ) ;
34+ await Deno . copyFile ( file , zipFile ) ;
35+ await unzip ( zipFile ) ;
36+
37+ // Open the core xml document and match the matches
38+ const docXml = join ( temp , "word" , "document.xml" ) ;
39+ const xml = await Deno . readTextFile ( docXml ) ;
40+ const result = await k ( xml ) ;
41+ return result ;
42+ } finally {
43+ await Deno . remove ( temp , { recursive : true } ) ;
44+ }
45+ } ;
46+
47+ export const withPptxContent = async < T > (
48+ file : string ,
49+ slideNumber : number ,
50+ k : ( xml : string ) => Promise < T >
51+ ) => {
52+ const [ _dir , stem ] = dirAndStem ( file ) ;
53+ const temp = await Deno . makeTempDir ( ) ;
54+ try {
55+ // Move the pptx to a temp dir and unzip it
56+ const zipFile = join ( temp , stem + ".zip" ) ;
57+ await Deno . copyFile ( file , zipFile ) ;
58+ await unzip ( zipFile ) ;
59+
60+ // Open the core xml document and match the matches
61+ const slidePath = join ( temp , "ppt" , "slides" ) ;
62+ const slideFile = join ( slidePath , `slide${ slideNumber } .xml` ) ;
63+ assert (
64+ existsSync ( slideFile ) ,
65+ `Slide number ${ slideNumber } is not in the Pptx` ,
66+ ) ;
67+ const xml = await Deno . readTextFile ( slideFile ) ;
68+ const result = await k ( xml ) ;
69+ return result ;
70+ } finally {
71+ await Deno . remove ( temp , { recursive : true } ) ;
72+ }
73+ } ;
4474
4575export const noErrors : Verify = {
4676 name : "No Errors" ,
@@ -432,6 +462,18 @@ export const verifyDocXDocument = (
432462 } ) ;
433463} ;
434464
465+ export const verifyPptxDocument = (
466+ callback : ( doc : string ) => Promise < void > ,
467+ name ?: string ,
468+ ) : ( file : string , slideNumber : number ) => Verify => {
469+ return ( file : string , slideNumber : number ) => ( {
470+ name : name ?? "Inspecting Pptx" ,
471+ verify : async ( _output : ExecuteOutput [ ] ) => {
472+ return await withPptxContent ( file , slideNumber , callback ) ;
473+ } ,
474+ } ) ;
475+ } ;
476+
435477const xmlChecker = (
436478 selectors : string [ ] ,
437479 noMatchSelectors ?: string [ ] ,
@@ -493,6 +535,18 @@ export const ensureDocxXpath = (
493535 ) ( file ) ;
494536} ;
495537
538+ export const ensurePptxXpath = (
539+ file : string ,
540+ slideNumber : number ,
541+ selectors : string [ ] ,
542+ noMatchSelectors ?: string [ ] ,
543+ ) : Verify => {
544+ return verifyPptxDocument (
545+ xmlChecker ( selectors , noMatchSelectors ) ,
546+ "Inspecting Pptx for XPath selectors" ,
547+ ) ( file , slideNumber ) ;
548+ } ;
549+
496550export const ensureDocxRegexMatches = (
497551 file : string ,
498552 regexes : ( string | RegExp ) [ ] ,
0 commit comments