提交 dd8ad803 编写于 作者: fxy060608's avatar fxy060608

重构进阶语法测试

上级 5a508ff2
此差异已折叠。
type AsyncOptions = {
type: string;
success: (res: string) => void;
fail: (res: string) => void;
complete: (res: string) => void;
};
type SyntaxResult = {
name: string
};
type SyncResult = {
msg: string
}
/**
* 导出一个属性
*/
export const MAX = 100;
/**
* 导出一个同步方法
* @returns
*/
export function testSync(msg: string): SyncResult {
console.log("log test");
const res: SyncResult = {
msg: `hello ${msg}`
}
return res
}
/**
* 导出一个同步方法(触发了数组越界异常)
*/
export function testSyncError() {
const arr: string[] = [];
console.log(arr[1]);
}
/**
* 导出一个带callback的同步方法
* @param opts
*/
export function testSyncWithCallback(opts: AsyncOptions) {
if (opts.type == "success") {
opts.success("success");
} else {
opts.fail("fail");
}
opts.complete("complete");
const res: SyntaxResult = {
name: "testSyncWithCallback"
}
return res
}
/**
* 导出一个异步方法
* @returns
*/
export async function testAsync(opts: AsyncOptions): Promise<SyntaxResult> {
if (opts.type == "success") {
opts.success("success");
} else {
opts.fail("fail");
}
opts.complete("complete");
const res: SyntaxResult = {
name: "testAsync"
}
return res
}
type TestOptions = {
name: string;
callback: (res: string) => void;
};
export class Test {
id: number;
name: string;
static type: string = "Test";
constructor(id: number, options: TestOptions) {
this.id = id;
this.name = options.name;
options.callback("Test.constructor");
}
static testClassStaticSyncWithCallback(opts: AsyncOptions): SyntaxResult {
return testSyncWithCallback(opts);
}
static async testClassStaticAsync(opts: AsyncOptions): Promise<SyntaxResult> {
const res = await testAsync(opts);
return res;
}
testClassSyncWithCallback(opts: AsyncOptions): SyntaxResult {
return testSyncWithCallback(opts);
}
async testClassAsync(opts: AsyncOptions): Promise<SyntaxResult> {
const res = await testAsync(opts);
return res;
}
}
import { log } from "./utils.uts";
type AsyncOptions = {
type: string;
success: (res: string) => void;
fail: (res: string) => void;
complete: (res: string) => void;
};
/**
* 导出一个属性
*/
export const MAX = 100;
/**
* 导出一个同步方法
* @returns
*/
export function testSync(msg: string) {
console.log("log test");
log("log test1");
return {
msg: `hello ${msg}`,
};
}
/**
* 导出一个同步方法(触发了数组越界异常)
*/
export function testSyncError() {
const arr: string[] = [];
console.log(arr[1]);
}
/**
* 导出一个带callback的同步方法
* @param opts
*/
export function testSyncWithCallback(opts: AsyncOptions) {
if (opts.type == "success") {
opts.success("success");
} else {
opts.fail("fail");
}
opts.complete("complete");
return { name: "testSyncWithCallback" };
}
/**
* 导出一个异步方法
* @returns
*/
export async function testAsync(opts: AsyncOptions) {
if (opts.type == "success") {
opts.success("success");
} else {
opts.fail("fail");
}
opts.complete("complete");
return { name: "testAsync" };
}
type TestOptions = {
name: string;
callback: (res: string) => void;
};
export class Test {
id: number;
name: string;
static type: string = "Test";
constructor(id: number, options: TestOptions) {
this.id = id;
this.name = options.name;
options.callback("Test.constructor");
}
static testClassStaticSyncWithCallback(opts: AsyncOptions): UTSJSONObject {
return testSyncWithCallback(opts);
}
static async testClassStaticAsync(opts: AsyncOptions): Promise<UTSJSONObject> {
const res = await testAsync(opts);
return res;
}
testClassSyncWithCallback(opts: AsyncOptions): UTSJSONObject {
return testSyncWithCallback(opts);
}
async testClassAsync(opts: AsyncOptions): Promise<UTSJSONObject> {
const res = await testAsync(opts);
return res;
}
}
import { log } from "./utils.uts";
type AsyncOptions = {
type: string;
success: (res: string) => void;
fail: (res: string) => void;
complete: (res: string) => void;
};
type SyntaxResult = {
name: string
};
type SyncResult = {
msg: string
}
/**
* 导出一个属性
*/
export const MAX = 100;
/**
* 导出一个同步方法
* @returns
*/
export function testSync(msg: string): SyncResult {
console.log("log test");
log("log test1");
const res: SyncResult = {
msg: `hello ${msg}`
}
return res
// return {
// msg: `hello ${msg}`,
// };
}
/**
* 导出一个同步方法(触发了数组越界异常)
*/
export function testSyncError() {
const arr: string[] = [];
console.log(arr[1]);
}
/**
* 导出一个带callback的同步方法
* @param opts
*/
export function testSyncWithCallback(opts: AsyncOptions): SyntaxResult {
if (opts.type == "success") {
opts.success("success");
} else {
opts.fail("fail");
}
opts.complete("complete");
const res: SyntaxResult = {
name: "testSyncWithCallback"
}
return res;
// return { name: "testSyncWithCallback" };
}
/**
* 导出一个异步方法
* @returns
*/
export async function testAsync(opts: AsyncOptions): Promise<SyntaxResult> {
if (opts.type == "success") {
opts.success("success");
} else {
opts.fail("fail");
}
opts.complete("complete");
const res: SyntaxResult = {
name: "testAsync"
}
return res;
// return { name: "testAsync" };
}
type TestOptions = {
name: string;
callback: (res: string) => void;
};
export class Test {
id: number;
name: string;
static type: string = "Test";
constructor(id: number, options: TestOptions) {
this.id = id;
this.name = options.name;
options.callback("Test.constructor");
}
static testClassStaticSyncWithCallback(opts: AsyncOptions): SyntaxResult {
return testSyncWithCallback(opts);
}
static async testClassStaticAsync(opts: AsyncOptions): Promise<SyntaxResult> {
const res = await testAsync(opts);
return res;
}
testClassSyncWithCallback(opts: AsyncOptions): SyntaxResult {
return testSyncWithCallback(opts);
}
async testClassAsync(opts: AsyncOptions): Promise<SyntaxResult> {
const res = await testAsync(opts);
return res;
}
}
export function log(msg: string) {
console.log(msg);
}
import { RequestTask, SyncOptions } from "./interface.uts";
import { log } from "./utils.uts";
type AsyncOptions = {
type : string;
success : (res : string) => void;
fail : (res : string) => void;
complete : (res : string) => void;
};
type SyntaxResult = {
name : string
};
type SyncResult = {
msg : string
}
/**
* 导出一个属性
*/
export const MAX = 100;
/**
* 导出一个同步方法
* @returns
*/
export function testSync(msg : string) : SyncResult {
console.log("log test");
log("log test1");
const res : SyncResult = {
msg: `hello ${msg}`
}
return res
// return {
// msg: `hello ${msg}`,
// };
}
/**
* 导出一个同步方法(触发了数组越界异常)
*/
export function testSyncError() {
const arr : string[] = [];
console.log(arr[1]);
}
/**
* 导出一个带callback的同步方法
* @param opts
*/
export function testSyncWithCallback(opts : AsyncOptions) : SyntaxResult {
if (opts.type == "success") {
opts.success("success");
} else {
opts.fail("fail");
}
opts.complete("complete");
const res : SyntaxResult = {
name: "testSyncWithCallback"
}
return res;
// return { name: "testSyncWithCallback" };
}
/**
* 导出一个异步方法
* @returns
*/
export async function testAsync(opts : AsyncOptions) : Promise<SyntaxResult> {
if (opts.type == "success") {
opts.success("success");
} else {
opts.fail("fail");
}
opts.complete("complete");
const res : SyntaxResult = {
name: "testAsync"
}
return res;
// return { name: "testAsync" };
}
type TestOptions = {
name : string;
callback : (res : string) => void;
};
export class Test {
id : number;
name : string;
static type : string = "Test";
constructor(id : number, options : TestOptions) {
this.id = id;
this.name = options.name;
options.callback("Test.constructor");
}
static testClassStaticSyncWithCallback(opts : AsyncOptions) : SyntaxResult {
return testSyncWithCallback(opts);
}
static async testClassStaticAsync(opts : AsyncOptions) : Promise<SyntaxResult> {
const res = await testAsync(opts);
return res;
}
testClassSyncWithCallback(opts : AsyncOptions) : SyntaxResult {
return testSyncWithCallback(opts);
}
async testClassAsync(opts : AsyncOptions) : Promise<SyntaxResult> {
const res = await testAsync(opts);
return res;
}
}
class RequestTaskImpl implements RequestTask {
url : string
constructor(url : string) {
this.url = url
}
abort() : RequestTask {
return this
}
onCallback(callback : (res : string) => void) {
callback("onCallback")
}
sync(options : SyncOptions) : string {
options.success?.("success")
options.complete?.("success")
return "sync"
}
}
export function request(url : string) : RequestTask {
return new RequestTaskImpl(url)
}
\ No newline at end of file
export type SyncOptions = {
success ?: (res : string) => void
fail ?: (res : string) => void
complete ?: (res : string) => void
}
export interface RequestTask {
url : string
abort() : RequestTask
onCallback(callback : (res : string) => void) : void
sync(options : SyncOptions) : string
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册