diff --git a/.gitignore b/.gitignore
index fc8e2f844179d54cab90ac79d6f4dd4d2729270c..c0599005619158ee62620d5fc584217fda209e8e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,4 +9,10 @@
/entry/.preview
.cxx
/node_modules
-**/package-lock.json
\ No newline at end of file
+/.preview
+**/build
+.hvigor
+**/package-lock.json
+/oh_modules
+/entry/oh_modules
+/oh-package-lock.json5
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 83a93bb65c32856a6923ada5122d404106238e0f..6a1f6c3777fb9626354df857df61b786e50756d4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## v2.0.0
+
+- 适配DevEco Studio 版本:4.0 Beta2(4.0.3.600),OpenHarmony SDK:API10(4.0.10.11)
+- ArkTS新语法适配
+
## v1.0.2
- 适配DevEco Studio 版本:3.1 Beta1(3.1.0.200),OpenHarmony SDK:API9(3.2.10.6)
diff --git a/OAT.xml b/OAT.xml
index e480420805d62fc02ef582ed19f3758a11db26f8..da697f87b1b2a9bac400d76948ac39ddf73065ba 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -17,6 +17,18 @@
desc="版权免责声明文件,无需修改"
name="NOTICE"
type="filename"/>
+
+
+
+
+
+
+
+
+
diff --git a/README.OpenSource b/README.OpenSource
index 1c4f51e612598f7f9eaab0d1604fbd5e8111a681..b354aa5f8dcd4513141d836b048e92a79932f293 100644
--- a/README.OpenSource
+++ b/README.OpenSource
@@ -4,8 +4,8 @@
"License": "BSD License",
"License File": " LICENSE ",
"Version Number": "2.2",
- "Owner" : "Hamcrest"
+ "Owner" : "xiafeng@huawei.com"
"Upstream URL": "https://github.com/hamcrest/JavaHamcrest",
- "Description": "Java (and original) version of Hamcrest"
+ "Description": "Hamcrest is a library of matchers, which can be combined in to create flexible expressions of intent in tests. They've also been used for other purposes"
}
]
\ No newline at end of file
diff --git a/README.md b/README.md
index fd9ee608267a566c1e373335e42563989f839333..3f568191dee14ae6a5d984c8dca09f811f4e44fa 100644
--- a/README.md
+++ b/README.md
@@ -7,9 +7,9 @@
## 下载安装
```shell
-npm install @ohos/hamcrest --save
+ohpm install @ohos/hamcrest
```
-OpenHarmony npm环境配置等更多内容,请参考 [如何安装OpenHarmony npm包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_npm_usage.md) 。
+OpenHarmony ohpm环境配置等更多内容,请参考 [如何安装OpenHarmony ohpm包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md) 。
## 使用说明
1. 引入文件及代码依赖
@@ -24,12 +24,222 @@ OpenHarmony npm环境配置等更多内容,请参考 [如何安装OpenHarmony
3. 调用匹配器匹配
```
- allOf() {
- let matcher = AllOf.allOfMatches(StringContains.containsString('expected'), StringContains.containsString('value'))
- console.info("allOf: " + matcher.matches('expected value'))
- console.info("allOf: " + matcher.matches('value expected'))
- console.info("allOf: " + matcher.matches('expected valu'))
- }
+hasProperty() {
+ let matcher = HasProperty.hasProperty('name')
+ console.info(TAG + "hasProperty: " + matcher.matches({ name: 'Joe' }))
+ console.info(TAG + "hasProperty: " + matcher.matches({ name: 'Joel' }))
+ console.info(TAG + "hasProperty: " + matcher.matches({ age: 19 }))
+ }
+
+ hasLength() {
+ let matcher = CharSequenceLength.hasLength(4);
+ console.info(TAG + "hasLength: " + matcher.matches('aaaa'))
+ console.info(TAG + "hasLength: " + matcher.matches('aaa'))
+ console.info(TAG + "hasLength: " + matcher.matches('aa a'))
+ }
+
+ anyOf() {
+ let matcherAnyOf = AnyOf.anyOfMatches(IsBlankString.blankString(),
+ IsEqualIgnoringCase.equalToIgnoringCase('aaa'))
+ console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches('AAA'))
+ console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches('bbb'))
+ console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches(''))
+ console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches('\n\r\t'))
+ }
+
+ containsString() {
+ let matcher = StringContains.containsString('rat')
+ console.info(TAG + "containsString: " + matcher.matches('jim the rat'))
+ console.info(TAG + "containsString: " + matcher.matches('jim the rats'))
+ let matcher2 = StringContains.containsString('rats');
+ console.info(TAG + "containsString: " + matcher2.matches('jim the rat'))
+ let matcher3 = StringContains.containsStringIgnoringCase('Jim')
+ console.info(TAG + "containsStringIgnoringCase: " + matcher3.matches('jim the rat'))
+ }
+
+ allOf() {
+ let matcher = AllOf.allOfMatches(StringContains.containsString('expected'), StringContains.containsString('value'))
+ console.info(TAG + "allOf: " + matcher.matches('expected value'))
+ console.info(TAG + "allOf: " + matcher.matches('value expected'))
+ console.info(TAG + "allOf: " + matcher.matches('expected valu'))
+ }
+
+ endsWith() {
+ let matcher = StringEndsWith.endsWith('test')
+ console.info(TAG + "endsWith: " + matcher.matches('aaabbbtest'))
+ console.info(TAG + "endsWith: " + matcher.matches('aaabbbtests'))
+ console.info(TAG + "endsWith: " + matcher.matches('testdjsdojw'))
+
+ let matcher2 = StringEndsWith.endsWithIgnoringCase('Test')
+ console.info(TAG + "endsWithIgnoringCase: " + matcher2.matches('this test'))
+ }
+
+ isNaN() {
+ let matcher = IsNaN.notANumber()
+ console.info(TAG + "isNaN: " + matcher.matches(7))
+ console.info(TAG + "isNaN: " + matcher.matches(7.7))
+ console.info(TAG + "isNaN: " + matcher.matches(Number.NaN))
+ }
+
+ isEqual() {
+ const value = [1, 2]
+ let matcher = IsEqual.equalTo(value)
+ console.info(TAG + "isEqual: " + matcher.matches([1, 3]))
+ console.info(TAG + "isEqual: " + matcher.matches([1, 2]))
+ let matcher2 = IsEqual.equalTo("string value")
+ console.info(TAG + "isEqual: " + matcher2.matches("string value"))
+ console.info(TAG + "isEqual: " + matcher2.matches("string values"))
+ }
+
+ equalIgnoringCase() {
+ let matcher = IsEqualIgnoringCase.equalToIgnoringCase('Hello')
+ console.log(TAG + 'equalIgnoringCase:' + matcher.matches('heLLo'))
+ console.log(TAG + 'equalIgnoringCase:' + matcher.matches('hello'))
+ console.log(TAG + 'equalIgnoringCase:' + matcher.matches('HELLO'))
+ }
+
+ orderingComparison() {
+ let matcher = OrderingComparison.greaterThan(5)
+ console.log(TAG + 'orderingComparison:' + matcher.matches('6'))
+ console.log(TAG + 'orderingComparison:' + matcher.matches('4'))
+ console.log(TAG + 'orderingComparison:' + matcher.matches('5'))
+
+ let matcher2 = OrderingComparison.greaterThanOrEqualTo(5)
+ console.log(TAG + 'orderingComparison:' + matcher2.matches('6'))
+ console.log(TAG + 'orderingComparison:' + matcher2.matches('4'))
+ console.log(TAG + 'orderingComparison:' + matcher2.matches('5'))
+
+ let matcher3 = OrderingComparison.lessThan(5)
+ console.log(TAG + 'orderingComparison:' + matcher3.matches('6'))
+ console.log(TAG + 'orderingComparison:' + matcher3.matches('4'))
+ console.log(TAG + 'orderingComparison:' + matcher3.matches('5'))
+
+ let matcher4 = OrderingComparison.lessThanOrEqualTo(5)
+ console.log(TAG + 'orderingComparison:' + matcher4.matches('6'))
+ console.log(TAG + 'orderingComparison:' + matcher4.matches('4'))
+ console.log(TAG + 'orderingComparison:' + matcher4.matches('5'))
+
+ let matcher5 = OrderingComparison.comparesEqualTo(5)
+ console.log(TAG + 'orderingComparison:' + matcher5.matches(5.00))
+ console.log(TAG + 'orderingComparison:' + matcher5.matches(5.1))
+ console.log(TAG + 'orderingComparison:' + matcher5.matches(0.0))
+ }
+
+ isBlackString() {
+ let matcher = IsBlankString.blankString();
+ console.log(TAG + 'isBlackString :' + matcher.matches(''))
+ console.log(TAG + 'isBlackString :' + matcher.matches('\n\r\t'))
+
+ let matcher2 = IsBlankString.blankOrNullString();
+ console.log(TAG + 'isBlackString: enter matcher2:' + matcher2.matches('\n\r\t'))
+ console.log(TAG + 'isBlackString: enter matcher2:' + matcher2.matches('null'))
+ console.log(TAG + 'isBlackString: enter matcher2:' + matcher2.matches(null))
+ }
+
+ isCloseTo() {
+ let matcher = IsCloseTo.closeTo(1.1, 0.0);
+ console.log(TAG + 'IsCloseTo :' + matcher.matches(1.10))
+
+ let matcher2 = IsCloseTo.closeTo(1.111111111, 0.0);
+ console.log(TAG + 'IsCloseTo :' + matcher2.matches(1.1111111112))
+ }
+
+ isNull() {
+ let matcher = IsNull.nullValue()
+ console.log(TAG + 'isNull :' + matcher.matches(null))
+ console.log(TAG + 'isNull :' + matcher.matches('null'))
+ console.log(TAG + 'isNull :' + matcher.matches(''))
+ }
+
+ combinationMatch() {
+ let matcher = IsNot.not(StringContains.containsString('expected'));
+ console.info(TAG + "combinationMatch: " + matcher.matches("expected value"))
+ console.info(TAG + "combinationMatch: " + matcher.matches('another value'))
+
+ let match = Is.is(StringStartsWith.startsWith('hamjest'))
+ console.info(TAG + "combinationMatch: " + match.matches('hamjest is awesome'))
+ }
+
+ isArray() {
+ let matcher: Matcher = IsArray.array(IsEqual.equalTo('a'), IsEqual.equalTo('b'), IsEqual.equalTo('c'))
+ console.info(TAG + "isArray: " + matcher.matches(['a', 'b', 'c']))
+ console.info(TAG + "isArray: " + matcher.matches(['a', 'd', 'b']))
+ console.info(TAG + "isArray: " + matcher.matches(['a', 'b']))
+ }
+
+ isIn() {
+ let matcher: Matcher = IsIn.isIn(["bar", "foo"])
+ console.info(TAG + "isIn: " + matcher.matches("bar"))
+ console.info(TAG + "isIn: " + matcher.matches(["bar", "foo"]))
+
+ }
+
+ every() {
+ let matcher: Matcher> = Every.everyItem(StringContains.containsString('a'))
+ console.info(TAG + "every: " + matcher.matches(["AaA", "BaB", "CaC"]))
+ console.info(TAG + "every: " + matcher.matches(["AAA", "BaB", "CbC"]))
+ }
+
+ matchesPattern() {
+ let matcher = MatchesPattern.matchesPattern(new RegExp('bb'))
+ console.info(TAG + "matchesPattern: " + matcher.matches('aabbcc'))
+ console.info(TAG + "matchesPattern: " + matcher.matches('aabcc'))
+ console.info(TAG + "matchesPattern: " + matcher.matches('abc'))
+
+ let matcher2 = MatchesPattern.matchesStringPattern("^Hello.*$")
+ console.info(TAG + "matchesPattern: " + matcher2.matches('Hello, world!'))
+ console.info(TAG + "matchesPattern: " + matcher2.matches('ello, world!'))
+ }
+
+ isEqualCompressingWhiteSpace() {
+ let matcher = IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace('hamjest')
+ console.info(TAG + "isEqualCompressingWhiteSpace: " + matcher.matches(' hamjest'))
+ console.info(TAG + "isEqualCompressingWhiteSpace: " + matcher.matches(' ham jest'))
+ console.info(TAG + "isEqualCompressingWhiteSpace: " + matcher.matches('Ham jest'))
+ }
+
+ isSame() {
+ let arr: Array = new Array(1)
+ arr[0] = "hello"
+
+ let arr1: Array = new Array(1)
+ arr1[0] = "hello"
+
+ let matcher = IsSame.sameInstance(arr)
+ console.info(TAG + "isSame sameInstance: " + matcher.matches(arr))
+ console.info(TAG + "isSame: sameInstance" + matcher.matches(arr1))
+
+ let str: string = "hello"
+ let matcher1 = IsSame.theInstance(str)
+ console.info(TAG + "isSame: theInstance:" + matcher1.matches(str))
+
+ let matcher2 = IsSame.theInstance(arr)
+ console.info(TAG + "isSame: theInstance:" + matcher2.matches(arr1))
+ }
+
+ isIterableContaining() {
+ let map: Map = new Map()
+ map.set("name", "张三")
+ let matcher = IsIterableContaining.hasItem(StringContains.containsString('张三'))
+ console.info(TAG + "isIterableContaining hasItem : " + matcher.matches(map))
+
+ let matcher1 = IsIterableContaining.hasItem(StringContains.containsString('王'))
+ console.info(TAG + "isIterableContaining hasItem : " + matcher1.matches(map))
+ }
+
+ isEmptyString() {
+ let matcher :Matcher= IsEmptyString.emptyString()
+ let test:string=""
+ console.info(TAG + "isEmptyString : " + matcher.matches(test))
+
+ let test2:string="hello"
+ console.info(TAG + "isEmptyString : " + matcher.matches(test2))
+
+ let matcher2 = IsEmptyString.emptyOrNullString()
+ console.info(TAG + "isEmptyString : " + matcher2.matches(""))
+ console.info(TAG + "isEmptyString : " + matcher2.matches("z"))
+ console.info(TAG + "isEmptyString : " + matcher2.matches(null))
+ }
```
## 接口说明
@@ -49,7 +259,7 @@ OpenHarmony npm环境配置等更多内容,请参考 [如何安装OpenHarmony
在下述版本验证通过:
-- DevEco Studio 版本:3.1 Beta1(3.1.0.200),OpenHarmony SDK:API9(3.2.10.6)
+- DevEco Studio 版本:4.0 Beta2(4.0.3.600),OpenHarmony SDK:API10(4.0.10.11)
## 目录结构
````
@@ -60,11 +270,63 @@ OpenHarmony npm环境配置等更多内容,请参考 [如何安装OpenHarmony
| |---- src
| |---- main
| |---- components
+| |---- beans # 核心文件夹
+| |---- HasProperty.ts # 匹配属性
+| |---- collection # 集合核心文件夹
+| |---- ArrayMatching.ts # 数组匹配器
+| |---- HasItemInArray.ts # 匹配数组是否包含某一个item
+| |---- IsArray.ts # 匹配是否是一个数组
+| |---- IsArrayWithSize.ts # 匹配是某一个长度的数组
+| |---- IsIn.ts # 某一个元素是否包含在某一个数组
+| |---- IsMapContaining.ts # Map匹配器
+| |---- IsMapWithSize.ts # 判断是某一个长度的Map
| |---- core # 核心文件夹
-| |---- Every.ets # 匹配每一个
-| |---- AllOf.ets # 匹配所有
-| |---- IsAnything.ets # 匹配任意
-| |---- StringContains.ets # 匹配包含字符串
+| |---- Every.ts # 匹配每一个
+| |---- AllOf.ts # 匹配所有
+| |---- AnyOf.ts # 匹配任意
+| |---- CombinableMatcher.ts # 组合匹配器
+| |---- Is.ts # 是否是
+| |---- IsEqual.ts # 是否相等
+| |---- IsAnything.ts # 匹配任意
+| |---- IsInstanceOf.ts # 类型匹配
+| |---- IsIterableContaining.ts # 可迭代包含
+| |---- IsNot.ts # 计算匹配器的逻辑否定
+| |---- IsNull.ts # 是否是NUll
+| |---- IsSame.ts # 是不是一样
+| |---- ShortcutCombination.ts # 快捷组合方式
+| |---- StringContains.ts # 匹配包含字符串
+| |---- StringEndsWith.ts # 是否是以特定子字符串结尾。
+| |---- StringRegularExpression.ts # 字符串规则表达
+| |---- StringStartsWith.ts # 是否是以特定子字符串开始。
+| |---- SubstringMatcher.ts # 字符串截取匹配器
+| |---- internal # 核心文件夹
+| |---- ArrayIterator.ts # 数组迭代器
+| |---- NullSafety.ts # null是否安全
+| |---- SelfDescribingValue.ts # 自描述值
+| |---- SelfDescribingValueIterator.ts # 自描述值迭代器
+| |---- number # 核心文件夹
+| |---- IsCloseTo.ts # 是否在一个区间
+| |---- IsNaN.ts # 是否是NaN
+| |---- OrderingComparison.ts # 排序比较
+| |---- text # 核心文件夹
+| |---- CharSequenceLength.ts # 字符序列长度
+| |---- IsBlankString.ts # 是否是空字符串
+| |---- IsEmptyString.ts # 是否是空字符串
+| |---- IsEqualCompressingWhiteSpace.ts # 是否等于压缩空格
+| |---- IsEqualIgnoringCase.ts # 是否相等忽略大小写
+| |---- MatchesPattern.ts # 匹配器模型
+| |---- BaseDescription.ts # 描述基类
+| |---- BaseMatcher.ts # 匹配器基类
+| |---- CustomMatcher.ts # 自定义匹配器
+| |---- Description.ts # 描述
+| |---- DiagnosingMatcher.ts # 诊断匹配器
+| |---- FeatureMatcher.ts # 特性匹配
+| |---- Matcher.ts # 匹配器
+| |---- MatcherAssert.ts #匹配器断言
+| |---- NullDescription.ts # Null描述
+| |---- SelfDescribing.ts # 描述自身的能力
+| |---- StringDescription.ts # 字符串描述
+
| |---- README.md # 安装使用方法
````
diff --git a/TEST.md b/TEST.md
new file mode 100644
index 0000000000000000000000000000000000000000..dbbc83611344638ef5009ab994c694d5f30423bc
--- /dev/null
+++ b/TEST.md
@@ -0,0 +1,45 @@
+## Hamcrest单元测试用例
+
+该测试用例基于OpenHarmony系统下,采用[原库测试用例](https://github.com/hamcrest/JavaHamcrest/tree/master/hamcrest/src/test/java/org/hamcrest) 进行单元测试
+
+**单元测试用例覆盖情况**
+
+### Hamcrest
+
+| 接口名 | 是否通过 | 备注 |
+|-----------------------------------------------------------| -------- | ---- |
+| HasProperty.hasProperty | pass | |
+| CharSequenceLength.hasLength | pass | |
+| AnyOf.anyOfMatches | pass | |
+| StringContains.containsString | pass | |
+| AllOf.allOfMatches | pass | |
+| StringEndsWith.endsWith | pass | |
+| StringEndsWith.endsWithIgnoringCase | pass | |
+| StringStartWith.endsWith | pass | |
+| StringStartWith.endsWithIgnoringCase | pass | |
+| IsNaN.notANumber | pass | |
+| IsEqual.equalTo | pass | |
+| IsEqualIgnoringCase.equalToIgnoringCase | pass | |
+| OrderingComparison.greaterThan | pass | |
+| OrderingComparison.greaterThanOrEqualT | pass | |
+| OrderingComparison.lessThan | pass | |
+| OrderingComparison.lessThanOrEqualTo | pass | |
+| OrderingComparison.comparesEqualTo | pass | |
+| IsBlankString.blankString | pass | |
+| IsBlankString.blankOrNullString | pass | |
+| IsCloseTo.closeTo | pass | |
+| IsNull.nullValue | pass | |
+| IsNot.not | pass | |
+| Is.is | pass | |
+| IsArray.array | pass | |
+| IsIn.isIn | pass | |
+| Every.everyItem | pass | |
+| MatchesPattern.matchesStringPattern | pass | |
+| MatchesPattern.matchesPattern | pass | |
+| IsEqualCompressingWhiteSpace.equalToIgnoringWhiteSpace | pass | |
+| IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace | pass | |
+| IsSame.sameInstance | pass | |
+| IsSame.theInstance | pass | |
+| IsIterableContaining.hasItem | pass | |
+| IsEmptyString.emptyString | pass | |
+| IsEmptyString.emptyOrNullString | pass | |
\ No newline at end of file
diff --git a/build-profile.json5 b/build-profile.json5
index 281e050363d46c549f0e64e20286f901bd171fdb..e7a99ed23afa4383ac89113a569cb8635b7e92cc 100644
--- a/build-profile.json5
+++ b/build-profile.json5
@@ -1,13 +1,14 @@
{
"app": {
- "signingConfigs": [
- ],
- "compileSdkVersion": 9,
- "compatibleSdkVersion": 9,
+ "signingConfigs": [],
"products": [
{
"name": "default",
- "signingConfig": "default",
+ "compileSdkVersion": 10,
+ "compatibleSdkVersion": 10,
+ "targetSdkVersion": 10,
+ "runtimeOS": "OpenHarmony",
+ "signingConfig": "default"
}
]
},
diff --git a/entry/.gitignore b/entry/.gitignore
index 5a6ba80fa3d9498a23ae8ae7d9518f8743fa8a96..e2713a2779c5a3e0eb879efe6115455592caeea5 100644
--- a/entry/.gitignore
+++ b/entry/.gitignore
@@ -1,4 +1,6 @@
/node_modules
+/oh_modules
/.preview
/build
-/.cxx
\ No newline at end of file
+/.cxx
+/.test
\ No newline at end of file
diff --git a/entry/build-profile.json5 b/entry/build-profile.json5
index f8f03407f77914b43168aeca6bb0929efd6700b4..a4c1be63b3f0a3eb731a9b49d5af317a52b21c27 100644
--- a/entry/build-profile.json5
+++ b/entry/build-profile.json5
@@ -1,6 +1,7 @@
{
"apiType": 'stageMode',
"buildOption": {
+ "compileMode": "esmodule"
},
"targets": [
{
diff --git a/entry/package.json b/entry/oh-package.json5
similarity index 84%
rename from entry/package.json
rename to entry/oh-package.json5
index d7f66cc552f18506126491d5134b2a46d63a8cc2..48abbe288b616b949dc5f3307c4df1afde8652a8 100644
--- a/entry/package.json
+++ b/entry/oh-package.json5
@@ -1,6 +1,7 @@
{
"license": "BSD License",
"devDependencies": {},
+ "author": "",
"name": "entry",
"ohos": {
"org": "huawei",
@@ -8,8 +9,8 @@
"buildTool": "hvigor"
},
"description": "example description",
- "repository": {},
- "version": "1.0.2",
+ "main": "",
+ "version": "2.0.0",
"dependencies": {
"@ohos/hamcrest": "file:../hamcrest"
}
diff --git a/entry/src/main/ets/entryability/EntryAbility.ts b/entry/src/main/ets/entryability/EntryAbility.ts
index 23a118a770b242511d842c4a225574f7fbd3925f..cff257d2f4beb37d9b4a42fde3ed38b7a24bdce2 100644
--- a/entry/src/main/ets/entryability/EntryAbility.ts
+++ b/entry/src/main/ets/entryability/EntryAbility.ts
@@ -30,7 +30,7 @@ export default class EntryAbility extends UIAbility {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
- windowStage.loadContent('pages/Index', (err, data) => {
+ windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
diff --git a/entry/src/main/ets/pages/index.ets b/entry/src/main/ets/pages/index.ets
index a9f6850d1f692454101aeec1fa5f5c741f79a3c5..37d4391e40ead8974589ec1e24c9ddde34a5c74d 100644
--- a/entry/src/main/ets/pages/index.ets
+++ b/entry/src/main/ets/pages/index.ets
@@ -13,424 +13,625 @@
* limitations under the License.
*/
-import {HasProperty} from '@ohos/hamcrest'
-import {StringContains} from '@ohos/hamcrest'
-import {StringStartsWith} from '@ohos/hamcrest'
-import {StringEndsWith} from '@ohos/hamcrest'
-import {AllOf} from '@ohos/hamcrest'
-import {AnyOf} from '@ohos/hamcrest'
-import {IsNot} from '@ohos/hamcrest'
-import {Is} from '@ohos/hamcrest'
-import {IsEqual} from '@ohos/hamcrest'
-import {IsNaN} from '@ohos/hamcrest'
-import {IsEqualIgnoringCase} from '@ohos/hamcrest'
-import {CharSequenceLength} from '@ohos/hamcrest'
-import {IsBlankString} from '@ohos/hamcrest'
-import {OrderingComparison} from '@ohos/hamcrest'
-import {IsCloseTo} from '@ohos/hamcrest'
-import {IsNull} from '@ohos/hamcrest'
-import {IsArray} from '@ohos/hamcrest'
-import {IsIn} from '@ohos/hamcrest'
-import {MatchesPattern} from '@ohos/hamcrest'
-import {Every} from '@ohos/hamcrest'
+import { HasProperty, IsEmptyString, IsEqualCompressingWhiteSpace, IsIterableContaining, IsSame } from '@ohos/hamcrest'
+import { StringContains } from '@ohos/hamcrest'
+import { StringStartsWith } from '@ohos/hamcrest'
+import { StringEndsWith } from '@ohos/hamcrest'
+import { AllOf } from '@ohos/hamcrest'
+import { AnyOf } from '@ohos/hamcrest'
+import { IsNot } from '@ohos/hamcrest'
+import { Is } from '@ohos/hamcrest'
+import { IsEqual } from '@ohos/hamcrest'
+import { IsNaN } from '@ohos/hamcrest'
+import { IsEqualIgnoringCase } from '@ohos/hamcrest'
+import { CharSequenceLength } from '@ohos/hamcrest'
+import { IsBlankString } from '@ohos/hamcrest'
+import { OrderingComparison } from '@ohos/hamcrest'
+import { IsCloseTo } from '@ohos/hamcrest'
+import { IsNull } from '@ohos/hamcrest'
+import { IsArray } from '@ohos/hamcrest'
+import { IsIn } from '@ohos/hamcrest'
+import { MatchesPattern } from '@ohos/hamcrest'
+import { Every } from '@ohos/hamcrest'
+import { Matcher } from '@ohos/hamcrest/src/main/ets/components/Matcher'
const TAG = 'HAMCREST '
@Entry
@Component
struct Index {
- scroller: Scroller = new Scroller()
-
- hasProperty() {
- let matcher = HasProperty.hasProperty('name')
- console.info(TAG + "hasProperty: " + matcher.matches({ name: 'Joe' }))
- console.info(TAG + "hasProperty: " + matcher.matches({ name: 'Joel' }))
- console.info(TAG + "hasProperty: " + matcher.matches({ age: 19 }))
- }
-
- hasLength() {
- let matcher = CharSequenceLength.hasLength(4);
- console.info(TAG + "hasLength: " + matcher.matches('aaaa'))
- console.info(TAG + "hasLength: " + matcher.matches('aaa'))
- console.info(TAG + "hasLength: " + matcher.matches('aa a'))
- }
-
- anyOf() {
- let matcherAnyOf = AnyOf.anyOfMatches(IsBlankString.blankString(),
- IsEqualIgnoringCase.equalToIgnoringCase('aaa'))
- console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches('AAA'))
- console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches('bbb'))
- console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches(''))
- console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches('\n\r\t'))
- }
-
- containsString() {
- let matcher = StringContains.containsString('rat')
- console.info(TAG + "containsString: " + matcher.matches('jim the rat'))
- console.info(TAG + "containsString: " + matcher.matches('jim the rats'))
- let matcher2 = StringContains.containsString('rats');
- console.info(TAG + "containsString: " + matcher2.matches('jim the rat'))
- }
-
- allOf() {
- let matcher = AllOf.allOfMatches(StringContains.containsString('expected'), StringContains.containsString('value'))
- console.info(TAG + "allOf: " + matcher.matches('expected value'))
- console.info(TAG + "allOf: " + matcher.matches('value expected'))
- console.info(TAG + "allOf: " + matcher.matches('expected valu'))
- }
-
- endsWith() {
- let matcher = StringEndsWith.endsWith('test')
- console.info(TAG + "endsWith: " + matcher.matches('aaabbbtest'))
- console.info(TAG + "endsWith: " + matcher.matches('aaabbbtests'))
- console.info(TAG + "endsWith: " + matcher.matches('testdjsdojw'))
- }
-
- isNaN() {
- let matcher = IsNaN.notANumber()
- console.info(TAG + "isNaN: " + matcher.matches(7))
- console.info(TAG + "isNaN: " + matcher.matches(7.7))
- console.info(TAG + "isNaN: " + matcher.matches(NaN))
- }
-
- isEqual() {
- const value = [1, 2]
- let matcher = IsEqual.equalTo(value)
- console.info(TAG + "isEqual: " + matcher.matches([1, 3]))
- console.info(TAG + "isEqual: " + matcher.matches([1, 2]))
- let matcher2 = IsEqual.equalTo("string value")
- console.info(TAG + "isEqual: " + matcher2.matches("string value"))
- console.info(TAG + "isEqual: " + matcher2.matches("string values"))
- }
-
- equalIgnoringCase() {
- let matcher = IsEqualIgnoringCase.equalToIgnoringCase('Hello')
- console.log(TAG + 'equalIgnoringCase:' + matcher.matches('heLLo'))
- console.log(TAG + 'equalIgnoringCase:' + matcher.matches('hello'))
- console.log(TAG + 'equalIgnoringCase:' + matcher.matches('HELLO'))
- }
-
- orderingComparison() {
- let matcher = OrderingComparison.greaterThan(5)
- console.log(TAG + 'orderingComparison:' + matcher.matches('6'))
- console.log(TAG + 'orderingComparison:' + matcher.matches('4'))
- console.log(TAG + 'orderingComparison:' + matcher.matches('5'))
-
- let matcher2 = OrderingComparison.greaterThanOrEqualTo(5)
- console.log(TAG + 'orderingComparison:' + matcher2.matches('6'))
- console.log(TAG + 'orderingComparison:' + matcher2.matches('4'))
- console.log(TAG + 'orderingComparison:' + matcher2.matches('5'))
-
- let matcher3 = OrderingComparison.lessThan(5)
- console.log(TAG + 'orderingComparison:' + matcher3.matches('6'))
- console.log(TAG + 'orderingComparison:' + matcher3.matches('4'))
- console.log(TAG + 'orderingComparison:' + matcher3.matches('5'))
-
- let matcher4 = OrderingComparison.lessThanOrEqualTo(5)
- console.log(TAG + 'orderingComparison:' + matcher4.matches('6'))
- console.log(TAG + 'orderingComparison:' + matcher4.matches('4'))
- console.log(TAG + 'orderingComparison:' + matcher4.matches('5'))
- }
-
- isBlackString() {
- let matcher = IsBlankString.blankString();
- console.log(TAG + 'isBlackString :' + matcher.matches(''))
- console.log(TAG + 'isBlackString :' + matcher.matches('\n\r\t'))
-
- let matcher2 = IsBlankString.blankOrNullString();
- console.log(TAG + 'isBlackString: enter matcher2:' + matcher2.matches('\n\r\t'))
- console.log(TAG + 'isBlackString: enter matcher2:' + matcher2.matches('null'))
- console.log(TAG + 'isBlackString: enter matcher2:' + matcher2.matches(null))
- }
-
- isCloseTo() {
- let matcher = IsCloseTo.closeTo(1.1, 0.0);
- console.log(TAG + 'IsCloseTo :' + matcher.matches(1.10))
-
- let matcher2 = IsCloseTo.closeTo(1.111111111, 0.0);
- console.log(TAG + 'IsCloseTo :' + matcher2.matches(1.1111111112))
- }
-
- isNull() {
- let matcher = IsNull.nullValue()
- console.log(TAG + 'isNull :' + matcher.matches(null))
- console.log(TAG + 'isNull :' + matcher.matches('null'))
- console.log(TAG + 'isNull :' + matcher.matches(''))
- }
-
- combinationMatch() {
- let matcher = IsNot.not(StringContains.containsString('expected'));
- console.info(TAG + "combinationMatch: " + matcher.matches("expected value"))
- console.info(TAG + "combinationMatch: " + matcher.matches('another value'))
-
- let match = Is.is(StringStartsWith.startsWith('hamjest'))
- console.info(TAG + "combinationMatch: " + match.matches('hamjest is awesome'))
- }
-
- isArray() {
- let matcher = IsArray.array(IsEqual.equalTo('a'), IsEqual.equalTo('b'), IsEqual.equalTo('c'))
- console.info(TAG + "isArray: " + matcher.matches(['a', 'b', 'c']))
- console.info(TAG + "isArray: " + matcher.matches(['a', 'd', 'b']))
- console.info(TAG + "isArray: " + matcher.matches(['a', 'b']))
- }
-
- isIn() {
- let matcher = IsIn.isIn(["bar", "foo"])
- console.info(TAG + "isIn: " + matcher.matches("bar"))
- console.info(TAG + "isIn: " + matcher.matches(["bar", "foo"]))
-
- }
-
- every() {
- let matcher = Every.everyItem(StringContains.containsString('a'))
- console.info(TAG + "every: " + matcher.matches(["AaA", "BaB", "CaC"]))
- console.info(TAG + "every: " + matcher.matches(["AAA", "BaB", "CbC"]))
- }
-
- matchesPattern() {
- let matcher = MatchesPattern.matchesPattern(new RegExp('bb'))
- console.info(TAG + "matchesPattern: " + matcher.matches('aabbcc'))
- console.info(TAG + "matchesPattern: " + matcher.matches('aabcc'))
- console.info(TAG + "matchesPattern: " + matcher.matches('abc'))
- }
-
- build() {
-
- Stack({ alignContent: Alignment.TopStart }) {
- Scroll(this.scroller) {
- Column() {
- Button() {
- Text('hasProperty')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.hasProperty.bind(this))
-
- Button() {
- Text('hasLength')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(() => {
- this.hasLength()
- })
-
- Button() {
- Text('anyOf')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.anyOf.bind(this))
-
- Button() {
- Text('containsString')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.containsString.bind(this))
-
- Button() {
- Text('allOf')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.allOf.bind(this))
-
- Button() {
- Text('endsWith')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.endsWith.bind(this))
-
- Button() {
- Text('isNaN')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.isNaN.bind(this))
-
- Button() {
- Text('isEqual')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.isEqual.bind(this))
-
- Button() {
- Text('IsEqualIgnoringCase')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.equalIgnoringCase.bind(this))
-
- Button() {
- Text('orderingComparison')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.orderingComparison.bind(this))
-
- Button() {
- Text('isBlackString')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.isBlackString.bind(this))
-
- Button() {
- Text('isCloseTo')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.isCloseTo.bind(this))
-
- Button() {
- Text('isNull')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.isNull.bind(this))
-
- Button() {
- Text('combinationMatch')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.combinationMatch.bind(this))
-
- Button() {
- Text('IsArray')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.isArray.bind(this))
-
- Button() {
- Text('IsIn')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.isIn.bind(this))
-
- Button() {
- Text('every')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.every.bind(this))
-
- Button() {
- Text('matchesPattern')
- .fontSize(25)
- .fontWeight(FontWeight.Bold)
- .padding({ left: 16, right: 16 })
- }.type(ButtonType.Capsule)
- .margin({
- top: 20
- })
- .backgroundColor('#0D9FFB')
- .onClick(this.matchesPattern.bind(this))
-
- }.width('100%')
- }
- .scrollable(ScrollDirection.Vertical).scrollBar(BarState.On)
- .scrollBarColor(Color.Gray).scrollBarWidth(1)
- .onScroll((xOffset: number, yOffset: number) => {
- console.info(xOffset + ' ' + yOffset)
- })
- .onScrollEdge((side: Edge) => {
- console.info('To the edge')
- })
- .onScrollEnd(() => {
- console.info('Scroll Stop')
- })
-
- }.width('100%').height('100%')
- }
+ scroller: Scroller = new Scroller()
+
+ hasProperty() {
+ let matcher = HasProperty.hasProperty('name')
+ console.info(TAG + "hasProperty: " + matcher.matches({ name: 'Joe' }))
+ console.info(TAG + "hasProperty: " + matcher.matches({ name: 'Joel' }))
+ console.info(TAG + "hasProperty: " + matcher.matches({ age: 19 }))
+ }
+
+ hasLength() {
+ let matcher = CharSequenceLength.hasLength(4);
+ console.info(TAG + "hasLength: " + matcher.matches('aaaa'))
+ console.info(TAG + "hasLength: " + matcher.matches('aaa'))
+ console.info(TAG + "hasLength: " + matcher.matches('aa a'))
+ }
+
+ anyOf() {
+ let matcherAnyOf = AnyOf.anyOfMatches(IsBlankString.blankString(),
+ IsEqualIgnoringCase.equalToIgnoringCase('aaa'))
+ console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches('AAA'))
+ console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches('bbb'))
+ console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches(''))
+ console.log(TAG + 'anyOf: enter matcherAnyOf:' + matcherAnyOf.matches('\n\r\t'))
+ }
+
+ containsString() {
+ let matcher = StringContains.containsString('rat')
+ console.info(TAG + "containsString: " + matcher.matches('jim the rat'))
+ console.info(TAG + "containsString: " + matcher.matches('jim the rats'))
+ let matcher2 = StringContains.containsString('rats');
+ console.info(TAG + "containsString: " + matcher2.matches('jim the rat'))
+ let matcher3 = StringContains.containsStringIgnoringCase('Jim')
+ console.info(TAG + "containsStringIgnoringCase: " + matcher3.matches('jim the rat'))
+ }
+
+ allOf() {
+ let matcher = AllOf.allOfMatches(StringContains.containsString('expected'), StringContains.containsString('value'))
+ console.info(TAG + "allOf: " + matcher.matches('expected value'))
+ console.info(TAG + "allOf: " + matcher.matches('value expected'))
+ console.info(TAG + "allOf: " + matcher.matches('expected valu'))
+ }
+
+ endsWith() {
+ let matcher = StringEndsWith.endsWith('test')
+ console.info(TAG + "endsWith: " + matcher.matches('aaabbbtest'))
+ console.info(TAG + "endsWith: " + matcher.matches('aaabbbtests'))
+ console.info(TAG + "endsWith: " + matcher.matches('testdjsdojw'))
+
+ let matcher2 = StringEndsWith.endsWithIgnoringCase('Test')
+ console.info(TAG + "endsWithIgnoringCase: " + matcher2.matches('this test'))
+ }
+
+ isNaN() {
+ let matcher = IsNaN.notANumber()
+ console.info(TAG + "isNaN: " + matcher.matches(7))
+ console.info(TAG + "isNaN: " + matcher.matches(7.7))
+ console.info(TAG + "isNaN: " + matcher.matches(Number.NaN))
+ }
+
+ isEqual() {
+ const value = [1, 2]
+ let matcher = IsEqual.equalTo(value)
+ console.info(TAG + "isEqual: " + matcher.matches([1, 3]))
+ console.info(TAG + "isEqual: " + matcher.matches([1, 2]))
+ let matcher2 = IsEqual.equalTo("string value")
+ console.info(TAG + "isEqual: " + matcher2.matches("string value"))
+ console.info(TAG + "isEqual: " + matcher2.matches("string values"))
+ }
+
+ equalIgnoringCase() {
+ let matcher = IsEqualIgnoringCase.equalToIgnoringCase('Hello')
+ console.log(TAG + 'equalIgnoringCase:' + matcher.matches('heLLo'))
+ console.log(TAG + 'equalIgnoringCase:' + matcher.matches('hello'))
+ console.log(TAG + 'equalIgnoringCase:' + matcher.matches('HELLO'))
+ }
+
+ orderingComparison() {
+ let matcher = OrderingComparison.greaterThan(5)
+ console.log(TAG + 'orderingComparison:' + matcher.matches('6'))
+ console.log(TAG + 'orderingComparison:' + matcher.matches('4'))
+ console.log(TAG + 'orderingComparison:' + matcher.matches('5'))
+
+ let matcher2 = OrderingComparison.greaterThanOrEqualTo(5)
+ console.log(TAG + 'orderingComparison:' + matcher2.matches('6'))
+ console.log(TAG + 'orderingComparison:' + matcher2.matches('4'))
+ console.log(TAG + 'orderingComparison:' + matcher2.matches('5'))
+
+ let matcher3 = OrderingComparison.lessThan(5)
+ console.log(TAG + 'orderingComparison:' + matcher3.matches('6'))
+ console.log(TAG + 'orderingComparison:' + matcher3.matches('4'))
+ console.log(TAG + 'orderingComparison:' + matcher3.matches('5'))
+
+ let matcher4 = OrderingComparison.lessThanOrEqualTo(5)
+ console.log(TAG + 'orderingComparison:' + matcher4.matches('6'))
+ console.log(TAG + 'orderingComparison:' + matcher4.matches('4'))
+ console.log(TAG + 'orderingComparison:' + matcher4.matches('5'))
+
+ let matcher5 = OrderingComparison.comparesEqualTo(5)
+ console.log(TAG + 'orderingComparison:' + matcher5.matches(5.00))
+ console.log(TAG + 'orderingComparison:' + matcher5.matches(5.1))
+ console.log(TAG + 'orderingComparison:' + matcher5.matches(0.0))
+ }
+
+ isBlackString() {
+ let matcher = IsBlankString.blankString();
+ console.log(TAG + 'isBlackString :' + matcher.matches(''))
+ console.log(TAG + 'isBlackString :' + matcher.matches('\n\r\t'))
+
+ let matcher2 = IsBlankString.blankOrNullString();
+ console.log(TAG + 'isBlackString: enter matcher2:' + matcher2.matches('\n\r\t'))
+ console.log(TAG + 'isBlackString: enter matcher2:' + matcher2.matches('null'))
+ console.log(TAG + 'isBlackString: enter matcher2:' + matcher2.matches(null))
+ }
+
+ isCloseTo() {
+ let matcher = IsCloseTo.closeTo(1.1, 0.0);
+ console.log(TAG + 'IsCloseTo :' + matcher.matches(1.10))
+
+ let matcher2 = IsCloseTo.closeTo(1.111111111, 0.0);
+ console.log(TAG + 'IsCloseTo :' + matcher2.matches(1.1111111112))
+ }
+
+ isNull() {
+ let matcher = IsNull.nullValue()
+ console.log(TAG + 'isNull :' + matcher.matches(null))
+ console.log(TAG + 'isNull :' + matcher.matches('null'))
+ console.log(TAG + 'isNull :' + matcher.matches(''))
+ }
+
+ combinationMatch() {
+ let matcher = IsNot.not(StringContains.containsString('expected'));
+ console.info(TAG + "combinationMatch: " + matcher.matches("expected value"))
+ console.info(TAG + "combinationMatch: " + matcher.matches('another value'))
+
+ let match = Is.is(StringStartsWith.startsWith('hamjest'))
+ console.info(TAG + "combinationMatch: " + match.matches('hamjest is awesome'))
+ }
+
+ isArray() {
+ let matcher: Matcher = IsArray.array(IsEqual.equalTo('a'), IsEqual.equalTo('b'), IsEqual.equalTo('c'))
+ console.info(TAG + "isArray: " + matcher.matches(['a', 'b', 'c']))
+ console.info(TAG + "isArray: " + matcher.matches(['a', 'd', 'b']))
+ console.info(TAG + "isArray: " + matcher.matches(['a', 'b']))
+ }
+
+ isIn() {
+ let matcher: Matcher = IsIn.isIn(["bar", "foo"])
+ console.info(TAG + "isIn: " + matcher.matches("bar"))
+ console.info(TAG + "isIn: " + matcher.matches(["bar", "foo"]))
+
+ }
+
+ every() {
+ let matcher: Matcher> = Every.everyItem(StringContains.containsString('a'))
+ console.info(TAG + "every: " + matcher.matches(["AaA", "BaB", "CaC"]))
+ console.info(TAG + "every: " + matcher.matches(["AAA", "BaB", "CbC"]))
+ }
+
+ matchesPattern() {
+ let matcher = MatchesPattern.matchesPattern(new RegExp('bb'))
+ console.info(TAG + "matchesPattern: " + matcher.matches('aabbcc'))
+ console.info(TAG + "matchesPattern: " + matcher.matches('aabcc'))
+ console.info(TAG + "matchesPattern: " + matcher.matches('abc'))
+
+ let matcher2 = MatchesPattern.matchesStringPattern("^Hello.*$")
+ console.info(TAG + "matchesPattern: " + matcher2.matches('Hello, world!'))
+ console.info(TAG + "matchesPattern: " + matcher2.matches('ello, world!'))
+ }
+
+ isEqualCompressingWhiteSpace() {
+ let matcher = IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace('hamjest')
+ console.info(TAG + "isEqualCompressingWhiteSpace: " + matcher.matches(' hamjest'))
+ console.info(TAG + "isEqualCompressingWhiteSpace: " + matcher.matches(' ham jest'))
+ console.info(TAG + "isEqualCompressingWhiteSpace: " + matcher.matches('Ham jest'))
+ }
+
+ isSame() {
+ let arr: Array = new Array(1)
+ arr[0] = "hello"
+
+ let arr1: Array = new Array(1)
+ arr1[0] = "hello"
+
+ let matcher = IsSame.sameInstance(arr)
+ console.info(TAG + "isSame sameInstance: " + matcher.matches(arr))
+ console.info(TAG + "isSame: sameInstance" + matcher.matches(arr1))
+
+ let str: string = "hello"
+ let matcher1 = IsSame.theInstance(str)
+ console.info(TAG + "isSame: theInstance:" + matcher1.matches(str))
+
+ let matcher2 = IsSame.theInstance(arr)
+ console.info(TAG + "isSame: theInstance:" + matcher2.matches(arr1))
+ }
+
+ isIterableContaining() {
+ let map: Map = new Map()
+ map.set("name", "张三")
+ let matcher = IsIterableContaining.hasItem(StringContains.containsString('张三'))
+ console.info(TAG + "isIterableContaining hasItem : " + matcher.matches(map))
+
+ let matcher1 = IsIterableContaining.hasItem(StringContains.containsString('王'))
+ console.info(TAG + "isIterableContaining hasItem : " + matcher1.matches(map))
+ }
+
+ isEmptyString() {
+ let matcher :Matcher= IsEmptyString.emptyString()
+ let test:string=""
+ console.info(TAG + "isEmptyString : " + matcher.matches(test))
+
+ let test2:string="hello"
+ console.info(TAG + "isEmptyString : " + matcher.matches(test2))
+
+ let matcher2 = IsEmptyString.emptyOrNullString()
+ console.info(TAG + "isEmptyString : " + matcher2.matches(""))
+ console.info(TAG + "isEmptyString : " + matcher2.matches("z"))
+ console.info(TAG + "isEmptyString : " + matcher2.matches(null))
+ }
+
+ build() {
+
+ Stack({ alignContent: Alignment.TopStart }) {
+ Scroll(this.scroller) {
+ Column() {
+ Button() {
+ Text('hasProperty')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.hasProperty()
+ })
+
+ Button() {
+ Text('hasLength')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.hasLength()
+ })
+
+ Button() {
+ Text('anyOf')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.anyOf()
+ })
+
+ Button() {
+ Text('containsString')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.containsString()
+ })
+
+ Button() {
+ Text('allOf')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.allOf()
+ })
+
+ Button() {
+ Text('endsWith')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.endsWith()
+ })
+
+ Button() {
+ Text('isNaN')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.isNaN()
+ })
+
+ Button() {
+ Text('isEqual')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.isEqual()
+ })
+
+ Button() {
+ Text('IsEqualIgnoringCase')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.equalIgnoringCase()
+ })
+
+ Button() {
+ Text('orderingComparison')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.orderingComparison()
+ })
+
+ Button() {
+ Text('isBlackString')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.isBlackString()
+ })
+
+ Button() {
+ Text('isCloseTo')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.isCloseTo()
+ })
+
+ Button() {
+ Text('isNull')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.isNull()
+ })
+
+ Button() {
+ Text('combinationMatch')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.combinationMatch()
+ })
+
+ Button() {
+ Text('IsArray')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.isArray()
+ })
+
+ Button() {
+ Text('IsIn')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.isIn()
+ })
+
+ Button() {
+ Text('every')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.every()
+ })
+
+ Button() {
+ Text('matchesPattern')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.matchesPattern()
+ })
+
+ Button() {
+ Text('isEqualCompressingWhiteSpace')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.isEqualCompressingWhiteSpace()
+ })
+
+ Button() {
+ Text('isSame')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.isSame()
+ })
+
+ Button() {
+ Text('isIterableContaining')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.isIterableContaining()
+ })
+
+ Button() {
+ Text('isEmptyString')
+ .fontSize(25)
+ .fontWeight(FontWeight.Bold)
+ .padding({ left: 16, right: 16 })
+ }
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .height(50)
+ .backgroundColor('#0D9FFB')
+ .onClick(() => {
+ this.isEmptyString()
+ })
+
+ }.width('100%')
+ }
+ .scrollable(ScrollDirection.Vertical)
+ .scrollBar(BarState.On)
+ .scrollBarColor(Color.Gray)
+ .scrollBarWidth(1)
+ .onScroll((xOffset: number, yOffset: number) => {
+ console.info(xOffset + ' ' + yOffset)
+ })
+ .onScrollEdge((side: Edge) => {
+ console.info('To the edge')
+ })
+ .onScrollEnd(() => {
+ console.info('Scroll Stop')
+ })
+
+ }.width('100%').height('100%')
+ }
}
\ No newline at end of file
diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5
index f6353470a13a33b01f3f042e937af5730f0cd611..6f0c4dc9554bb008802fb8507fe910d3697a8fdf 100644
--- a/entry/src/main/module.json5
+++ b/entry/src/main/module.json5
@@ -20,13 +20,13 @@
"abilities": [
{
"name": "EntryAbility",
- "srcEntrance": "./ets/entryability/EntryAbility.ts",
+ "srcEntry": "./ets/entryability/EntryAbility.ts",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
- "visible": true,
+ "exported": true,
"skills": [
{
"entities": [
diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json
index 1898d94f58d6128ab712be2c68acc7c98e9ab9ce..feec276e105eeb8d621c20aaf838f318b0a94150 100644
--- a/entry/src/main/resources/base/profile/main_pages.json
+++ b/entry/src/main/resources/base/profile/main_pages.json
@@ -1,5 +1,5 @@
{
"src": [
- "pages/Index"
+ "pages/index"
]
}
diff --git a/entry/src/ohosTest/ets/TestAbility/TestAbility.ets b/entry/src/ohosTest/ets/TestAbility/TestAbility.ets
index a856212e1b2946a215bafa1d5b200b1f8d18640d..790a2cb96fa47ae4b3693d8da98efbccc585e9a4 100644
--- a/entry/src/ohosTest/ets/TestAbility/TestAbility.ets
+++ b/entry/src/ohosTest/ets/TestAbility/TestAbility.ets
@@ -19,15 +19,17 @@ import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
+import AbilityConstant from '@ohos.app.ability.AbilityConstant';
+import Want from '@ohos.app.ability.Want';
export default class TestAbility extends UIAbility {
- onCreate(want, launchParam) {
+ onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
- var abilityDelegator: any
+ let abilityDelegator: ESObject
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
- var abilityDelegatorArguments: any
+ let abilityDelegatorArguments: ESObject
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
diff --git a/entry/src/ohosTest/ets/test/Ability.test.ets b/entry/src/ohosTest/ets/test/Ability.test.ets
index a023be85272c876df2b35d4c044990bbeadfafe0..19cba984096708a2b324b7e5a8831b4d36c6ea3c 100644
--- a/entry/src/ohosTest/ets/test/Ability.test.ets
+++ b/entry/src/ohosTest/ets/test/Ability.test.ets
@@ -15,188 +15,670 @@
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import {
- HasProperty,
- StringContains,
- StringStartsWith,
- StringEndsWith,
- AllOf,
- AnyOf,
- IsNot,
- Is,
- IsEqual,
- IsNaN,
- IsEqualIgnoringCase,
- CharSequenceLength,
- IsBlankString,
- OrderingComparison,
- IsCloseTo,
- IsNull,
- IsArray,
- IsIn,
- MatchesPattern,
- Every
+ HasProperty,
+ StringContains,
+ StringStartsWith,
+ StringEndsWith,
+ AllOf,
+ AnyOf,
+ IsNot,
+ Is,
+ IsEqual,
+ IsNaN,
+ IsEqualIgnoringCase,
+ CharSequenceLength,
+ IsBlankString,
+ OrderingComparison,
+ IsCloseTo,
+ IsNull,
+ IsArray,
+ IsIn,
+ MatchesPattern,
+ Every,
+ IsEmptyString,
+ IsEqualCompressingWhiteSpace,
+ IsIterableContaining,
+ IsSame
} from '@ohos/hamcrest'
+import { Matcher } from '@ohos/hamcrest/src/main/ets/components/Matcher'
export default function abilityTest() {
- describe('ActsAbilityTest', function () {
- // Defines a test suite. Two parameters are supported: test suite name and test suite function.
- beforeAll(function () {
- // Presets an action, which is performed only once before all test cases of the test suite start.
- // This API supports only one parameter: preset action function.
- })
- beforeEach(function () {
- // Presets an action, which is performed before each unit test case starts.
- // The number of execution times is the same as the number of test cases defined by **it**.
- // This API supports only one parameter: preset action function.
- })
- afterEach(function () {
- // Presets a clear action, which is performed after each unit test case ends.
- // The number of execution times is the same as the number of test cases defined by **it**.
- // This API supports only one parameter: clear action function.
- })
- afterAll(function () {
- // Presets a clear action, which is performed after all test cases of the test suite end.
- // This API supports only one parameter: clear action function.
- })
- it('hasProperty', 0, function () {
- let matcher = HasProperty.hasProperty('name')
- expect(matcher.matches({
- name: 'Joe'
- })).assertTrue()
- expect(matcher.matches({
- name: 'Joel'
- })).assertTrue()
- expect(matcher.matches({
- age: 19
- })).assertFalse()
- })
- it('hasLength', 0, function () {
- let matcher = CharSequenceLength.hasLength(4);
- expect(matcher.matches('aaaa')).assertTrue()
- expect(matcher.matches('aaa')).assertFalse()
- expect(matcher.matches('aa a')).assertTrue()
- })
- it('anyOf', 0, function () {
- let matcher = AnyOf.anyOfMatches(IsBlankString.blankString(),
- IsEqualIgnoringCase.equalToIgnoringCase('aaa'))
- expect(matcher.matches('AAA')).assertTrue()
- expect(matcher.matches('bbb')).assertFalse()
- expect(matcher.matches('')).assertFalse()
- expect(matcher.matches('\n\r\t')).assertTrue()
- })
- it('containsString', 0, function () {
- let matcher = StringContains.containsString('rat')
- let matcher2 = StringContains.containsString('rats')
- expect(matcher.matches('jim the rat')).assertTrue()
- expect(matcher.matches('jim the rats')).assertTrue()
- expect(matcher2.matches('jim the rat')).assertFalse()
- })
- it('allOf', 0, function () {
- let matcher = AllOf.allOfMatches(StringContains.containsString('expected'), StringContains.containsString('value'))
- expect(matcher.matches('expected value')).assertTrue()
- expect(matcher.matches('value expected')).assertTrue()
- expect(matcher.matches('expected valu')).assertFalse()
- })
- it('endsWith', 0, function () {
- let matcher = StringEndsWith.endsWith('test')
- expect(matcher.matches('aaabbbtest')).assertTrue()
- expect(matcher.matches('aaabbbtests')).assertFalse()
- expect(matcher.matches('testdjsdojw')).assertFalse()
- })
- it('isNaN', 0, function () {
- let matcher = IsNaN.notANumber()
- expect(matcher.matches(7)).assertFalse()
- expect(matcher.matches(7.7)).assertFalse()
- expect(matcher.matches(NaN)).assertTrue()
- })
- it('isEqual', 0, function () {
- const value = [1, 2]
- let matcher = IsEqual.equalTo(value)
- expect(matcher.matches([1, 3])).assertFalse()
- expect(matcher.matches([1, 2])).assertTrue()
- let matcher2 = IsEqual.equalTo("string value")
- expect(matcher2.matches("string value")).assertTrue()
- expect(matcher2.matches("string values")).assertFalse()
- })
- it('equalIgnoringCase', 0, function () {
- let matcher = IsEqualIgnoringCase.equalToIgnoringCase('Hello')
- expect(matcher.matches('heLLo')).assertTrue()
- expect(matcher.matches('hello')).assertTrue()
- expect(matcher.matches('HELLO')).assertTrue()
- })
- it('orderingComparison', 0, function () {
- let matcher = OrderingComparison.greaterThan(5)
- expect(matcher.matches('6')).assertTrue()
- expect(matcher.matches('4')).assertFalse()
- expect(matcher.matches('5')).assertFalse()
-
- let matcher2 = OrderingComparison.greaterThanOrEqualTo(5)
- expect(matcher2.matches('6')).assertTrue()
- expect(matcher2.matches('4')).assertFalse()
- expect(matcher2.matches('5')).assertTrue()
-
- let matcher3 = OrderingComparison.lessThan(5)
- expect(matcher3.matches('6')).assertFalse()
- expect(matcher3.matches('4')).assertTrue()
- expect(matcher3.matches('5')).assertFalse()
-
- let matcher4 = OrderingComparison.lessThanOrEqualTo(5)
- expect(matcher4.matches('6')).assertFalse()
- expect(matcher4.matches('4')).assertTrue()
- expect(matcher4.matches('5')).assertTrue()
- })
- it('isBlackString', 0, function () {
- let matcher = IsBlankString.blankString();
- expect(matcher.matches('')).assertFalse()
- expect(matcher.matches('\n\r\t')).assertTrue()
-
- let matcher2 = IsBlankString.blankOrNullString();
- expect(matcher2.matches('\n\r\t')).assertTrue()
- expect(matcher2.matches('null')).assertFalse()
- expect(matcher2.matches(null)).assertTrue()
- })
- it('IsCloseTo', 0, function () {
- let matcher = IsCloseTo.closeTo(1.1, 0.0);
- expect(matcher.matches(1.10)).assertTrue()
+ describe('ActsAbilityTest', () => {
+ // Defines a test suite. Two parameters are supported: test suite name and test suite function.
+ beforeAll(() => {
+ // Presets an action, which is performed only once before all test cases of the test suite start.
+ // This API supports only one parameter: preset action function.
+ })
+ beforeEach(() => {
+ // Presets an action, which is performed before each unit test case starts.
+ // The number of execution times is the same as the number of test cases defined by **it**.
+ // This API supports only one parameter: preset action function.
+ })
+ afterEach(() => {
+ // Presets a clear action, which is performed after each unit test case ends.
+ // The number of execution times is the same as the number of test cases defined by **it**.
+ // This API supports only one parameter: clear action function.
+ })
+ afterAll(() => {
+ // Presets a clear action, which is performed after all test cases of the test suite end.
+ // This API supports only one parameter: clear action function.
+ })
+ it('hasProperty', 0, () => {
+ let matcher = HasProperty.hasProperty('name')
+ expect(matcher.matches({
+ name: 'Joe'
+ })).assertTrue()
+ })
- let matcher2 = IsCloseTo.closeTo(1.111111111, 0.0);
- expect(matcher2.matches(1.1111111112)).assertFalse()
- })
- it('isNull', 0, function () {
- let matcher = IsNull.nullValue()
- expect(matcher.matches(null)).assertTrue()
- expect(matcher.matches('null')).assertFalse()
- expect(matcher.matches('')).assertFalse()
- })
- it('combinationMatch', 0, function () {
- let matcher = IsNot.not(StringContains.containsString('expected'));
- expect(matcher.matches("expected value")).assertFalse()
- expect(matcher.matches('another value')).assertTrue()
+ it('hasPropertyFalse', 0, () => {
+ let matcher = HasProperty.hasProperty('name')
+ expect(matcher.matches({
+ age: 19
+ })).assertFalse()
+ })
- let match = Is.is(StringStartsWith.startsWith('hamjest'))
- expect(match.matches('hamjest is awesome')).assertTrue()
- })
- it('isArray', 0, function () {
- let matcher = IsArray.array(IsEqual.equalTo('a'), IsEqual.equalTo('b'), IsEqual.equalTo('c'))
- expect(matcher.matches(['a', 'b', 'c'])).assertTrue()
- expect(matcher.matches(['a', 'd', 'b'])).assertFalse()
- expect(matcher.matches(['a', 'b'])).assertFalse()
- })
- it('isIn', 0, function () {
- let matcher = IsIn.isIn(["bar", "foo"])
- expect(matcher.matches("bar")).assertTrue()
- expect(matcher.matches(["bar", "foo"])).assertFalse()
- })
- it('every', 0, function () {
- let matcher = Every.everyItem(StringContains.containsString('a'))
- expect(matcher.matches(["AaA", "BaB", "CaC"])).assertTrue()
- expect(matcher.matches(["AAA", "BaB", "CbC"])).assertFalse()
- })
- it('matchesPattern', 0, function () {
- let matcher = MatchesPattern.matchesPattern(new RegExp('bb'))
- expect(matcher.matches('aabbcc')).assertTrue()
- expect(matcher.matches('aabcc')).assertFalse()
- expect(matcher.matches('abc')).assertFalse()
+ it('hasPropertyEmpty', 0, () => {
+ let matcher = HasProperty.hasProperty('name')
+ expect(matcher.matches({
+ "": "dany"
+ })).assertFalse()
+ })
+
+ it('hasLength', 0, () => {
+ let matcher = CharSequenceLength.hasLength(4);
+ expect(matcher.matches('aaaa')).assertTrue()
+ })
+
+ it('hasLengthFalse', 0, () => {
+ let matcher = CharSequenceLength.hasLength(4);
+ expect(matcher.matches('aaa')).assertFalse()
+ })
+
+ it('hasLengthEmpty', 0, () => {
+ let matcher = CharSequenceLength.hasLength(4);
+ expect(matcher.matches('')).assertFalse()
+ })
+
+ it('hasLengthNum', 0, () => {
+ let matcher = CharSequenceLength.hasLength(4);
+ expect(matcher.matches(1234)).assertFalse()
+ })
+
+ it('hasLengthBoolean', 0, () => {
+ let matcher = CharSequenceLength.hasLength(4);
+ expect(matcher.matches(true)).assertFalse()
+ })
+
+ it('hasLengthContainsBlank', 0, () => {
+ let matcher = CharSequenceLength.hasLength(4);
+ expect(matcher.matches('aa a')).assertTrue()
+ })
+
+ it('hasLengthContainsChinese', 0, () => {
+ let matcher = CharSequenceLength.hasLength(4);
+ expect(matcher.matches('aa你好 a')).assertFalse()
+ })
+
+ it('anyOfUpperEndBlank', 0, () => {
+ let matcher = AnyOf.anyOfMatches(IsBlankString.blankString(),
+ IsEqualIgnoringCase.equalToIgnoringCase('AAA '))
+ expect(matcher.matches('AAA')).assertFalse()
+ })
+
+ it('anyOfUpperCase', 0, () => {
+ let matcher = AnyOf.anyOfMatches(IsBlankString.blankString(),
+ IsEqualIgnoringCase.equalToIgnoringCase('aaa'))
+ expect(matcher.matches('AAA')).assertTrue()
+ })
+
+ it('anyOfLowerCase', 0, () => {
+ let matcher = AnyOf.anyOfMatches(IsBlankString.blankString(),
+ IsEqualIgnoringCase.equalToIgnoringCase('aaa'))
+ expect(matcher.matches('bbb')).assertFalse()
+ })
+
+ it('anyOfContainsBlank', 0, () => {
+ let matcher = AnyOf.anyOfMatches(IsBlankString.blankString(),
+ IsEqualIgnoringCase.equalToIgnoringCase('aaa'))
+ expect(matcher.matches('')).assertFalse()
+ })
+
+ it('containsStringTrue', 0, () => {
+ let matcher = StringContains.containsString('rat')
+ expect(matcher.matches('jim the rat')).assertTrue()
+ expect(matcher.matches('jim the rats')).assertTrue()
+ })
+
+ it('containsStringFalse', 0, () => {
+ let matcher2 = StringContains.containsString('rats')
+ expect(matcher2.matches('jim the rat')).assertFalse()
+ })
+
+ it('containsStringPart', 0, () => {
+ let matcher2 = StringContains.containsString('ra')
+ expect(matcher2.matches('jim the rat')).assertTrue()
+ })
+
+ it('containsStringEmpty', 0, () => {
+ let matcher2 = StringContains.containsString(' ')
+ expect(matcher2.matches('ra ')).assertTrue()
+ })
+
+ it('containsStringIgnoringCase', 0, () => {
+ let matcher = StringContains.containsString('rat')
+ expect(matcher.matches('jim the rat')).assertTrue()
+ })
+
+ it('containsStringIgnoringCaseUpper', 0, () => {
+ let matcher = StringContains.containsStringIgnoringCase('Jim')
+ expect(matcher.matches('jim the rat')).assertTrue()
+ })
+
+ it('containsStringIgnoringCaseFalse', 0, () => {
+ let matcher = StringContains.containsString('ct')
+ expect(matcher.matches('jim the rat')).assertFalse()
+ })
+
+ it('allOfTrue', 0, () => {
+ let matcher = AllOf.allOfMatches(StringContains.containsString('expected'), StringContains.containsString('value'))
+ expect(matcher.matches('expected value')).assertTrue()
+ expect(matcher.matches('value expected')).assertTrue()
+ })
+
+ it('allOfFalse', 0, () => {
+ let matcher = AllOf.allOfMatches(StringContains.containsString('expected'), StringContains.containsString('value'))
+ expect(matcher.matches('expected valu')).assertFalse()
+ })
+
+ it('allOfContainsBlank', 0, () => {
+ let matcher = AllOf.allOfMatches(StringContains.containsString('expected'), StringContains.containsString(' value'))
+ expect(matcher.matches('expected value')).assertTrue()
+ })
+
+ it('endsWithTrue', 0, () => {
+ let matcher = StringEndsWith.endsWith('test')
+ expect(matcher.matches('aaabbbtest')).assertTrue()
+ })
+
+ it('endsWithContainsBlank', 0, () => {
+ let matcher = StringEndsWith.endsWith('test')
+ expect(matcher.matches('aaabbbtest ')).assertFalse()
+ })
+
+ it('endsWithContainsBlankTrue', 0, () => {
+ let matcher = StringEndsWith.endsWith('test ')
+ expect(matcher.matches('aaabbbtest ')).assertTrue()
+ })
+
+ it('endsWithFalse', 0, () => {
+ let matcher = StringEndsWith.endsWith('test')
+ expect(matcher.matches('aaabbbtests')).assertFalse()
+ expect(matcher.matches('testdjsdojw')).assertFalse()
+ })
+
+ it('endsWithIgnoringCase', 0, () => {
+ let matcher = StringEndsWith.endsWithIgnoringCase('Test')
+ expect(matcher.matches('this test')).assertTrue()
+ })
+
+ it('endsWithIgnoringCaseFalse', 0, () => {
+ let matcher = StringEndsWith.endsWithIgnoringCase('test')
+ expect(matcher.matches('this test ')).assertFalse()
+ })
+
+ it('endsWithIgnoringCaseBlank', 0, () => {
+ let matcher = StringEndsWith.endsWithIgnoringCase(' ')
+ expect(matcher.matches('this test ')).assertTrue()
+ })
+
+ it('isNaNTrue', 0, () => {
+ let matcher = IsNaN.notANumber()
+ expect(matcher.matches(Number.NaN)).assertTrue()
+ })
+
+ it('isNaNNum', 0, () => {
+ let matcher = IsNaN.notANumber()
+ expect(matcher.matches(Number.MAX_VALUE)).assertFalse()
+ })
+
+ it('isNaNStr', 0, () => {
+ let matcher = IsNaN.notANumber()
+ expect(matcher.matches("NaN")).assertFalse()
+ })
+
+ it('isNaNFalse', 0, () => {
+ let matcher = IsNaN.notANumber()
+ expect(matcher.matches(7)).assertFalse()
+ expect(matcher.matches(7.7)).assertFalse()
+ })
+
+ it('isEqualArray', 0, () => {
+ const value = [1, 2]
+ let matcher = IsEqual.equalTo(value)
+ expect(matcher.matches([1, 2])).assertTrue()
+ })
+
+ it('isEqualArrayFalse', 0, () => {
+ const value = [1, 2]
+ let matcher = IsEqual.equalTo(value)
+ expect(matcher.matches([1, 3])).assertFalse()
+ })
+
+ it('isEqualString', 0, () => {
+ let matcher2 = IsEqual.equalTo("string value")
+ expect(matcher2.matches("string value")).assertTrue()
+ })
+
+ it('isEqualStringFalse', 0, () => {
+ let matcher2 = IsEqual.equalTo("string value")
+ expect(matcher2.matches("string values")).assertFalse()
+ })
+
+ it('equalIgnoringCaseUpper', 0, () => {
+ let matcher = IsEqualIgnoringCase.equalToIgnoringCase('Hello')
+ expect(matcher.matches('HELLO')).assertTrue()
+ })
+
+ it('equalIgnoringCaseUpperFalse', 0, () => {
+ let matcher = IsEqualIgnoringCase.equalToIgnoringCase('Hello')
+ expect(matcher.matches('HELL O')).assertFalse()
+ })
+
+ it('equalIgnoringCaseLower', 0, () => {
+ let matcher = IsEqualIgnoringCase.equalToIgnoringCase('Hello')
+ expect(matcher.matches('heLLo')).assertTrue()
+ expect(matcher.matches('hello')).assertTrue()
+ })
+
+ it('equalIgnoringCaseLowerFalse', 0, () => {
+ let matcher = IsEqualIgnoringCase.equalToIgnoringCase('Hello')
+ expect(matcher.matches('heL Lo')).assertFalse()
+ })
+
+ it('orderingComparisonGreaterThan', 0, () => {
+ let matcher = OrderingComparison.greaterThan(5)
+ expect(matcher.matches('6')).assertTrue()
+ })
+
+ it('orderingComparisonGreaterThanFalse', 0, () => {
+ let matcher = OrderingComparison.greaterThan(5)
+ expect(matcher.matches('5')).assertFalse()
+ })
+
+ it('orderingComparisonGreaterThanOrEqualToTrue', 0, () => {
+ let matcher2 = OrderingComparison.greaterThanOrEqualTo(5)
+ expect(matcher2.matches('6')).assertTrue()
+ })
+
+ it('orderingComparisonGreaterThanOrEqualToFalse', 0, () => {
+ let matcher2 = OrderingComparison.greaterThanOrEqualTo(5)
+ expect(matcher2.matches('4')).assertFalse()
+ })
+
+ it('orderingComparisonGreaterThanOrEqualToFloat', 0, () => {
+ let matcher2 = OrderingComparison.greaterThanOrEqualTo(5)
+ expect(matcher2.matches('5.0')).assertTrue()
+ })
+
+ it('orderingComparisonLessThan', 0, () => {
+ let matcher3 = OrderingComparison.lessThan(5)
+ expect(matcher3.matches('4')).assertTrue()
+ })
+
+ it('orderingComparisonLessThanFalse', 0, () => {
+ let matcher3 = OrderingComparison.lessThan(5)
+ expect(matcher3.matches('6')).assertFalse()
+ })
+
+ it('orderingComparisonLessThanFloat', 0, () => {
+ let matcher3 = OrderingComparison.lessThan(5)
+ expect(matcher3.matches('6.0')).assertFalse()
+ })
+
+ it('orderingComparisonLessThanSame', 0, () => {
+ let matcher3 = OrderingComparison.lessThan(5)
+ expect(matcher3.matches('5')).assertFalse()
+ })
+
+ it('orderingComparisonLessThanOrEqualTo', 0, () => {
+ let matcher4 = OrderingComparison.lessThanOrEqualTo(5)
+ expect(matcher4.matches('5')).assertTrue()
+ })
+
+ it('orderingComparisonLessThanOrEqualToFalse', 0, () => {
+ let matcher4 = OrderingComparison.lessThanOrEqualTo(5)
+ expect(matcher4.matches('6')).assertFalse()
+ })
+
+ it('orderingComparesEqualTo', 0, () => {
+ let matcher4 = OrderingComparison.comparesEqualTo(5)
+ expect(matcher4.matches(5.00)).assertTrue()
+ })
+
+ it('orderingComparesEqualToFalse', 0, () => {
+ let matcher4 = OrderingComparison.comparesEqualTo(5)
+ expect(matcher4.matches(5.1)).assertFalse()
+ })
+
+ it('orderingComparesEqualToZero', 0, () => {
+ let matcher4 = OrderingComparison.comparesEqualTo(0)
+ expect(matcher4.matches(0.0)).assertTrue()
+ })
+
+ it('isBlackString', 0, () => {
+ let matcher = IsBlankString.blankString();
+ expect(matcher.matches(' ')).assertTrue()
+ })
+
+ it('isBlackStringFalse', 0, () => {
+ let matcher = IsBlankString.blankString();
+ expect(matcher.matches('')).assertFalse()
+ })
+
+ it('isBlackStringEscape', 0, () => {
+ let matcher = IsBlankString.blankString();
+ expect(matcher.matches('\n\r\t')).assertTrue()
+ })
+
+ it('isBlankOrNullStringNull', 0, () => {
+ let matcher2 = IsBlankString.blankOrNullString();
+ expect(matcher2.matches(null)).assertTrue()
+ })
+
+ it('isBlankOrNullStringBlank', 0, () => {
+ let matcher2 = IsBlankString.blankOrNullString();
+ expect(matcher2.matches(" ")).assertTrue()
+ })
+
+ it('isBlankOrNullStringEmpty', 0, () => {
+ let matcher2 = IsBlankString.blankOrNullString();
+ expect(matcher2.matches("")).assertFalse()
+ })
+
+ it('isBlankOrNullStringFalse', 0, () => {
+ let matcher2 = IsBlankString.blankOrNullString();
+ expect(matcher2.matches('null')).assertFalse()
+ })
+
+ it('isBlankOrNullStringEscape', 0, () => {
+ let matcher2 = IsBlankString.blankOrNullString();
+ expect(matcher2.matches('\n\r\t')).assertTrue()
+ })
+
+ it('IsCloseToTrue', 0, () => {
+ let matcher = IsCloseTo.closeTo(1.1, 0.0);
+ expect(matcher.matches(1.10)).assertTrue()
+ })
+
+ it('IsCloseToZero', 0, () => {
+ let matcher = IsCloseTo.closeTo(1.1, 0.0);
+ expect(matcher.matches(0.0)).assertFalse()
+ })
+
+ it('IsCloseToFalse', 0, () => {
+ let matcher2 = IsCloseTo.closeTo(1.111111111, 0.0);
+ expect(matcher2.matches(1.1111111112)).assertFalse()
+ })
+
+ it('isNullTrue', 0, () => {
+ let matcher = IsNull.nullValue()
+ expect(matcher.matches(null)).assertTrue()
+ })
+
+ it('isNullFalse', 0, () => {
+ let matcher = IsNull.nullValue()
+ expect(matcher.matches('null')).assertFalse()
+ expect(matcher.matches('')).assertFalse()
+ })
+
+ it('isNullFalseUndefined', 0, () => {
+ let matcher = IsNull.nullValue()
+ expect(matcher.matches(undefined)).assertTrue()
+ })
+
+ it('combinationMatchNot', 0, () => {
+ let matcher = IsNot.not(StringContains.containsString('expected'));
+ expect(matcher.matches('another value')).assertTrue()
+ })
+
+ it('combinationMatchNotFalse', 0, () => {
+ let matcher = IsNot.not(StringContains.containsString('expected'));
+ expect(matcher.matches("expected value")).assertFalse()
+ })
+
+ it('combinationMatchNotFalsePart', 0, () => {
+ let matcher = IsNot.not(StringContains.containsString('expec'));
+ expect(matcher.matches("expected value")).assertFalse()
+ })
+
+ it('startsWithIgnoringCaseUpper', 0, () => {
+ let match = Is.is(StringStartsWith.startsWithIgnoringCase('Hamjest')) //
+ expect(match.matches('hamjest is awesome')).assertTrue()
+ })
+
+ it('startsWithIgnoringCaseFalse', 0, () => {
+ let match = Is.is(StringStartsWith.startsWithIgnoringCase(' hamjest')) //
+ expect(match.matches('hamjest is awesome')).assertFalse()
+ })
+
+ it('startsWithIgnoringCase', 0, () => {
+ let match = Is.is(StringStartsWith.startsWithIgnoringCase('hamjest')) //
+ expect(match.matches('hamjest is awesome')).assertTrue()
+ })
+
+ it('combinationMatchIs', 0, () => {
+ let match = Is.is(StringStartsWith.startsWith('hamjest')) //
+ expect(match.matches('hamjest is awesome')).assertTrue()
+ })
+
+ it('combinationMatchIsFalse', 0, () => {
+ let match = Is.is(StringStartsWith.startsWith('hamjest')) //
+ expect(match.matches('amjest is awesome')).assertFalse()
+ })
+
+ it('combinationMatchIsStartBlank', 0, () => {
+ let match = Is.is(StringStartsWith.startsWith('hamjest')) //
+ expect(match.matches(' hamjest is awesome')).assertFalse()
+ })
+
+ it('isArrayTrue', 0, () => {
+ let matcher: Matcher = IsArray.array(IsEqual.equalTo('a'), IsEqual.equalTo('b'), IsEqual.equalTo('c'))
+ expect(matcher.matches(['a', 'b', 'c'])).assertTrue()
+ })
+
+ it('isArrayFalse', 0, () => {
+ let matcher: Matcher = IsArray.array(IsEqual.equalTo('a'), IsEqual.equalTo('b'), IsEqual.equalTo('c'))
+ expect(matcher.matches(['a', 'd', 'b'])).assertFalse()
+ expect(matcher.matches(['a', 'b'])).assertFalse()
+ })
+
+ it('isArrayPart', 0, () => {
+ let matcher: Matcher = IsArray.array(IsEqual.equalTo('a'), IsEqual.equalTo('b'), IsEqual.equalTo('c'))
+ expect(matcher.matches(['a', 'b'])).assertFalse()
+ })
+
+ it('isArrayThan', 0, () => {
+ let matcher: Matcher = IsArray.array(IsEqual.equalTo('a'), IsEqual.equalTo('b'), IsEqual.equalTo('c'))
+ expect(matcher.matches(['a', 'b', 'c', 'd'])).assertFalse()
+ })
+
+ it('isInTrue', 0, () => {
+ let matcher: Matcher = IsIn.isIn(["bar", "foo"])
+ expect(matcher.matches("bar")).assertTrue()
+ })
+
+ it('isInThan', 0, () => {
+ let matcher: Matcher = IsIn.isIn(["bar", "foo"])
+ expect(matcher.matches(["bar", "foo", "egg"])).assertFalse()
+ })
+
+ it('isInFalse', 0, () => {
+ let matcher: Matcher = IsIn.isIn(["bar", "foo"])
+ expect(matcher.matches(["bar", "foo"])).assertFalse()
+ })
+
+ it('everyTrue', 0, () => {
+ let matcher: Matcher> = Every.everyItem(StringContains.containsString('a'))
+ expect(matcher.matches(["AaA", "BaB", "CaC"])).assertTrue()
+ })
+
+ it('everyEmpty', 0, () => {
+ let matcher: Matcher> = Every.everyItem(StringContains.containsString(' '))
+ expect(matcher.matches(["AaA", "BaB", "CaC"])).assertFalse()
+ })
+
+ it('everyFalse', 0, () => {
+ let matcher: Matcher> = Every.everyItem(StringContains.containsString('a'))
+ expect(matcher.matches(["AAA", "BaB", "CbC"])).assertFalse()
+ })
+
+ it('matchesStringPattern', 0, () => {
+ let matcher = MatchesPattern.matchesStringPattern("^Hello.*$")
+ expect(matcher.matches('Hello, world!')).assertTrue()
+ })
+
+ it('matchesStringPatternFalse', 0, () => {
+ let matcher = MatchesPattern.matchesStringPattern("^Hello.*$")
+ expect(matcher.matches('ello, world')).assertFalse()
+ })
+
+ it('matchesPatternTrue', 0, () => {
+ let matcher = MatchesPattern.matchesPattern(new RegExp('bb'))
+ expect(matcher.matches('aabbcc')).assertTrue()
+ })
+
+ it('matchesPatternContainsBlank', 0, () => {
+ let matcher = MatchesPattern.matchesPattern(new RegExp('b b'))
+ expect(matcher.matches('aab bcc')).assertTrue()
+ })
+
+ it('matchesPatternFalse', 0, () => {
+ let matcher = MatchesPattern.matchesPattern(new RegExp('bb'))
+ expect(matcher.matches('aabcc')).assertFalse()
+ expect(matcher.matches('abc')).assertFalse()
+ })
+
+ it('equalToIgnoringWhiteSpace', 0, () => {
+ let match = IsEqualCompressingWhiteSpace.equalToIgnoringWhiteSpace('hamjest ') //
+ expect(match.matches('hamjest')).assertTrue()
+ })
+
+ it('equalToIgnoringWhiteSpaceMid', 0, () => {
+ let match = IsEqualCompressingWhiteSpace.equalToIgnoringWhiteSpace('hamjest')
+ expect(match.matches('hamj est')).assertTrue()
+ })
+
+ it('equalToIgnoringWhiteSpaceFalse', 0, () => {
+ let match = IsEqualCompressingWhiteSpace.equalToIgnoringWhiteSpace('Hamj est')
+ expect(match.matches('hamjest')).assertFalse()
+ })
+
+ it('equalToIgnoringWhiteSpaceStart', 0, () => {
+ let match = IsEqualCompressingWhiteSpace.equalToIgnoringWhiteSpace('hamjest')
+ expect(match.matches(' hamjest')).assertTrue()
+ })
+
+ it('equalToCompressingWhiteSpace', 0, () => {
+ let match = IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace(' hamjest')
+ expect(match.matches('hamjest')).assertTrue()
+ })
+
+ it('equalToCompressingWhiteSpaceFalse', 0, () => {
+ let match = IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace('Ham jest')
+ expect(match.matches('hamjest')).assertFalse()
+ })
+
+ it('equalToCompressingWhiteSpaceMid', 0, () => {
+ let match = IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace('hamj est')
+ expect(match.matches('hamjest')).assertTrue()
+ })
+
+ it('equalToCompressingWhiteSpaceStart', 0, () => {
+ let match = IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace('hamjest ')
+ expect(match.matches('hamjest')).assertTrue()
+ })
+
+ it('isSameSameInstance', 0, () => {
+ let arr: Array = new Array(1)
+ arr[0] = "hello"
+ let match = IsSame.sameInstance(arr)
+ expect(match.matches(arr)).assertTrue()
+ })
+
+ it('isSameSameInstanceFalse', 0, () => {
+ let arr: Array = new Array(1)
+ arr[0] = "hello"
+
+ let arr1: Array = new Array(1)
+ arr1[0] = "hello"
+ let match = IsSame.sameInstance(arr)
+ expect(match.matches(arr1)).assertFalse()
+ })
+
+ it('isSameTheInstance', 0, () => {
+ let str: string = "hello"
+ let match = IsSame.theInstance(str)
+ expect(match.matches(str)).assertTrue()
+ })
+
+ it('isSameTheInstanceFalse', 0, () => {
+ let arr: Array = new Array(1)
+ arr[0] = "hello"
+
+ let arr1: Array = new Array(1)
+ arr1[0] = "hello"
+ let match = IsSame.theInstance(arr)
+ expect(match.matches(arr1)).assertFalse()
+ })
+
+ it('hasItem', 0, () => {
+ let map: Map = new Map()
+ map.set("name", "张三")
+ let match = IsIterableContaining.hasItem(StringContains.containsString('张三'))
+ expect(match.matches(map)).assertTrue()
+ })
+
+ it('hasItemFalse', 0, () => {
+ let map: Map = new Map()
+ map.set("name", "张三")
+ let match = IsIterableContaining.hasItem(StringContains.containsString('王'))
+ expect(match.matches(map)).assertFalse()
+ })
+
+ it('hasItemContainsBlank', 0, () => {
+ let map: Map = new Map()
+ map.set("name", " ")
+ map.set("age", "34")
+ let match = IsIterableContaining.hasItem(StringContains.containsString('34'))
+ expect(match.matches(map)).assertTrue()
+ })
+
+ it('isEmptyString', 0, () => {
+ let match = IsEmptyString.emptyString()
+ let str: string = ""
+ expect(match.matches(str)).assertTrue()
+ })
+
+ it('isEmptyStringFalse', 0, () => {
+ let match = IsEmptyString.emptyString()
+ let str: string = "hello"
+ expect(match.matches(str)).assertFalse()
+ })
+
+ it('isEmptyStringEmpty', 0, () => {
+ let match = IsEmptyString.emptyOrNullString()
+ expect(match.matches("")).assertTrue()
+ })
+
+ it('isEmptyStringEmptyFalse', 0, () => {
+ let match = IsEmptyString.emptyOrNullString()
+ expect(match.matches("z")).assertFalse()
+ })
+
+ it('isEmptyStringNull', 0, () => {
+ let match = IsEmptyString.emptyOrNullString()
+ expect(match.matches(null)).assertTrue()
+ })
})
- })
+
}
\ No newline at end of file
diff --git a/entry/src/ohosTest/module.json5 b/entry/src/ohosTest/module.json5
index 476d15376f43323426498a79fb3d58a658a27a56..cf86f4bff8b1c8a6496f896a873fbc9d7b19803a 100644
--- a/entry/src/ohosTest/module.json5
+++ b/entry/src/ohosTest/module.json5
@@ -14,11 +14,11 @@
"abilities": [
{
"name": "TestAbility",
- "srcEntrance": "./ets/testability/TestAbility.ets",
+ "srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
- "visible": true,
+ "exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
diff --git a/entry/src/ohosTest/resources/base/profile/test_pages.json b/entry/src/ohosTest/resources/base/profile/test_pages.json
index b7e7343cacb32ce982a45e76daad86e435e054fe..ce16c7cb24e9d770436f349d3a2b93c6e11b673c 100644
--- a/entry/src/ohosTest/resources/base/profile/test_pages.json
+++ b/entry/src/ohosTest/resources/base/profile/test_pages.json
@@ -1,5 +1,5 @@
{
"src": [
- "testability/pages/Index"
+ "Testability/pages/Index"
]
}
diff --git a/hamcrest/.gitignore b/hamcrest/.gitignore
index 5a6ba80fa3d9498a23ae8ae7d9518f8743fa8a96..e2713a2779c5a3e0eb879efe6115455592caeea5 100644
--- a/hamcrest/.gitignore
+++ b/hamcrest/.gitignore
@@ -1,4 +1,6 @@
/node_modules
+/oh_modules
/.preview
/build
-/.cxx
\ No newline at end of file
+/.cxx
+/.test
\ No newline at end of file
diff --git a/hamcrest/package.json b/hamcrest/oh-package.json5
similarity index 68%
rename from hamcrest/package.json
rename to hamcrest/oh-package.json5
index 81cd00360e85d47daae2a6da449ae4362aa5b7a9..f1ed02dc890b39a3fec59868ee2562a65858eadb 100644
--- a/hamcrest/package.json
+++ b/hamcrest/oh-package.json5
@@ -1,27 +1,24 @@
{
- "types": "",
"keywords": [
"OpenHarmony",
"hamcrest",
"HarmonyOS"
],
"author": "hihope",
- "description": "可组合使用的匹配器库",
"ohos": {
"org": "opensource"
},
+ "description": "一个匹配器库,它提供了一套匹配符Matcher,可以组合起来在测试中创建灵活的意图表达",
"main": "index.ets",
"repository": "https://gitee.com/openharmony-sig/Hamcrest",
"type": "module",
- "version": "1.0.2",
+ "version": "2.0.0",
"tags": [
"OpenHarmony",
"hamcrest",
"HarmonyOS"
],
- "dependencies": {
- "assertion-error": "^1.1.0"
- },
+ "dependencies": {},
"license": "BSD License",
"devDependencies": {},
"name": "@ohos/hamcrest"
diff --git a/hamcrest/src/main/ets/components/BaseDescription.ets b/hamcrest/src/main/ets/components/BaseDescription.ts
similarity index 100%
rename from hamcrest/src/main/ets/components/BaseDescription.ets
rename to hamcrest/src/main/ets/components/BaseDescription.ts
diff --git a/hamcrest/src/main/ets/components/BaseMatcher.ets b/hamcrest/src/main/ets/components/BaseMatcher.ts
similarity index 100%
rename from hamcrest/src/main/ets/components/BaseMatcher.ets
rename to hamcrest/src/main/ets/components/BaseMatcher.ts
diff --git a/hamcrest/src/main/ets/components/CustomMatcher.ets b/hamcrest/src/main/ets/components/CustomMatcher.ts
similarity index 100%
rename from hamcrest/src/main/ets/components/CustomMatcher.ets
rename to hamcrest/src/main/ets/components/CustomMatcher.ts
diff --git a/hamcrest/src/main/ets/components/Description.ets b/hamcrest/src/main/ets/components/Description.ts
similarity index 100%
rename from hamcrest/src/main/ets/components/Description.ets
rename to hamcrest/src/main/ets/components/Description.ts
diff --git a/hamcrest/src/main/ets/components/DiagnosingMatcher.ets b/hamcrest/src/main/ets/components/DiagnosingMatcher.ts
similarity index 100%
rename from hamcrest/src/main/ets/components/DiagnosingMatcher.ets
rename to hamcrest/src/main/ets/components/DiagnosingMatcher.ts
diff --git a/hamcrest/src/main/ets/components/FeatureMatcher.ets b/hamcrest/src/main/ets/components/FeatureMatcher.ts
similarity index 100%
rename from hamcrest/src/main/ets/components/FeatureMatcher.ets
rename to hamcrest/src/main/ets/components/FeatureMatcher.ts
diff --git a/hamcrest/src/main/ets/components/Matcher.ets b/hamcrest/src/main/ets/components/Matcher.ts
similarity index 100%
rename from hamcrest/src/main/ets/components/Matcher.ets
rename to hamcrest/src/main/ets/components/Matcher.ts
diff --git a/hamcrest/src/main/ets/components/MatcherAssert.ets b/hamcrest/src/main/ets/components/MatcherAssert.ts
similarity index 90%
rename from hamcrest/src/main/ets/components/MatcherAssert.ets
rename to hamcrest/src/main/ets/components/MatcherAssert.ts
index 774d17812acbe8de401ae1c969a8b781661eb3ca..f46097adae234624f9faa02d34ffe35473657747 100644
--- a/hamcrest/src/main/ets/components/MatcherAssert.ets
+++ b/hamcrest/src/main/ets/components/MatcherAssert.ts
@@ -16,7 +16,6 @@
import {Matcher} from './Matcher'
import {Description} from './Description'
import {StringDescription} from './StringDescription'
-import AssertionError from 'assertion-error'
export class MatcherAssert {
public static assertThat(actual: any, matcher: Matcher): void {
@@ -34,13 +33,13 @@ export class MatcherAssert {
.appendText(" but: ");
matcher.describeMismatch(actual, description);
- throw new AssertionError(description.toString());
+ throw new Error(description.toString());
}
}
public static assertThatWithReason(reason: String, assertion: boolean): void {
if (!assertion) {
- throw new AssertionError(reason.toString());
+ throw new Error(reason.toString());
}
}
}
diff --git a/hamcrest/src/main/ets/components/NullDescription.ets b/hamcrest/src/main/ets/components/NullDescription.ts
similarity index 100%
rename from hamcrest/src/main/ets/components/NullDescription.ets
rename to hamcrest/src/main/ets/components/NullDescription.ts
diff --git a/hamcrest/src/main/ets/components/SelfDescribing.ets b/hamcrest/src/main/ets/components/SelfDescribing.ts
similarity index 100%
rename from hamcrest/src/main/ets/components/SelfDescribing.ets
rename to hamcrest/src/main/ets/components/SelfDescribing.ts
diff --git a/hamcrest/src/main/ets/components/StringDescription.ets b/hamcrest/src/main/ets/components/StringDescription.ts
similarity index 100%
rename from hamcrest/src/main/ets/components/StringDescription.ets
rename to hamcrest/src/main/ets/components/StringDescription.ts
diff --git a/hamcrest/src/main/ets/components/beans/HasProperty.ets b/hamcrest/src/main/ets/components/beans/HasProperty.ts
similarity index 89%
rename from hamcrest/src/main/ets/components/beans/HasProperty.ets
rename to hamcrest/src/main/ets/components/beans/HasProperty.ts
index cb67b6c2bd4ad5ba61d4d363ad406d74cc046163..75e7439219a1c5eb1b0627603e2e0e32f8ac0b06 100644
--- a/hamcrest/src/main/ets/components/beans/HasProperty.ets
+++ b/hamcrest/src/main/ets/components/beans/HasProperty.ts
@@ -25,7 +25,7 @@ export class HasProperty extends BaseMatcher {
}
public matches(obj: T): boolean {
- return obj == null ? false : obj.hasOwnProperty(this.propertyName)
+ return obj == null ? false : this.hasOwn(obj,this.propertyName)
}
public describeMismatch(item: T, mismatchDescription: Description): void {
@@ -51,4 +51,13 @@ export class HasProperty extends BaseMatcher {
public static hasProperty(propertyName: string): Matcher