-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4998 from vector-im/feature/bma/command_parser
Small iteration on command parser
- Loading branch information
Showing
5 changed files
with
113 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Small iteration on command parser and unit test it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
vector/src/test/java/im/vector/app/features/command/CommandParserTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.command | ||
|
||
import org.amshove.kluent.shouldBeEqualTo | ||
import org.junit.Test | ||
|
||
class CommandParserTest { | ||
@Test | ||
fun parseSlashCommandEmpty() { | ||
test("/", ParsedCommand.ErrorEmptySlashCommand) | ||
} | ||
|
||
@Test | ||
fun parseSlashCommandUnknown() { | ||
test("/unknown", ParsedCommand.ErrorUnknownSlashCommand("/unknown")) | ||
test("/unknown with param", ParsedCommand.ErrorUnknownSlashCommand("/unknown")) | ||
} | ||
|
||
@Test | ||
fun parseSlashCommandNotACommand() { | ||
test("", ParsedCommand.ErrorNotACommand) | ||
test("test", ParsedCommand.ErrorNotACommand) | ||
test("// test", ParsedCommand.ErrorNotACommand) | ||
} | ||
|
||
@Test | ||
fun parseSlashCommandEmote() { | ||
test("/me test", ParsedCommand.SendEmote("test")) | ||
test("/me", ParsedCommand.ErrorSyntax(Command.EMOTE)) | ||
} | ||
|
||
@Test | ||
fun parseSlashCommandRemove() { | ||
// Nominal | ||
test("/remove @foo:bar", ParsedCommand.RemoveUser("@foo:bar", null)) | ||
// With a reason | ||
test("/remove @foo:bar a reason", ParsedCommand.RemoveUser("@foo:bar", "a reason")) | ||
// Trim the reason | ||
test("/remove @foo:bar a reason ", ParsedCommand.RemoveUser("@foo:bar", "a reason")) | ||
// Alias | ||
test("/kick @foo:bar", ParsedCommand.RemoveUser("@foo:bar", null)) | ||
// Error | ||
test("/remove", ParsedCommand.ErrorSyntax(Command.REMOVE_USER)) | ||
} | ||
|
||
private fun test(message: String, expectedResult: ParsedCommand) { | ||
val commandParser = CommandParser() | ||
val result = commandParser.parseSlashCommand(message) | ||
result shouldBeEqualTo expectedResult | ||
} | ||
} |