|
| 1 | +import assert from "assert"; |
| 2 | +import tmp from 'tmp'; |
| 3 | +import util, { TextDecoder } from 'util'; |
| 4 | +import { Uri, workspace } from "vscode"; |
| 5 | +import { TestSuite } from "."; |
| 6 | +import { Tools } from "../api/Tools"; |
| 7 | +import { instance } from "../instantiate"; |
| 8 | +import { CommandResult } from "../typings"; |
| 9 | +import { getMemberUri } from "../filesystems/qsys/QSysFs"; |
| 10 | + |
| 11 | +export const EncodingSuite: TestSuite = { |
| 12 | + name: `Encoding tests`, |
| 13 | + after: async () => { |
| 14 | + const connection = instance.getConnection(); |
| 15 | + connection?.setOverrideCcsid(undefined); |
| 16 | + }, |
| 17 | + |
| 18 | + before: async () => { |
| 19 | + const config = instance.getConfig()!; |
| 20 | + assert.ok(config.enableSourceDates, `Source dates must be enabled for this test.`); |
| 21 | + }, |
| 22 | + |
| 23 | + tests: [ |
| 24 | + { |
| 25 | + name: `Encoding 37`, test: async () => { |
| 26 | + const connection = instance.getConnection(); |
| 27 | + const config = instance.getConfig()!; |
| 28 | + |
| 29 | + const lines = [ |
| 30 | + `Hello world` |
| 31 | + ].join(`\n`); |
| 32 | + |
| 33 | + const tempLib = config!.tempLibrary; |
| 34 | + |
| 35 | + connection?.setOverrideCcsid(37); |
| 36 | + |
| 37 | + const file = `TEST37`; |
| 38 | + |
| 39 | + await connection!.runCommand({ command: `CRTSRCPF FILE(${tempLib}/${file}) RCDLEN(112) CCSID(37)`, noLibList: true }); |
| 40 | + await connection!.runCommand({ command: `ADDPFM FILE(${tempLib}/${file}) MBR(THEMEMBER) SRCTYPE(TXT)`, noLibList: true }); |
| 41 | + |
| 42 | + const theBadOneUri = getMemberUri({library: tempLib, file, name: `THEMEMBER`, extension: `TXT`}); |
| 43 | + |
| 44 | + await workspace.fs.readFile(theBadOneUri); |
| 45 | + |
| 46 | + await workspace.fs.writeFile(theBadOneUri, Buffer.from(lines, `utf8`)); |
| 47 | + |
| 48 | + const memberContentBuf = await workspace.fs.readFile(theBadOneUri); |
| 49 | + const fileContent = new TextDecoder().decode(memberContentBuf) |
| 50 | + |
| 51 | + assert.strictEqual(fileContent, lines); |
| 52 | + }, |
| 53 | + }, |
| 54 | + // { |
| 55 | + // name: `Encoding 273`, test: async () => { |
| 56 | + // const connection = instance.getConnection(); |
| 57 | + // const config = instance.getConfig()!; |
| 58 | + |
| 59 | + // const lines = [ |
| 60 | + // `Hello world`, |
| 61 | + // `àáãÄÜö£øß` |
| 62 | + // ].join(`\n`); |
| 63 | + |
| 64 | + // const tempLib = config!.tempLibrary; |
| 65 | + |
| 66 | + // connection?.setOverrideCcsid(37); |
| 67 | + |
| 68 | + // const file = `TEST273`; |
| 69 | + |
| 70 | + // await connection!.runCommand({ command: `CRTSRCPF FILE(${tempLib}/${file}) RCDLEN(112) CCSID(273)`, noLibList: true }); |
| 71 | + // await connection!.runCommand({ command: `ADDPFM FILE(${tempLib}/${file}) MBR(THEMEMBER) SRCTYPE(TXT)`, noLibList: true }); |
| 72 | + |
| 73 | + // const theBadOneUri = getMemberUri({library: tempLib, file, name: `THEMEMBER`, extension: `TXT`}); |
| 74 | + |
| 75 | + // await workspace.fs.readFile(theBadOneUri); |
| 76 | + |
| 77 | + // await workspace.fs.writeFile(theBadOneUri, Buffer.from(lines, `utf8`)); |
| 78 | + |
| 79 | + // const memberContentBuf = await workspace.fs.readFile(theBadOneUri); |
| 80 | + // const fileContent = new TextDecoder().decode(memberContentBuf) |
| 81 | + |
| 82 | + // assert.strictEqual(fileContent, lines); |
| 83 | + // } |
| 84 | + // } |
| 85 | + ] |
| 86 | +}; |
0 commit comments