支持使用负数

This commit is contained in:
2024-06-30 15:23:29 +08:00
parent 5599e5d024
commit 68f377ceda
2 changed files with 17 additions and 7 deletions

View File

@@ -6,6 +6,18 @@
#include <Order.h>
#include "OptionsException.h"
TEST(Option, ) {
try {
ling::Order order({"--number", "-10"});
const auto number = order.addOption({"-n", "--number"}, ling::Order::INT);
order.analysis();
ASSERT_TRUE(number.isExistence());
ASSERT_EQ(number.getInt64(), -10);
} catch (const ling::OptionsException &e) {
ASSERT_FALSE(e.what());
}
}
TEST(Option, 16) {
try {
ling::Order order({"--hex", "0x1F", "--hex2", "0x1f"});
@@ -66,8 +78,12 @@ TEST(Option, 异常参数测试) {
const auto cancel = order.addOption({"--cancel"});
try {
order.analysis();
ASSERT_FALSE("异常处理失败");
ASSERT_EQ(pts.getString(), "--all");
ASSERT_FALSE(all.isExistence());
ASSERT_TRUE(ok.isExistence());
ASSERT_FALSE(cancel.isExistence());
} catch (const ling::OptionsException &e) {
ASSERT_FALSE("解析失败");
}
}