Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-decorators
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
koishi-decorators
Commits
f95469e6
Commit
f95469e6
authored
Mar 13, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests
parent
4a46240e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
src/registry/registries/command-put.ts
src/registry/registries/command-put.ts
+1
-1
tests/register.spec.ts
tests/register.spec.ts
+16
-2
No files found.
src/registry/registries/command-put.ts
View file @
f95469e6
...
...
@@ -47,7 +47,7 @@ export namespace CommandPut {
preRegistry
.
extend
(
'
arg
'
,
(
data
,
cmd
,
ctx
,
nativeType
)
=>
{
let
arg
=
cmd
.
_arguments
[
data
.
index
];
if
(
arg
)
{
if
(
!
arg
)
{
arg
=
{};
cmd
.
_arguments
[
data
.
index
]
=
arg
;
}
...
...
tests/register.spec.ts
View file @
f95469e6
import
{
CommandUsage
,
PutArg
,
PutOption
,
UseCommand
,
UseEvent
,
UseMiddleware
,
}
from
'
../src/decorators
/decorators
'
;
}
from
'
../src/decorators
'
;
import
{
App
,
Command
,
Next
,
Session
}
from
'
koishi
'
;
import
{
Registrar
}
from
'
../src/register
'
;
import
{
EventNameAndPrepend
}
from
'
../src/def
'
;
...
...
@@ -30,6 +31,11 @@ class MyClass {
async
onEcho
(@
PutOption
(
'
content
'
,
'
-c <content>
'
)
content
:
string
)
{
return
`bot:
${
content
}
`
;
}
@
UseCommand
(
'
count
'
)
async
onCount
(@
PutArg
(
0
)
count
:
number
)
{
return
`I have
${
count
}
dresses.`
;
}
}
const
registrar
=
new
Registrar
(
new
MyClass
());
...
...
@@ -54,7 +60,7 @@ describe('Register', () => {
expect
((
result
.
data
as
EventNameAndPrepend
).
name
).
toBe
(
'
message
'
);
});
it
(
'
should register command
'
,
()
=>
{
it
(
'
should register command
and infer option type
'
,
()
=>
{
const
result
=
registrar
.
register
(
app
,
'
onEcho
'
);
expect
(
result
.
type
).
toBe
(
'
command
'
);
const
command
:
Command
=
result
.
result
;
...
...
@@ -65,4 +71,12 @@ describe('Register', () => {
'
bot: hello
'
,
);
});
it
(
'
should infer argument type
'
,
()
=>
{
const
result
=
registrar
.
register
(
app
,
'
onCount
'
);
expect
(
result
.
type
).
toBe
(
'
command
'
);
const
command
:
Command
=
result
.
result
;
expect
(
command
.
_arguments
[
0
].
type
).
toBe
(
'
number
'
);
expect
(
command
.
execute
({
args
:
[
'
4
'
]
})).
resolves
.
toBe
(
'
I have 4 dresses.
'
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment