- 按键认证大神
- 2699998
- 3587
- 11
- 2173 朵
- 7386 个
- 1021 个
- 91120
- 2014-08-23
|
1#
t
T
发表于 2022-04-04 22:32
|
|只看楼主
断言是什么? “断言” 在语文中的意思是“断定”、“十分肯定地说” 在编程中是指对某种假设条件进行检测。 如果条件成立就不进行任何操作, 如果条件不成立就捕捉到这种错误, 并打印出错误信息,终止程序执行。
| 在《代码大全 Code Complete》中对断言的解释 1、用错误处理代码来处理预期会发生的情况,用断言来处理绝不应该发生的情况 2、把断言看作是可执行的注释——你不能依赖它来让代码正常工作,但与编程语言中的注释相比,它能更主动的对程序中的假定做出说明。
| 断言的目的是为了我们开发者能更容易发现自己的业务逻辑错误,且不影响到程序实际生产的效率。 | 插件预览插件例子-断言成功- ' 导入神梦断言插件
- Import "SmAssert.dll"
- ' 判断插件版本号
- SmAssert "1.1.0.0" = SmAssert.Ver(), "出错,插件版本号不匹配!"
- ' 断言成功例子
- SmAssert.IsTrue True
- SmAssert.IsFalse False
- SmAssert.IsEquals 1, 1
- SmAssert.IsNotEquals 1, 2
- SmAssert.IsContains "神梦插件", "神梦科技|神梦无痕|神梦插件"
- SmAssert.IsNotContains "SMWH", "神梦科技|神梦无痕|神梦插件"
- SmAssert.IsMatches "QQ:\d+", "QQ:1042207232"
- SmAssert.IsNotMatches "QQ:\d+", "作者:神梦无痕"
- SmAssert.IsBetween 1, 100, 88
- SmAssert.IsNotBetween 99, 0, 666
- SmAssert.That Array(3.14, "SMWH"), "=", Array(3.14, "SMWH")
- SmAssert.That Null, "=", Null
- SmAssert.That Empty, "=", Empty
- SmAssert.That 1024, "=", 1024
- SmAssert.That 1024, ">", 1000
- SmAssert.That 1024, "<", 2048
- SmAssert.That "SMWHff", ">=", "SMWH"
- SmAssert.That "神梦", "<=", "神梦无痕"
- SmAssert.That 0.1 + 0.2, "~=", 0.3
- SmAssert.That 1 + 1, "<>", 3
- SmAssert.That 1 + 1, "!=", 4
- SmAssert.That "天使", "In", "每个人心中都住着[天使]"
- SmAssert.That "魔鬼", "Not In", "每个人心中都住着[天使]"
- SmAssert.That "傲慢", "In", Array("傲慢", "嫉妒", "暴怒", "懒惰", "贪婪", "暴食", "色欲")
- SmAssert.That "自私", "Not In", Array("傲慢", "嫉妒", "暴怒", "懒惰", "贪婪", "暴食", "色欲")
- SmAssert.That Array("富强", "和谐", "爱国", "敬业", "友善"), "In", Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法制", "爱国", "敬业", "诚信", "友善")
- SmAssert.That Array("可爱", "高富帅"), "Not In", Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法制", "爱国", "敬业", "诚信", "友善")
- SmAssert.That SmAssert, "Is", SmAssert
- SmAssert.That SmAssert, "Not Is", Nothing
复制代码 插件例子-断言失败- ' 导入神梦断言插件
- Import "SmAssert.dll"
- '判断插件版本
- SmAssert "1.0.0.0" = SmAssert.Ver(), "出错,插件版本号不匹配!"
- ' 断言失败例子
- SmAssert.Fail
- SmAssert.IsTrue False
- SmAssert.IsFalse True
- SmAssert.IsEquals 1, 2
- SmAssert.IsNotEquals 1, 1
- SmAssert.IsContains "SMWH", "神梦科技|神梦无痕|神梦插件"
- SmAssert.IsNotContains "神梦插件", "神梦科技|神梦无痕|神梦插件"
- SmAssert.IsMatches "QQ:\d+", "作者:神梦无痕"
- SmAssert.IsNotMatches "QQ:\d+", "QQ:1042207232"
- SmAssert.IsBetween 1, 100, 888
- SmAssert.IsBetween 99, 0, 66
- SmAssert.That Array(3.14, "SMWH"), "=", Array("SMWH")
- SmAssert.That Null, "=", "Null"
- SmAssert.That Empty, "=", "Empty"
- SmAssert.That 1024, "=", 10240
- SmAssert.That 1024, ">", 10000
- SmAssert.That 1024, "<", 0.2048
- SmAssert.That "SMWH", ">=", "SMWHff"
- SmAssert.That "神梦无痕", "<=", "神梦"
- SmAssert.That 0.1 + 0.2, "~=", 3
- SmAssert.That 1 + 1, "<>", 2
- SmAssert.That 1 + 1, "!=", 2
- SmAssert.That "天使", "In", "每个人心中都住着[恶魔]"
- SmAssert.That "魔鬼", "Not In", "每个人心中都住着[魔鬼]"
- SmAssert.That "自私", "In", Array("傲慢", "嫉妒", "暴怒", "懒惰", "贪婪", "暴食", "色欲")
- SmAssert.That "傲慢", "Not In", Array("傲慢", "嫉妒", "暴怒", "懒惰", "贪婪", "暴食", "色欲")
- SmAssert.That Array("懒惰", "贪婪"), "In", Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法制", "爱国", "敬业", "诚信", "友善")
- SmAssert.That Array("富强", "民主"), "Not In", Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法制", "爱国", "敬业", "诚信", "友善")
- SmAssert.That SmAssert, "Is", Nothing
- SmAssert.That SmAssert, "Not Is", SmAssert
复制代码 插件下载百度网盘:https://pan.baidu.com/s/1bQSH7eLQgBJsBayZXr9i6Q?pwd=96kg 提取密码: 96kg
交流Q群: 624655641
|