« get me outta code hell

test: isContentString (unit) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-06 10:53:52 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-06 12:50:32 -0400
commit8b1ea1a61d4aef404224b72b90200466d65d2562 (patch)
tree0ae29b726a545af2e0b81b4b7526a601595c2c4b /test
parentb154efef70cffd3374a4e410cbecb89ce3ea1690 (diff)
test: isContentString (unit)
Diffstat (limited to 'test')
-rw-r--r--test/unit/data/things/validators.js105
1 files changed, 105 insertions, 0 deletions
diff --git a/test/unit/data/things/validators.js b/test/unit/data/things/validators.js
index 8fed27ff..02c8c501 100644
--- a/test/unit/data/things/validators.js
+++ b/test/unit/data/things/validators.js
@@ -18,6 +18,7 @@ import {
   // Wiki data
   isColor,
   isCommentary,
+  isContentString,
   isContribution,
   isContributionList,
   isDimensions,
@@ -166,6 +167,110 @@ t.test('isCommentary', t => {
   t.throws(() => isCommentary(`Technically, ah, er:</i>\nCorrect`));
 });
 
+t.test('isContentString', t => {
+  t.plan(10);
+
+  t.ok(isContentString(`Hello, world!`));
+  t.ok(isContentString(`Hello...\nWorld!`));
+
+  const quickThrows = (string, description) =>
+    t.throws(() => isContentString(string), description);
+
+  quickThrows(
+    `Snooping\u200bas usual, I\u200bSEE.`,
+    {
+      [Symbol.for(`hsmusic.aggregate.translucent`)]: 'single',
+      message: `Errors validating content string`,
+      errors: [{
+        message: /^Illegal characters found in content string/,
+        errors: [
+          {message: `Matched "\u200b" between "ing" and "as " (pos: 9)`},
+        ],
+      }],
+    });
+
+  quickThrows(
+    `Oh\u200bdear,\n` +
+    `Oh dear,\n` +
+    `oh-dear-oh-dear-\u200boh dear.`,
+    {
+      errors: [{
+        message: /^Illegal characters found in content string/,
+        errors: [
+          {message: `Matched "\u200b" between "Oh" and "dea" (line: 1, col: 3)`},
+          {message: `Matched "\u200b" between "ar-" and "oh " (line: 3, col: 17)`},
+        ],
+      }],
+    });
+
+  quickThrows(
+    `  Room at the start.`,
+    {
+      errors: [{
+        message: `Whitespace found at start or end`,
+        errors: [
+          {message: `Matched "  " at start`},
+        ],
+      }],
+    });
+
+  quickThrows(
+    `Room at the end.      `,
+    {
+      errors: [{
+        message: `Whitespace found at start or end`,
+        errors: [
+          {message: `Matched "      " at end`},
+        ],
+      }],
+    });
+
+  quickThrows(
+    `      Room on both sides. `,
+    {
+      errors: [{
+        message: `Whitespace found at start or end`,
+        errors: [
+          {message: `Matched "      " at start`},
+          {message: `Matched " " at end`},
+        ],
+      }],
+    });
+
+  quickThrows(
+    `We're going multiline! \n` +
+    `That we are, aye.    \n` +
+    `      \n`,
+    `Yessir.`,
+    {
+      errors: [{
+        message: `Whitespace found at end of line`,
+        errors: [
+          {message: `Matched " " at end of line 1`},
+          {message: `Matched "    " at end of line 2`},
+          {messaeg: `Matched "      " as all of line 3`},
+        ],
+      }],
+    });
+
+  t.doesNotThrow(() =>
+    isContentString(
+      `It's cool.\n` +
+      `  It's cool.\n` +
+      `    It's cool.\n` +
+      `      It's so cool.`));
+
+  t.doesNotThrow(() =>
+    isContentString(
+      `\n` +
+      `\n` +
+      `It's okay for\n` +
+      `blank lines\n` +
+      `\n` +
+      `just about anywhere.\n` +
+      ``));
+});
+
 t.test('isContribution', t => {
   t.plan(4);
   t.ok(isContribution({who: 'artist:toby-fox', what: 'Music'}));