Skip to content

Commit

Permalink
test: 💍 complete test
Browse files Browse the repository at this point in the history
  • Loading branch information
waynewyang committed Dec 13, 2023
1 parent bb8860c commit 7b48910
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 40 deletions.
15 changes: 0 additions & 15 deletions src/compare/index.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/generateGet/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export { TypeFromProperties } from "./typeFromProperties"
export { getProperty } from "./generateGet"
export { equal, IEqual } from "./compare"
export { Result } from "./result"
export { Capacity, DefaultCapacityOptions } from "./capacity"
export { EnhanceNumber } from "./enhanceNumber"
1 change: 1 addition & 0 deletions test/capacity/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* limitations under the respective licenses.
********************************************************************************/

//@ts-ignore
import assert from "assert"
import { it } from "mocha"
import { Capacity } from "../../src/capacity"
Expand Down
42 changes: 42 additions & 0 deletions test/enhanceNumber/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* (c) 2023 unipackage
*
* Licensed under either the MIT License (the "MIT License") or the Apache License, Version 2.0
* (the "Apache License"). You may not use this file except in compliance with one of these
* licenses. You may obtain a copy of the MIT License at
*
* https://opensource.org/licenses/MIT
*
* Or the Apache License, Version 2.0 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 MIT License or the Apache License for the specific language governing permissions and
* limitations under the respective licenses.
********************************************************************************/

import assert from "assert"
import { it } from "mocha"
import { EnhanceNumber } from "../../src/enhanceNumber"

//@ts-ignore
describe("EnhanceNumber Test", () => {
it("formatPercent test", () => {
const res = new EnhanceNumber(0.35565656).formatPercent(2)
assert.deepStrictEqual(res, "35.57%")
})

it("formatNumber test", () => {
const res = new EnhanceNumber(0.35565656).formatNumber(2)
assert.deepStrictEqual(res, "0.36")
})

it("formatNumber test", () => {
const en1 = new EnhanceNumber(1.25)
const en2 = new EnhanceNumber(2.3)
assert.deepStrictEqual(en1.plus(en2).formatNumber(1), "3.6")
})
})
4 changes: 4 additions & 0 deletions test/enhanceNumber/num-format.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'num-format' {
function FormatNumber(number: number, precision?: number, locale?: string): string
function FormatPercent(number: number, precision?: number, locale?: string): string
}
32 changes: 32 additions & 0 deletions test/result/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* (c) 2023 unipackage
*
* Licensed under either the MIT License (the "MIT License") or the Apache License, Version 2.0
* (the "Apache License"). You may not use this file except in compliance with one of these
* licenses. You may obtain a copy of the MIT License at
*
* https://opensource.org/licenses/MIT
*
* Or the Apache License, Version 2.0 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 MIT License or the Apache License for the specific language governing permissions and
* limitations under the respective licenses.
********************************************************************************/

//@ts-ignore
import assert from "assert"
import { it } from "mocha"
import { Result } from "../../src/result"

//@ts-ignore
describe("Result Test", () => {
it("usage", () => {
const res: Result<string> = { ok: true, data: "test" }
assert.deepStrictEqual(res.data, "test")
})
})
43 changes: 43 additions & 0 deletions test/typeFromProperties/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* (c) 2023 unipackage
*
* Licensed under either the MIT License (the "MIT License") or the Apache License, Version 2.0
* (the "Apache License"). You may not use this file except in compliance with one of these
* licenses. You may obtain a copy of the MIT License at
*
* https://opensource.org/licenses/MIT
*
* Or the Apache License, Version 2.0 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 MIT License or the Apache License for the specific language governing permissions and
* limitations under the respective licenses.
********************************************************************************/

//@ts-ignore
import assert from "assert"
import { it } from "mocha"
import { TypeFromProperties } from "../../src/typeFromProperties"

interface Base {
boolElement: boolean
stringElement: string
getString(): string
}

//@ts-ignore
describe("TypeFromProperties Test", () => {
it("usage", () => {
const expected: TypeFromProperties<Base> = {
boolElement: true,
stringElement: "test",
}
//@ts-nocheck
//@ts-ignore
assert.deepStrictEqual(expected.getString, undefined)
})
})

0 comments on commit 7b48910

Please sign in to comment.