summaryrefslogtreecommitdiff
path: root/src/components/rich-text/node-format.test.ts
diff options
context:
space:
mode:
authorBertrand Yuan <189593334+bertyuan@users.noreply.github.com>2026-03-26 00:19:31 +0800
committerGitHub <noreply@github.com>2026-03-26 00:19:31 +0800
commitf247a8c4a863ec430f4a705b5c493d652c8429bd (patch)
tree71d0985970984c105582f6e3c370b254f38e9bbe /src/components/rich-text/node-format.test.ts
parentf7a02fe0e112cf108fc5f22872f1efc077e99fe8 (diff)
parentcd3c4bc89c169616b38bdb7443bb4eb7571b020c (diff)
Merge pull request #12 from bertyuan/fix-vitestv1.1
Fix vitest
Diffstat (limited to 'src/components/rich-text/node-format.test.ts')
-rw-r--r--src/components/rich-text/node-format.test.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/components/rich-text/node-format.test.ts b/src/components/rich-text/node-format.test.ts
new file mode 100644
index 0000000..476a0d9
--- /dev/null
+++ b/src/components/rich-text/node-format.test.ts
@@ -0,0 +1,40 @@
+import { describe, expect, test } from 'vitest';
+import {
+ IS_BOLD,
+ IS_CODE,
+ IS_HIGHLIGHT,
+ IS_ITALIC,
+ IS_STRIKETHROUGH,
+ IS_SUBSCRIPT,
+ IS_SUPERSCRIPT,
+ IS_UNDERLINE,
+} from './node-format';
+
+describe('node format bit flags', () => {
+ test('uses power-of-two values for unique bitmasks', () => {
+ const flags = [
+ IS_BOLD,
+ IS_ITALIC,
+ IS_STRIKETHROUGH,
+ IS_UNDERLINE,
+ IS_CODE,
+ IS_SUBSCRIPT,
+ IS_SUPERSCRIPT,
+ IS_HIGHLIGHT,
+ ];
+
+ for (const flag of flags) {
+ expect((flag & (flag - 1)) === 0).toBe(true);
+ }
+ });
+
+ test('can combine and detect individual flags with bitwise operations', () => {
+ const format = IS_BOLD | IS_ITALIC | IS_CODE;
+
+ expect((format & IS_BOLD) !== 0).toBe(true);
+ expect((format & IS_ITALIC) !== 0).toBe(true);
+ expect((format & IS_CODE) !== 0).toBe(true);
+ expect((format & IS_UNDERLINE) !== 0).toBe(false);
+ });
+});
+