Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sfm-js
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dakkar
sfm-js
Commits
33c0b6c9
Commit
33c0b6c9
authored
3 years ago
by
marihachi
Browse files
Options
Downloads
Patches
Plain Diff
biyo
parent
473f7770
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/api.ts
+9
-9
9 additions, 9 deletions
test/api.ts
test/node.ts
+1
-1
1 addition, 1 deletion
test/node.ts
test/parser.ts
+46
-46
46 additions, 46 deletions
test/parser.ts
with
56 additions
and
56 deletions
test/api.ts
+
9
−
9
View file @
33c0b6c9
import
assert
from
'
assert
'
;
import
{
extract
,
inspect
,
parse
,
toString
}
from
'
../built/index
'
;
import
*
as
mfm
from
'
../built/index
'
;
import
{
TEXT
,
CENTER
,
FN
,
UNI_EMOJI
,
MENTION
,
EMOJI_CODE
,
HASHTAG
,
N_URL
,
BOLD
,
SMALL
,
ITALIC
,
STRIKE
,
QUOTE
,
MATH_BLOCK
,
SEARCH
,
CODE_BLOCK
,
LINK
}
from
'
./node
'
;
...
...
@@ -17,42 +17,42 @@ I'm @ai, A bot of misskey!
https://github.com/syuilo/ai
</center>
after`
;
assert
.
strictEqual
(
toString
(
parse
(
input
)),
input
);
assert
.
strictEqual
(
mfm
.
toString
(
mfm
.
parse
(
input
)),
input
);
});
});
describe
(
'
inspect
'
,
()
=>
{
it
(
'
replace text
'
,
()
=>
{
const
input
=
'
good morning [tada everynyan!]
'
;
const
result
=
parse
(
input
);
inspect
(
result
,
node
=>
{
const
result
=
mfm
.
parse
(
input
);
mfm
.
inspect
(
result
,
node
=>
{
if
(
node
.
type
==
'
text
'
)
{
node
.
props
.
text
=
node
.
props
.
text
.
replace
(
/good morning/g
,
'
hello
'
);
}
});
assert
.
strictEqual
(
toString
(
result
),
'
hello [tada everynyan!]
'
);
assert
.
strictEqual
(
mfm
.
toString
(
result
),
'
hello [tada everynyan!]
'
);
});
});
describe
(
'
extract
'
,
()
=>
{
it
(
'
basic
'
,
()
=>
{
const
nodes
=
parse
(
'
@hoge @piyo @bebeyo
'
);
const
nodes
=
mfm
.
parse
(
'
@hoge @piyo @bebeyo
'
);
const
expect
=
[
MENTION
(
'
hoge
'
,
null
,
'
@hoge
'
),
MENTION
(
'
piyo
'
,
null
,
'
@piyo
'
),
MENTION
(
'
bebeyo
'
,
null
,
'
@bebeyo
'
)
];
assert
.
deepStrictEqual
(
extract
(
nodes
,
'
mention
'
),
expect
);
assert
.
deepStrictEqual
(
mfm
.
extract
(
nodes
,
'
mention
'
),
expect
);
});
it
(
'
nested
'
,
()
=>
{
const
nodes
=
parse
(
'
abc:hoge:[tada 123 @hoge :foo:]:piyo:
'
);
const
nodes
=
mfm
.
parse
(
'
abc:hoge:[tada 123 @hoge :foo:]:piyo:
'
);
const
expect
=
[
EMOJI_CODE
(
'
hoge
'
),
EMOJI_CODE
(
'
foo
'
),
EMOJI_CODE
(
'
piyo
'
)
];
assert
.
deepStrictEqual
(
extract
(
nodes
,
'
emojiCode
'
),
expect
);
assert
.
deepStrictEqual
(
mfm
.
extract
(
nodes
,
'
emojiCode
'
),
expect
);
});
});
});
This diff is collapsed.
Click to expand it.
test/node.ts
+
1
−
1
View file @
33c0b6c9
import
{
MfmFn
,
MfmInline
,
MfmNode
,
NodeType
}
from
'
../built
'
;
export
const
QUOTE
=
(
children
:
MfmNode
[]):
NodeType
<
'
quote
'
>
=>
{
return
{
type
:
'
quote
'
,
children
};
};
export
const
SEARCH
=
(
query
:
string
,
content
:
string
):
NodeType
<
'
search
'
>
=>
{
return
{
type
:
'
search
'
,
props
:
{
query
,
content
}
};
};
export
const
CODE_BLOCK
=
(
code
:
string
,
lang
:
string
|
null
):
NodeType
<
'
blockCode
'
>
=>
{
return
{
type
:
'
blockCode
'
,
props
:
{
code
,
lang
}
};
};
...
...
This diff is collapsed.
Click to expand it.
test/parser.ts
+
46
−
46
View file @
33c0b6c9
import
assert
from
'
assert
'
;
import
{
parse
}
from
'
../built/index
'
;
import
*
as
mfm
from
'
../built/index
'
;
import
{
createNode
}
from
'
../built/util
'
;
import
{
TEXT
,
CENTER
,
FN
,
UNI_EMOJI
,
MENTION
,
EMOJI_CODE
,
HASHTAG
,
N_URL
,
BOLD
,
SMALL
,
ITALIC
,
STRIKE
,
QUOTE
,
MATH_BLOCK
,
SEARCH
,
CODE_BLOCK
,
LINK
...
...
@@ -10,7 +10,7 @@ describe('parser', () => {
it
(
'
普通のテキストを入力すると1つのテキストノードが返される
'
,
()
=>
{
const
input
=
'
abc
'
;
const
output
=
[
TEXT
(
'
abc
'
)];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -22,7 +22,7 @@ describe('parser', () => {
TEXT
(
'
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
複数行の引用ブロックを使用できる
'
,
()
=>
{
const
input
=
`
...
...
@@ -34,7 +34,7 @@ describe('parser', () => {
TEXT
(
'
abc
\n
123
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
引用ブロックはブロックをネストできる
'
,
()
=>
{
const
input
=
`
...
...
@@ -49,7 +49,7 @@ describe('parser', () => {
])
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
引用ブロックはインライン構文を含んだブロックをネストできる
'
,
()
=>
{
const
input
=
`
...
...
@@ -66,7 +66,7 @@ describe('parser', () => {
])
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -80,7 +80,7 @@ describe('parser', () => {
content
:
input
})
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
[Search]
'
,
()
=>
{
const
input
=
'
MFM 書き方 123 [Search]
'
;
...
...
@@ -90,7 +90,7 @@ describe('parser', () => {
content
:
input
})
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
search
'
,
()
=>
{
const
input
=
'
MFM 書き方 123 search
'
;
...
...
@@ -100,7 +100,7 @@ describe('parser', () => {
content
:
input
})
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
[search]
'
,
()
=>
{
const
input
=
'
MFM 書き方 123 [search]
'
;
...
...
@@ -110,7 +110,7 @@ describe('parser', () => {
content
:
input
})
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
検索
'
,
()
=>
{
const
input
=
'
MFM 書き方 123 検索
'
;
...
...
@@ -120,7 +120,7 @@ describe('parser', () => {
content
:
input
})
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
[検索]
'
,
()
=>
{
const
input
=
'
MFM 書き方 123 [検索]
'
;
...
...
@@ -130,7 +130,7 @@ describe('parser', () => {
content
:
input
})
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
it
(
'
ブロックの前後にあるテキストが正しく解釈される
'
,
()
=>
{
...
...
@@ -140,7 +140,7 @@ describe('parser', () => {
SEARCH
(
'
hoge piyo bebeyo
'
,
'
hoge piyo bebeyo 検索
'
),
TEXT
(
'
123
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -148,17 +148,17 @@ describe('parser', () => {
it
(
'
コードブロックを使用できる
'
,
()
=>
{
const
input
=
'
```
\n
abc
\n
```
'
;
const
output
=
[
CODE_BLOCK
(
'
abc
'
,
null
)];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
コードブロックには複数行のコードを入力できる
'
,
()
=>
{
const
input
=
'
```
\n
a
\n
b
\n
c
\n
```
'
;
const
output
=
[
CODE_BLOCK
(
'
a
\n
b
\n
c
'
,
null
)];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
コードブロックは言語を指定できる
'
,
()
=>
{
const
input
=
'
```js
\n
const a = 1;
\n
```
'
;
const
output
=
[
CODE_BLOCK
(
'
const a = 1;
'
,
'
js
'
)];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
ブロックの前後にあるテキストが正しく解釈される
'
,
()
=>
{
const
input
=
'
abc
\n
```
\n
const abc = 1;
\n
```
\n
123
'
;
...
...
@@ -167,7 +167,7 @@ describe('parser', () => {
CODE_BLOCK
(
'
const abc = 1;
'
,
null
),
TEXT
(
'
123
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -177,7 +177,7 @@ describe('parser', () => {
const
output
=
[
MATH_BLOCK
(
'
math1
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
ブロックの前後にあるテキストが正しく解釈される
'
,
()
=>
{
const
input
=
'
abc
\n\\
[math1
\\
]
\n
123
'
;
...
...
@@ -186,21 +186,21 @@ describe('parser', () => {
MATH_BLOCK
(
'
math1
'
),
TEXT
(
'
123
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
行末以外に閉じタグがある場合はマッチしない
'
,
()
=>
{
const
input
=
'
\\
[aaa
\\
]after
'
;
const
output
=
[
TEXT
(
'
\\
[aaa
\\
]after
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
行頭以外に開始タグがある場合はマッチしない
'
,
()
=>
{
const
input
=
'
before
\\
[aaa
\\
]
'
;
const
output
=
[
TEXT
(
'
before
\\
[aaa
\\
]
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -212,7 +212,7 @@ describe('parser', () => {
TEXT
(
'
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
multiple text
'
,
()
=>
{
const
input
=
'
before
\n
<center>
\n
abc
\n
123
\n\n
piyo
\n
</center>
\n
after
'
;
...
...
@@ -223,7 +223,7 @@ describe('parser', () => {
]),
TEXT
(
'
after
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -231,7 +231,7 @@ describe('parser', () => {
it
(
'
basic
'
,
()
=>
{
const
input
=
'
:abc:
'
;
const
output
=
[
EMOJI_CODE
(
'
abc
'
)];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -239,7 +239,7 @@ describe('parser', () => {
it
(
'
basic
'
,
()
=>
{
const
input
=
'
今起きた😇
'
;
const
output
=
[
TEXT
(
'
今起きた
'
),
UNI_EMOJI
(
'
😇
'
)];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -251,7 +251,7 @@ describe('parser', () => {
TEXT
(
'
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
内容にはインライン構文を利用できる
'
,
()
=>
{
const
input
=
'
***123**abc**123***
'
;
...
...
@@ -264,7 +264,7 @@ describe('parser', () => {
TEXT
(
'
123
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
内容は改行できる
'
,
()
=>
{
const
input
=
'
***123
\n
**abc**
\n
123***
'
;
...
...
@@ -277,7 +277,7 @@ describe('parser', () => {
TEXT
(
'
\n
123
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -289,7 +289,7 @@ describe('parser', () => {
TEXT
(
'
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
内容にはインライン構文を利用できる
'
,
()
=>
{
const
input
=
'
**123~~abc~~123**
'
;
...
...
@@ -302,7 +302,7 @@ describe('parser', () => {
TEXT
(
'
123
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
内容は改行できる
'
,
()
=>
{
const
input
=
'
**123
\n
~~abc~~
\n
123**
'
;
...
...
@@ -315,7 +315,7 @@ describe('parser', () => {
TEXT
(
'
\n
123
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -327,7 +327,7 @@ describe('parser', () => {
TEXT
(
'
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
内容にはインライン構文を利用できる
'
,
()
=>
{
const
input
=
'
<small>abc**123**abc</small>
'
;
...
...
@@ -340,7 +340,7 @@ describe('parser', () => {
TEXT
(
'
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
内容は改行できる
'
,
()
=>
{
const
input
=
'
<small>abc
\n
**123**
\n
abc</small>
'
;
...
...
@@ -353,7 +353,7 @@ describe('parser', () => {
TEXT
(
'
\n
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -365,7 +365,7 @@ describe('parser', () => {
TEXT
(
'
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
内容にはインライン構文を利用できる
'
,
()
=>
{
const
input
=
'
<i>abc**123**abc</i>
'
;
...
...
@@ -378,7 +378,7 @@ describe('parser', () => {
TEXT
(
'
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
内容は改行できる
'
,
()
=>
{
const
input
=
'
<i>abc
\n
**123**
\n
abc</i>
'
;
...
...
@@ -391,7 +391,7 @@ describe('parser', () => {
TEXT
(
'
\n
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -403,7 +403,7 @@ describe('parser', () => {
TEXT
(
'
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -419,7 +419,7 @@ describe('parser', () => {
it
(
'
and unicode emoji
'
,
()
=>
{
const
input
=
'
#️⃣abc123#abc
'
;
const
output
=
[
UNI_EMOJI
(
'
#️⃣
'
),
TEXT
(
'
abc123
'
),
HASHTAG
(
'
abc
'
)];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -431,7 +431,7 @@ describe('parser', () => {
N_URL
(
'
https://misskey.io/@ai
'
),
TEXT
(
'
.
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -444,7 +444,7 @@ describe('parser', () => {
]),
TEXT
(
'
.
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
silent flag
'
,
()
=>
{
...
...
@@ -455,7 +455,7 @@ describe('parser', () => {
]),
TEXT
(
'
.
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
do not yield url node even if label is recognisable as a url
'
,
()
=>
{
...
...
@@ -467,7 +467,7 @@ describe('parser', () => {
]),
TEXT
(
'
.
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
do not yield link node even if label is recognisable as a link
'
,
()
=>
{
...
...
@@ -479,7 +479,7 @@ describe('parser', () => {
]),
TEXT
(
'
.
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -491,7 +491,7 @@ describe('parser', () => {
TEXT
(
'
abc
'
)
])
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
@@ -521,6 +521,6 @@ after`;
]),
TEXT
(
'
after
'
)
];
assert
.
deepStrictEqual
(
parse
(
input
),
output
);
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment