import { testLawtextToStd } from "../testHelper";
import $figStruct, { figStructToLines } from "./$figStruct";
describe("Test $figStruct and figStructToLines", () => {
it("Success case", () => {
/* eslint-disable no-irregular-whitespace */
const lawtextWithMarker = `\
:fig-struct:A図
# 別表第二 外国旅行の旅費(第三十五条―第三十七条、第三十九条、第四十条、第四十一条関係)
`;
const expectedErrorMessages: string[] = [];
const expectedRendered = `\
:fig-struct:A図
`.replace(/\r?\n/g, "\r\n");
const expectedValue = {
tag: "FigStruct",
attr: {},
children: [
{
tag: "FigStructTitle",
attr: {},
children: ["A図"],
},
{
tag: "Fig",
attr: { src: "./pict/S27F03901000056-005.jpg" },
children: [],
},
],
};
testLawtextToStd(
lawtextWithMarker,
expectedRendered,
expectedValue,
expectedErrorMessages,
(vlines, env) => {
const result = $figStruct.match(0, vlines, env);
// console.log(JSON.stringify(vlines, null, 2));
// if (result.ok) console.log(JSON.stringify(result.value.value.json(false), undefined, 2));
// if (result.ok) writeFileSync("out__parsed.json", JSON.stringify(result.value.value.json(false), undefined, 2));
// if (result.ok) writeFileSync("out__expected.json", JSON.stringify(expectedValue, undefined, 2));
return result;
},
el => {
const lines = figStructToLines(el, []);
// console.log(JSON.stringify(lines, null, 2));
return lines;
},
);
});
it("Success case", () => {
/* eslint-disable no-irregular-whitespace */
const lawtextWithMarker = `\
:fig-struct:
# 別表第二 外国旅行の旅費(第三十五条―第三十七条、第三十九条、第四十条、第四十一条関係)
`;
const expectedErrorMessages: string[] = [];
const expectedRendered = `\
`.replace(/\r?\n/g, "\r\n");
const expectedValue = {
tag: "FigStruct",
attr: {},
children: [
{
tag: "Fig",
attr: { src: "./pict/S27F03901000056-005.jpg" },
children: [],
},
],
};
testLawtextToStd(
lawtextWithMarker,
expectedRendered,
expectedValue,
expectedErrorMessages,
(vlines, env) => {
const result = $figStruct.match(0, vlines, env);
// console.log(JSON.stringify(vlines, null, 2));
// if (result.ok) console.log(JSON.stringify(result.value.value.json(false), undefined, 2));
// if (result.ok) writeFileSync("out__parsed.json", JSON.stringify(result.value.value.json(false), undefined, 2));
// if (result.ok) writeFileSync("out__expected.json", JSON.stringify(expectedValue, undefined, 2));
return result;
},
el => {
const lines = figStructToLines(el, []);
// console.log(JSON.stringify(lines, null, 2));
return lines;
},
);
});
it("Success case", () => {
/* eslint-disable no-irregular-whitespace */
const lawtextWithMarker = `\
:fig-struct:
# 別表第二 外国旅行の旅費(第三十五条―第三十七条、第三十九条、第四十条、第四十一条関係)
`;
const expectedErrorMessages: string[] = [];
const expectedRendered = `\
:fig-struct:
`.replace(/\r?\n/g, "\r\n");
const expectedValue = {
tag: "FigStruct",
attr: {},
children: [],
};
testLawtextToStd(
lawtextWithMarker,
expectedRendered,
expectedValue,
expectedErrorMessages,
(vlines, env) => {
const result = $figStruct.match(0, vlines, env);
// console.log(JSON.stringify(vlines, null, 2));
// if (result.ok) console.log(JSON.stringify(result.value.value.json(false), undefined, 2));
// if (result.ok) writeFileSync("out__parsed.json", JSON.stringify(result.value.value.json(false), undefined, 2));
// if (result.ok) writeFileSync("out__expected.json", JSON.stringify(expectedValue, undefined, 2));
return result;
},
el => {
const lines = figStructToLines(el, []);
// console.log(JSON.stringify(lines, null, 2));
return lines;
},
);
});
it("Success with errors case", () => {
/* eslint-disable no-irregular-whitespace */
const lawtextWithMarker = `\
:fig-struct:
!
!
# 別表第二 外国旅行の旅費(第三十五条―第三十七条、第三十九条、第四十条、第四十一条関係)
`;
const expectedErrorMessages: string[] = ["$figStruct: Figタグ に src 属性が設定されていません。"];
const expectedRendered = `\
`.replace(/\r?\n/g, "\r\n");
const expectedValue = {
tag: "FigStruct",
attr: {},
children: [
{
tag: "Fig",
attr: { src: "" },
children: [],
},
],
};
testLawtextToStd(
lawtextWithMarker,
expectedRendered,
expectedValue,
expectedErrorMessages,
(vlines, env) => {
const result = $figStruct.match(0, vlines, env);
// console.log(JSON.stringify(vlines, null, 2));
// if (result.ok) console.log(JSON.stringify(result.value.value.json(false), undefined, 2));
// if (result.ok) writeFileSync("out__parsed.json", JSON.stringify(result.value.value.json(false), undefined, 2));
// if (result.ok) writeFileSync("out__expected.json", JSON.stringify(expectedValue, undefined, 2));
return result;
},
el => {
const lines = figStructToLines(el, []);
// console.log(JSON.stringify(lines, null, 2));
return lines;
},
);
});
it("Success with errors case", () => {
/* eslint-disable no-irregular-whitespace */
const lawtextWithMarker = `\
:fig-struct:
!第三条 私権の享有は、出生に始まる。
一 外国人は、法令又は条約の規定により禁止される場合を除き、私権を享有する。
!
# 別表第二 外国旅行の旅費(第三十五条―第三十七条、第三十九条、第四十条、第四十一条関係)
`;
const expectedErrorMessages: string[] = ["$figStructChildrenBlock: この部分をパースできませんでした。"];
const expectedRendered = `\
`.replace(/\r?\n/g, "\r\n");
const expectedValue = {
tag: "FigStruct",
attr: {},
children: [
{
tag: "Fig",
attr: { src: "./pict/S27F03901000056-005.jpg" },
children: [],
},
],
};
testLawtextToStd(
lawtextWithMarker,
expectedRendered,
expectedValue,
expectedErrorMessages,
(vlines, env) => {
const result = $figStruct.match(0, vlines, env);
// console.log(JSON.stringify(vlines, null, 2));
// if (result.ok) console.log(JSON.stringify(result.value.value.json(false), undefined, 2));
// if (result.ok) writeFileSync("out__parsed.json", JSON.stringify(result.value.value.json(false), undefined, 2));
// if (result.ok) writeFileSync("out__expected.json", JSON.stringify(expectedValue, undefined, 2));
return result;
},
el => {
const lines = figStructToLines(el, []);
// console.log(JSON.stringify(lines, null, 2));
return lines;
},
);
});
});