3const fs = require("fs");
4const path = require("path");
6const cmsFile = path.resolve(__dirname, "../../../js/lib/cms.js");
7const source = fs.readFileSync(cmsFile, "utf8");
8const match = source.match(/function cmsFieldValue\([^)]*\) \{[\s\S]*?\n \}/);
11 throw new Error("cmsFieldValue wurde in cms.js nicht gefunden.");
14const cmsFieldValue = Function(`"use strict"; return (${match[0]});`)();
16 [0, 0, "Numerische Null muss erhalten bleiben"],
17 ["0", "0", "Statuswert 0 muss erhalten bleiben"],
18 [1, 1, "Numerische Eins muss erhalten bleiben"],
19 ["1", "1", "Statuswert 1 muss erhalten bleiben"],
20 [null, "", "null wird als leeres Feld dargestellt"],
21 [undefined, "", "undefined wird als leeres Feld dargestellt"],
24for (const [input, expected, label] of cases) {
25 const actual = cmsFieldValue(input);
26 if (actual !== expected) {
27 throw new Error(`${label}: erwartet ${String(expected)}, erhalten ${String(actual)}`);
31console.log("OK cms_zero_field_value_test");